matrix

package module
v0.0.0-...-ac1304b Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2013 License: LGPL-3.0 Imports: 8 Imported by: 12

README

matrix

Column order matrix implementation suitable for BLAS/LAPACK libraries.

Changes

New sub-matrix interface that resembles go slices. Creating a sub-matrix does
not copy elements and changes to submatrix are visible in the original matrix.

Depreciated row and column handling functions. Use sub-matrix instead.

Todo

  • ComplexMatrix not up to level of FloatMatrix

Documentation

Overview

Package matrix implements column major matrices.

Index

Constants

View Source
const ATOL = 1e-8

Default absolute tolerance

View Source
const ColumnOrder = DataOrder(1)
View Source
const Lower = Tridiagonal(1)
View Source
const RTOL = 1.0000000000000001e-05

Default relative tolenrance, these are spyed from Python NumPy

View Source
const RowOrder = DataOrder(0)
View Source
const StackDown = Stacking(0)
View Source
const StackRight = Stacking(1)
View Source
const Symmetric = Tridiagonal(0)
View Source
const Upper = Tridiagonal(2)

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 DiagonalIndexes

func DiagonalIndexes(m Matrix) []int

Create index set for diagonal 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 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 Indexes

func Indexes(specs ...int) []int

Create an index set. Three argument call is (start, end, step) where start < end and step > 0. It produces set of indexes from start to end-1 with step interval. Two argument call is interpreted as (start, end, 1) and one argument call as (0, end, 1).

func MakeDiagonalSet

func MakeDiagonalSet(n int) []int

Create index set to access diagonal entries of matrix of size (n, n).

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 *FloatMatrix, indexes ...int) float64

Find element-wise maximum.

func Min

func Min(A *FloatMatrix, indexes ...int) float64

Find element-wise minimum.

func NotEqual

func NotEqual(A, B Matrix) bool

Test if matrices A and B are not equal. Returns true if matrices are of different size or if not all element values are equal.

func PanicOnError

func PanicOnError(flag bool)

func Reshape

func Reshape(m Matrix, rows, cols int, steps ...int)

Change matrix shape if number of elements match to rows*cols. Optional 3rd arguments is the new row stride of data. Row stride is not changed unless given or if current row stride is equal to number of rows in matrix. On the second case new row stride is set equal to new row count.

func RowIndexes

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

Create index set for a row in matrix M.

func Set

func Set(x, y Matrix)

Set x = y ie. copy y to x. Matrices must have same number of elements but are not required to have same shape. **DEPRECEATED**

func Sum

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

Return sum of elements

Types

type CScalar

type CScalar complex128

Complex constant

func (CScalar) Complex

func (self CScalar) Complex() complex128

Return self as complex128.

func (CScalar) Float

func (self CScalar) Float() float64

Return real(self).

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 ComplexMatrixFromTable

func ComplexMatrixFromTable(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 ComplexNormal

func ComplexNormal(rows, cols int) *ComplexMatrix

Create random matrix with element's real and imaginary parts from [0.0, 1.0).

func ComplexNormalSymmetric

func ComplexNormalSymmetric(n int) *ComplexMatrix

Create symmetric n by n random matrix with element's real and imaginary parts from normal distribution.

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 ComplexUniform

func ComplexUniform(rows, cols int) *ComplexMatrix

Create random matrix with element's real and imaginary parts from [0.0, 1.0).

func ComplexUniformSymmetric

func ComplexUniformSymmetric(n int) *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, indexes ...int) *ComplexMatrix

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

func (*ComplexMatrix) AddIndexes

func (A *ComplexMatrix) AddIndexes(indexes []int, values []complex128) *ComplexMatrix

Compute in-place A[indexes[i]] += values[i]. Indexes are in column-major order.

func (*ComplexMatrix) Apply

func (A *ComplexMatrix) Apply(fn func(complex128) complex128, indexes ...int) *ComplexMatrix

Compute A = fn(A) by applying function fn element wise to A. If indexes array is non-empty function is applied to elements of A indexed by the contents of indexes.

func (*ComplexMatrix) ApplyConst

func (A *ComplexMatrix) ApplyConst(x complex128, fn func(complex128, complex128) complex128, indexes ...int) *ComplexMatrix

Compute A = fn(A, x) by applying function fn element wise to A. If indexes array is non-empty function is applied to elements of A indexed by the contents of indexes.

func (*ComplexMatrix) ApplyConstValues

func (A *ComplexMatrix) ApplyConstValues(values []complex128, fn func(complex128, complex128) complex128, indexes ...int) *ComplexMatrix

Compute A = fn(A, x) by applying function fn element wise to A.

For all i in indexes: A[indexes[i]] = fn(A[indexes[i]], values[i])

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

func (A *ComplexMatrix) Conj() *ComplexMatrix

Compute in-place conjugate A[i,j]

func (*ComplexMatrix) Copy

func (A *ComplexMatrix) Copy() (B *ComplexMatrix)

Create a copy of matrix.

func (*ComplexMatrix) CopyTo

func (A *ComplexMatrix) CopyTo(B *ComplexMatrix) error

Copy A to B, A and B number of elements need not match. Copies min(A.NumElements(), B.NumElements()) from start of A to start of B.

func (*ComplexMatrix) Div

Compute element-wise division A /= B. Return A. If A and B sizes do not match A is returned unaltered.

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

func (A *ComplexMatrix) Exp() *ComplexMatrix

Compute in-place Exp(A)

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) 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. **DEPRECEATED**

func (*ComplexMatrix) GetColumnArray

func (A *ComplexMatrix) GetColumnArray(i int, vals []complex128) []complex128

Get copy of i'th column. **DEPRECEATED**

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 elements from column-major indexes. Return new array.

func (*ComplexMatrix) GetIndexesFromArray

func (A *ComplexMatrix) GetIndexesFromArray(indexes []int) []complex128

Get values for indexed elements. **DEPRECEATED**

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. **DEPRECEATED**

func (*ComplexMatrix) GetRowArray

func (A *ComplexMatrix) GetRowArray(i int, vals []complex128) []complex128

Get copy of i'th row. **DEPRECEATED**

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. **DEPRECEATED**

func (*ComplexMatrix) Inv

func (A *ComplexMatrix) Inv(indexes ...int) *ComplexMatrix

Compute in-place inverse A[i,j] = 1.0/A[i,j]. If indexes is empty calculates for all elements

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

func (A *ComplexMatrix) Log() *ComplexMatrix

Compute in-place Log(A)

func (*ComplexMatrix) Log10

func (A *ComplexMatrix) Log10() *ComplexMatrix

Compute in-place Log10(A)

func (*ComplexMatrix) MakeCopy

func (A *ComplexMatrix) MakeCopy() Matrix

Create a copy of matrix.

func (*ComplexMatrix) Minus

Compute element-wise difference A -= B. Return A. If A and B sizes do not match A is returned unaltered.

func (*ComplexMatrix) Mul

Compute element-wise product A *= B. Return A. If A and B sizes do not match A is returned unaltered.

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 element-wise sum A += B. Return A. If A and B sizes do not match A is returned unaltered.

func (*ComplexMatrix) Pow

Compute in-place Pow(A, x)

func (*ComplexMatrix) Rows

func (A *ComplexMatrix) Rows() int

Return number of rows.

func (*ComplexMatrix) Scale

func (A *ComplexMatrix) Scale(alpha complex128, indexes ...int) *ComplexMatrix

Compute in-place product A[i,j] *= alpha

func (*ComplexMatrix) ScaleIndexes

func (A *ComplexMatrix) ScaleIndexes(indexes []int, values []complex128) *ComplexMatrix

Compute in-place A[indexes[i]] *= values[i]. Indexes are in column-major order.

func (*ComplexMatrix) Set

func (A *ComplexMatrix) Set(B *ComplexMatrix) error

Set A = B, copy values, A and B sizes must match.

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. **DEPRECEATED**

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(val complex128, indexes ...int)

Set element values in column-major ordering. Negative indexes are relative to the last element of the matrix. If len(indexes) is zero sets all elements.

func (*ComplexMatrix) SetIndexesFromArray

func (A *ComplexMatrix) SetIndexesFromArray(indexes []int, values []complex128)

Set values of indexed elements. **DEPRECEATED**

func (*ComplexMatrix) SetRowArray

func (A *ComplexMatrix) SetRowArray(i int, vals []complex128)

Set values of i'th row. **DEPRECEATED**

func (*ComplexMatrix) SetSize

func (A *ComplexMatrix) SetSize(nrows, ncols int, step ...int)

Set dimensions. Does not affect element allocations. Optional 3rd argument sets also the row stride of data.

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

func (A *ComplexMatrix) Sqrt() *ComplexMatrix

Compute in-place Sqrt(A)

func (*ComplexMatrix) String

func (A *ComplexMatrix) String() string

Convert matrix to row-major string representation.

func (*ComplexMatrix) SubMatrix

func (A *ComplexMatrix) SubMatrix(row, col int, size ...int) *ComplexMatrix

Make a submatrix of A starting from position row, col. Returns a new matrix. If size not given it is assumed to be [A.Rows()-row, A.Cols()-col].

func (*ComplexMatrix) SubMatrixOf

func (A *ComplexMatrix) SubMatrixOf(B *ComplexMatrix, row, col int, size ...int) *ComplexMatrix

Set A to be submatrix of B

func (*ComplexMatrix) Times

Compute matrix product C = A * B where A is m*p and B is p*n. Returns a new m*n matrix.

func (*ComplexMatrix) Transpose

func (A *ComplexMatrix) Transpose() *ComplexMatrix

Copy and transpose matrix. Returns new matrix.

type ConstFloat

type ConstFloat struct {
	Value float64
}

Produce constant value

func (*ConstFloat) Next

func (g *ConstFloat) Next() float64

type DataOrder

type DataOrder int

Matrix constructor data order

type FScalar

type FScalar float64

Float constant

func (FScalar) Complex

func (self FScalar) Complex() complex128

Return complex(self, 0)

func (FScalar) Float

func (self FScalar) Float() float64

Return self as float64.

type FloatGenerator

type FloatGenerator interface {
	Next() float64
}

Interface for producing float numbers

type FloatMatrix

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

A column-major matrix backed by a flat array of all elements.

func Abs

func Abs(A *FloatMatrix, indexes ...int) *FloatMatrix

Compute element-wise C = Abs(A). Returns a new matrix.

func Add

func Add(A *FloatMatrix, alpha float64, indexes ...int) *FloatMatrix

Make a copy C of A and compute C += alpha for all elements in the matrix if list of indexes is empty. Otherwise compute C[indexes[i]] += alpha for indexes in column-major order.

func AddAt

func AddAt(A *FloatMatrix, values []float64, indexes []int) *FloatMatrix

Make copy C of A and compute C[indexes[i]] += values[i]. Indexes are in column-major order. Returns a new matrix.

func Apply

func Apply(A *FloatMatrix, fn func(float64) float64, indexes ...int) *FloatMatrix

Makes a copy C of A and applies function fn to elements of then new copy C. If indexes is non empty then function is applied to all elements of C indexed by indexes array. Otherwise function is applied to all elements of A. New value of element in C is fn(A[i]). Returns a new matrix.

func ApplyConst

func ApplyConst(A *FloatMatrix, x float64, fn func(float64, float64) float64, indexes ...int) *FloatMatrix

Makes a copy C of A and applies function fn to elements of then new copy C. If indexes is non empty then function is applied to all elements of C indexed by indexes array. Otherwise function is applied to all elements of A. New value of element in C is fn(A[i], x). Returns a new matrix.

func ApplyConstValues

func ApplyConstValues(A *FloatMatrix, values []float64, fn func(float64, float64) float64, indexes ...int) *FloatMatrix

Makes a copy C of A and applies function fn to elements of the new copy C pointed by the contexts of indexes array. New value of element in C is fn(A[indexes[i]], values[i]). Returns new matrix.

func Div

func Div(A, B *FloatMatrix) *FloatMatrix

Compute element wise division C[i,j] = A[i,j] / B[i,j]. Returns new matrix.

func Exp

func Exp(A *FloatMatrix, indexes ...int) *FloatMatrix

Compute element-wise C = Exp(A). Returns a new matrix.

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. *DEPRECEATED*

func FloatIdentity

func FloatIdentity(rows int) *FloatMatrix

Create new identity matrix. Row count must equal column count. *DEPRECEATED*

func FloatMatrixFromTable

func FloatMatrixFromTable(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 FloatMatrixStacked

func FloatMatrixStacked(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 FloatNew

func FloatNew(rows, cols int, elements []float64, order ...DataOrder) *FloatMatrix

Create a column-major matrix from a flat array of elements. Assumes values are in column-major order.

func FloatNormal

func FloatNormal(rows, cols int) *FloatMatrix

Create random matrix with elements from normal distribution (mean=0.0, stddev=1.0) *DEPRECEATED*

func FloatNormalSymmetric

func FloatNormalSymmetric(n int, uplo ...Tridiagonal) *FloatMatrix

Create symmetric n by n random matrix with elements from normal distribution. *DEPRECEATED*

func FloatOnes

func FloatOnes(rows, cols int) *FloatMatrix

Create new matrix initialized to one. *DEPRECEATED*

func FloatParse

func FloatParse(s string) (A *FloatMatrix, err error)

func FloatUniform

func FloatUniform(rows, cols int) *FloatMatrix

Create random matrix with elements from [0.0, 1.0) uniformly distributed..

func FloatUniformSymmetric

func FloatUniformSymmetric(n int, uplo ...Tridiagonal) *FloatMatrix

Create symmetric n by n random matrix with elements from [0.0, 1.0). *DEPRECEATED*

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 FloatNew(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 Inv

func Inv(A *FloatMatrix, indexes ...int) *FloatMatrix

Make a copy C of A and compute inverse C[i] = 1.0/C[i]. If indexes is empty calculates for all elements. Returns a new matrix.

func Log

func Log(A *FloatMatrix, indexes ...int) *FloatMatrix

Compute element-wise C = Log(A). Returns a new matrix.

func Log10

func Log10(A *FloatMatrix, indexes ...int) *FloatMatrix

Return copy of A with each element as Log10(A). Returns a new matrix.

func Log1p

func Log1p(A *FloatMatrix, indexes ...int) *FloatMatrix

Return copy of A with each element as Log1p(A). Returns a new matrix.

func Log2

func Log2(A *FloatMatrix, indexes ...int) *FloatMatrix

Return copy of A with each element as Log2(A). Returns a new matrix

func Minus

func Minus(matrices ...*FloatMatrix) *FloatMatrix

Compute element-wise difference A - B - C -... Returns a new matrix.

func Mul

func Mul(A, B *FloatMatrix) *FloatMatrix

Compute element-wise product C[i,j] = A[i,j] * B[i,j]. Returns new matrix.

func Plus

func Plus(matrices ...*FloatMatrix) *FloatMatrix

Compute element-wise sum A + B + C +... Returns a new matrix.

func Pow

func Pow(A *FloatMatrix, exp float64, indexes ...int) *FloatMatrix

Compute element-wise C = Pow(A). Returns a new matrix.

func Scale

func Scale(A *FloatMatrix, alpha float64, indexes ...int) *FloatMatrix

Make a copy C of A and compute C *= alpha for all elements in the matrix if list of indexes is empty. Otherwise compute C[i] *= alpha for i in indexes array.

func ScaleAt

func ScaleAt(A *FloatMatrix, values []float64, indexes []int) *FloatMatrix

Make a copy C of A and compute for all k in indexes: C[k] *= values[k]. Indexes are in column-major order. Returns a new matrix

func Sqrt

func Sqrt(A *FloatMatrix, indexes ...int) *FloatMatrix

Compute element-wise C = Sqrt(A). Returns a new matrix.

func Times

func Times(A, 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) 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) AddIndexes

func (A *FloatMatrix) AddIndexes(indexes []int, values []float64) *FloatMatrix

Compute in-place A[indexes[i]] += values[i]. Indexes are in column-major order.

func (*FloatMatrix) AllClose

func (A *FloatMatrix) AllClose(B *FloatMatrix, tolerances ...float64) bool

Return true if A is element-wise equal to with a tolerance. The tolerance values are positive, typically very small numbers. If tolerances parameter is not given default values are used. If one tolerance value is given, it is used as absolute tolerance. If two values are given, first is used as absolute tolerance and second as relative tolerance.

func (*FloatMatrix) Apply

func (A *FloatMatrix) Apply(fn func(float64) float64, indexes ...int) *FloatMatrix

Compute A = fn(A) by applying function fn element wise to A. If indexes array is non-empty function is applied to elements of A indexed by the contents of indexes.

func (*FloatMatrix) ApplyConst

func (A *FloatMatrix) ApplyConst(x float64, fn func(float64, float64) float64, indexes ...int) *FloatMatrix

Compute A = fn(A, x) by applying function fn element wise to A. If indexes array is non-empty function is applied to elements of A indexed by the contents of indexes.

For all i in A:       A[i]          = fn(A[i], x)           if len(indexes) == 0
For all i in indexes: A[indexes[i]] = fn(A[indexes[i]], x)  if len(indexes) > 0

func (*FloatMatrix) ApplyConstValues

func (A *FloatMatrix) ApplyConstValues(values []float64, fn func(float64, float64) float64, indexes ...int) *FloatMatrix

Compute A = fn(A, x) by applying function fn element wise to A.

For all i in indexes: A[indexes[i]] = fn(A[indexes[i]], values[i])

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. **DEPRECEATED**

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

func (A *FloatMatrix) CopyTo(B *FloatMatrix) error

Copy A to B, A and B number of elements need not match. Copies min(A.NumElements(), B.NumElements()) from start of A to start of B.

func (*FloatMatrix) Diag

func (A *FloatMatrix) Diag(B *FloatMatrix) *FloatMatrix

Make B diagonal of matrix A as submatrix vector.

func (*FloatMatrix) DiagOf

func (A *FloatMatrix) DiagOf(B *FloatMatrix) *FloatMatrix

Make A diagonal of matrix B as submatrix vector.

func (*FloatMatrix) Div

func (A *FloatMatrix) Div(B *FloatMatrix) *FloatMatrix

Compute element-wise division A /= B. Return A. If A and B sizes do not match A is returned unaltered.

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 A = Exp(A).

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) 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. **DEPRECEATED** Use SubMatrix function instead.

func (*FloatMatrix) GetColumnArray

func (A *FloatMatrix) GetColumnArray(i int, vec []float64) []float64

Get copy of i'th column. See GetRow. **DEPRECEATED**

func (*FloatMatrix) GetIndex

func (A *FloatMatrix) GetIndex(i int) float64

Get element value from column-major index position.

func (*FloatMatrix) GetIndexes

func (A *FloatMatrix) GetIndexes(indexes ...int) []float64

Get elements from column-major indexes. Return new array.

func (*FloatMatrix) GetIndexesFromArray

func (A *FloatMatrix) GetIndexesFromArray(indexes []int) []float64

Get values for indexed elements. **DEPRECEATED**

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. **DEPRECEATED** Use SubMatrix function instead.

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. **DEPRECEATED**

func (*FloatMatrix) GetSubMatrix

func (A *FloatMatrix) GetSubMatrix(row, col int, sizes ...int) (m *FloatMatrix)

Get sub-matrix starting at (row, col). Sizes parameters define (nrows, ncols) number of rows and number of columns. If len(sizes) is zero size is then (nrows, ncols) is (Rows()-row, Cols()-col).If len(sizes) is one then (nrows, ncols) is (sizes[0], Cols()-col) In all other cases (nrows, ncols) is (sizes[0], sizes[1]). Return nil if nrows+row >= A.Rows() or ncols+col >= A.Cols() **DEPRECEATED**

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

func (A *FloatMatrix) Inv(indexes ...int) *FloatMatrix

Compute in-place inverse A[i,j] = 1.0/A[i,j]. If indexes is empty calculates for all elements

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 A = Log(A).

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 A -= B. Return A. If A and B sizes do not match A is returned unaltered. Not guaranteed to work for overlapping submatrices.

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 A *= B. Return A. If A and B sizes do not match A is returned unaltered.

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 A += B. Return A. If A and B sizes do not match A is returned unaltered.

func (*FloatMatrix) Pow

func (A *FloatMatrix) Pow(exp float64) *FloatMatrix

Compute element-wise A = Pow(A).

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

func (A *FloatMatrix) ScaleIndexes(indexes []int, values []float64) *FloatMatrix

Compute in-place A[indexes[i]] *= values[i]. Indexes are in column-major order.

func (*FloatMatrix) Set

func (A *FloatMatrix) Set(B *FloatMatrix) error

Set A = B, copy values, A and B sizes must match.

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(). **DEPRECEATED**

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). **DEPRECEATED**

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. **DEPRECEATED**

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. **DEPRECEATED**

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. **DEPRECEATED**

func (*FloatMatrix) SetColumnArray

func (A *FloatMatrix) SetColumnArray(i int, vals []float64)

Set values of i'th column. **DEPRECEATED**

func (*FloatMatrix) SetFrom

func (A *FloatMatrix) SetFrom(g FloatGenerator, indexes ...int) *FloatMatrix

func (*FloatMatrix) SetFromTrm

func (A *FloatMatrix) SetFromTrm(g FloatGenerator, tridiagonal ...Tridiagonal) *FloatMatrix

func (*FloatMatrix) SetIndex

func (A *FloatMatrix) SetIndex(i int, val float64)

Set value of i'th element.

func (*FloatMatrix) SetIndexes

func (A *FloatMatrix) SetIndexes(val float64, indexes ...int)

Set element values in column-major ordering. Negative indexes are relative to the last element of the matrix. If len(indexes) is zero sets all elements.

func (*FloatMatrix) SetIndexesFromArray

func (A *FloatMatrix) SetIndexesFromArray(values []float64, indexes ...int)

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. **DEPRECEATED**

func (*FloatMatrix) SetRowArray

func (A *FloatMatrix) SetRowArray(i int, vals []float64)

Set values of i'th row. **DEPRECEATED**

func (*FloatMatrix) SetSize

func (A *FloatMatrix) SetSize(nrows, ncols int, step ...int)

Set dimensions. Does not affect element allocations. Optional 3rd argument sets also the row stride of data.

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. **DEPRECEATED** (Use B.SubMatrixOf(A, row, col).Set(C))

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

func (A *FloatMatrix) Sqrt() *FloatMatrix

Compute element-wise A = Sqrt(A).

func (*FloatMatrix) String

func (A *FloatMatrix) String() string

Convert matrix to row-major string representation.

func (*FloatMatrix) SubMatrix

func (A *FloatMatrix) SubMatrix(B *FloatMatrix, row, col int, size ...int) *FloatMatrix

Make B a submatrix of A with top left corner at (row, col).

If no size argument is given then size of (A.Rows()-row, A.Cols()-col) is assumed. The variadic size argument can be either (nrows, ncols) or (nrows, ncols, nstep). The first form sets B size to (nrows, ncols). The second form is used to create diagonal vectors over A by setting nrows to one, ncols properly and nstep to A.LeadingIndex()+1. Other combinations of parameters in three argument form may create unexpected access patterns to underlying matrix.

func (*FloatMatrix) SubMatrixOf

func (A *FloatMatrix) SubMatrixOf(B *FloatMatrix, row, col int, size ...int) *FloatMatrix

Set A to be submatrix of B starting from position row, col. Returns A. The size argument can be either: nrows, ncols or nrows, ncols, nstep. The first form is used to create row or column vectors or normal submatrices. Three argument form is used to create diagonal vectors by setting nrows to one, ncols to number of columns and nstep to A.LeadingIndex()+1. Other combinations of parameters in three argument form may create unexpected access patterns to underlying matrix.

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.

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
	// size of the leading index.
	LeadingIndex() int
	// 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

type NormalFloat

type NormalFloat struct {
	Mean   float64
	StdDev float64
}

Produce normally distributed value

func (*NormalFloat) Next

func (g *NormalFloat) Next() float64

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.

type Tridiagonal

type Tridiagonal int

Tridiagonal matrix type

type UniformFloat

type UniformFloat struct {
	Low  float64
	High float64
}

Produce uniformly distributed value

func (*UniformFloat) Next

func (g *UniformFloat) Next() float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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