Documentation ¶
Index ¶
- Variables
- func Equal(a, b Matrix) bool
- func Formatted(m Matrix, options ...FormatOption) fmt.Formatter
- func Max(a Matrix) float32
- func Min(a Matrix) float32
- func Norm(a Matrix, norm float32) float32
- func Row(dst []float32, i int, a Matrix) []float32
- func Sum(a Matrix) float32
- type Dense
- func (m *Dense) Add(a, b Matrix)
- func (m *Dense) Apply(fn func(i, j int, v float32) float32, a Matrix)
- func (m *Dense) At(i, j int) float32
- func (m *Dense) Augment(a, b Matrix)
- func (m *Dense) Caps() (r, c int)
- func (m *Dense) CloneFrom(a Matrix)
- func (m *Dense) ColView(j int) Vector
- func (m *Dense) Copy(a Matrix) (r, c int)
- func (m *Dense) Dims() (r, c int)
- func (m *Dense) DivElem(a, b Matrix)
- func (m *Dense) IsEmpty() bool
- func (m *Dense) Mul(a, b Matrix)
- func (m *Dense) MulElem(a, b Matrix)
- func (m *Dense) RawMatrix() blas32.General
- func (m *Dense) RowView(i int) Vector
- func (m *Dense) Scale(f float32, a Matrix)
- func (m *Dense) Set(i, j int, v float32)
- func (m *Dense) SetCol(j int, src []float32)
- func (m *Dense) SetRow(i int, src []float32)
- func (m *Dense) Slice(i, k, j, l int) Matrix
- func (m *Dense) Stack(a, b Matrix)
- func (m *Dense) Sub(a, b Matrix)
- func (m *Dense) T() Matrix
- func (m *Dense) Zero()
- type Error
- type FormatOption
- type Matrix
- type Normer
- type RawMatrixer
- type RawVectorer
- type Transpose
- type Untransposer
- type VecDense
- func (v *VecDense) AddVec(a, b Vector)
- func (v *VecDense) At(i, j int) float32
- func (v *VecDense) AtVec(i int) float32
- func (v *VecDense) Cap() int
- func (v *VecDense) CloneFromVec(a Vector)
- func (v *VecDense) ColViewOf(m RawMatrixer, j int)
- func (v *VecDense) CopyVec(a Vector) int
- func (v *VecDense) Dims() (r, c int)
- func (v *VecDense) DivElemVec(a, b Vector)
- func (v *VecDense) IsEmpty() bool
- func (v *VecDense) Len() int
- func (v *VecDense) RawVector() blas32.Vector
- func (v *VecDense) RowViewOf(m RawMatrixer, i int)
- func (v *VecDense) SetVec(i int, val float32)
- func (v *VecDense) SliceVec(i, k int) Vector
- func (v *VecDense) SubVec(a, b Vector)
- func (v *VecDense) T() Matrix
- type Vector
Constants ¶
This section is empty.
Variables ¶
var ( ErrNegativeDimension = Error{"mat: negative dimension"} ErrIndexOutOfRange = Error{"mat: index out of range"} ErrReuseNonEmpty = Error{"mat: reuse of non-empty matrix"} ErrRowAccess = Error{"mat: row index out of range"} ErrColAccess = Error{"mat: column index out of range"} ErrVectorAccess = Error{"mat: vector index out of range"} ErrZeroLength = Error{"mat: zero length in matrix dimension"} ErrRowLength = Error{"mat: row length mismatch"} ErrColLength = Error{"mat: col length mismatch"} ErrSquare = Error{"mat: expect square matrix"} ErrNormOrder = Error{"mat: invalid norm order for matrix"} ErrSingular = Error{"mat: matrix is singular"} ErrShape = Error{"mat: dimension mismatch"} ErrIllegalStride = Error{"mat: illegal stride"} ErrPivot = Error{"mat: malformed pivot list"} ErrTriangle = Error{"mat: triangular storage mismatch"} ErrTriangleSet = Error{"mat: triangular set out of bounds"} ErrBandwidth = Error{"mat: bandwidth out of range"} ErrBandSet = Error{"mat: band set out of bounds"} ErrDiagSet = Error{"mat: diagonal set out of bounds"} ErrSliceLengthMismatch = Error{"mat: input slice length mismatch"} ErrNotPSD = Error{"mat: input not positive symmetric definite"} ErrFailedEigen = Error{"mat: eigendecomposition not successful"} )
Functions ¶
func Equal ¶
Equal returns whether the matrices a and b have the same size and are element-wise equal.
func Formatted ¶
func Formatted(m Matrix, options ...FormatOption) fmt.Formatter
Formatted returns a fmt.Formatter for the matrix m using the given options.
func Max ¶
Max returns the largest element value of the matrix A.
Max will panic with ErrZeroLength if the matrix has zero size.
func Min ¶
Min returns the smallest element value of the matrix A.
Min will panic with ErrZeroLength if the matrix has zero size.
func Norm ¶
Norm returns the specified norm of the matrix A. Valid norms are:
1 - The maximum absolute column sum 2 - The Frobenius norm, the square root of the sum of the squares of the elements Inf - The maximum absolute row sum
If a is a Normer, its Norm method will be used to calculate the norm.
Norm will panic with ErrNormOrder if an illegal norm is specified and with ErrShape if the matrix has zero size.
Types ¶
type Dense ¶
type Dense struct {
// contains filtered or unexported fields
}
Dense is a dense matrix representation.
func DenseCopyOf ¶
DenseCopyOf returns a newly allocated copy of the elements of a.
func NewDense ¶
NewDense creates a new Dense matrix with r rows and c columns. If data == nil, a new slice is allocated for the backing slice. If len(data) == r*c, data is used as the backing slice, and changes to the elements of the returned Dense will be reflected in data. If neither of these is true, NewDense will panic. NewDense will panic if either r or c is zero.
The data must be arranged in row-major order, i.e. the (i*c + j)-th element in the data slice is the {i, j}-th element in the matrix.
func (*Dense) Add ¶
Add adds a and b element-wise, placing the result in the receiver. Add will panic if the two matrices do not have the same shape.
func (*Dense) Apply ¶
Apply applies the function fn to each of the elements of a, placing the resulting matrix in the receiver. The function fn takes a row/column index and element value and returns some function of that tuple.
func (*Dense) Augment ¶
Augment creates the augmented matrix of a and b, where b is placed in the greater indexed columns. Augment will panic if the two input matrices do not have the same number of rows or the constructed augmented matrix is not the same shape as the receiver.
func (*Dense) CloneFrom ¶
CloneFrom makes a copy of a into the receiver, overwriting the previous value of the receiver. The clone from operation does not make any restriction on shape and will not cause shadowing.
See the ClonerFrom interface for more information.
func (*Dense) ColView ¶
ColView returns a Vector reflecting the column j, backed by the matrix data.
See ColViewer for more information.
func (*Dense) Copy ¶
Copy makes a copy of elements of a into the receiver. It is similar to the built-in copy; it copies as much as the overlap between the two matrices and returns the number of rows and columns it copied. If a aliases the receiver and is a transposed Dense or VecDense, with a non-unitary increment, Copy will panic.
See the Copier interface for more information.
func (*Dense) DivElem ¶
DivElem performs element-wise division of a by b, placing the result in the receiver. DivElem will panic if the two matrices do not have the same shape.
func (*Dense) IsEmpty ¶
IsEmpty returns whether the receiver is empty. Empty matrices can be the receiver for size-restricted operations. The receiver can be emptied using Reset.
func (*Dense) Mul ¶
Mul takes the matrix product of a and b, placing the result in the receiver. If the number of columns in a does not equal the number of rows in b, Mul will panic.
func (*Dense) MulElem ¶
MulElem performs element-wise multiplication of a and b, placing the result in the receiver. MulElem will panic if the two matrices do not have the same shape.
func (*Dense) RawMatrix ¶
RawMatrix returns the underlying blas32.General used by the receiver. Changes to elements in the receiver following the call will be reflected in returned blas32.General.
func (*Dense) RowView ¶
RowView returns row i of the matrix data represented as a column vector, backed by the matrix data.
See RowViewer for more information.
func (*Dense) Scale ¶
Scale multiplies the elements of a by f, placing the result in the receiver.
See the Scaler interface for more information.
func (*Dense) SetCol ¶
SetCol sets the values in the specified column of the matrix to the values in src. len(src) must equal the number of rows in the receiver.
func (*Dense) SetRow ¶
SetRow sets the values in the specified rows of the matrix to the values in src. len(src) must equal the number of columns in the receiver.
func (*Dense) Slice ¶
Slice returns a new Matrix that shares backing data with the receiver. The returned matrix starts at {i,j} of the receiver and extends k-i rows and l-j columns. The final row in the resulting matrix is k-1 and the final column is l-1. Slice panics with ErrIndexOutOfRange if the slice is outside the capacity of the receiver.
func (*Dense) Stack ¶
Stack appends the rows of b onto the rows of a, placing the result into the receiver with b placed in the greater indexed rows. Stack will panic if the two input matrices do not have the same number of columns or the constructed stacked matrix is not the same shape as the receiver.
func (*Dense) Sub ¶
Sub subtracts the matrix b from a, placing the result in the receiver. Sub will panic if the two matrices do not have the same shape.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents matrix handling errors. These errors can be recovered by Maybe wrappers.
type FormatOption ¶
type FormatOption func(*formatter)
FormatOption is a functional option for matrix formatting.
type Matrix ¶
type Matrix interface { // Dims returns the dimensions of a Matrix. Dims() (r, c int) // At returns the value of a matrix element at row i, column j. // It will panic if i or j are out of bounds for the matrix. At(i, j int) float32 // T returns the transpose of the Matrix. Whether T returns a copy of the // underlying data is implementation dependent. // This method may be implemented using the Transpose type, which // provides an implicit matrix transpose. T() Matrix }
Matrix is the basic matrix interface type.
type Normer ¶
A Normer can compute a norm of the matrix. Valid norms are:
1 - The maximum absolute column sum 2 - The Frobenius norm, the square root of the sum of the squares of the elements Inf - The maximum absolute row sum
type RawMatrixer ¶
A RawMatrixer can return a blas32.General representation of the receiver. Changes to the blas32.General.Data slice will be reflected in the original matrix, changes to the Rows, Cols and Stride fields will not.
type RawVectorer ¶
A RawVectorer can return a blas32.Vector representation of the receiver. Changes to the blas32.Vector.Data slice will be reflected in the original matrix, changes to the Inc field will not.
type Transpose ¶
type Transpose struct {
Matrix Matrix
}
Transpose is a type for performing an implicit matrix transpose. It implements the Matrix interface, returning values from the transpose of the matrix within.
func (Transpose) At ¶
At returns the value of the element at row i and column j of the transposed matrix, that is, row j and column i of the Matrix field.
func (Transpose) Dims ¶
Dims returns the dimensions of the transposed matrix. The number of rows returned is the number of columns in the Matrix field, and the number of columns is the number of rows in the Matrix field.
func (Transpose) Untranspose ¶
Untranspose returns the Matrix field.
type Untransposer ¶
type Untransposer interface { // Untranspose returns the underlying Matrix stored for the implicit transpose. Untranspose() Matrix }
Untransposer is a type that can undo an implicit transpose.
type VecDense ¶
type VecDense struct {
// contains filtered or unexported fields
}
VecDense represents a column vector.
func NewVecDense ¶
NewVecDense creates a new VecDense of length n. If data == nil, a new slice is allocated for the backing slice. If len(data) == n, data is used as the backing slice, and changes to the elements of the returned VecDense will be reflected in data. If neither of these is true, NewVecDense will panic. NewVecDense will panic if n is zero.
func (*VecDense) At ¶
At returns the element at row i. It panics if i is out of bounds or if j is not zero.
func (*VecDense) CloneFromVec ¶
CloneFromVec makes a copy of a into the receiver, overwriting the previous value of the receiver.
func (*VecDense) ColViewOf ¶
func (v *VecDense) ColViewOf(m RawMatrixer, j int)
ColViewOf reflects the column j of the RawMatrixer m, into the receiver backed by the same underlying data. The receiver must either be empty have length equal to the number of rows of m.
func (*VecDense) CopyVec ¶
CopyVec makes a copy of elements of a into the receiver. It is similar to the built-in copy; it copies as much as the overlap between the two vectors and returns the number of elements it copied.
func (*VecDense) Dims ¶
Dims returns the number of rows and columns in the matrix. Columns is always 1 for a non-Reset vector.
func (*VecDense) DivElemVec ¶
DivElemVec performs element-wise division of a by b, placing the result in the receiver.
func (*VecDense) IsEmpty ¶
IsEmpty returns whether the receiver is empty. Empty matrices can be the receiver for size-restricted operations. The receiver can be emptied using Reset.
func (*VecDense) RawVector ¶
RawVector returns the underlying blas32.Vector used by the receiver. Changes to elements in the receiver following the call will be reflected in returned blas32.Vector.
func (*VecDense) RowViewOf ¶
func (v *VecDense) RowViewOf(m RawMatrixer, i int)
RowViewOf reflects the row i of the RawMatrixer m, into the receiver backed by the same underlying data. The receiver must either be empty or have length equal to the number of columns of m.
func (*VecDense) SetVec ¶
SetVec sets the element at row i to the value val. It panics if i is out of bounds.
func (*VecDense) SliceVec ¶
SliceVec returns a new Vector that shares backing data with the receiver. The returned matrix starts at i of the receiver and extends k-i elements. SliceVec panics with ErrIndexOutOfRange if the slice is outside the capacity of the receiver.