Libraries.Compute.Vector Documentation
This class represents a mathematical vector of number values.
Example Code
use Libraries.Compute.Vector
Vector vector
vector:SetSize(2)
vector:Set(0, 4.8)
vector:Set(1, 3.2)
output vector:ToText()
Inherits from: Libraries.Language.Object
Actions Documentation
Add(Libraries.Compute.Vector vector)
This action adds this vector onto the current one. Because this action changes the vector being added on, a copy may be needed for non-destructive operations.
Parameters
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
Vector vector2
vector2:SetSize(3)
vector:Add(vector2)
//this will output 0s because both vectors are 0
output vector:ToText()
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Copy()
This action returns a copy of the current vector. The new vector's components are a deep copy.
Return
Libraries.Compute.Vector: a new vector that is a deep copy.
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(2)
vector:Set(0, 4.8)
vector:Set(1, 3.2)
Vector copyVector
copyVector = vector:Copy()
output copyVector:ToText()
Distance(Libraries.Compute.Vector vector)
This action calculates the euclidian distance between two vectors.
Parameters
Return
number:
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
Vector vector2
vector2:SetSize(3)
output vector:Distance(vector2) //0
Divide(number value)
This action divides this scalar onto the current one. Because this action changes the vector being added on, a copy may be needed for non-destructive operations.
Parameters
- number value
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
vector:Divide(1)
//this will output 0s because both vectors are 0
output vector:ToText()
DotProduct(Libraries.Compute.Vector vector)
This action calculates the dot product between the two vectors. More information can be found about dot products here: https://en.wikipedia.org/wiki/Dot_product
Parameters
Return
number:
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
Vector vector2
vector2:SetSize(3)
output vector:DotProduct(vector2)
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
Get(integer index)
This action returns a number at a particular point in the vector.
Parameters
- integer index: where in the vector to get a number
Return
number: the value to return
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
output vector:Get(0)
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetSize()
This action returns the size of the vector
Return
integer: the size
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
output vector:GetSize()
IsEmpty()
This action returns a boolean value, true if the container is empty and false if it contains any items.
Return
boolean: Returns true when the container is empty and false when it is not.
Example
use Libraries.Containers.Array
Vector myArray
myArray:SetSize(10)
myArray:Set(0, 22)
myArray:Set(1, 33)
myArray:Set(2, 45)
myArray:Set(3, 22)
boolean result = myArray:IsEmpty()
output result
Multiply(number value)
This action multiplies this scalar onto the current one. Because this action changes the vector being added on, a copy may be needed for non-destructive operations.
Parameters
- number value
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
vector:Multiply(1)
//this will output 0s because both vectors are 0
output vector:ToText()
Set(integer index, number value)
This action sets a number at a particular point in the vector.
Parameters
- integer index: where in the vector to get a number
- number value: the value to put in the vector.
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
vector:Set(0, 2)
output vector:Get(0)
SetSize(integer size)
This action sets the size of the vector. Note that this action must be called before the vector is used. This is because the vector class is optimized for memory.
Parameters
- integer size
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
output vector:GetSize()
Sort()
This action sorts the values of the array using a merge sort algorithm. It is guaranteed to execute in O(n log n).
Example
use Libraries.Containers.Array
Vector myArray
myArray:Add(33)
myArray:Add(13)
myArray:Add(43)
myArray:Sort()
Sort(Libraries.Containers.Support.Comparison comparison)
This action sorts the values of the array using a merge sort algorithm. It is guaranteed to execute in O(n log n).
Parameters
Example
use Libraries.Containers.Array
SomeCustomComparison custom
Vector myArray
myArray:Add(33)
myArray:Add(13)
myArray:Add(43)
myArray:Sort(custom)
Subtract(Libraries.Compute.Vector vector)
This action subtracts this vector onto the current one. Because this action changes the vector being added on, a copy may be needed for non-destructive operations.
Parameters
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
Vector vector2
vector2:SetSize(3)
vector:Subtract(vector2)
//this will output 0s because both vectors are 0
output vector:ToText()
ToText()
This action returns a text representation of the vector.
Return
text: a text representation of the vector
Example
use Libraries.Compute.Vector
Vector vector
vector:SetSize(2)
vector:Set(0, 4.8)
vector:Set(1, 3.2)
output vector:ToText()
On this page
Variables TableAction Documentation- Add(Libraries.Compute.Vector vector)
- Compare(Libraries.Language.Object object)
- Copy()
- Distance(Libraries.Compute.Vector vector)
- Divide(number value)
- DotProduct(Libraries.Compute.Vector vector)
- Equals(Libraries.Language.Object object)
- Get(integer index)
- GetHashCode()
- GetSize()
- IsEmpty()
- Multiply(number value)
- Set(integer index, number value)
- SetSize(integer size)
- Sort()
- Sort(Libraries.Containers.Support.Comparison comparison)
- Subtract(Libraries.Compute.Vector vector)
- ToText()