matrix

package
v0.0.0-...-0d80f57 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2012 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package matrix implements column major matrices.

Index

Constants

View Source
const ColumnOrder = DataOrder(1)
View Source
const RowOrder = DataOrder(0)
View Source
const StackDown = Stacking(0)
View Source
const StackRight = Stacking(1)

Variables

View Source
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

func ColumnIndexes(m Matrix, col int) []int

Create index set for a column in matrix M.

func Equal

func Equal(A, B Matrix) bool

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

func EqualElementTypes(As ...Matrix) bool

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

func EqualTypes(As ...Matrix) bool

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

func MakeDiagonalSet(rows, cols int) []int

Create index set to access diagonal entries of matrix.

indexes := MakeDiagonalSet(A.Size())

func MakeIndexSet

func MakeIndexSet(start, end, step int) []int

Create a set of indexes from start to end-1 with interval step.

func Max

func Max(A Matrix) float64

Find maximum element value for matrix. For complex matrix returns NaN.

func Min

func Min(A Matrix) float64

Find minimum element value for matrix. For complex matrix returns NaN.

func NotEqual

func NotEqual(A, B Matrix) bool

Test if matrices A and B are not equal. Returns false if sizes of the matrices do not match or if all A[i,j] == B[i,j]

func RowIndexes

func RowIndexes(m Matrix, row int) []int

Create index set for a row in matrix M.

Types

type CScalar

type CScalar complex128

Return real(self).

func (CScalar) Complex

func (self CScalar) Complex() complex128

Return self.

func (CScalar) Float

func (self CScalar) Float() float64

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 ComplexZeros

func ComplexZeros(rows, cols int) *ComplexMatrix

Create new zero filled matrix.

func (*ComplexMatrix) Add

func (A *ComplexMatrix) Add(alpha complex128) *ComplexMatrix

Compute in-place sum A[i,j] += alpha

func (*ComplexMatrix) Apply

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

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

func (A *ComplexMatrix) Cols() int

Return number of columns.

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

func (A *ComplexMatrix) MakeCopy() Matrix

Create a copy of matrix.

func (*ComplexMatrix) Minus

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

Compute sum C = A + B. Returns a new matrix.

func (*ComplexMatrix) Rows

func (A *ComplexMatrix) Rows() int

Return number of rows.

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

func (A *ComplexMatrix) Size() (int, int)

Return size of the matrix as rows, cols pair.

func (*ComplexMatrix) SizeMatch

func (A *ComplexMatrix) SizeMatch(rows, cols int) bool

Return true if size of A is equal to parameter size (rows, cols).

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

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 DataOrder

type DataOrder int

Matrix constructor data order

type FScalar

type FScalar float64

Float constant

func (FScalar) Add

func (self FScalar) Add(a float64) FScalar

func (FScalar) Complex

func (self FScalar) Complex() complex128

Return complex(self, 0)

func (FScalar) Float

func (self FScalar) Float() float64

Return self

func (FScalar) Inv

func (self FScalar) Inv() FScalar

func (FScalar) Scale

func (self FScalar) Scale(a float64) FScalar

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 FloatOnes

func FloatOnes(rows, cols int) *FloatMatrix

Create new matrix initialized to one.

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 FloatZeros

func FloatZeros(rows, cols int) *FloatMatrix

Create new zero filled matrix.

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

func (A *FloatMatrix) Cols() int

Return number of columns.

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

func (A *FloatMatrix) Copy() (B *FloatMatrix)

Create a copy of matrix.

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

func (A *FloatMatrix) Rows() int

Return number of rows.

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

func (A *FloatMatrix) Size() (int, int)

Return size of the matrix as rows, cols pair.

func (*FloatMatrix) SizeMatch

func (A *FloatMatrix) SizeMatch(rows, cols int) bool

Return true if size of A is equal to parameter size (rows, cols).

func (*FloatMatrix) String

func (A *FloatMatrix) String() string

Convert matrix to row-major string representation.

func (*FloatMatrix) Sum

func (A *FloatMatrix) Sum(indexes ...int) float64

Return sum of elements

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

func Abs(A Matrix) Matrix

Return copy of A with each element as Abs(A[i,j]). Returns a float matrix for complex valued matrix.

func Conj

func Conj(A Matrix) Matrix

Return conjugate copy of A with each element as Conj(A[i,j]). Returns nil for float valued matrix.

func Div

func Div(A, B Matrix) (Matrix, error)

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 Exp

func Exp(A Matrix) Matrix

Return copy of A with each element as Exp(A[i,j]).

func Inv

func Inv(A Matrix) Matrix

Return copy of A with each element as 1/A[i,j].

func Log

func Log(A Matrix) Matrix

Return copy of A with each element as Log(A[i,j]).

func Log10

func Log10(A Matrix) Matrix

Return copy of A with each element as Log10(A[i,j]).

func Log1p

func Log1p(A Matrix) Matrix

Return copy of A with each element as Log1p(A[i,j]). Returns nil for complex valued matrix.

func Log2

func Log2(A Matrix) Matrix

Return copy of A with each element as Log2(A[i,j]). Returns nil for complex valued matrix.

func Mul

func Mul(ml ...Matrix) (Matrix, error)

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.

func Pow

func Pow(A Matrix, y Scalar) Matrix

Return copy of A with each element as Pow(A[i,j], y).

func Sqrt

func Sqrt(A Matrix) Matrix

Return copy of A with each element as Sqrt(A[i,j]).

func Sum

func Sum(ml ...Matrix) (Matrix, error)

Return new matrix which is element wise sum 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.

type Stacking

type Stacking int

Stacking direction for matrix constructor.

Jump to

Keyboard shortcuts

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