Vectors

It is important to note that the calls that are referenced in this section are made using the standard vector tools, but can alternatively be made using the vectorf tools to utilize the floating point library. The float versions of the operations are more computationally efficient, but less accurate.

Constructors

  • Create a vector from a one-dimensional Lua table
    • d = vector({1, 2, 3, 4});
  • Create a vector using a delegate to initialize the elements
    • d = vector(3, function (i) return i*i; end);
  • Create a vector with all elements initialized to the given value
    • d = vector(3, 0.5);
  • Create a vector with all elements initialized to zero
    • d = vector(3);
  • Create a dense vector from a one-dimensional Lua table
    • d = vector.dense({1, 2, 3, 4, 5, 6, 7, 8, 9});
  • Create a dense vector using a delegate to initialize the elements
    • d = vector.dense(3, function (i) return i; end);
  • Create a dense vector with all elements initialized to the give value
    • d = vector.dense(3, 0.5);
  • Create a dense vector with all elements initialized to zero
    • d = vector.dense(3);
  • Create a random vector
    • d = vector.random(3)
  • Create a random vector with the specified length, uniformly distributed between the minimum and maximum values
    • d = vector.random(3, 0, 1)
  • Create a random vector with the specified length, minimum and maximum values, and random seed
    • d = vector.random(3, 0, 1, 1234)
  • Create a vector containing a linear range with specified start, step, and stop values
    • d = vector.linearRange(0, 2, 8)
  • Create a linearly spaced vector with the specified start, stop, and length
    • d = vector.linearSpaced(0, 14, 3)
  • Create a complex vector from a one-dimensional Lua table
    • c = vectorc({1 + 2*complex.i, 2, 3, 4, 5, 6, 7, 8, 9})
  • Create a complex vector using a delegate to initialize the elements
    • c = vectorc(3, function (i) return i*complex.i; end)
  • Create a complex vector with all elements initialized to the give value
    • c = vectorc(3, 0.5 + complex.i)
  • Create a random complex vector with the specified length, uniformly distributed between the minimum and maximum values
    • c = vectorc.random(3, 0, 1)

Subvectors

  • Return the subvector starting at the specified index and including the rest of the vector
    • v = d:subvector(index)
  • Return the subvector starting at the specified index and having the given length
    • v = d:subvector(index, count)
  • Modify current vector by setting subvector stating at the given index to new value
    • d:subvector(index, valueVector)
  • Modify current vector by setting subvector stating at the given index and including specified number of elements to new value
    • d:subvector(index, count, valueVector)

Miscellaneous 

  • Return number of vector elements
    • n = d.count
  • Clone a vector
    • v = d:clone()
  • Return a vector whose elements have been cycled by the given integer, e.g. for d = {1,2,3,4}, set v = {3,4,1,2} using
    • v = d:cycle(2)
  • Convert vector to vectorf
    • v = d:toFloat()
  • Convert vectorf to vector
    • v = d:toDouble()
  • Convert vectorc to real and imaginary vectors
    • r, i = c:toCartesian()
  • Convert vectorc to magnitude and phase vectors
    • m, p = c:toPolar()
  • Return a complex vector containing the Fast Fourier Transform of the input vector
    • c = d:fft()
  • Return a complex vector containing the inverse Fast Fourier Transform of the input vector
    • c = d:ifft()

Math

  • Return the absolute maximum value of the elements
    • n = d:absmax()
  • Return the absolute minimum value of the elements
    • n = d:absmin()
  • Return the maximum value of the elements
    • n = d:max()
  • Return the minimum value of the elements
    • n = d:min()
  • Return a vector of the ceiling of each element
    • v = d:ceiling()
  • Return a vector of the floor of each element
    • v = d:floor()
  • Return the dot product of two vectors (d and c)
    • n = d:dot(c)
  • Return the p-norm of a vector, specify p
    • n = d:norm(p)
  • Return the infinity-norm of a vector
    • n = d:normInf()
  • Return the L1-norm of a vector
    • n = d:normL1()
  • Return the L2-norm of a vector
    • n = d:normL2()
  • Return the outer product of two vectors (d and c)
    • m = d:outerProduct(c)
  • Return the point-wise division of each element (d by c)
    • v = d:pdiv(c)
  • Return the exponential of each vector element
    • v = d:pexp()
  • Return the logarithm of each vector element
    • v = d:plog()
  • Return the point-wise modulus of each element (d and c
    • v = d:pmod(c)
  • Return the point-wise multiplication of each element (d and c)
    • v = d:pmul(c)
  • Return each vector element to the specified exponent
    • v = d:ppow(e)
  • Return the point-wise remainder of each element (d and c)
    • v = d:prem(c)
  • Return the point-wise trigonometric function result of each vector element 
    • v = d:psin()
    • v = d:pcos()
    • v = d:ptan()
    • v = d:pasin()
    • v = d:pacos()
    • v = d:patan()
    • v = d:psinh()
    • v = d:pcosh()
    • v = d:ptanh()

Comparison

  • Return a vector of 1's and 0's for the less-than comparison (d < e, where e is a vector or a number) 
    • v = d:less(e)
  • Return a vector of 1's and 0's for the less-than or equal to comparison (d <= e, where e is a vector or a number)
    • v = d:lessOrEqual(e)
  • Return a vector of 1's and 0's for the greater-than comparison (d > e, where e is a vector or a number) 
    • v = d:greater(e)
  • Return a vector of 1's and 0's for the greater-than or equal to comparison (d >= e, where e is a vector or a number)
    • v = d:greaterOrEqual(e)
  • Return a vector of 1's, -1's and 0's denoting the sign of each vector element
    • v = d:sign()

Indexing

  • local n = vectorName[1];
  • ans = myVector.at(1);

Operators

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division(/)