matrix

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultEpsilon represents the minimum precision for matrix math operations.
	DefaultEpsilon = 0.000001
)

Variables

View Source
var (
	// ErrDimensionMismatch is a typical error.
	ErrDimensionMismatch = errors.New("dimension mismatch")

	// ErrSingularValue is a typical error.
	ErrSingularValue = errors.New("singular value")
)
View Source
var (
	// ErrPolyRegArraysSameLength is a common error.
	ErrPolyRegArraysSameLength = errors.New("polynomial array inputs must be the same length")
)

Functions

func Poly

func Poly(xvalues, yvalues []float64, degree int) ([]float64, error)

Poly returns the polynomial regress of a given degree over the given values.

Types

type Matrix

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

Matrix represents a 2d dense array of floats.

func Eye

func Eye(n int) *Matrix

Eye returns the eye matrix.

func Identity

func Identity(order int) *Matrix

Identity returns the identity matrix of a given order.

func New

func New(rows, cols int, values ...float64) *Matrix

New returns a new matrix.

func NewFromArrays

func NewFromArrays(a [][]float64) *Matrix

NewFromArrays creates a matrix from a jagged array set.

func Ones

func Ones(rows, cols int) *Matrix

Ones returns an matrix of ones.

func Zero

func Zero(rows, cols int) *Matrix

Zero returns a matrix of a given size zeroed.

func (*Matrix) Arrays

func (m *Matrix) Arrays() [][]float64

Arrays returns the matrix as a two dimensional jagged array.

func (*Matrix) Augment

func (m *Matrix) Augment(m2 *Matrix) (*Matrix, error)

Augment concatenates two matrices about the horizontal.

func (*Matrix) Col

func (m *Matrix) Col(col int) Vector

Col returns a column of the matrix as a vector.

func (*Matrix) Copy

func (m *Matrix) Copy() *Matrix

Copy returns a duplicate of a given matrix.

func (*Matrix) Diagonal

func (m *Matrix) Diagonal() *Matrix

Diagonal returns a matrix from the diagonal of a matrix.

func (*Matrix) DiagonalVector

func (m *Matrix) DiagonalVector() Vector

DiagonalVector returns a vector from the diagonal of a matrix.

func (*Matrix) Each

func (m *Matrix) Each(action func(row, col int, value float64))

Each applies the action to each element of the matrix in rows => cols order.

func (*Matrix) Epsilon

func (m *Matrix) Epsilon() float64

Epsilon returns the maximum precision for math operations.

func (*Matrix) Equals

func (m *Matrix) Equals(other *Matrix) bool

Equals returns if a matrix equals another matrix.

func (*Matrix) Get

func (m *Matrix) Get(row, col int) float64

Get returns the element at the given row, col.

func (*Matrix) Inverse

func (m *Matrix) Inverse() (*Matrix, error)

Inverse returns a matrix such that M*I==1.

func (*Matrix) IsSquare

func (m *Matrix) IsSquare() bool

IsSquare returns if the row count is equal to the column count.

func (*Matrix) IsSymmetric

func (m *Matrix) IsSymmetric() bool

IsSymmetric returns if the matrix is symmetric about its diagonal.

func (*Matrix) L

func (m *Matrix) L() *Matrix

L returns the matrix with zeros below the diagonal.

func (*Matrix) LU

func (m *Matrix) LU() (l, u, p *Matrix)

LU performs the LU decomposition.

func (*Matrix) Multiply

func (m *Matrix) Multiply(m2 *Matrix) (m3 *Matrix, err error)

Multiply multiplies two matrices.

func (*Matrix) Pivotize

func (m *Matrix) Pivotize() *Matrix

Pivotize does something i'm not sure what.

func (*Matrix) QR

func (m *Matrix) QR() (q, r *Matrix)

QR performs the qr decomposition.

func (*Matrix) Round

func (m *Matrix) Round() *Matrix

Round rounds all the values in a matrix to it epsilon, returning a reference to the original

func (*Matrix) Row

func (m *Matrix) Row(row int) Vector

Row returns a row of the matrix as a vector.

func (*Matrix) ScaleRow

func (m *Matrix) ScaleRow(row int, scale float64)

ScaleRow applies a scale to an entire row.

func (*Matrix) Set

func (m *Matrix) Set(row, col int, val float64)

Set sets a value.

func (*Matrix) Size

func (m *Matrix) Size() (rows, cols int)

Size returns the dimensions of the matrix.

func (*Matrix) String

func (m *Matrix) String() string

String returns a string representation of the matrix.

func (*Matrix) SubMatrix

func (m *Matrix) SubMatrix(i, j, rows, cols int) *Matrix

SubMatrix returns a sub matrix from a given outer matrix.

func (*Matrix) SwapRows

func (m *Matrix) SwapRows(i, j int)

SwapRows swaps a row in the matrix in place.

func (*Matrix) Times

func (m *Matrix) Times(m2 *Matrix) (*Matrix, error)

Times returns the product of a matrix and another.

func (*Matrix) Transpose

func (m *Matrix) Transpose() *Matrix

Transpose flips a matrix about its diagonal, returning a new copy.

func (*Matrix) U

func (m *Matrix) U() *Matrix

U returns the matrix with zeros above the diagonal. Does not include the diagonal.

func (*Matrix) WithEpsilon

func (m *Matrix) WithEpsilon(epsilon float64) *Matrix

WithEpsilon sets the epsilon on the matrix and returns a reference to the matrix.

type Vector

type Vector []float64

Vector is just an array of values.

func (Vector) DotProduct

func (v Vector) DotProduct(v2 Vector) (result float64, err error)

DotProduct returns the dot product of two vectors.

Jump to

Keyboard shortcuts

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