mat

package
v0.0.0-...-b5d641a Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 1 Imported by: 5

Documentation

Overview

mat contains routines for executing operations on matrices. Opersions are split into easy to use methods which might be somewhat wasteful with memory consumption and execution time and slightly less easy to use methods which require explictly managing LU decomposition.

Pretty much everything only works on square matrices because that's all I've needed so far.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultVec

func MultVec(m *Matrix, v, out []float64)

TODO: test.

func VecMult

func VecMult(v []float64, m *Matrix, out []float64)

TODO: test.

Types

type LUFactors

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

LUFactors contains data fields neccessary for a number of matrix operations. Exporting this type allows calling routines to better manage their memory consumption and to prevent recomputing the same decomposition many times.

func NewLUFactors

func NewLUFactors(n int) *LUFactors

NewLUFactors creates an LUFactors instance of the requested dimensions.

func (*LUFactors) Determinant

func (luf *LUFactors) Determinant() float64

Determinant compute the determinant of of the matrix represented by the given LU decomposition.

func (*LUFactors) InvertAt

func (luf *LUFactors) InvertAt(out *Matrix) *Matrix

InvertAt inverts the matrix represented by the given LU decomposition and writes the results into the specified out matrix.

func (*LUFactors) SolveMatrix

func (luf *LUFactors) SolveMatrix(b, x *Matrix) *Matrix

SolveMatrix solves the equation m * x = b.

x and b may point to the same physical memory.

func (*LUFactors) SolveVector

func (luf *LUFactors) SolveVector(bs, xs []float64) []float64

SolveVector solves M * xs = bs for xs.

bs and xs may poin to the same physical memory.

type LUFactors32

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

LUFactors32 contains data fields neccessary for a number of matrix operations. Exporting this type allows calling routines to better manage their memory consumption and to prevent recomputing the same decomposition many times.

func NewLUFactors32

func NewLUFactors32(n int) *LUFactors32

NewLUFactors32 creates an LUFactors32 instance of the requested dimensions.

func (*LUFactors32) Determinant

func (luf *LUFactors32) Determinant() float32

Determinant compute the determinant of of the matrix represented by the given LU decomposition.

func (*LUFactors32) InvertAt

func (luf *LUFactors32) InvertAt(out *Matrix32) *Matrix32

InvertAt inverts the matrix represented by the given LU decomposition and writes the results into the specified out matrix.

func (*LUFactors32) SolveMatrix

func (luf *LUFactors32) SolveMatrix(b, x *Matrix32) *Matrix32

SolveMatrix solves the equation m * x = b.

x and b may point to the same physical memory.

func (*LUFactors32) SolveVector

func (luf *LUFactors32) SolveVector(bs, xs []float32) []float32

SolveVector solves M * xs = bs for xs.

bs and xs may poin to the same physical memory.

type Matrix

type Matrix struct {
	Vals          []float64
	Width, Height int
}

Matrix represents a matrix of float64 values.

func NewMatrix

func NewMatrix(vals []float64, width, height int) *Matrix

NewMatrix32 creates a matrix with the specified values and dimensions.

func (*Matrix) Determinant

func (m *Matrix) Determinant() float64

Determinant computes the determinant of a matrix.

func (*Matrix) Init

func (m *Matrix) Init(vals []float64, width, height int)

Init initializes a matrix with the specified values and dimensions.

func (*Matrix) Invert

func (m *Matrix) Invert() *Matrix

Invert computes the inverse of a matrix.

func (*Matrix) LU

func (m *Matrix) LU() *LUFactors

LU returns the LU decomposition of a matrix.

func (*Matrix) LUFactorsAt

func (m *Matrix) LUFactorsAt(luf *LUFactors)

LUFactorsAt stores the LU decomposition of a matrix at the specified location.

func (*Matrix) Mult

func (m1 *Matrix) Mult(m2 *Matrix) *Matrix

Mult multiplies two matrices together.

func (*Matrix) MultAt

func (m1 *Matrix) MultAt(m2, out *Matrix) *Matrix

Mult multiplies to matrices together and writes the result to the specified matrix.

func (*Matrix) SolveMatrix

func (m *Matrix) SolveMatrix(b *Matrix) *Matrix

SolveMatrix solves the equation m * x = b for x.

func (*Matrix) SolveVector

func (m *Matrix) SolveVector(bs []float64) []float64

SolveVector solves the equation m * xs = bs for xs.

func (*Matrix) Transpose

func (m *Matrix) Transpose() *Matrix

func (*Matrix) TransposeAt

func (m *Matrix) TransposeAt(out *Matrix)

type Matrix32

type Matrix32 struct {
	Vals          []float32
	Width, Height int
}

Matrix32 represents a matrix of float32 values.

func NewMatrix32

func NewMatrix32(vals []float32, width, height int) *Matrix32

NewMatrix32 creates a matrix with the specified values and dimensions.

func (*Matrix32) Determinant

func (m *Matrix32) Determinant() float32

Determinant computes the determinant of a matrix.

func (*Matrix32) Init

func (m *Matrix32) Init(vals []float32, width, height int)

Init initializes a matrix with the specified values and dimensions.

func (*Matrix32) Invert

func (m *Matrix32) Invert() *Matrix32

Invert computes the inverse of a matrix.

func (*Matrix32) LU

func (m *Matrix32) LU() *LUFactors32

LU returns the LU decomposition of a matrix.

func (*Matrix32) LUFactorsAt

func (m *Matrix32) LUFactorsAt(luf *LUFactors32)

LUFactorsAt stores the LU decomposition of a matrix at the specified location.

func (*Matrix32) Mult

func (m1 *Matrix32) Mult(m2 *Matrix32) *Matrix32

Mult multiplies two matrices together.

func (*Matrix32) MultAt

func (m1 *Matrix32) MultAt(m2, out *Matrix32) *Matrix32

Mult multiplies to matrices together and writes the result to the specified matrix.

func (*Matrix32) SolveMatrix

func (m *Matrix32) SolveMatrix(b *Matrix32) *Matrix32

SolveMatrix solves the equation m * x = b for x.

func (*Matrix32) SolveVector

func (m *Matrix32) SolveVector(bs []float32) []float32

SolveVector solves the equation m * xs = bs for xs.

Jump to

Keyboard shortcuts

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