Documentation ¶
Overview ¶
Package matrix implements column major matrices.
Index ¶
- Constants
- Variables
- func ColumnIndexes(m Matrix, col int) []int
- func Equal(A, B Matrix) bool
- func EqualElementTypes(As ...Matrix) bool
- func EqualTypes(As ...Matrix) bool
- func MakeDiagonalSet(rows, cols int) []int
- func MakeIndexSet(start, end, step int) []int
- func Max(A Matrix) float64
- func Min(A Matrix) float64
- func NotEqual(A, B Matrix) bool
- func RowIndexes(m Matrix, row int) []int
- type CScalar
- type ComplexMatrix
- func ComplexIdentity(rows, cols int) (A *ComplexMatrix, err error)
- func ComplexMatrixStacked(data [][]complex128, order DataOrder) *ComplexMatrix
- func ComplexNew(rows, cols int, elements []complex128) *ComplexMatrix
- func ComplexNumbers(rows, cols int, value complex128) *ComplexMatrix
- func ComplexOnes(rows, cols int) *ComplexMatrix
- func ComplexParse(s string) (A *ComplexMatrix, err error)
- func ComplexRandom(rows, cols int, nonNeg bool) *ComplexMatrix
- func ComplexRandomSymmetric(n int, nonNeg bool) *ComplexMatrix
- func ComplexValue(value complex128) *ComplexMatrix
- func ComplexVector(elements []complex128) *ComplexMatrix
- func ComplexZeros(rows, cols int) *ComplexMatrix
- func (A *ComplexMatrix) Add(alpha complex128) *ComplexMatrix
- func (A *ComplexMatrix) Apply(C *ComplexMatrix, fn func(complex128) complex128) *ComplexMatrix
- func (A *ComplexMatrix) Apply2(fn func(complex128, complex128) complex128, x complex128) *ComplexMatrix
- func (A *ComplexMatrix) ApplyToIndexes(C *ComplexMatrix, indexes []int, fn func(complex128) complex128) *ComplexMatrix
- func (A *ComplexMatrix) Cols() int
- func (A *ComplexMatrix) Complex() complex128
- func (A *ComplexMatrix) ComplexArray() []complex128
- func (A *ComplexMatrix) Copy() (B *ComplexMatrix)
- func (A *ComplexMatrix) Div(alpha complex128) *ComplexMatrix
- func (A *ComplexMatrix) Equal(B *ComplexMatrix) bool
- func (A *ComplexMatrix) EqualTypes(mats ...Matrix) bool
- func (A *ComplexMatrix) Float() float64
- func (A *ComplexMatrix) FloatArray() []float64
- func (A *ComplexMatrix) Get(indexes ...int) []complex128
- func (A *ComplexMatrix) GetAt(i int, j int) (val complex128)
- func (A *ComplexMatrix) GetColumn(i int, vec *ComplexMatrix) *ComplexMatrix
- func (A *ComplexMatrix) GetColumnArray(i int, vals []complex128) []complex128
- func (A *ComplexMatrix) GetIndex(i int) complex128
- func (A *ComplexMatrix) GetIndexes(indexes []int) []complex128
- func (A *ComplexMatrix) GetRow(i int, vec *ComplexMatrix) *ComplexMatrix
- func (A *ComplexMatrix) GetRowArray(i int, vals []complex128) []complex128
- func (A *ComplexMatrix) GetSlice(start, end int) []complex128
- func (A *ComplexMatrix) IsComplex() bool
- func (A *ComplexMatrix) LeadingIndex() int
- func (A *ComplexMatrix) MakeCopy() Matrix
- func (A *ComplexMatrix) Minus(B *ComplexMatrix) *ComplexMatrix
- func (A *ComplexMatrix) Mult(alpha complex128) *ComplexMatrix
- func (A *ComplexMatrix) Neg() *ComplexMatrix
- func (A *ComplexMatrix) NumElements() int
- func (A *ComplexMatrix) Plus(B *ComplexMatrix) *ComplexMatrix
- func (A *ComplexMatrix) Rows() int
- func (A *ComplexMatrix) SetAt(val complex128, i int, j int)
- func (A *ComplexMatrix) SetColumnArray(i int, vals []complex128)
- func (A *ComplexMatrix) SetIndex(i int, v complex128)
- func (A *ComplexMatrix) SetIndexes(indexes []int, values []complex128)
- func (A *ComplexMatrix) SetRowArray(i int, vals []complex128)
- func (A *ComplexMatrix) SetSize(nrows, ncols int)
- func (A *ComplexMatrix) Size() (int, int)
- func (A *ComplexMatrix) SizeMatch(rows, cols int) bool
- func (A *ComplexMatrix) String() string
- func (A *ComplexMatrix) Sub(alpha complex128) *ComplexMatrix
- func (A *ComplexMatrix) Times(B *ComplexMatrix) *ComplexMatrix
- func (A *ComplexMatrix) Transpose() *ComplexMatrix
- func (A *ComplexMatrix) TransposeInPlace() *ComplexMatrix
- type DataOrder
- type FScalar
- type FloatMatrix
- func FloatDiagonal(rows int, values ...float64) *FloatMatrix
- func FloatIdentity(rows int) *FloatMatrix
- func FloatMatrixCombined(direction Stacking, mlist ...*FloatMatrix) (*FloatMatrix, []int)
- func FloatMatrixStacked(data [][]float64, order ...DataOrder) *FloatMatrix
- func FloatNew(rows, cols int, elements []float64) *FloatMatrix
- func FloatOnes(rows, cols int) *FloatMatrix
- func FloatParse(s string) (A *FloatMatrix, err error)
- func FloatParsePy(s string) (A *FloatMatrix, err error)
- func FloatParseSpe(s string) (A *FloatMatrix, err error)
- func FloatRandom(rows, cols int, nonNeg bool) *FloatMatrix
- func FloatRandomSymmetric(n int, nonNeg bool) *FloatMatrix
- func FloatValue(value float64) *FloatMatrix
- func FloatVector(elements []float64) *FloatMatrix
- func FloatWithValue(rows, cols int, value float64) *FloatMatrix
- func FloatZeros(rows, cols int) *FloatMatrix
- func (A *FloatMatrix) Add(alpha float64, indexes ...int) *FloatMatrix
- func (A *FloatMatrix) Apply(C *FloatMatrix, fn func(float64) float64) *FloatMatrix
- func (A *FloatMatrix) ApplyConst(C *FloatMatrix, fn func(float64, float64) float64, x float64) *FloatMatrix
- func (A *FloatMatrix) ApplyToIndexes(C *FloatMatrix, indexes []int, fn func(float64) float64) *FloatMatrix
- func (A *FloatMatrix) Cols() int
- func (A *FloatMatrix) Complex() complex128
- func (A *FloatMatrix) ComplexArray() []complex128
- func (A *FloatMatrix) ConvertToString() string
- func (A *FloatMatrix) Copy() (B *FloatMatrix)
- func (A *FloatMatrix) Div(B *FloatMatrix) *FloatMatrix
- func (A *FloatMatrix) Equal(B *FloatMatrix) bool
- func (A *FloatMatrix) EqualTypes(mats ...Matrix) bool
- func (A *FloatMatrix) Exp() *FloatMatrix
- func (A *FloatMatrix) Float() float64
- func (A *FloatMatrix) FloatArray() []float64
- func (A *FloatMatrix) Get(indexes ...int) []float64
- func (A *FloatMatrix) GetAt(i int, j int) (val float64)
- func (A *FloatMatrix) GetColumn(i int, vec *FloatMatrix) *FloatMatrix
- func (A *FloatMatrix) GetColumnArray(i int, vec []float64) []float64
- func (A *FloatMatrix) GetIndex(i int) float64
- func (A *FloatMatrix) GetIndexes(indexes []int) []float64
- func (A *FloatMatrix) GetRow(i int, vec *FloatMatrix) *FloatMatrix
- func (A *FloatMatrix) GetRowArray(i int, vals []float64) []float64
- func (A *FloatMatrix) GetSlice(start, end int) []float64
- func (A *FloatMatrix) Greater(B *FloatMatrix) bool
- func (A *FloatMatrix) GreaterOrEqual(B *FloatMatrix) bool
- func (A *FloatMatrix) IsComplex() bool
- func (A *FloatMatrix) LeadingIndex() int
- func (A *FloatMatrix) Less(B *FloatMatrix) bool
- func (A *FloatMatrix) LessOrEqual(B *FloatMatrix) bool
- func (A *FloatMatrix) Log() *FloatMatrix
- func (A *FloatMatrix) MakeCopy() Matrix
- func (A *FloatMatrix) Max(indexes ...int) float64
- func (A *FloatMatrix) Min(indexes ...int) float64
- func (A *FloatMatrix) Minus(B *FloatMatrix) *FloatMatrix
- func (A *FloatMatrix) Mod(alpha float64, indexes ...int) *FloatMatrix
- func (A *FloatMatrix) Mul(B *FloatMatrix) *FloatMatrix
- func (A *FloatMatrix) NumElements() int
- func (A *FloatMatrix) Plus(B *FloatMatrix) *FloatMatrix
- func (A *FloatMatrix) Pow(exp float64) *FloatMatrix
- func (A *FloatMatrix) Rows() int
- func (A *FloatMatrix) Scale(alpha float64, indexes ...int) *FloatMatrix
- func (A *FloatMatrix) Set(val float64, indexes ...int)
- func (A *FloatMatrix) SetAt(i, j int, val float64)
- func (A *FloatMatrix) SetAtColumn(i int, rows []int, vals *FloatMatrix)
- func (A *FloatMatrix) SetAtColumnArray(i int, rows []int, vals []float64)
- func (A *FloatMatrix) SetAtRow(i int, cols []int, vals *FloatMatrix)
- func (A *FloatMatrix) SetAtRowArray(i int, cols []int, vals []float64)
- func (A *FloatMatrix) SetColumn(i int, vals *FloatMatrix)
- func (A *FloatMatrix) SetColumnArray(i int, vals []float64)
- func (A *FloatMatrix) SetIndex(i int, val float64)
- func (A *FloatMatrix) SetIndexes(indexes []int, values []float64)
- func (A *FloatMatrix) SetRow(i int, vals *FloatMatrix)
- func (A *FloatMatrix) SetRowArray(i int, vals []float64)
- func (A *FloatMatrix) SetSize(nrows, ncols int)
- func (A *FloatMatrix) SetSubMatrix(row, col int, mat *FloatMatrix) error
- func (A *FloatMatrix) SetValue(val float64)
- func (A *FloatMatrix) Size() (int, int)
- func (A *FloatMatrix) SizeMatch(rows, cols int) bool
- func (A *FloatMatrix) String() string
- func (A *FloatMatrix) Sum(indexes ...int) float64
- func (A *FloatMatrix) Times(B *FloatMatrix) *FloatMatrix
- func (A *FloatMatrix) ToString(format string) string
- func (A *FloatMatrix) Transpose() *FloatMatrix
- func (A *FloatMatrix) TransposeInPlace() *FloatMatrix
- type Matrix
- func Abs(A Matrix) Matrix
- func Conj(A Matrix) Matrix
- func Div(A, B Matrix) (Matrix, error)
- func Exp(A Matrix) Matrix
- func Inv(A Matrix) Matrix
- func Log(A Matrix) Matrix
- func Log10(A Matrix) Matrix
- func Log1p(A Matrix) Matrix
- func Log2(A Matrix) Matrix
- func Mul(ml ...Matrix) (Matrix, error)
- func Pow(A Matrix, y Scalar) Matrix
- func Sqrt(A Matrix) Matrix
- func Sum(ml ...Matrix) (Matrix, error)
- type Scalar
- type Stacking
Constants ¶
const ColumnOrder = DataOrder(1)
const RowOrder = DataOrder(0)
const StackDown = Stacking(0)
const StackRight = Stacking(1)
Variables ¶
var ( //The matrix returned was nil. ErrorNilMatrix error_ = error_(errorNilMatrix) //The dimensions of the inputs do not make sense for this operation. ErrorDimensionMismatch error_ = error_(errorDimensionMismatch) //The indices provided are out of bounds. ErrorIllegalIndex error_ = error_(errorIllegalIndex) //The matrix provided has a singularity. ExceptionSingular error_ = error_(exceptionSingular) //The matrix provided is not positive semi-definite. ExceptionNotSPD error_ = error_(exceptionNotSPD) //Not corrent type ExceptionIllegalType error_ = error_(exceptionIllegalType) )
Functions ¶
func ColumnIndexes ¶
Create index set for a column in matrix M.
func Equal ¶
Test if matrices A and B are equal. Returns false if sizes of the matrices do not match or if any A[i,j] != B[i,j]
func EqualElementTypes ¶
Test if parameter matrices have same element type, float or complex. It is based on method IsComplex(). Returns true if call IsComplex for all matrices return same result. Also returns true if parameter count is <= 1.
func EqualTypes ¶
Test if matrices are of same type. Return true if all are same type as the first element, otherwise return false. For parameter count <=1 return true.
func MakeDiagonalSet ¶
Create index set to access diagonal entries of matrix.
indexes := MakeDiagonalSet(A.Size())
func MakeIndexSet ¶
Create a set of indexes from start to end-1 with interval step.
Types ¶
type ComplexMatrix ¶
type ComplexMatrix struct {
// contains filtered or unexported fields
}
A column-major dense matrix backed by a flat array of all elements.
func ComplexIdentity ¶
func ComplexIdentity(rows, cols int) (A *ComplexMatrix, err error)
Create new identity matrix. Row count must equal column count.
func ComplexMatrixStacked ¶
func ComplexMatrixStacked(data [][]complex128, order DataOrder) *ComplexMatrix
Create a column-major matrix from a array of arrays. Parameter rowOrder indicates if data is array of rows or array of columns.
func ComplexNew ¶
func ComplexNew(rows, cols int, elements []complex128) *ComplexMatrix
Create a column-major matrix from a flat array of elements.
func ComplexNumbers ¶
func ComplexNumbers(rows, cols int, value complex128) *ComplexMatrix
Create new matrix initialized to value.
func ComplexOnes ¶
func ComplexOnes(rows, cols int) *ComplexMatrix
Create new matrix initialized to one.
func ComplexParse ¶
func ComplexParse(s string) (A *ComplexMatrix, err error)
Parse a matlab-style row-major matrix representation eg [a b c; d e f] and return a Matrix. Each element is pair of floats e.g. [(1.0+0i) (0.0+0i); (4-2i) (-1-2i)]
func ComplexRandom ¶
func ComplexRandom(rows, cols int, nonNeg bool) *ComplexMatrix
Create random matrix with element's real and imaginary parts from [0.0, 1.0) if nonNeg is true otherwise in range (-1.0, 1.0)
func ComplexRandomSymmetric ¶
func ComplexRandomSymmetric(n int, nonNeg bool) *ComplexMatrix
Create symmetric n by n random matrix with element's real and imaginary parts from [0.0, 1.0).
func ComplexValue ¶
func ComplexValue(value complex128) *ComplexMatrix
Create a singleton matrix from flot value.
func ComplexVector ¶
func ComplexVector(elements []complex128) *ComplexMatrix
Create a column major vector from an array of elements
func (*ComplexMatrix) Add ¶
func (A *ComplexMatrix) Add(alpha complex128) *ComplexMatrix
Compute in-place sum A[i,j] += alpha
func (*ComplexMatrix) Apply ¶
func (A *ComplexMatrix) Apply(C *ComplexMatrix, fn func(complex128) complex128) *ComplexMatrix
Compute A = fn(C) by applying function fn element wise to A. For all i, j: A[i,j] = fn(C[i,j]). If C == nil reduces to A[i,j] = fn(A[i,j]). Returns self.
func (*ComplexMatrix) Apply2 ¶
func (A *ComplexMatrix) Apply2(fn func(complex128, complex128) complex128, x complex128) *ComplexMatrix
Compute C = fn(A, x) by applying function fn element wise to A. For all i, j: C[i,j] = fn(A[i,j], x). Returns new matrix.
func (*ComplexMatrix) ApplyToIndexes ¶
func (A *ComplexMatrix) ApplyToIndexes(C *ComplexMatrix, indexes []int, fn func(complex128) complex128) *ComplexMatrix
Compute C = fn(A) by applying function fn to all elements in indexes. For all i in indexes: C[i] = fn(A[i]). If C is nil then computes inplace A = fn(A). If C is not nil then sizes of A and C must match. Returns pointer to the result matrix.
func (*ComplexMatrix) Complex ¶
func (A *ComplexMatrix) Complex() complex128
Return the first element column-major element array.
func (*ComplexMatrix) ComplexArray ¶
func (A *ComplexMatrix) ComplexArray() []complex128
Return the flat column-major element array.
func (*ComplexMatrix) Copy ¶
func (A *ComplexMatrix) Copy() (B *ComplexMatrix)
Create a copy of matrix.
func (*ComplexMatrix) Div ¶
func (A *ComplexMatrix) Div(alpha complex128) *ComplexMatrix
Compute in-place division A[i,j] /= alpha
func (*ComplexMatrix) Equal ¶
func (A *ComplexMatrix) Equal(B *ComplexMatrix) bool
Test for equality. Return true if for all i,j: all A[i,j] = B[i,j]
func (*ComplexMatrix) EqualTypes ¶
func (A *ComplexMatrix) EqualTypes(mats ...Matrix) bool
Test if parameter matrices are of same type as self.
func (*ComplexMatrix) Float ¶
func (A *ComplexMatrix) Float() float64
Return Nan for float singleton.
func (*ComplexMatrix) FloatArray ¶
func (A *ComplexMatrix) FloatArray() []float64
Return nil for float array
func (*ComplexMatrix) Get ¶
func (A *ComplexMatrix) Get(indexes ...int) []complex128
Get elements from column-major indexes. Return new array.
func (*ComplexMatrix) GetAt ¶
func (A *ComplexMatrix) GetAt(i int, j int) (val complex128)
Get the element in the i'th row and j'th column.
func (*ComplexMatrix) GetColumn ¶
func (A *ComplexMatrix) GetColumn(i int, vec *ComplexMatrix) *ComplexMatrix
Get copy of i'th column. See GetRow.
func (*ComplexMatrix) GetColumnArray ¶
func (A *ComplexMatrix) GetColumnArray(i int, vals []complex128) []complex128
Get copy of i'th column.
func (*ComplexMatrix) GetIndex ¶
func (A *ComplexMatrix) GetIndex(i int) complex128
Get i'th element in column-major ordering
func (*ComplexMatrix) GetIndexes ¶
func (A *ComplexMatrix) GetIndexes(indexes []int) []complex128
Get values for indexed elements.
func (*ComplexMatrix) GetRow ¶
func (A *ComplexMatrix) GetRow(i int, vec *ComplexMatrix) *ComplexMatrix
Get copy of i'th row. Return parameter matrix. If vec is too small reallocate new vector and return it.
func (*ComplexMatrix) GetRowArray ¶
func (A *ComplexMatrix) GetRowArray(i int, vals []complex128) []complex128
Get copy of i'th row.
func (*ComplexMatrix) GetSlice ¶
func (A *ComplexMatrix) GetSlice(start, end int) []complex128
Get a slice from the underlying storage array. Changing entries in the returned slices changes the matrix. Be carefull with this.
func (*ComplexMatrix) IsComplex ¶
func (A *ComplexMatrix) IsComplex() bool
Return true for complex matrix.
func (*ComplexMatrix) LeadingIndex ¶
func (A *ComplexMatrix) LeadingIndex() int
Return the leading index size. Column major matrices it is row count.
func (*ComplexMatrix) Minus ¶
func (A *ComplexMatrix) Minus(B *ComplexMatrix) *ComplexMatrix
Compute difference C = A - B. Returns a new matrix.
func (*ComplexMatrix) Mult ¶
func (A *ComplexMatrix) Mult(alpha complex128) *ComplexMatrix
Compute in-place product A[i,j] *= alpha
func (*ComplexMatrix) Neg ¶
func (A *ComplexMatrix) Neg() *ComplexMatrix
Compute in-place negation -A[i,j]
func (*ComplexMatrix) NumElements ¶
func (A *ComplexMatrix) NumElements() int
Return total number of elements.
func (*ComplexMatrix) Plus ¶
func (A *ComplexMatrix) Plus(B *ComplexMatrix) *ComplexMatrix
Compute sum C = A + B. Returns a new matrix.
func (*ComplexMatrix) SetAt ¶
func (A *ComplexMatrix) SetAt(val complex128, i int, j int)
Set the element in the i'th row and j'th column to val.
func (*ComplexMatrix) SetColumnArray ¶
func (A *ComplexMatrix) SetColumnArray(i int, vals []complex128)
Set values of i'th column.
func (*ComplexMatrix) SetIndex ¶
func (A *ComplexMatrix) SetIndex(i int, v complex128)
Set i'th element in column-major ordering
func (*ComplexMatrix) SetIndexes ¶
func (A *ComplexMatrix) SetIndexes(indexes []int, values []complex128)
Set values of indexed elements.
func (*ComplexMatrix) SetRowArray ¶
func (A *ComplexMatrix) SetRowArray(i int, vals []complex128)
Set values of i'th row.
func (*ComplexMatrix) SetSize ¶
func (A *ComplexMatrix) SetSize(nrows, ncols int)
Set dimensions. Does not affect element allocations.
func (*ComplexMatrix) String ¶
func (A *ComplexMatrix) String() string
Convert matrix to row-major string representation.
func (*ComplexMatrix) Sub ¶
func (A *ComplexMatrix) Sub(alpha complex128) *ComplexMatrix
Compute in-place difference A[i,j] -= alpha
func (*ComplexMatrix) Times ¶
func (A *ComplexMatrix) Times(B *ComplexMatrix) *ComplexMatrix
Compute product C = A * B. Returns a new matrix.
func (*ComplexMatrix) Transpose ¶
func (A *ComplexMatrix) Transpose() *ComplexMatrix
Copy and transpose matrix. Returns new matrix.
func (*ComplexMatrix) TransposeInPlace ¶
func (A *ComplexMatrix) TransposeInPlace() *ComplexMatrix
Transpose matrix in place. Returns original.
type FloatMatrix ¶
type FloatMatrix struct {
// contains filtered or unexported fields
}
A column-major matrix backed by a flat array of all elements.
func FloatDiagonal ¶
func FloatDiagonal(rows int, values ...float64) *FloatMatrix
Make a square matrix with diagonal set to values. If len(values) is one then all entries on diagonal is set to values[0]. If len(values) is greater than one then diagonals are set from the list values starting from (0,0) until the diagonal is full or values are exhausted.
func FloatIdentity ¶
func FloatIdentity(rows int) *FloatMatrix
Create new identity matrix. Row count must equal column count.
func FloatMatrixCombined ¶
func FloatMatrixCombined(direction Stacking, mlist ...*FloatMatrix) (*FloatMatrix, []int)
Create a new matrix from a list of matrices. New matrix has dimension (M, colmax) if direction is StackDown, and (rowmax, N) if direction is StackRight. M is sum of row counts of argument matrices and N is sum of column counts of arguments. Colmax is the largest column count of matrices and rowmax is the largest row count. Return new matrix and array of submatrix sizes, row counts for StackDown and column counts for StackRight
func FloatMatrixStacked ¶
func FloatMatrixStacked(data [][]float64, order ...DataOrder) *FloatMatrix
Create a column-major matrix from a array of arrays. Parameter order indicates if data is array of rows (RowOrder) or array of columns (ColumnOrder).
func FloatNew ¶
func FloatNew(rows, cols int, elements []float64) *FloatMatrix
Create a column-major matrix from a flat array of elements. Assumes values are in column-major order.
func FloatParse ¶
func FloatParse(s string) (A *FloatMatrix, err error)
Parse a matlab-style row-major matrix representation eg [a b c; d e f] and return a DenseFLoatMatrix.
func FloatParsePy ¶
func FloatParsePy(s string) (A *FloatMatrix, err error)
Parse python cvxopt string representation of a matrix.
[1,0 2.0 3.0] [1.1 2.1 3.1]
Returns a new FloatMatrix.
func FloatParseSpe ¶
func FloatParseSpe(s string) (A *FloatMatrix, err error)
Parse string in format '{nrows ncols [element list]}'
func FloatRandom ¶
func FloatRandom(rows, cols int, nonNeg bool) *FloatMatrix
Create random matrix with elements from [0.0, 1.0).
func FloatRandomSymmetric ¶
func FloatRandomSymmetric(n int, nonNeg bool) *FloatMatrix
Create symmetric n by n random matrix with elements from [0.0, 1.0).
func FloatValue ¶
func FloatValue(value float64) *FloatMatrix
Create a singleton matrix from float value. Shorthand for calling MakeMatrix(1, 1, value-array-of-length-one).
func FloatVector ¶
func FloatVector(elements []float64) *FloatMatrix
Create a column major vector from an array of elements. Shorthand for call MakeMatrix(len(elems), 1, elems).
func FloatWithValue ¶
func FloatWithValue(rows, cols int, value float64) *FloatMatrix
Create new matrix initialized to value.
func (*FloatMatrix) Add ¶
func (A *FloatMatrix) Add(alpha float64, indexes ...int) *FloatMatrix
Compute in-place A += alpha for all elements in the matrix if list of indexes is empty. Otherwise compute A[i] += alpha for indexes in column-major order.
func (*FloatMatrix) Apply ¶
func (A *FloatMatrix) Apply(C *FloatMatrix, fn func(float64) float64) *FloatMatrix
Compute A = fn(C) by applying function fn element wise to C. For all i, j: A[i,j] = fn(C[i,j]). If C is nil then computes inplace A = fn(A). If C is not nil then sizes of A and C must match. Returns pointer to self.
func (*FloatMatrix) ApplyConst ¶
func (A *FloatMatrix) ApplyConst(C *FloatMatrix, fn func(float64, float64) float64, x float64) *FloatMatrix
Compute A = fn(C, x) by applying function fn element wise to C. For all i, j: A[i,j] = fn(C[i,j], x).
func (*FloatMatrix) ApplyToIndexes ¶
func (A *FloatMatrix) ApplyToIndexes(C *FloatMatrix, indexes []int, fn func(float64) float64) *FloatMatrix
Compute A = fn(C) by applying function fn to all elements in indexes. For all i in indexes: A[i] = fn(C[i]). If C is nil then computes inplace A = fn(A). If C is not nil then sizes of A and C must match. Returns pointer to self.
func (*FloatMatrix) Complex ¶
func (A *FloatMatrix) Complex() complex128
Return Nan for complex singleton.
func (*FloatMatrix) ComplexArray ¶
func (A *FloatMatrix) ComplexArray() []complex128
Return nil for complex array
func (*FloatMatrix) ConvertToString ¶
func (A *FloatMatrix) ConvertToString() string
Convert matrix to row-major string representation.
func (*FloatMatrix) Div ¶
func (A *FloatMatrix) Div(B *FloatMatrix) *FloatMatrix
Compute element wise division C[i,] = A[i,j] / B[i,j]. Returns new matrix.
func (*FloatMatrix) Equal ¶
func (A *FloatMatrix) Equal(B *FloatMatrix) bool
Test for equality. Return true if for all i,j: all A[i,j] = B[i,j]
func (*FloatMatrix) EqualTypes ¶
func (A *FloatMatrix) EqualTypes(mats ...Matrix) bool
Test if parameter matrices are of same type as self.
func (*FloatMatrix) Exp ¶
func (A *FloatMatrix) Exp() *FloatMatrix
Compute element-wise C = Exp(A). Returns a new matrix.
func (*FloatMatrix) Float ¶
func (A *FloatMatrix) Float() float64
Return the first element column-major element array.
func (*FloatMatrix) FloatArray ¶
func (A *FloatMatrix) FloatArray() []float64
Return the flat column-major element array.
func (*FloatMatrix) Get ¶
func (A *FloatMatrix) Get(indexes ...int) []float64
Get elements from column-major indexes. Return new array.
func (*FloatMatrix) GetAt ¶
func (A *FloatMatrix) GetAt(i int, j int) (val float64)
Get the element in the i'th row and j'th column.
func (*FloatMatrix) GetColumn ¶
func (A *FloatMatrix) GetColumn(i int, vec *FloatMatrix) *FloatMatrix
Get copy of i'th column. See GetRow.
func (*FloatMatrix) GetColumnArray ¶
func (A *FloatMatrix) GetColumnArray(i int, vec []float64) []float64
Get copy of i'th column. See GetRow.
func (*FloatMatrix) GetIndex ¶
func (A *FloatMatrix) GetIndex(i int) float64
func (*FloatMatrix) GetIndexes ¶
func (A *FloatMatrix) GetIndexes(indexes []int) []float64
Get values for indexed elements.
func (*FloatMatrix) GetRow ¶
func (A *FloatMatrix) GetRow(i int, vec *FloatMatrix) *FloatMatrix
Get copy of i'th row. Return parameter matrix. If vec is too small reallocate new vector and return it.
func (*FloatMatrix) GetRowArray ¶
func (A *FloatMatrix) GetRowArray(i int, vals []float64) []float64
Get copy of i'th row. Row elements are copied to vals array. Returns the array. If vals array is too small new slice is allocated and returned with row elements.
func (*FloatMatrix) GetSlice ¶
func (A *FloatMatrix) GetSlice(start, end int) []float64
Get a slice from the underlying storage array. Changing entries in the returned slices changes the matrix. Be carefull with this.
func (*FloatMatrix) Greater ¶
func (A *FloatMatrix) Greater(B *FloatMatrix) bool
Test for element wise greater-than. Return true if for all i,j: A[i,j] > B[i,j]
func (*FloatMatrix) GreaterOrEqual ¶
func (A *FloatMatrix) GreaterOrEqual(B *FloatMatrix) bool
Test for element wise greater-than-or-equal. Return true if for all i,j: A[i,j] >= B[i,j]
func (*FloatMatrix) IsComplex ¶
func (A *FloatMatrix) IsComplex() bool
Return false for float matrix.
func (*FloatMatrix) LeadingIndex ¶
func (A *FloatMatrix) LeadingIndex() int
Return the leading index size. Column major matrices it is row count.
func (*FloatMatrix) Less ¶
func (A *FloatMatrix) Less(B *FloatMatrix) bool
Test for element wise less-than. Return true if for all i,j: A[i,j] < B[i,j]
func (*FloatMatrix) LessOrEqual ¶
func (A *FloatMatrix) LessOrEqual(B *FloatMatrix) bool
Test for element wise less-or-equal. Return true if for all i,j: A[i,j] <= B[i,j]
func (*FloatMatrix) Log ¶
func (A *FloatMatrix) Log() *FloatMatrix
Compute element-wise C = Log(A). Returns a new matrix.
func (*FloatMatrix) MakeCopy ¶
func (A *FloatMatrix) MakeCopy() Matrix
func (*FloatMatrix) Max ¶
func (A *FloatMatrix) Max(indexes ...int) float64
Find element-wise maximum.
func (*FloatMatrix) Min ¶
func (A *FloatMatrix) Min(indexes ...int) float64
Find element-wise minimum.
func (*FloatMatrix) Minus ¶
func (A *FloatMatrix) Minus(B *FloatMatrix) *FloatMatrix
Compute element-wise difference C = A - B. Returns a new matrix.
func (*FloatMatrix) Mod ¶
func (A *FloatMatrix) Mod(alpha float64, indexes ...int) *FloatMatrix
Compute in-place remainder A[i,j] %= alpha
func (*FloatMatrix) Mul ¶
func (A *FloatMatrix) Mul(B *FloatMatrix) *FloatMatrix
Compute element-wise product C[i,j] = A[i,j] * B[i,j]. Returns new matrix.
func (*FloatMatrix) NumElements ¶
func (A *FloatMatrix) NumElements() int
Return total number of elements.
func (*FloatMatrix) Plus ¶
func (A *FloatMatrix) Plus(B *FloatMatrix) *FloatMatrix
Compute element-wise sum C = A + B. Returns a new matrix.
func (*FloatMatrix) Pow ¶
func (A *FloatMatrix) Pow(exp float64) *FloatMatrix
Compute element-wise C = Pow(A). Returns a new matrix.
func (*FloatMatrix) Scale ¶
func (A *FloatMatrix) Scale(alpha float64, indexes ...int) *FloatMatrix
Compute in-place A *= alpha for all elements in the matrix if list of indexes is empty. Otherwise compute A[i] *= alpha for indexes in column-major order.
func (*FloatMatrix) Set ¶
func (A *FloatMatrix) Set(val float64, indexes ...int)
Set element values in column-major ordering. Negative indexes are relative to the last element of the matrix.
func (*FloatMatrix) SetAt ¶
func (A *FloatMatrix) SetAt(i, j int, val float64)
Set the element in the i'th row and j'th column to val.
func (*FloatMatrix) SetAtColumn ¶
func (A *FloatMatrix) SetAtColumn(i int, rows []int, vals *FloatMatrix)
Set values on i'th column of rows pointer by rows array. It assumes that max(rows) < vals.NumElements().
func (*FloatMatrix) SetAtColumnArray ¶
func (A *FloatMatrix) SetAtColumnArray(i int, rows []int, vals []float64)
Set values on i'th column of rows pointed by rows array. It assumes that len(rows) <= len(vals).
func (*FloatMatrix) SetAtRow ¶
func (A *FloatMatrix) SetAtRow(i int, cols []int, vals *FloatMatrix)
Set values on i'th row of columns pointed with cols array. For all j in indexes: A[i,j] = vals[j]. Matrix vals is either (A.Cols(),1) or (1, A.Cols()) matrix.
func (*FloatMatrix) SetAtRowArray ¶
func (A *FloatMatrix) SetAtRowArray(i int, cols []int, vals []float64)
Set values on i'th row of columns pointed with cols array. For all j in indexes: A[i,j] = vals[k] where k is j's index in indexes array.
func (*FloatMatrix) SetColumn ¶
func (A *FloatMatrix) SetColumn(i int, vals *FloatMatrix)
Set values of i'th column. Matrix vals is either (A.Rows(), 1) or (1, A.Rows()) matrix.
func (*FloatMatrix) SetColumnArray ¶
func (A *FloatMatrix) SetColumnArray(i int, vals []float64)
Set values of i'th column.
func (*FloatMatrix) SetIndex ¶
func (A *FloatMatrix) SetIndex(i int, val float64)
Set value of i'th element.
func (*FloatMatrix) SetIndexes ¶
func (A *FloatMatrix) SetIndexes(indexes []int, values []float64)
Set values of indexed elements.
func (*FloatMatrix) SetRow ¶
func (A *FloatMatrix) SetRow(i int, vals *FloatMatrix)
Set values of i'th row. Matrix vals is either (A.Cols(), 1) or (1, A.Cols()) matrix.
func (*FloatMatrix) SetRowArray ¶
func (A *FloatMatrix) SetRowArray(i int, vals []float64)
Set values of i'th row.
func (*FloatMatrix) SetSize ¶
func (A *FloatMatrix) SetSize(nrows, ncols int)
Set dimensions. Does not affect element allocations.
func (*FloatMatrix) SetSubMatrix ¶
func (A *FloatMatrix) SetSubMatrix(row, col int, mat *FloatMatrix) error
Set values for sub-matrix starting at (row, col). If row+mat.Rows() greater than A.Rows() or col+mat.Cols() greater than A.Cols() matrix A is not changed.
func (*FloatMatrix) SetValue ¶
func (A *FloatMatrix) SetValue(val float64)
Set value of singleton matrix.
func (*FloatMatrix) String ¶
func (A *FloatMatrix) String() string
Convert matrix to row-major string representation.
func (*FloatMatrix) Times ¶
func (A *FloatMatrix) Times(B *FloatMatrix) *FloatMatrix
Compute matrix product C = A * B where A is m*p and B is p*n. Returns a new m*n matrix.
func (*FloatMatrix) ToString ¶
func (A *FloatMatrix) ToString(format string) string
Convert matrix to row-major string representation using format as element format.
func (*FloatMatrix) Transpose ¶
func (A *FloatMatrix) Transpose() *FloatMatrix
Copy and transpose matrix. Returns new matrix.
func (*FloatMatrix) TransposeInPlace ¶
func (A *FloatMatrix) TransposeInPlace() *FloatMatrix
Transpose matrix in place. Returns original.
type Matrix ¶
type Matrix interface { // The number of rows in this matrix. Rows() int // The number of columns in this matrix. Cols() int // The number of elements in this matrix. NumElements() int // Returns underlying float64 array for BLAS/LAPACK routines. Returns nil // if matrix is complex128 valued. FloatArray() []float64 // Returns underlying complex128 array for BLAS/LAPACK routines. Returns nil // if matrix is float64 valued matrix. ComplexArray() []complex128 // Returns true if matrix is complex valued. False otherwise. IsComplex() bool // For all float valued matrices return the value of A[0,0]. Returns NaN // if not float valued. Float() float64 // For all complex valued matrices return the value of A[0,0]. Returns // NaN if not complex valued. Complex() complex128 // Matrix in string format. String() string // Make a copy and return as Matrix interface type. MakeCopy() Matrix // Match size. Return true if equal. SizeMatch(int, int) bool // Get matrix size. Return pair (rows, cols). Size() (int, int) // Test for type equality. EqualTypes(...Matrix) bool }
Minimal interface for linear algebra packages BLAS/LAPACK
func Abs ¶
Return copy of A with each element as Abs(A[i,j]). Returns a float matrix for complex valued matrix.
func Conj ¶
Return conjugate copy of A with each element as Conj(A[i,j]). Returns nil for float valued matrix.
func Div ¶
Return new matrix which is element wise division A / B. A and B matrices must be of same type and have equal number of elements.
func Log1p ¶
Return copy of A with each element as Log1p(A[i,j]). Returns nil for complex valued matrix.
func Log2 ¶
Return copy of A with each element as Log2(A[i,j]). Returns nil for complex valued matrix.
func Mul ¶
Return new matrix which is element wise product of argument matrices. A and B matrices must be of same type and have equal number of elements.
type Scalar ¶
type Scalar interface { Float() float64 Complex() complex128 }
Interface for real and complex scalars.