matrix

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNonPrimeFieldOrder is returned if the field order is nonprime
	ErrNonPrimeFieldOrder = errors.New("non prime field order")
	// ErrNilMatrix is returned if it's a nil matrix
	ErrNilMatrix = errors.New("nil matrix")
	// ErrZeroRows is returned if the number of row of the matrix is zero
	ErrZeroRows = errors.New("zero rows")
	// ErrZeroColumns is returned if the number of column of the matrix is zero
	ErrZeroColumns = errors.New("zero columns")
	// ErrInconsistentColumns is returned if the column rank is inconsistent in this matrix
	ErrInconsistentColumns = errors.New("inconsistent columns")
	// ErrZeroOrNegativeRank is returned if the rank is zero or negative
	ErrZeroOrNegativeRank = errors.New("zero or negative rank")
	// ErrOutOfRange is returned if the index is out of the column or row range
	ErrOutOfRange = errors.New("out of range")
	// ErrInconsistentNumber is returned if the two matrixes are the inconsistent number
	ErrInconsistentNumber = errors.New("inconsistent number")
	// ErrNotSquareMatrix is returned if it's not a square matrix
	ErrNotSquareMatrix = errors.New("not a square matrix")
	// ErrNotInvertableMatrix is returned if it's not an invertable matrix
	ErrNotInvertableMatrix = errors.New("not invertable matrix")
	// ErrMaximalSizeOfMatrice is returned if the number of column or row exceeds the given bound
	ErrMaximalSizeOfMatrice = errors.New("the number of column or row exceeds the given bound")
)

Functions

This section is empty.

Types

type Matrix

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

Matrix is the struct for matrix operation

func NewMatrix

func NewMatrix(fieldOrder *big.Int, matrix [][]*big.Int) (*Matrix, error)

NewMatrix checks the input matrix slices. It returns error if the number of rows or columns is zero or the number of column is inconsistent.

func (*Matrix) Add

func (m *Matrix) Add(matrix *Matrix) (*Matrix, error)

Add adds the matrix The standard addition of Matrices

func (*Matrix) Copy

func (m *Matrix) Copy() *Matrix

Copy returns a copied matrix

func (*Matrix) DeleteColumn

func (m *Matrix) DeleteColumn(nLowerIndex, nUpperIndex uint64) (*Matrix, error)

DeleteColumn deletes the columns from nLowerIndex to nUpperIndex Ex: a_11 a_12 a_13 a_14 a_21 a_22 a_23 a_24 a_31 a_32 a_33 a_34 a_41 a_42 a_43 a_44 Then DeleteRow(1, 2) will gives a_11 a_14 a_21 a_24 a_31 a_34 a_41 a_44

func (*Matrix) DeleteRow

func (m *Matrix) DeleteRow(nLowerIndex, nUpperIndex uint64) (*Matrix, error)

DeleteRow deletes the rows from nLowerIndex to nUpperIndex Ex: a_11 a_12 a_13 a_14 a_21 a_22 a_23 a_24 a_31 a_32 a_33 a_34 a_41 a_42 a_43 a_44 Then DeleteRow(1, 2) will gives a_11 a_12 a_13 a_14 a_41 a_42 a_43 a_44

func (*Matrix) Determinant

func (m *Matrix) Determinant() (*big.Int, error)

Determinant returns the determinant of the matrix

func (*Matrix) Equal

func (m *Matrix) Equal(m2 *Matrix) bool

func (*Matrix) Get

func (m *Matrix) Get(i, j uint64) *big.Int

Get gets the element at (i, j)

func (*Matrix) GetColumn

func (m *Matrix) GetColumn(nIndex uint64) ([]*big.Int, error)

GetColumn gets column at the index Assume matrixA = [ 1, 2, 3 ]

[ 2, 4, 5 ]
[ 5, 10, 3]

Then the output of GetColumn(matrixA, nIndex) is the indicated column. Ex: GetColumn(matrixA, 2)= [3, 5, 3], GetColumn(matrixA, 1)=[2, 4, 10]

func (*Matrix) GetMatrix

func (m *Matrix) GetMatrix() [][]*big.Int

func (*Matrix) GetMatrixRank

func (m *Matrix) GetMatrixRank(fieldOrder *big.Int) (uint64, error)

GetMatrixRank returns the number of linearly independent column over finite field with order fieldOrder. As give the index of rows of a matrix, this function will find nonzero value such that this value has the smallest index of rows.

func (*Matrix) GetNumberColumn

func (m *Matrix) GetNumberColumn() uint64

func (*Matrix) GetNumberRow

func (m *Matrix) GetNumberRow() uint64

func (*Matrix) GetRow

func (m *Matrix) GetRow(nIndex uint64) ([]*big.Int, error)

GetRow gets row at the index Assume matrixA = [ 1, 2, 3 ]

[ 2, 4, 5 ]
[ 5, 10, 3]

Then the output of GetColumn(matrixA, nIndex ) is the indicated row. Ex: GetRow(matrixA, 2)= [5, 10, 3], GetRow(matrixA, 1)=[2, 4, 5]

func (*Matrix) Inverse

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

Inverse gets the inverse matrix

func (*Matrix) IsSquare

func (m *Matrix) IsSquare() bool

IsSquare checks if this matrix is square or not

func (*Matrix) Pseudoinverse

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

Pseudoinverse is the general inverse of non-square matrix. This is a special case of Pseudoinverse. In particular, if the matrix is non-singular and square, then Pseudoinverse is the standard inverse matrix. More details can be found in https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse If m^t*m is invertible. In this case, an explicitly formula is : (m^t*m)^(-1)*m^t. TODO: This function only works under the following conditions: - the columns of m are linearly independent - row rank >= column rank

func (*Matrix) Transpose

func (m *Matrix) Transpose() *Matrix

Transpose transposes the matrix This function give the transpose of input. Ex: A =[ 1, 2 ] (i.e. 1X2 matrix) output is [ 1 ] (i.e. 2X1 matrix)

[ 2 ]

Jump to

Keyboard shortcuts

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