module Geode::MatrixVectors(M, N)

Overview

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.

Direct including types

Defined in:

geode/matrices/vectors.cr

Instance Method Summary

Instance Method Detail

def &*(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)

[View source]
def *(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)

[View source]
def column? #

Indicates whether this matrix is a column vector.

Returns true if the matrix has one column.


[View source]
def row? #

Indicates whether this matrix is a row vector.

Returns true if the matrix has one row.


[View source]
def to_vector : CommonVector #

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)

[View source]