Documentation ¶
Overview ¶
Package mat defines matrices and operations with them.
Index ¶
- func AreEqual(m1, m2 ReadOnlyMatrix) bool
- func FillMatrixWithData(matrix MutableMatrix, data []float64)
- func HasZeroInMainDiagonal(m ReadOnlyMatrix) bool
- func IsRowDominant(m ReadOnlyMatrix) bool
- func IsSquare(m ReadOnlyMatrix) bool
- func IsSymmetric(m ReadOnlyMatrix) bool
- func MainDiagonal(m ReadOnlyMatrix) vec.ReadOnlyVector
- func MatrixContainsData(matrix ReadOnlyMatrix, data []float64) bool
- func ToImage(m ReadOnlyMatrix, filePath string)
- type DenseMat
- func (m *DenseMat) AddToValue(row, col int, value float64)
- func (m DenseMat) Cols() int
- func (m DenseMat) NonZeroIndicesAtRow(row int) []int
- func (m DenseMat) RowTimesVector(row int, v vec.ReadOnlyVector) float64
- func (m DenseMat) Rows() int
- func (m *DenseMat) SetIdentityRow(row int)
- func (m *DenseMat) SetValue(row, col int, value float64)
- func (m *DenseMat) SetZeroCol(col int)
- func (m DenseMat) TimesMatrix(other ReadOnlyMatrix) ReadOnlyMatrix
- func (m DenseMat) TimesVector(v vec.ReadOnlyVector) vec.ReadOnlyVector
- func (m DenseMat) Value(row, col int) float64
- type MutableMatrix
- type ReadOnlyMatrix
- type SparseMat
- func (m *SparseMat) AddToValue(row, col int, value float64)
- func (m SparseMat) Cols() int
- func (m SparseMat) NonZeroIndicesAtRow(row int) []int
- func (m SparseMat) RowTimesVector(row int, vector vec.ReadOnlyVector) float64
- func (m SparseMat) Rows() int
- func (m *SparseMat) SetIdentityRow(row int)
- func (m *SparseMat) SetValue(row, col int, value float64)
- func (m *SparseMat) SetZeroCol(col int)
- func (m SparseMat) TimesMatrix(other ReadOnlyMatrix) ReadOnlyMatrix
- func (m SparseMat) TimesVector(vector vec.ReadOnlyVector) vec.ReadOnlyVector
- func (m SparseMat) Value(row, col int) float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AreEqual ¶
func AreEqual(m1, m2 ReadOnlyMatrix) bool
AreEqual returns true iff matrices have the same number of rows and columns with exactly the same values in matching positions.
func FillMatrixWithData ¶
func FillMatrixWithData(matrix MutableMatrix, data []float64)
FillMatrixWithData fills the matrix using the given slice of float64 numbers. This function expects the matrix to have the same number of items as the slice.
func HasZeroInMainDiagonal ¶
func HasZeroInMainDiagonal(m ReadOnlyMatrix) bool
HasZeroInMainDiagonal returns true if a zero is found in the matrix main diagonal.
func IsRowDominant ¶
func IsRowDominant(m ReadOnlyMatrix) bool
IsRowDominant returns true if for every row in the matrix, the element in the main diagonal is greater than every other element.
func IsSquare ¶
func IsSquare(m ReadOnlyMatrix) bool
IsSquare returns true if the given matrix has the same number of rows and columns.
func IsSymmetric ¶
func IsSymmetric(m ReadOnlyMatrix) bool
IsSymmetric returns true if the given matrix is square and equals to it's traspose.
func MainDiagonal ¶
func MainDiagonal(m ReadOnlyMatrix) vec.ReadOnlyVector
MainDiagonal returns a vector containing the values of the main diagonal.
func MatrixContainsData ¶
func MatrixContainsData(matrix ReadOnlyMatrix, data []float64) bool
MatrixContainsData tests whether a given matrix has exactly the same data as the slice of float64 numbers.
The number of items in the matrix and the slice need to be the same in order for this test to return true.
func ToImage ¶
func ToImage(m ReadOnlyMatrix, filePath string)
ToImage creates an image with as many width pixels as columns has the matrix and as many height pixels as rows.
Each pixel will be colored:
- Gray if the value is zero
- Red if the value is positive
- Blue if the value is negative
Types ¶
type DenseMat ¶
type DenseMat struct {
// contains filtered or unexported fields
}
A DenseMat is an implementation of a dense Matrix.
Dense matrices allocate all the memory required to store every value. Every value which hasn't been explecitly set is zero.
func MakeDense ¶
MakeDense creates a new dense matrix (stores zeroes) with the given rows and columns filled with zeroes.
func MakeDenseWithData ¶
MakeDenseWithData creates a new matrix initialized with the given data.
func MakeSquareDense ¶
MakeSquareDense creates a new dense matrix (strores zeroes) with the given dimension all filled with zeroes.
func (*DenseMat) AddToValue ¶
AddToValue adds the given value to the existing value in the indicated row and column.
func (DenseMat) NonZeroIndicesAtRow ¶
NonZeroIndicesAtRow returns a slice with all non-zero elements indices for the given row.
func (DenseMat) RowTimesVector ¶
func (m DenseMat) RowTimesVector(row int, v vec.ReadOnlyVector) float64
RowTimesVector returns the result of multiplying the row at the given index times the given vector.
func (*DenseMat) SetIdentityRow ¶
SetIdentityRow sets the given row as identity: one in the main diagonal value, and zeroes in all other positions of the row.
func (*DenseMat) SetZeroCol ¶
SetZeroCol sets all the values in the given column as zero.
func (DenseMat) TimesMatrix ¶
func (m DenseMat) TimesMatrix(other ReadOnlyMatrix) ReadOnlyMatrix
TimesMatrix multiplies this matrix with other.
func (DenseMat) TimesVector ¶
func (m DenseMat) TimesVector(v vec.ReadOnlyVector) vec.ReadOnlyVector
TimesVector creates a new vector result of multiplying this matrix and a vector.
type MutableMatrix ¶
type MutableMatrix interface { ReadOnlyMatrix /* Methods */ SetValue(int, int, float64) AddToValue(int, int, float64) SetZeroCol(int) SetIdentityRow(int) }
A MutableMatrix defines the contract for a matrix which implements the ReadOnlyMatrix and also provides methods that allow the mutation of its data.
type ReadOnlyMatrix ¶
type ReadOnlyMatrix interface { /* Properties */ Rows() int Cols() int NonZeroIndicesAtRow(int) []int /* Methods */ Value(int, int) float64 /* Operations */ RowTimesVector(row int, v vec.ReadOnlyVector) float64 TimesVector(v vec.ReadOnlyVector) vec.ReadOnlyVector TimesMatrix(other ReadOnlyMatrix) ReadOnlyMatrix }
A ReadOnlyMatrix defines the contract for a matrix whose methods can't (and shouldn't) mutate the matrix.
The operations defined in a ReadOnlyMatrix should always return a new instance, never mutate the matrix.
func CholeskyDecomposition ¶
func CholeskyDecomposition(m ReadOnlyMatrix) ReadOnlyMatrix
CholeskyDecomposition computes the Cholesky lower matrix for a square, symmetric matrix.
func IncompleteCholeskyDecomposition ¶
func IncompleteCholeskyDecomposition(m ReadOnlyMatrix) ReadOnlyMatrix
IncompleteCholeskyDecomposition computes the Incomplete Cholesky lower matrix decomposition for the given square and symmetric matrix.
type SparseMat ¶
type SparseMat struct {
// contains filtered or unexported fields
}
A SparseMat is a matrix where the zeroes aren't stored.
func MakeIdentity ¶
MakeIdentity creates a new sparse matrix with all zeroes except in the main diagonal, which has ones.
func MakeSparse ¶
MakeSparse creates a new sparse matrix with the given number of rows and columns.
func MakeSparseWithData ¶
MakeSparseWithData creates a new sparse matrix initialized with the given data.
This method is mainly used for testing purposes as it makes no sense to create a sparse matrix with a given data slice. Most of the elements in a sparse matrix should be zero.
func MakeSquareSparse ¶
MakeSquareSparse creates a new square sparse matrix with the given number of rows and columns.
func (*SparseMat) AddToValue ¶
AddToValue adds the given value to the existing value in the indicated row and column.
func (SparseMat) NonZeroIndicesAtRow ¶
NonZeroIndicesAtRow returns a slice with all non-zero elements indices for the given row.
func (SparseMat) RowTimesVector ¶
func (m SparseMat) RowTimesVector(row int, vector vec.ReadOnlyVector) float64
RowTimesVector returns the result of multiplying the row at the given index times the given vector.
func (*SparseMat) SetIdentityRow ¶
SetIdentityRow sets the given row as identity: one in the main diagonal value, and zeroes in all other positions of the row.
func (*SparseMat) SetZeroCol ¶
SetZeroCol sets all the values in the given column as zero.
func (SparseMat) TimesMatrix ¶
func (m SparseMat) TimesMatrix(other ReadOnlyMatrix) ReadOnlyMatrix
TimesMatrix multiplies this matrix times other.
func (SparseMat) TimesVector ¶
func (m SparseMat) TimesVector(vector vec.ReadOnlyVector) vec.ReadOnlyVector
TimesVector multiplies this matrix and a vector.