mat64

package
v0.0.0-...-40ed44c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2015 License: BSD-3-Clause Imports: 8 Imported by: 0

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

Constants

View Source
const (
	ErrIndexOutOfRange = Error("mat64: index out of range")
	ErrRowAccess       = Error("mat64: row index out of range")
	ErrColAccess       = Error("mat64: column 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")
)
View Source
const (
	ErrUplo = "mat64: blas64.Symmetric not upper"
)

Variables

This section is empty.

Functions

func Det

func Det(a Matrix) float64

Det returns the determinant of the matrix a.

func Format

func Format(m Matrix, margin int, dot byte, fs fmt.State, c rune)

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

func Inner(x []float64, A Matrix, y []float64) float64

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 len(x) != m or len(y) != n when A is an m x n matrix.

func Maybe

func Maybe(fn Panicker) (err error)

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

type ApplyFunc func(r, c int, v float64) float64

An ApplyFunc takes a row/column index and element value and returns some function of that tuple.

type Applyer

type Applyer interface {
	Apply(f ApplyFunc, a Matrix)
}

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

type ApproxEqualer interface {
	EqualsApprox(b Matrix, epsilon float64) bool
}

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 CholeskyFactor

type CholeskyFactor struct {
	L   *Dense
	SPD bool
}

func Cholesky

func Cholesky(a *Dense) CholeskyFactor

CholeskyL returns the left Cholesky decomposition of the matrix a and whether the matrix is symmetric and positive definite. The returned matrix l is a lower triangular matrix such that a = l.l'.

func (CholeskyFactor) Solve

func (f CholeskyFactor) Solve(b *Dense) (x *Dense)

CholeskySolve returns a matrix x that solves a.x = b where a = l.l'. The matrix b must have the same number of rows as a, and a must be symmetric and positive definite. The matrix b is overwritten by the operation.

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

type ColViewer interface {
	ColView(c int) *Vector
}

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

type Copier interface {
	Copy(a Matrix) (r, c int)
}

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
}

func DenseCopyOf

func DenseCopyOf(a Matrix) *Dense

DenseCopyOf returns a newly allocated copy of the elements of a.

func Inverse

func Inverse(a Matrix) (*Dense, error)

Inverse returns the inverse or pseudoinverse of the matrix a. It returns a nil matrix and ErrSingular if a is singular.

func NewDense

func NewDense(r, c int, mat []float64) *Dense

NewDense initializes and returns a *Dense of size r-by-c. Data stores in mat should be row-major, i.e., the (i, j) element in matrix should be at (i*c + j)-th position in mat. Note that NewDense(0, 0, nil) can be used for undetermined size matrix initialization.

func Solve

func Solve(a, b Matrix) (x *Dense, err error)

Solve returns a matrix x that satisfies ax = b. It returns a nil matrix and ErrSingular if a is singular.

func (*Dense) Add

func (m *Dense) Add(a, b Matrix)

Add adds a and b element-wise and saves the result into m.

func (*Dense) Apply

func (m *Dense) Apply(f ApplyFunc, a Matrix)

func (*Dense) At

func (m *Dense) At(r, c int) float64

func (*Dense) Augment

func (m *Dense) Augment(a, b Matrix)

func (*Dense) Caps

func (m *Dense) Caps() (r, c int)

func (*Dense) Clone

func (m *Dense) Clone(a Matrix)

func (*Dense) Col

func (m *Dense) Col(dst []float64, j int) []float64

func (*Dense) ColView

func (m *Dense) ColView(j int) *Vector

func (*Dense) Copy

func (m *Dense) Copy(a Matrix) (r, c int)

func (*Dense) Dims

func (m *Dense) Dims() (r, c int)

Dims returns number of rows and number of columns.

func (*Dense) DivElem

func (m *Dense) DivElem(a, b Matrix)

func (*Dense) Dot

func (m *Dense) Dot(b Matrix) float64

func (*Dense) Equals

func (m *Dense) Equals(b Matrix) bool

func (*Dense) EqualsApprox

func (m *Dense) EqualsApprox(b Matrix, epsilon float64) bool

func (*Dense) Exp

func (m *Dense) Exp(a Matrix)

Exp uses the scaling and squaring method described in section 3 of http://www.cs.cornell.edu/cv/researchpdf/19ways+.pdf.

func (*Dense) Grow

func (m *Dense) Grow(r, c int) Matrix

func (*Dense) L

func (m *Dense) L(a Matrix)

func (Dense) MarshalBinary

func (m Dense) MarshalBinary() ([]byte, error)

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) Max

func (m *Dense) Max() float64

func (*Dense) Min

func (m *Dense) Min() float64

func (*Dense) Mul

func (m *Dense) Mul(a, b Matrix)

Mul multiplies two matrix and saves the result in m. Note that the arguments a or b should be either Matrix or *Dense. Therfore, if a or b is of type Dense, you'll need to pass them by address. For example: m.Mul(a, &b) when a is *Dense and b is Dense.

func (*Dense) MulElem

func (m *Dense) MulElem(a, b Matrix)

func (*Dense) MulTrans

func (m *Dense) MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool)

func (*Dense) Norm

func (m *Dense) Norm(ord float64) float64

Norm calculates general matrix p-norm of m. It currently supports p = 1, -1, +Inf, -Inf, 2, -2.

func (*Dense) Pow

func (m *Dense) Pow(a Matrix, n int)

func (*Dense) RankOne

func (m *Dense) RankOne(a Matrix, alpha float64, x, y []float64)

RankOne performs a rank-one update to the matrix b and stores the result in the receiver

m = a + alpha * x * y'

func (*Dense) RawMatrix

func (m *Dense) RawMatrix() blas64.General

func (*Dense) RawRowView

func (m *Dense) RawRowView(i int) []float64

func (*Dense) Reset

func (m *Dense) Reset()

func (*Dense) Row

func (m *Dense) Row(dst []float64, i int) []float64

Row will copy the i-th row into dst and return it. If dst is nil, it will make a new slice for copying/returning.

func (*Dense) RowView

func (m *Dense) RowView(i int) *Vector

func (*Dense) Scale

func (m *Dense) Scale(f float64, a Matrix)

func (*Dense) Set

func (m *Dense) Set(r, c int, v float64)

func (*Dense) SetCol

func (m *Dense) SetCol(j int, src []float64) int

func (*Dense) SetRawMatrix

func (m *Dense) SetRawMatrix(b blas64.General)

func (*Dense) SetRow

func (m *Dense) SetRow(i int, src []float64) int

func (*Dense) Stack

func (m *Dense) Stack(a, b Matrix)

func (*Dense) Sub

func (m *Dense) Sub(a, b Matrix)

func (*Dense) Sum

func (m *Dense) Sum() float64

func (*Dense) TCopy

func (m *Dense) TCopy(a Matrix)

TCopy will copy the transpose of a and save it into m.

func (*Dense) Trace

func (m *Dense) Trace() float64

func (*Dense) U

func (m *Dense) U(a Matrix)

func (*Dense) UnmarshalBinary

func (m *Dense) UnmarshalBinary(data []byte) error

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.

func (*Dense) View

func (m *Dense) View(i, j, r, c int) Matrix

type Deter

type Deter interface {
	Det() float64
}

A Deter can return the determinant of the represented matrix.

type Dotter

type Dotter interface {
	Dot(b Matrix) float64
}

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

type Equaler interface {
	Equals(b Matrix) bool
}

An Equaler can compare the matrices represented by b and the receiver. Matrices with non-equal shapes are not equal.

type Error

type Error string

Type Error represents matrix handling errors. These errors can be recovered by Maybe wrappers.

func (Error) Error

func (err Error) Error() string

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

type Grower interface {
	Caps() (r, c int)
	Grow(r, c int) Matrix
}

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

type Inver interface {
	Inv(a Matrix) error
}

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

func LQ(a *Dense) LQFactor

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

func (f LQFactor) IsFullRank() bool

IsFullRank returns whether the L matrix and hence a has full rank.

func (LQFactor) L

func (f LQFactor) L() *Dense

L returns the lower triangular factor for the LQ decomposition.

func (LQFactor) Solve

func (f LQFactor) Solve(b *Dense) (x *Dense)

Solve computes minimum norm least squares solution of a.x = b where b has as many rows as a. A matrix x is returned that minimizes the two norm of Q*R*X-B. Solve will panic if a is not full rank.

type LUFactors

type LUFactors struct {
	LU    *Dense
	Pivot []int
	Sign  int
}

func LU

func LU(a *Dense) LUFactors

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 LUGaussian

func LUGaussian(a *Dense) LUFactors

LUGaussian performs an LU Decomposition for an m-by-n matrix a using Gaussian elimination. L and U are found using the "daxpy"-based elimination algorithm used in LINPACK and MATLAB.

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 LUGaussian 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

func (f LUFactors) Det() float64

Det returns the determinant of matrix a decomposed into lu. The matrix a must have been square.

func (LUFactors) IsSingular

func (f LUFactors) IsSingular() bool

IsSingular returns whether the the upper triangular factor and hence a is singular.

func (LUFactors) L

func (f LUFactors) L() *Dense

L returns the lower triangular factor of the LU decomposition.

func (LUFactors) Solve

func (f LUFactors) Solve(b *Dense) (x *Dense)

Solve computes a solution of a.x = b where b has as many rows as a. A matrix x is returned that minimizes the two norm of L*U*X - B(piv,:). Solve will panic if a is singular. The matrix b is overwritten during the call.

func (LUFactors) U

func (f LUFactors) U() *Dense

U returns the upper triangular factor of the LU decomposition.

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

type MulTranser interface {
	MulTrans(a Matrix, aTrans bool, b Matrix, bTrans bool)
}

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

type Normer interface {
	Norm(o float64) float64
}

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 Panicker

type Panicker func()

A Panicker is a function that may panic.

type Power

type Power interface {
	Pow(a Matrix, n int)
}

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

func QR(a *Dense) QRFactor

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

func (f QRFactor) H() *Dense

H returns the Householder vectors in a lower trapezoidal matrix whose columns define the reflections.

func (QRFactor) IsFullRank

func (f QRFactor) IsFullRank() bool

IsFullRank returns whether the R matrix and hence a has full rank.

func (QRFactor) Q

func (f QRFactor) Q() *Dense

Q generates and returns the (economy-sized) orthogonal factor.

func (QRFactor) R

func (f QRFactor) R() *Dense

R returns the upper triangular factor for the QR decomposition.

func (QRFactor) Solve

func (f QRFactor) Solve(b *Dense) (x *Dense)

Solve computes a least squares solution of a.x = b where b has as many rows as a. A matrix x is returned that minimizes the two norm of Q*R*X-B. Solve will panic if a is not full rank. The matrix b is overwritten during the call.

type RawColViewer

type RawColViewer interface {
	RawColView(c int) *Vector
}

A RawColViewer can return a slice of float64 reflecting a column that is backed by the matrix data.

type RawMatrixSetter

type RawMatrixSetter interface {
	SetRawMatrix(a blas64.General)
}

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

type RawMatrixer interface {
	RawMatrix() blas64.General
}

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

type RawRowViewer interface {
	RawRowView(r int) []float64
}

A RawRowViewer can return a slice of float64 reflecting a row that is backed by the matrix data.

type RawSymmetricer

type RawSymmetricer interface {
	RawSymmetric() blas64.Symmetric
}

A RawSymmetricer can return a view of itself as a BLAS Symmetric matrix.

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

type RowViewer interface {
	RowView(r int) *Vector
}

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

type Scaler interface {
	Scale(c float64, a Matrix)
}

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

func NewSymDense(n int, mat []float64) *SymDense

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) AddSym

func (s *SymDense) AddSym(a, b Symmetric)

func (*SymDense) At

func (t *SymDense) At(r, c int) float64

At returns the element at row r and column c.

func (*SymDense) CopySym

func (s *SymDense) CopySym(a Symmetric) int

func (*SymDense) Dims

func (s *SymDense) Dims() (r, c int)

func (*SymDense) RankTwo

func (s *SymDense) RankTwo(a Symmetric, alpha float64, x, y []float64)

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

func (s *SymDense) RawSymmetric() blas64.Symmetric

RawSymmetric returns the matrix as a blas64.Symmetric. The returned value must be stored in upper triangular format.

func (*SymDense) SetSym

func (t *SymDense) SetSym(r, c int, v float64)

SetSym sets the elements at (r,c) and (c,r) to the value v.

func (*SymDense) SymRankOne

func (s *SymDense) SymRankOne(a Symmetric, alpha float64, x []float64)

SymRankOne performs a symetric rank-one update to the matrix a and stores the result in the receiver

s = a + alpha * x * x'

func (*SymDense) Symmetric

func (s *SymDense) Symmetric() int

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 Triangular

type Triangular struct {
	// contains filtered or unexported fields
}

Triangular represents an upper or lower triangular matrix.

func NewTriangular

func NewTriangular(n int, upper bool, mat []float64) *Triangular

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 (*Triangular) At

func (t *Triangular) At(r, c int) float64

At returns the element at row r and column c.

func (*Triangular) Dims

func (t *Triangular) Dims() (r, c int)

func (*Triangular) RawTriangular

func (t *Triangular) RawTriangular() blas64.Triangular

func (*Triangular) SetTri

func (t *Triangular) SetTri(r, c int, v float64)

Set sets the element at row r and column c. Set panics if the location is outside the appropriate half of the matrix.

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

func NewVector(n int, data []float64) *Vector

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) At

func (m *Vector) At(r, c int) float64

func (*Vector) Dims

func (m *Vector) Dims() (r, c int)

func (*Vector) Len

func (m *Vector) Len() int

Len returns the length of the vector.

func (*Vector) MulVec

func (m *Vector) MulVec(a Matrix, trans bool, b *Vector)

MulVec computes a * b if trans == false and a^T * b if trans == true. The result is stored into the reciever. MulVec panics if the number of columns in a does not equal the number of rows in b.

func (*Vector) RawVector

func (m *Vector) RawVector() blas64.Vector

func (*Vector) Reset

func (m *Vector) Reset()

func (*Vector) Set

func (m *Vector) Set(r, c int, v float64)

func (*Vector) ViewVec

func (m *Vector) ViewVec(i, n int) *Vector

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

type Viewer interface {
	View(i, j, r, c int) Matrix
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL