v3

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: LGPL-2.1 Imports: 6 Imported by: 14

Documentation

Overview

Package v3 implements a Matrix type representing a row-major 3D matrix (i.e. a Nx3 matrix). The v3.Matrix is used to represent the cartesian coordinates of sets of atoms in goChem. It is based int gonum's (github.com/gonum) Dense type, with some additional restrictions because of the fixed number of columns and with some additional functions that were found useful for the purposes of goChem.

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

Types

type Error

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

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 {
	*mat.Dense
}

The main container, must be able to implement any gonum interface. 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 funcitions in the library reflect this.

func Dense2Matrix

func Dense2Matrix(A *mat.Dense) *Matrix

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)

Generate and returns a Matrix with 3 columns from data.

func Zeros

func Zeros(vecs int) *Matrix

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

func (*Matrix) Add

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

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)

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

Puts a view of the given col of the matrix on the receiver

func (*Matrix) ColView

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

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

func (*Matrix) DelVec

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

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

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

Mul Wrapps 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

return the number of vecs in F.

func (*Matrix) Norm

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

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

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

Puts a view of the given row of the matrix in the receiver

func (*Matrix) Scale

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

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, Row *Matrix)

ScaleByRow scales each column of matrix A by row, putting the result in the received.

func (*Matrix) ScaleByVec

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

Scale each coordinates in A by the coordinate in coord. The result is put in F.

func (*Matrix) SetMatrix

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

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

Set the vectors whith index n = each value on clist, in the received to the n vector of A.

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 all the ith rows of matrix A, where i are the numbers in clist. The rows are in the same order than the clist.

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)

puts A stacked over B in F

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)

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)

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

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

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

Returns view of the given 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