v3

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: LGPL-2.1 Imports: 6 Imported by: 12

Documentation

Index

Constants

View Source
const (
	ErrNotXx3Matrix      = PanicMsg("goChem/v3: A VecMatrix should have 3 columns")
	ErrNoCrossProduct    = PanicMsg("goChem/v3: Invalid matrix for cross product")
	ErrNotOrthogonal     = PanicMsg("goChem/v3: Vectors nor orthogonal")
	ErrNotEnoughElements = PanicMsg("goChem/v3: not enough elements in Matrix")
	ErrGonum             = PanicMsg("goChem/v3: Error in gonum function")
	ErrEigen             = PanicMsg("goChem/v3: Can't obtain eigenvectors/eigenvalues of given matrix")
	ErrDeterminant       = PanicMsg("goChem/v3: Determinants are only available for 3x3 matrices")
	ErrShape             = PanicMsg("goChem/v3: Dimension mismatch")
	ErrIndexOutOfRange   = PanicMsg("mat64: index out of range")
)

Variables

This section is empty.

Functions

func KronekerDelta

func KronekerDelta(a, b, epsilon float64) float64

KronekerDelta is a naive implementation of the kroneker delta function.

func Matrix2Dense

func Matrix2Dense(A *Matrix) *mat.Dense

Matrix2Dense returns the A Gonum Dense matrix associated with A. Changes in one will be reflected in t he other

Types

type Error

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

Error is an error on the v3 package. Compatible with goChem

func (Error) Critical

func (err Error) Critical() bool

Critical return whether the error is critical or it can be ifnored

func (Error) Decorate

func (err Error) Decorate(dec string) []string

Decorate will add the dec string to the decoration slice of strings of the error, and return the resulting slice.

func (Error) Error

func (err Error) Error() string

Error returns a string with an error message.

type Matrix

type Matrix struct {
	//The main container, must be able to implement most
	//gonum interfaces
	*mat.Dense
}

Matrix is a set of vectors in 3D space. The underlying implementation varies. Within the package it is understood that a "vector" is a row vector, i.e. the cartesian coordinates of a point in 3D space. The name of some functions in the library reflect this.

func Dense2Matrix

func Dense2Matrix(A *mat.Dense) *Matrix

Dense2Matrix returns a *v3.Matrix from a Gonum dense matrix, which has to be Nx3

func EigenWrap

func EigenWrap(in *Matrix, epsilon float64) (*Matrix, []float64, error)

EigenWrap wraps the mat.Eigen structure in order to guarantee That the eigenvectors and eigenvalues are sorted according to the eigenvalues It also guarantees orthonormality and handness. I don't know how many of these are already guaranteed by Eig(). Will delete the unneeded parts And even this whole function when sure. The main reason for this function Is the compatibiliy with go.matrix. This function should dissapear when we have a pure Go blas.

func NewMatrix

func NewMatrix(data []float64) (*Matrix, error)

NewMatrix creates and returns a Matrix with 3 columns from data.

func Zeros

func Zeros(vecs int) *Matrix

Zeros returns a zero-filled Matrix with vecs vectors and 3 in the other dimension.

func (*Matrix) Add

func (F *Matrix) Add(A, B *Matrix)

Add puts the element-wise addition of matrices A and B into the receiver

func (*Matrix) AddFloat

func (F *Matrix) AddFloat(A *Matrix, B float64)

AddFloat puts in the receiver a matrix which elements are those of matrix A plus the float B.

func (*Matrix) AddRow

func (F *Matrix) AddRow(A, row *Matrix)

AddRow adds the row vector row to each row of the matrix A, putting the result on the receiver. Panics if matrices are mismatched. It will not work if A and row reference to the same Matrix.

func (*Matrix) AddVec

func (F *Matrix) AddVec(A, vec *Matrix)

AddVec adds a vector to the coordmatrix A putting the result on the received. depending on whether the underlying matrix to coordmatrix is col or row major, it could add a col or a row vector.

func (*Matrix) Col

func (F *Matrix) Col(dst []float64, i int) []float64

Col fills the dst slice of float64 with the ith col of matrix F and returns it. The slice must have the correct size or be nil, in which case a new slice will be created. This method is merely a frontend for the mat64.Col function of gonum.

func (*Matrix) ColSlice

func (F *Matrix) ColSlice(i int) *Matrix

ColSlice puts a view of the given col of the matrix on the receiver

func (*Matrix) ColView

func (F *Matrix) ColView(i int) *Matrix

ColView a view of the given col of the matrix on the receiver. This function is for compatibility with the gonum v1 API The older one might be deleted in the future, but, if at all, it will take time.

func (*Matrix) Cross

func (F *Matrix) Cross(a, b *Matrix)

Cross puts the cross product of the first vecs of a and b in the first vec of F. Panics if error.

func (*Matrix) DelRow

func (F *Matrix) DelRow(A *Matrix, i int)

DelRow deletes a row in matrix A, placing the results in the receiver. Equivalent to DelVec for compatibility.

func (*Matrix) DelVec

func (F *Matrix) DelVec(A *Matrix, i int)

DelVec deletes a (row) vector in matrix A, placing the results in the receiver.

func (*Matrix) Dot

func (F *Matrix) Dot(A *Matrix) float64

Dot gets the dot product between the first row of F and the first row of A. It's a vector dot product, to be used with 1-row matrices.

func (*Matrix) Len added in v0.6.3

func (F *Matrix) Len() int

Len return the number of (row) vectors in F. Equivalent to NVecs, but more in line with Go APIS.

func (*Matrix) Mul

func (F *Matrix) Mul(A, B mat.Matrix)

Mul Wraps mat.Mul to take care of the case when one of the arguments is also the received. Since the received is a Matrix, the mat64 function could check A (mat64.Dense) vs F (Matrix) and it would not know that internally F.Dense==A, hence the need for this function.

func (*Matrix) NVecs

func (F *Matrix) NVecs() int

NVecs return the number of (row) vectors in F.

func (*Matrix) Norm

func (F *Matrix) Norm(i float64) float64

Norm acts as a front-end for the mat64 function.

func (*Matrix) RawSlice added in v0.6.0

func (F *Matrix) RawSlice() []float64

RawSlice returns the underlying []float64 slice for the receiver. Changes on either the []float64 or the receiver are expected to reflect on the other.

func (*Matrix) Row

func (F *Matrix) Row(dst []float64, i int) []float64

Row fills the dst slice of float64 with the ith row of matrix F and returns it. The slice must have the correct size or be nil, in which case a new slice will be created. This method is merely a frontend for the mat64.Row function of gonum.

func (*Matrix) RowView

func (F *Matrix) RowView(i int) *Matrix

RowView puts a view of the given row of the matrix in the receiver Equivalent to VecView

func (*Matrix) Scale

func (F *Matrix) Scale(v float64, A *Matrix)

Scale multiplies each element in the matrix A by v

func (*Matrix) ScaleByCol

func (F *Matrix) ScaleByCol(A, Col mat.Matrix)

ScaleByCol scales each column of matrix A by Col, putting the result in the received.

func (*Matrix) ScaleByRow

func (F *Matrix) ScaleByRow(A, coord *Matrix)

ScaleByRow scales each coordinates in the A by the coordinate in the row-vector coord. The result is put in F. This is the old name fo the function, now called ScaleByVec. It is kept for compatibility

func (*Matrix) ScaleByVec

func (F *Matrix) ScaleByVec(A, Vec *Matrix)

ScaleByVec scales each column of matrix A by Vec, putting the result in the received.

func (*Matrix) SetMatrix

func (F *Matrix) SetMatrix(i, j int, A *Matrix)

SetMatrix the matrix A in the received starting from the ith row and jth col of the receiver.

func (*Matrix) SetVecs

func (F *Matrix) SetVecs(A *Matrix, clist []int)

SetVecs sets the vector F[clist[i]] to the vector A[i], for all indexes i in clist. nth vector of A. Indexes i must be positive or 0

func (*Matrix) Slice

func (F *Matrix) Slice(i, r, j, c int) *Matrix

Slice returns a view of F starting from i,j and spanning r rows and c columns. Changes in the view are reflected in F and vice-versa This function is to keep compatibility with the gonum v1 API.

func (*Matrix) SomeVecs

func (F *Matrix) SomeVecs(A *Matrix, clist []int)

SomeVecs Returns a matrix contaning a copy of the ith rows of matrix A, where i are the numbers in clist. The rows are in the same order than the clist. The numbers in clist must be positive or zero.

func (*Matrix) SomeVecsSafe

func (F *Matrix) SomeVecsSafe(A *Matrix, clist []int) error

SomeVecsSafe returns a matrix contaning all the ith vectors of matrix A, where i are the numbers in clist. The vectors are in the same order than the clist. It will try to recover so it returns an error instead of panicking.

func (*Matrix) Stack

func (F *Matrix) Stack(A, B *Matrix)

Stack puts A stacked over B in the receiver

func (*Matrix) StackVec

func (F *Matrix) StackVec(A, B *Matrix)

StackVec puts in F a matrix consistent of A over B or A to the left of B.

func (*Matrix) String

func (F *Matrix) String() string

String returns a neat string representation of a Matrix

func (*Matrix) Sub

func (F *Matrix) Sub(A, B *Matrix)

Sub puts the element-wise subtraction of matrices A and B into the receiver

func (*Matrix) SubRow

func (F *Matrix) SubRow(A, row *Matrix)

SubRow subtracts the row vector row to each row of the matrix A, putting the result on the receiver. Panics if matrices are mismatched. It will not work if A and row reference to the same Matrix.

func (*Matrix) SubVec

func (F *Matrix) SubVec(A, vec *Matrix)

SubVec subtracts the vector to each vector of the matrix A, putting the result on the receiver. Panics if matrices are mismatched. It will not work if A and row reference to the same Matrix.

func (*Matrix) SwapVecs

func (F *Matrix) SwapVecs(i, j int)

SwapVecs swaps the vectors i and j in the receiver

func (*Matrix) Tr

func (F *Matrix) Tr()

Tr performs an explicit, in-place tranpose of the receiver. it relies in the fact that v3 matrix are all 3D. If the receiver has more than 3 rows, the square submatrix of the first 3 rows will be transposed (i.e. no panic or returned error). it panics if the receiver has less than 3 rows.

func (*Matrix) TrRet added in v0.7.0

func (F *Matrix) TrRet() *Matrix

Returns the transpose of F. Does not modify F.

func (*Matrix) Unit

func (F *Matrix) Unit(A *Matrix)

Unit puts in the receiver the unit vector pointing in the same direction as the vector A (A divided by its norm).

func (*Matrix) VecSlice

func (F *Matrix) VecSlice(i int) *Matrix

VecSlice slice of the given vector of the matrix in the receiver This function is to keep compatibility with the new gonum v1 API

func (*Matrix) VecView

func (F *Matrix) VecView(i int) *Matrix

VecView eturns view of the ith vector of the matrix in the receiver

func (*Matrix) View

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

View returns a view of F starting from i,j and spanning r rows and c columns. Changes in the view are reflected in F and vice-versa This view has the wrong signature for the interface mat64.Viewer, But the right signatur was not possible to implement. Notice that very little memory allocation happens, only a couple of ints and pointers.

type PanicMsg

type PanicMsg string

PanicMsg is a message used for panics, even though it does satisfy the error interface. for errors use Error.

func (PanicMsg) Error

func (v PanicMsg) Error() string

Jump to

Keyboard shortcuts

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