## 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

## Summary

### Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Copy()This action returns a copy of the current vector.
DotProduct(Libraries.Compute.Vector vector)This action calculates the dot product between the two vectors.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
Get(integer index)This action returns a number at a particular point in the vector.
GetHashCode()This action gets the hash code for an object.
GetSize()This action returns the size of the vector
IsEmpty()This action returns a boolean value, true if the container is empty and false if it contains any items.
Set(integer index, number value)This action sets a number at a particular point in the vector.
SetSize(integer size)This action sets the size of the vector.
Sort()This action sorts the values of the array using a merge sort algorithm.
Subtract(Libraries.Compute.Vector vector)This action subtracts this vector onto the current one.
ToText()This action returns a text representation of the vector.

## Actions Documentation

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.

Example Code

``````use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)

Vector vector2
vector2:SetSize(3)

//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.

Example Code

``````Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)``````

#### Return

integer: The Compare result, Smaller, Equal, or Larger.

### Copy()

This action returns a copy of the current vector. The new vector's components are a deep copy.

Example Code

``````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()``````

#### Return

Libraries.Compute.Vector: a new vector that is a deep copy.

### 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

Example Code

``````use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)

Vector vector2
vector2:SetSize(3)
output vector:DotProduct(vector2)``````

number:

### Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

``````use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)``````

#### Return

boolean: True if the hash codes are equal and false if they are not equal.

### Get(integer index)

This action returns a number at a particular point in the vector.

Example Code

``````use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
output vector:Get(0)``````

#### Parameters

• integer index: where in the vector to get a number

#### Return

number: the value to return

### GetHashCode()

This action gets the hash code for an object.

Example Code

``````Object o
integer hash = o:GetHashCode()``````

#### Return

integer: The integer hash code of the object.

### GetSize()

This action returns the size of the vector

Example Code

``````use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
output vector:GetSize()``````

#### Return

integer: the size

### IsEmpty()

This action returns a boolean value, true if the container is empty and false if it contains any items.

Example Code

``````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``````

#### Return

boolean: Returns true when the container is empty and false when it is not.

### Set(integer index, number value)

This action sets a number at a particular point in the vector.

Example Code

``````use Libraries.Compute.Vector
Vector vector
vector:SetSize(3)
vector:Set(0, 2)
output vector:Get(0)``````

#### Parameters

• integer index: where in the vector to get a number
• number value: the value to put in the vector.

### 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.

Example Code

``````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 Code

``````use Libraries.Containers.Array
Vector myArray
myArray:Sort()``````

### 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.

Example Code

``````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.

Example Code

``````use Libraries.Compute.Vector

Vector vector
vector:SetSize(2)
vector:Set(0, 4.8)
vector:Set(1, 3.2)

output vector:ToText()``````

#### Return

text: a text representation of the vector