gomatrix

package module
v0.0.0-...-5799be8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: MIT Imports: 3 Imported by: 0

README

gomatrix

GoDoc pipeline status coverage report Go Report Card License MIT

A go package for scientific matrix operations.

TODO

  • F_2 matrix implementation
    • Create matrix
    • Set values to matrix
    • AddMatrix
    • MulMatrix
    • InvertMatrix
    • Partial gauss
    • Transpose
    • Permute (cols)
  • More todos...

Documentation

Overview

Package gomatrix Is a go package for scientific operations with matrices in F2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PartialXor

func PartialXor(x, y *big.Int, startCol, stopCol int) *big.Int

PartialXor xor's the bits from startCol to stopCol

@param *big.Int x The base number to xor @param *big.Int y The number with the bits to xor @param int startCol The start index of the bit mask @param int stopCol The stop index of the bit mask

@return *big.Int

Types

type F2

type F2 struct {
	N    int
	M    int
	Rows []*big.Int
}

F2 represents a matrix with entries that contains 0 or 1

Each row consists of one big Int with arbitrary size. Each column is one bit at 2**(column_index) of the big Int in each row.

func NewF2

func NewF2(n, m int) *F2

NewF2 creates a new matrix in F_2

@param int n The count of rows @param int m The count of columns

@return *F2

func (*F2) AddMatrix

func (f *F2) AddMatrix(m *F2) *F2

AddMatrix adds two matrices

This function adds a matrix to the matrix object. The result will be saved in the object, whose AddMatrix method was called.

@param *F2 m The matrix to add

@return *F2|nil

func (*F2) At

func (f *F2) At(i, j int) (int, error)

At returns the value at index i, j

@param int i The row index @param int j The column index

@return int, error|nil

func (*F2) CheckGaussian

func (f *F2) CheckGaussian(startRow, startCol, n int) bool

CheckGaussian checks if the given range in the matrix is the identity matrix

@param int startRow The row where the check starts @param int startCol The column where the check starts @param int n The size of the submatrix to check

@return bool

func (*F2) GaussianElimination

func (f *F2) GaussianElimination()

GaussianElimination converts the matrix to an echelon form

This function applies the gaussian elimination to the matrix in order to create an echelon form.

func (*F2) GetCol

func (f *F2) GetCol(i int) *big.Int

GetCol returns the column at index i

This function returns the column as big.Int after the index is verified. If an invalid index is used, the function returns nil.

@param int i The index for the column

@return *big.Int

func (*F2) GetSubMatrix

func (f *F2) GetSubMatrix(startRow, startCol, stopRow, stopCol int) *F2

GetSubMatrix gets the submatrix with boundaries included

@param int startRow The first row to include @param int startCol The first column to include @param int stopRow The last row to include @param int stopCol The last column to include

func (*F2) IsEqual

func (f *F2) IsEqual(m *F2) bool

IsEqual checks the equality of the matrix objects

This function compares the values of the matrix that is given with the matrix whose function is called.

@param *F2 m The matrix to compare with

@return bool

func (*F2) MulMatrix

func (f *F2) MulMatrix(m *F2) *F2

MulMatrix multiplies matrix f with matrix m

This functions multiplies matrix fxm. M could be a Nx1 matrix for a vector. If the matrices cannot be multiplied, nil is returned and f is not modified. If the multiplication was successful, the result is stored in f and returned.

@param *F2 m The matrix that is used for the multiplication

@return *F2

func (*F2) PartialGaussianElimination

func (f *F2) PartialGaussianElimination(startRow, startCol, stopRow, stopCol int)

PartialGaussianElimination performs a gaussian elimination on a part of the matrix

func (*F2) PartialGaussianWithLinearChecking

func (f *F2) PartialGaussianWithLinearChecking(
	startRow int,
	startCol int,
	stopRow int,
	stopCol int,
	linearCheck func(*F2, *F2, *F2, int, int, int, int, int) (*F2, *F2, error),
) (*F2, *F2, error)

PartialGaussianWithLinearChecking performs a partial gaussian elimination

This function performs a gaussian elimination on the matrix and calls the check callback after each iteration in order to verify that linear dependencies in the code could be resolved easily. The function returns the permutation matrix in addition to the error. For the linearCheck callback take a look at the resolver package.

func (*F2) PartialT

func (f *F2) PartialT(startRow, startCol, n int) error

PartialT partially transpose the matrix

This function partially transposes a matrix. The submatrix that is transposed need to be a square matrix.

@param int startRow The row to start @param int startCol The column to start @param int n The size of the submatrix

@return error

func (*F2) PermuteCols

func (f *F2) PermuteCols() *F2

PermuteCols permutes the columns of the matrix randomly

This function swaps columns randomly. The swap operation will be repeated on every column. After swapping the columns, the permutation matrix will be returned.

@return *F2

func (*F2) PrettyPrint

func (f *F2) PrettyPrint()

PrettyPrint prints the matrix to stdout

func (*F2) PrintCSV

func (f *F2) PrintCSV()

PrintCSV prints the matrix as csv

func (*F2) PrintLaTex

func (f *F2) PrintLaTex()

PrintLaTex prints the matrix as latex code

func (*F2) PrintSlim

func (f *F2) PrintSlim()

PrintSlim prints the matrix without whitespaces to stdout

func (*F2) Set

func (f *F2) Set(data []*big.Int) *F2

Set sets data from the data array

@param []*big.Int data The data to insert into the matrix

@return *F2|nil

func (*F2) SetSubMatrix

func (f *F2) SetSubMatrix(m *F2, startRow, startCol int) (*F2, error)

SetSubMatrix sets the submatrix into the current matrix

@param *F2 m The submatrix to use @param int startRow The first row to replace @param int startCol The first column to replace

@return *F2, error

func (*F2) SetToIdentity

func (f *F2) SetToIdentity() *F2

SetToIdentity sets the matrix to the identity matrix

This function sets the identity matrix into f. If f is a non square matrix, the remaining rows/columns will be set to 0.

func (*F2) SwapCols

func (f *F2) SwapCols(i, j int) error

SwapCols swaps the columns at index i with the row at index j

@param int i The index of the first columns to swap @param int j The index of the second columns to swap

@return error

func (*F2) SwapRows

func (f *F2) SwapRows(i, j int) error

SwapRows swaps the row at index i with the row at index j

@param int i The index of the first row to swap @param int j The index of the second row to swap

@return error

func (*F2) T

func (f *F2) T() *F2

T transposes matrix f

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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