module

Geode::MatrixVectors(M, N)

Methods for matrices interacting with vectors.

Intended to be used as a mix-in on matrix types. M and N are the number of rows and columns respectively.

Instance methods

&*(vector : CommonVector(U, P)) : CommonVector forall U, P

Multiplies the matrix by a vector.

The vector is treated as a single column matrix. Returns a vector of equal size. This method requires that the matrix is square (M == N) and the size of the vector matches the side length of this matrix.

Values will wrap instead of overflowing and raising an error.

matrix = Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
vector = Vector[1, 10, 100]
matrix &* vector # => (321, 654, 987)
Source
*(vector : CommonVector(U, P)) : CommonVector forall U, P

Multiplies the matrix by a vector.

The vector is treated as a single column matrix. Returns a vector of equal size. This method requires that the matrix is square (M == N) and the size of the vector matches the side length of this matrix.

matrix = Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
vector = Vector[1, 10, 100]
matrix * vector # => (321, 654, 987)
Source
column?

Indicates whether this matrix is a column vector.

Returns true if the matrix has one column.

Source
row?

Indicates whether this matrix is a row vector.

Returns true if the matrix has one row.

Source
to_vector

Converts this matrix to a vector.

Requires that the matrix is a row or column vector. That is, the matrix has one row or one column.

matrix = Matrix[[1, 2, 3]]
matrix.to_vector # => (1, 2, 3)
matrix = Matrix[[1], [2], [3]]
matrix.to_vector # => (1, 2, 3)
Source