Documentation
¶
Overview ¶
Package matrix is a go package that implements a simple matrix type. It has both methods for the type as well as functions for the most important operations: Mult, Add, Sub, MultScalar, AddScalar and HadamardProd. It uses concurrency only in the matrix multiplication, since its the only place where the overhead might actually be worth it.
Index ¶
- func Equal(rhs, lhs Matrix) bool
- type Matrix
- func Add(lhs, rhs Matrix) (Matrix, error)
- func HadamardProd(lhs, rhs Matrix) (Matrix, error)
- func Mult(lhs, rhs Matrix) (Matrix, error)
- func New(rows, cols int) Matrix
- func NewFrom(data [][]float64) Matrix
- func NewFromVec(rows, cols int, data []float64) Matrix
- func NewRandom(rows, cols int) Matrix
- func NewSquare(size int) Matrix
- func Sub(lhs, rhs Matrix) (Matrix, error)
- func Trans(m Matrix) (Matrix, error)
- func (m *Matrix) Add(other Matrix) error
- func (m *Matrix) AddScalar(val float64)
- func (m *Matrix) Col(col int) ([]float64, error)
- func (m *Matrix) Equal(other Matrix) bool
- func (m *Matrix) Get(row, col int) (float64, error)
- func (m *Matrix) IsSquare() bool
- func (m *Matrix) MarshalBinary() ([]byte, error)
- func (m *Matrix) Mult(other Matrix) error
- func (m *Matrix) MultScalar(val float64)
- func (m *Matrix) Row(row int) ([]float64, error)
- func (m *Matrix) Set(row, col int, val float64) error
- func (m Matrix) String() (s string)
- func (m *Matrix) Sub(other Matrix) error
- func (m *Matrix) Trans() error
- func (m *Matrix) UnmarshalBinary(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Matrix ¶
Matrix is a matrix of floats. The size of the matrix is publicly available, while its data only via getters.
func HadamardProd ¶
HadamardProd performs the hadamard product of matrices. It is an elementwise multiplication of each of the elements in both matrices, therefore they must have the exact same dimensions.
func NewFromVec ¶
NewFromVector creates a matrix from long vector. It just makes sure it can have a rectangular shape
func NewRandom ¶
NewRandom creates a matrix of a given size and fills the vectors with random floating point number ranging from 0..1
func (*Matrix) Add ¶
Add adds a value to first matrix and saves result in its data. Both matrices should have the same dimensions.
func (*Matrix) MarshalBinary ¶
MarshalBinary is the method needed to implement the BinaryMarshaler interface. With it one can call gob.Encode on the Matrix struct.
func (*Matrix) Mult ¶
Mult multiplies two matrices and saves result in first one. The two matrices must look the same, otherwise the shape of the first needs to change.
func (*Matrix) MultScalar ¶
MultScalar multiplies all elements of matrix by value.
func (*Matrix) Sub ¶
Add subtracts a value to first matrix and saves result in its data. Both matrices should have the same dimensions.
func (*Matrix) UnmarshalBinary ¶
MarshalBinary is the method needed to implement the BinaryUnmarshaler interface. With it one can call gob.Decode on the Matrix struct.