Documentation ¶
Overview ¶
Package mat64 provides basic linear algebra operations for float64 matrices.
Note that in all interfaces that assign the result to the receiver, the receiver must be either the correct dimensions for the result or a zero-sized matrix. In the latter case, matrix data is allocated and stored in the receiver. If the matrix dimensions do not match the result, the method must panic.
Index ¶
- Variables
- func Det(a Matrix) float64
- func Format(m Matrix, margin int, dot byte, fs fmt.State, c rune)
- func Inner(x *Vector, A Matrix, y *Vector) float64
- func Maybe(fn Panicker) (err error)
- func MaybeFloat(fn FloatPanicker) (f float64, err error)
- type Adder
- type ApplyFunc
- type Applyer
- type ApproxEqualer
- type Augmenter
- type BandWidther
- type Cloner
- type ColViewer
- type Copier
- type Dense
- func (m *Dense) Add(a, b Matrix)
- func (m *Dense) Apply(f ApplyFunc, a Matrix)
- func (m *Dense) At(r, c int) float64
- func (m *Dense) Augment(a, b Matrix)
- func (m *Dense) Caps() (r, c int)
- func (m *Dense) Clone(a Matrix)
- func (m *Dense) Col(dst []float64, j int) []float64
- 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) Dot(b Matrix) float64
- func (m *Dense) Equals(b Matrix) bool
- func (m *Dense) EqualsApprox(b Matrix, epsilon float64) bool
- func (m *Dense) Exp(a Matrix)
- func (m *Dense) Grow(r, c int) Matrix
- func (m *Dense) L(a Matrix)
- func (m Dense) MarshalBinary() ([]byte, error)
- func (m *Dense) Max() float64
- func (m *Dense) Min() float64
- func (m *Dense) Mul(a, b Matrix)
- func (m *Dense) MulElem(a, b Matrix)
- func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool)
- func (m *Dense) Norm(ord float64) float64
- func (m *Dense) Outer(x, y *Vector)
- func (m *Dense) Pow(a Matrix, n int)
- func (m *Dense) RankOne(a Matrix, alpha float64, x, y *Vector)
- func (m *Dense) RawMatrix() blas64.General
- func (m *Dense) RawRowView(i int) []float64
- func (m *Dense) Reset()
- func (m *Dense) Row(dst []float64, i int) []float64
- func (m *Dense) RowView(i int) *Vector
- func (m *Dense) Scale(f float64, a Matrix)
- func (m *Dense) Set(r, c int, v float64)
- func (m *Dense) SetCol(j int, src []float64) int
- func (m *Dense) SetRawMatrix(b blas64.General)
- func (m *Dense) SetRow(i int, src []float64) int
- func (m *Dense) SolveCholesky(t Triangular, b Matrix)
- func (m *Dense) SolveTri(a Triangular, trans bool, b Matrix)
- func (m *Dense) Stack(a, b Matrix)
- func (m *Dense) Sub(a, b Matrix)
- func (m *Dense) Sum() float64
- func (m *Dense) TCopy(a Matrix)
- func (m *Dense) Trace() float64
- func (m *Dense) U(a Matrix)
- func (m *Dense) UnmarshalBinary(data []byte) error
- func (m *Dense) View(i, j, r, c int) Matrix
- type Deter
- type Dotter
- type EigenFactors
- type ElemDiver
- type ElemMuler
- type Equaler
- type Error
- type Exper
- type FloatPanicker
- type Grower
- type Inver
- type LQFactor
- type LUFactors
- type Ler
- type Matrix
- type MulTranser
- type Muler
- type Mutable
- type Normer
- type Panicker
- type Power
- type QRFactor
- type RawColViewer
- type RawMatrixSetter
- type RawMatrixer
- type RawRowViewer
- type RawSymmetricer
- type RawTriangular
- type RawVectorer
- type Reseter
- type RowViewer
- type SVDFactors
- type Scaler
- type Stacker
- type Suber
- type Sumer
- type SymDense
- func (s *SymDense) AddSym(a, b Symmetric)
- func (s *SymDense) At(r, c int) float64
- func (s *SymDense) CopySym(a Symmetric) int
- func (s *SymDense) Dims() (r, c int)
- func (s *SymDense) RankTwo(a Symmetric, alpha float64, x, y []float64)
- func (s *SymDense) RawSymmetric() blas64.Symmetric
- func (s *SymDense) SetSym(r, c int, v float64)
- func (s *SymDense) SymRankOne(a Symmetric, alpha float64, x []float64)
- func (s *SymDense) Symmetric() int
- type Symmetric
- type Tracer
- type TransposeCopier
- type Transposer
- type TriDense
- func (t *TriDense) At(r, c int) float64
- func (t *TriDense) Cholesky(a Symmetric, upper bool) (ok bool)
- func (t *TriDense) Dims() (r, c int)
- func (t *TriDense) RawTriangular() blas64.Triangular
- func (t *TriDense) Reset()
- func (t *TriDense) SetTri(r, c int, v float64)
- func (t *TriDense) Triangle() (n int, upper bool)
- type Triangular
- type Uer
- type Vector
- func (v *Vector) AddVec(a, b *Vector)
- func (v *Vector) At(r, c int) float64
- func (v *Vector) CopyVec(a *Vector) (n int)
- func (v *Vector) Dims() (r, c int)
- func (v *Vector) DivElemVec(a, b *Vector)
- func (v *Vector) EqualsApproxVec(b *Vector, epsilon float64) bool
- func (v *Vector) EqualsVec(b *Vector) bool
- func (v *Vector) Len() int
- func (v *Vector) MulElemVec(a, b *Vector)
- func (v *Vector) MulVec(a Matrix, trans bool, b *Vector)
- func (v *Vector) RawVector() blas64.Vector
- func (v *Vector) Reset()
- func (v *Vector) SetVec(i int, val float64)
- func (v *Vector) SolveCholeskyVec(t Triangular, b *Vector)
- func (v *Vector) SubVec(a, b *Vector)
- func (v *Vector) ViewVec(i, n int) *Vector
- type VectorSetter
- type Vectorer
- type Viewer
Constants ¶
This section is empty.
Variables ¶
var ( ErrIndexOutOfRange = Error{"mat64: index out of range"} ErrRowAccess = Error{"mat64: row index out of range"} ErrColAccess = Error{"mat64: column index out of range"} ErrVectorAccess = Error{"mat64: vector index out of range"} ErrZeroLength = Error{"mat64: zero length in matrix definition"} ErrRowLength = Error{"mat64: row length mismatch"} ErrColLength = Error{"mat64: col length mismatch"} ErrSquare = Error{"mat64: expect square matrix"} ErrNormOrder = Error{"mat64: invalid norm order for matrix"} ErrSingular = Error{"mat64: matrix is singular"} ErrShape = Error{"mat64: dimension mismatch"} ErrIllegalStride = Error{"mat64: illegal stride"} ErrPivot = Error{"mat64: malformed pivot list"} ErrTriangle = Error{"mat64: triangular storage mismatch"} )
Functions ¶
func Format ¶
Format prints a pretty representation of m to the fs io.Writer. The format character c specifies the numerical representation of of elements; valid values are those for float64 specified in the fmt package, with their associated flags. In addition to this, a '#' for all valid verbs except 'v' indicates that zero values be represented by the dot character. The '#' associated with the 'v' verb formats the matrix with Go syntax representation. The printed range of the matrix can be limited by specifying a positive value for margin; If margin is greater than zero, only the first and last margin rows/columns of the matrix are output.
func Inner ¶
Inner computes the generalized inner product
x^T A y
between vectors x and y with matrix A. This is only a true inner product if A is symmetric positive definite, though the operation works for any matrix A.
Inner panics if x.Len != m or y.Len != n when A is an m x n matrix.
func Maybe ¶
Maybe will recover a panic with a type mat64.Error from fn, and return this error. Any other error is re-panicked.
func MaybeFloat ¶
func MaybeFloat(fn FloatPanicker) (f float64, err error)
MaybeFloat will recover a panic with a type mat64.Error from fn, and return this error. Any other error is re-panicked.
Types ¶
type Adder ¶
type Adder interface {
Add(a, b Matrix)
}
An Adder can add the matrices represented by a and b, placing the result in the receiver. Add will panic if the two matrices do not have the same shape.
type ApplyFunc ¶
An ApplyFunc takes a row/column index and element value and returns some function of that tuple.
type Applyer ¶
An Applyer can apply an Applyfunc f to each of the elements of the matrix represented by a, placing the resulting matrix in the receiver.
type ApproxEqualer ¶
An ApproxEqualer can compare the matrices represented by b and the receiver, with tolerance for element-wise equailty specified by epsilon. Matrices with non-equal shapes are not equal.
type Augmenter ¶
type Augmenter interface {
Augment(a, b Matrix)
}
An Augmenter can create the augmented matrix of a with b, where b is placed in the greater indexed columns. The result of augmentation is placed in the receiver, overwriting the previous value of the receiver. Augment will panic if the two input matrices do not have the same number of rows.
type BandWidther ¶
type BandWidther interface {
BandWidth() (k1, k2 int)
}
A BandWidther represents a banded matrix and can return the left and right half-bandwidths, k1 and k2.
type Cloner ¶
type Cloner interface {
Clone(a Matrix)
}
A Cloner can make a copy of a into the receiver, overwriting the previous value of the receiver. The clone operation does not make any restriction on shape.
type ColViewer ¶
A ColViewer can return a Vector reflecting a row that is backed by the matrix data. The Vector returned will have Len() == nRows.
type Copier ¶
A Copier can make a copy of elements of a into the receiver. The submatrix copied starts at row and column 0 and has dimensions equal to the minimum dimensions of the two matrices. The number of row and columns copied is returned.
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 Inverse ¶
Inverse returns the inverse or pseudoinverse of the matrix a. It returns a nil matrix and ErrSingular if a is singular.
func NewDense ¶
NewDense creates a new matrix of type Dense with dimensions r and c. If the mat argument is nil, a new data slice is allocated.
The data must be arranged in row-major order, i.e. the (i*c + j)-th element in mat is the {i, j}-th element in the matrix.
func Solve ¶
Solve returns a matrix x that satisfies ax = b. It returns a nil matrix and ErrSingular if a is singular.
func (*Dense) Add ¶
Add adds a and b element-wise, placing the result in the receiver.
See the Adder interface for more information.
func (*Dense) Apply ¶
Apply applies the function f to each of the elements of a, placing the resulting matrix in the receiver.
See the Applyer interface for more information.
func (*Dense) Augment ¶
Augment creates the augmented matrix of a and b, where b is placed in the greater indexed columns.
See the Augmenter interface for more information.
func (*Dense) Clone ¶
Clone makes a copy of a into the receiver, overwriting the previous value of the receiver. The clone operation does not make any restriction on shape.
See the Cloner interface for more information.
func (*Dense) Col ¶
Col copies the elements in the jth column of the matrix into the slice dst. If the provided slice is nil, a new slice is first allocated.
See the Vectorer interface for more information.
func (*Dense) ColView ¶
ColView returns a Vector reflecting col 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.
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.
See the ElemDiver interface for more information.
func (*Dense) Dot ¶
Dot returns the sum of the element-wise products of the elements of the receiver and b.
See the Dotter interface for more information.
func (*Dense) Equals ¶
Equals returns true if b and the receiver have the same size and contain all equal elements.
See the Equaler interface for more information.
func (*Dense) EqualsApprox ¶
EqualsApprox compares the matrices represented by b and the receiver, with tolerance for element-wise equality specified by epsilon.
See the ApproxEqualer interface for more information.
func (*Dense) Exp ¶
Exp calculates the exponential of the matrix a, e^a, placing the result in the receiver.
See the Exper interface for more information.
Exp uses the scaling and squaring method described in section 3 of http://www.cs.cornell.edu/cv/researchpdf/19ways+.pdf.
func (*Dense) Grow ¶
Grow returns an expanded copy of the receiver. The copy is expanded by r rows and c columns. If the dimensions of the new copy are outside the caps of the receiver a new allocation is made, otherwise not.
func (*Dense) L ¶
L places the lower triangular matrix of a in the receiver.
See the Ler interface for more information.
func (Dense) MarshalBinary ¶
MarshalBinary encodes the receiver into a binary form and returns the result.
Dense is little-endian encoded as follows:
0 - 8 number of rows (int64) 8 - 16 number of columns (int64) 16 - .. matrix data elements (float64) [0,0] [0,1] ... [0,ncols-1] [1,0] [1,1] ... [1,ncols-1] ... [nrows-1,0] ... [nrows-1,ncols-1]
func (*Dense) Mul ¶
Mul takes the matrix product of a and b, placing the result in the receiver.
See the Muler interface for more information.
func (*Dense) MulElem ¶
MulElem performs element-wise multiplication of a and b, placing the result in the receiver.
See the ElemMuler interface for more information.
func (*Dense) MulTrans ¶
MulTrans takes the matrix product of a and b, optionally transposing each, and placing the result in the receiver.
See the MulTranser interface for more information.
func (*Dense) Norm ¶
Norm returns the specified matrix p-norm of the receiver.
See the Normer interface for more information.
func (*Dense) Outer ¶
Outer calculates the outer product of x and y, and stores the result in the receiver. In order to update to an existing matrix, see RankOne.
m = x * y'
func (*Dense) Pow ¶
Pow calculates the integral power of the matrix a to n, placing the result in the receiver.
See the Power interface for more information.
func (*Dense) RankOne ¶
RankOne performs a rank-one update to the matrix a and stores the result in the receiver. If a is zero, see Outer.
m = a + alpha * x * y'
func (*Dense) RawMatrix ¶
RawMatrix returns the underlying blas64.General used by the receiver. Changes to elements in the receiver following the call will be reflected in returned blas64.General.
func (*Dense) RawRowView ¶
RawRowView returns a slice backed by the same array as backing the receiver.
func (*Dense) Reset ¶
func (m *Dense) Reset()
Reset zeros the dimensions of the matrix so that it can be reused as the receiver of a dimensionally restricted operation.
See the Reseter interface for more information.
func (*Dense) Row ¶
Row copies the elements in the ith row of the matrix into the slice dst. If the provided slice is nil, a new slice is first allocated.
See the Vectorer interface for more information.
func (*Dense) RowView ¶
RowView returns a Vector reflecting row i, 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 elements of the matrix in the specified column to the values of src.
See the VectorSetter interface for more information.
func (*Dense) SetRawMatrix ¶
SetRawMatrix sets the underlying blas64.General used by the receiver. Changes to elements in the receiver following the call will be reflected in b.
func (*Dense) SetRow ¶
SetRow sets the elements of the matrix in the specified row to the values of src.
See the VectorSetter interface for more information.
func (*Dense) SolveCholesky ¶
func (m *Dense) SolveCholesky(t Triangular, b Matrix)
SolveCholesky finds the matrix m that solves A * m = b where A = L * L^T or A = U^T * U, and U or L are represented by t, placing the result in the receiver.
func (*Dense) SolveTri ¶
func (m *Dense) SolveTri(a Triangular, trans bool, b Matrix)
SolveTri finds the matrix x that solves op(A) * X = B where A is a triangular matrix and op is specified by trans.
func (*Dense) Stack ¶
Stack appends the rows of b onto the rows of a, placing the result into the receiver.
See the Stacker interface for more information.
func (*Dense) Sub ¶
Sub subtracts the matrix b from a, placing the result in the receiver.
See the Suber interface for more information.
func (*Dense) Sum ¶
Sum returns the sum of the elements of the matrix.
See the Sumer interface for more information.
func (*Dense) TCopy ¶
TCopy makes a copy of the transpose the matrix represented by a, placing the result into the receiver.
See the TransposeCopier interface for more information.
func (*Dense) Trace ¶
Trace returns the trace of the matrix.
See the Tracer interface for more information.
func (*Dense) U ¶
U places the upper triangular matrix of a in the receiver.
See the Uer interface for more information.
func (*Dense) UnmarshalBinary ¶
UnmarshalBinary decodes the binary form into the receiver. It panics if the receiver is a non-zero Dense matrix.
See MarshalBinary for the on-disk layout.
type Deter ¶
type Deter interface {
Det() float64
}
A Deter can return the determinant of the represented matrix.
type Dotter ¶
A Dotter can determine the sum of the element-wise products of the elements of the receiver and b. If the shapes of the two matrices differ, Dot will panic.
type EigenFactors ¶
type EigenFactors struct { V *Dense // contains filtered or unexported fields }
func Eigen ¶
func Eigen(a *Dense, epsilon float64) EigenFactors
Eigen returns the Eigenvalues and eigenvectors of a square real matrix. The matrix a is overwritten during the decomposition. If a is symmetric, then a = v*D*v' where the eigenvalue matrix D is diagonal and the eigenvector matrix v is orthogonal.
If a is not symmetric, then the eigenvalue matrix D is block diagonal with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, lambda + i*mu, in 2-by-2 blocks, [lambda, mu; -mu, lambda]. The columns of v represent the eigenvectors in the sense that a*v = v*D, i.e. a.v equals v.D. The matrix v may be badly conditioned, or even singular, so the validity of the equation a = v*D*inverse(v) depends upon the 2-norm condition number of v.
func (EigenFactors) D ¶
func (f EigenFactors) D() *Dense
D returns the block diagonal eigenvalue matrix from the real and imaginary components d and e.
type ElemDiver ¶
type ElemDiver interface {
DivElem(a, b Matrix)
}
An ElemDiver can perform element-wise division a / b of the matrices represented by a and b, placing the result in the receiver. DivElem will panic if the two matrices do not have the same shape.
type ElemMuler ¶
type ElemMuler interface {
MulElem(a, b Matrix)
}
An ElemMuler can perform element-wise multiplication of the matrices represented by a and b, placing the result in the receiver. MulEmen will panic if the two matrices do not have the same shape.
type Equaler ¶
An Equaler can compare the matrices represented by b and the receiver. Matrices with non-equal shapes are not equal.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Type Error represents matrix handling errors. These errors can be recovered by Maybe wrappers.
type Exper ¶
type Exper interface {
Exp(a Matrix)
}
An Exper can perform a matrix exponentiation of the square matrix a. Exp will panic with ErrShape if a is not square.
type FloatPanicker ¶
type FloatPanicker func() float64
A FloatPanicker is a function that returns a float64 and may panic.
type Grower ¶
A Grower can grow the size of the represented matrix by the given number of rows and columns. Growing beyond the size given by the Caps method will result in the allocation of a new matrix and copying of the elements. If Grow is called with negative increments it will panic with ErrIndexOutOfRange.
type Inver ¶
An Inver can calculate the inverse of the matrix represented by a and stored in the receiver. ErrSingular is returned if there is no inverse of the matrix.
type LQFactor ¶
type LQFactor struct { LQ *Dense // contains filtered or unexported fields }
func LQ ¶
LQ computes an LQ Decomposition for an m-by-n matrix a with m <= n by Householder reflections. The LQ decomposition is an m-by-n orthogonal matrix q and an m-by-m lower triangular matrix l so that a = l.q. LQ will panic with ErrShape if m > n.
The LQ decomposition always exists, even if the matrix does not have full rank, so LQ will never fail unless m > n. The primary use of the LQ decomposition is in the least squares solution of non-square systems of simultaneous linear equations. This will fail if LQIsFullRank() returns false. The matrix a is overwritten by the decomposition.
func (LQFactor) IsFullRank ¶
IsFullRank returns whether the L matrix and hence a has full rank.
type LUFactors ¶
func LU ¶
LU performs an LU Decomposition for an m-by-n matrix a.
If m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a permutation vector piv of length m so that A(piv,:) = L*U.
If m < n, then L is m-by-m and U is m-by-n.
The LU decompostion with pivoting always exists, even if the matrix is singular, so LU will never fail. The primary use of the LU decomposition is in the solution of square systems of simultaneous linear equations. This will fail if IsSingular() returns true.
func (LUFactors) Det ¶
Det returns the determinant of matrix a decomposed into lu. The matrix a must have been square.
func (LUFactors) IsSingular ¶
IsSingular returns whether the the upper triangular factor and hence a is singular.
type Ler ¶
type Ler interface {
L(a Matrix)
}
An Ler can return the lower triangular matrix of the matrix represented by a, placing the result in the receiver. If the concrete value of a is the receiver, the upper residue is zeroed in place.
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 (r, c). It will panic if r or c are // out of bounds for the matrix. At(r, c int) float64 }
Matrix is the basic matrix interface type.
type MulTranser ¶
A MulTranser can determine the matrix product of a and b, optionally taking the transpose of either a, b, or both, placing the result in the receiver. It performs OpA(a) * OpB(b), where OpA is transpose(a) when aTrans is true, and does nothing when aTrans == blas.NoTrans. The same logic applies to OpB. If the number of columns in OpA(a) does not equal the number of rows in OpB(b), MulTrans will panic.
type Muler ¶
type Muler interface {
Mul(a, b Matrix)
}
A Muler can determine 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.
type Mutable ¶
type Mutable interface { // Set alters the matrix element at (r, c) to v. It will panic if r or c are out of // bounds for the matrix. Set(r, c int, v float64) Matrix }
Mutable is a matrix interface type that allows elements to be altered.
type Normer ¶
A Normer can return the specified matrix norm, o of the matrix represented by the receiver.
Valid order values are:
1 - max of the sum of the absolute values of columns -1 - min of the sum of the absolute values of columns Inf - max of the sum of the absolute values of rows -Inf - min of the sum of the absolute values of rows 0 - Frobenius norm
Norm will panic with ErrNormOrder if an illegal norm order is specified.
type Power ¶
A Power can raise a square matrix, a to a positive integral power, n. Pow will panic if n is negative or if a is not square.
type QRFactor ¶
type QRFactor struct { QR *Dense // contains filtered or unexported fields }
func QR ¶
QR computes a QR Decomposition for an m-by-n matrix a with m >= n by Householder reflections, the QR decomposition is an m-by-n orthogonal matrix q and an n-by-n upper triangular matrix r so that a = q.r. QR will panic with ErrShape if m < n.
The QR decomposition always exists, even if the matrix does not have full rank, so QR will never fail unless m < n. The primary use of the QR decomposition is in the least squares solution of non-square systems of simultaneous linear equations. This will fail if QRIsFullRank() returns false. The matrix a is overwritten by the decomposition.
func (QRFactor) H ¶
H returns the Householder vectors in a lower trapezoidal matrix whose columns define the reflections.
func (QRFactor) IsFullRank ¶
IsFullRank returns whether the R matrix and hence a has full rank.
type RawColViewer ¶
A RawColViewer can return a slice of float64 reflecting a column that is backed by the matrix data.
type RawMatrixSetter ¶
A RawMatrixSetter can set the underlying blas64.General used by the receiver. There is no restriction on the shape of the receiver. Changes to the receiver's elements will be reflected in the blas64.General.Data.
type RawMatrixer ¶
A RawMatrixer can return a blas64.General representation of the receiver. Changes to the blas64.General.Data slice will be reflected in the original matrix, changes to the Rows, Cols and Stride fields will not.
type RawRowViewer ¶
A RawRowViewer can return a slice of float64 reflecting a row that is backed by the matrix data.
type RawSymmetricer ¶
A RawSymmetricer can return a view of itself as a BLAS Symmetric matrix.
type RawTriangular ¶
type RawTriangular interface {
RawTriangular() blas64.Triangular
}
type RawVectorer ¶
A RawVectorer can return a blas64.Vector representation of the receiver. Changes to the blas64.Vector.Data slice will be reflected in the original matrix, changes to the Inc field will not.
type Reseter ¶
type Reseter interface {
Reset()
}
A Reseter can reset the matrix so that it can be reused as the receiver of a dimensionally restricted operation. This is commonly used when the matrix is being used a a workspace or temporary matrix.
If the matrix is a view, using the reset matrix may result in data corruption in elements outside the view.
type RowViewer ¶
A RowViewer can return a Vector reflecting a row that is backed by the matrix data. The Vector returned will have Len() == nCols.
type SVDFactors ¶
type SVDFactors struct { U *Dense Sigma []float64 V *Dense // contains filtered or unexported fields }
func SVD ¶
func SVD(a *Dense, epsilon, small float64, wantu, wantv bool) SVDFactors
SVD performs singular value decomposition for an m-by-n matrix a. The singular value decomposition is an m-by-n orthogonal matrix u, an n-by-n diagonal matrix s, and an n-by-n orthogonal matrix v so that a = u*s*v'. If a is a wide matrix a copy of its transpose is allocated, otherwise a is overwritten during the decomposition. Matrices u and v are only created when wantu and wantv are true respectively.
The singular values, sigma[k] = s[k][k], are ordered so that
sigma[0] >= sigma[1] >= ... >= sigma[n-1].
The matrix condition number and the effective numerical rank can be computed from this decomposition.
func (SVDFactors) Cond ¶
func (f SVDFactors) Cond() float64
Cond returns the 2-norm condition number for the S matrix.
func (SVDFactors) Rank ¶
func (f SVDFactors) Rank(epsilon float64) int
Rank returns the number of non-negligible singular values in the sigma held by the factorisation with the given epsilon.
func (SVDFactors) S ¶
func (f SVDFactors) S() *Dense
S returns a newly allocated S matrix from the sigma values held by the factorisation.
type Scaler ¶
A Scaler can perform scalar multiplication of the matrix represented by a with c, placing the result in the receiver.
type Stacker ¶
type Stacker interface {
Stack(a, b Matrix)
}
A Stacker can create the stacked matrix of a with b, where b is placed in the greater indexed rows. The result of stacking is placed in the receiver, overwriting the previous value of the receiver. Stack will panic if the two input matrices do not have the same number of columns.
type Suber ¶
type Suber interface {
Sub(a, b Matrix)
}
A Suber can subtract 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 Sumer ¶
type Sumer interface {
Sum() float64
}
A Sumer can return the sum of elements of the matrix represented by the receiver.
type SymDense ¶
type SymDense struct {
// contains filtered or unexported fields
}
SymDense is a symmetric matrix that uses Dense storage.
func NewSymDense ¶
NewSymDense constructs an n x n symmetric matrix. If len(mat) == n * n, mat will be used to hold the underlying data, or if mat == nil, new data will be allocated. The underlying data representation is the same as a Dense matrix, except the values of the entries in the lower triangular portion are completely ignored.
func (*SymDense) RankTwo ¶
RankTwo performs a symmmetric rank-two update to the matrix a and stores the result in the receiver
m = a + alpha * (x * y' + y * x')
func (*SymDense) RawSymmetric ¶
RawSymmetric returns the matrix as a blas64.Symmetric. The returned value must be stored in upper triangular format.
func (*SymDense) SymRankOne ¶
SymRankOne performs a symetric rank-one update to the matrix a and stores the result in the receiver
s = a + alpha * x * x'
type Symmetric ¶
type Symmetric interface { Matrix // Symmetric returns the number of rows/columns in the matrix. Symmetric() int }
Symmetric represents a symmetric matrix (where the element at {i, j} equals the element at {j, i}). Symmetric matrices are always square.
type Tracer ¶
type Tracer interface {
Trace() float64
}
A Tracer can return the trace of the matrix represented by the receiver. Trace will panic if the matrix is not square.
type TransposeCopier ¶
type TransposeCopier interface {
TCopy(a Matrix)
}
A TransposeCopier can make a copy of the transpose the matrix represented by a, placing the elements into the receiver.
type Transposer ¶
type Transposer interface {
T() Matrix
}
A Transposer can create a transposed view matrix from the matrix represented by the receiver. Changes made to the returned Matrix may be reflected in the original.
type TriDense ¶
type TriDense struct {
// contains filtered or unexported fields
}
TriDense represents an upper or lower triangular matrix in dense storage format.
func NewTriDense ¶
NewTriangular constructs an n x n triangular matrix. The constructed matrix is upper triangular if upper == true and lower triangular otherwise. If len(mat) == n * n, mat will be used to hold the underlying data, if mat == nil, new data will be allocated, and will panic if neither of these cases is true. The underlying data representation is the same as that of a Dense matrix, except the values of the entries in the opposite half are completely ignored.
func (*TriDense) Cholesky ¶
Cholesky calculates the Cholesky decomposition of the matrix A and returns whether the matrix is positive definite. The returned matrix is either a lower triangular matrix such that A = L * L^T or an upper triangular matrix such that A = U^T * U depending on the upper parameter.
func (*TriDense) RawTriangular ¶
func (t *TriDense) RawTriangular() blas64.Triangular
func (*TriDense) Reset ¶
func (t *TriDense) Reset()
Reset zeros the dimensions of the matrix so that it can be reused as the receiver of a dimensionally restricted operation.
See the Reseter interface for more information.
type Triangular ¶
type Uer ¶
type Uer interface {
U(a Matrix)
}
A Uer can return the upper triangular matrix of the matrix represented by a, placing the result in the receiver. If the concrete value of a is the receiver, the lower residue is zeroed in place.
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
Vector represents a column vector.
func NewVector ¶
NewVector creates a new Vector of length n. If len(data) == n, data is used as the backing data slice. If data == nil, a new slice is allocated. If neither of these is true, NewVector will panic.
func (*Vector) 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 matrices and returns the number of rows and columns it copied.
func (*Vector) DivElemVec ¶
DivElemVec performs element-wise division of a by b, placing the result in the receiver.
func (*Vector) EqualsApproxVec ¶
EqualsApproxVec compares the vectors represented by b and the receiver, with tolerance for element-wise equality specified by epsilon.
func (*Vector) EqualsVec ¶
Equals compares the vectors represented by b and the receiver and returns true if the vectors are element-wise equal.
func (*Vector) MulElemVec ¶
MulElemVec performs element-wise multiplication of a and b, placing the result in the receiver.
func (*Vector) MulVec ¶
MulVec computes a * b if trans == false and a^T * b if trans == true. The result is stored into the receiver. MulVec panics if the number of columns in a does not equal the number of rows in b.
func (*Vector) SetVec ¶
Set sets the element at row r to the value val. It panics if r is less than zero or greater than the length.
func (*Vector) SolveCholeskyVec ¶
func (v *Vector) SolveCholeskyVec(t Triangular, b *Vector)
SolveCholeskyVec finds the vector v that solves A * v = b where A = L * L^T or A = U^T * U, and U or L are represented by t, placing the result in the receiver.
func (*Vector) ViewVec ¶
ViewVec returns a sub-vector view of the receiver starting at element i and extending n columns. If i is out of range, or if n is zero or extend beyond the bounds of the Vector ViewVec will panic with ErrIndexOutOfRange. The returned Vector retains reference to the underlying vector.
type VectorSetter ¶
type VectorSetter interface { // SetRow sets the values of the specified row to the values held in a slice of float64. // It will panic if the index is out of bounds. The number of elements copied is // returned and will be the minimum of the length of the slice and the number of columns // in the matrix. SetRow(i int, src []float64) int // SetCol sets the values of the specified column to the values held in a slice of float64. // It will panic if the index is out of bounds. The number of elements copied is // returned and will be the minimum of the length of the slice and the number of rows // in the matrix. SetCol(i int, src []float64) int }
A VectorSetter can set rows and columns in the represented matrix.
type Vectorer ¶
type Vectorer interface { // Row returns a slice of float64 for the row specified. It will panic if the index // is out of bounds. If the call requires a copy and dst is not nil it will be used and // returned, if it is not nil the number of elements copied will be the minimum of the // length of the slice and the number of columns in the matrix. Row(dst []float64, i int) []float64 // Col returns a slice of float64 for the column specified. It will panic if the index // is out of bounds. If the call requires a copy and dst is not nil it will be used and // returned, if it is not nil the number of elements copied will be the minimum of the // length of the slice and the number of rows in the matrix. Col(dst []float64, j int) []float64 }
A Vectorer can return rows and columns of the represented matrix.
type Viewer ¶
A Viewer returns a submatrix view of the Matrix parameter, starting at row i, column j and extending r rows and c columns. If i or j are out of range, or r or c are zero or extend beyond the bounds of the matrix View will panic with ErrIndexOutOfRange. The returned matrix must retain the receiver's reference to the original matrix such that changes in the elements of the submatrix are reflected in the original and vice versa.