matlib

package module
v0.0.0-...-9648482 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2016 License: MIT Imports: 8 Imported by: 1

README

#matlib matlib is a small package for the creation and testing of matrices for openLCA. It uses the high performance math library OpenBLAS.

Usage

Checkout this repository:

git clone https://github.com/GreenDelta/matlib.git

Build the native library for native library for your system as described in native/Build_<your_os>.md.

File format

This package provides methods for loading (goblapack.Load) and saving (goblapack.Save) matrices from files in a simple binary format:

header 8 bytes
4 bytes: uint32, number of rows, little endian order
4 bytes: uint32, number of columns, little endian order

content, rows * columns * 8 bytes:
matrix data, float64, little endian and column major order

Here is a small Python script for writing a Numpy matrix in this format:

    m = numpy.load('path/to/file.npy')
    rows, cols = m.shape
    with open('path/to/file.bin', 'wb') as f:
      f.write(struct.pack("<i", rows))
      f.write(struct.pack("<i", cols))
      for col in range(0, cols):
        for row in range(0, rows):
          val = m[row, col]
          f.write(struct.pack("<d", val))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadColumn

func LoadColumn(file string, column int) ([]float64, error)

LoadColumn reads the given (zero-based) column from the given matrix file.

func Save

func Save(m *Matrix, file string) error

Save writes the matrix to the given file.

Types

type Matrix

type Matrix struct {
	Rows int
	Cols int
	Data []float64
}

Matrix is a dense matrix structure that holds the data in column-major order in a linear array. Because of this lay

func Eye

func Eye(size int) *Matrix

Eye returns the identity matrix of the given size.

func Load

func Load(file string) (*Matrix, error)

Load reads a matrix from the given file.

func MakeMatrix

func MakeMatrix(data [][]float64) *Matrix

MakeMatrix is a convenience function for creating a matrix from a 2 dimensional float slice. It is mainly used for testing purposes.

func Zeros

func Zeros(rows, cols int) *Matrix

Zeros creates a new matrix with all values as 0 of the give size.

func (*Matrix) Copy

func (m *Matrix) Copy() *Matrix

Copy creates a copy of the matrix.

func (*Matrix) Get

func (m *Matrix) Get(row, col int) float64

Get returns the value at the given row and column.

func (*Matrix) GetPtr

func (m *Matrix) GetPtr(row, col int) *float64

GetPtr returns a pointer to the matrix cell with the given row and column.

func (*Matrix) Invert

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

Invert calculates the inverse of the matrix.

func (*Matrix) InvertInPlace

func (m *Matrix) InvertInPlace() error

InvertInPlace calculates the inverse of the matrix which is stored directly in the original matrix.

func (*Matrix) Multiply

func (m *Matrix) Multiply(b *Matrix) (*Matrix, error)

Multiply calculates the matrix-matrix-product C = A * B where A is the matrix on which the method is called, B the method parameter, and C the return value.

func (*Matrix) Set

func (m *Matrix) Set(row, col int, value float64)

Set sets the matrix cell at the given row and column to the given value.

func (*Matrix) Subtract

func (m *Matrix) Subtract(b *Matrix) (*Matrix, error)

Subtract calculates A - B = C where A is the matrix on which this method is called, B the method parameter, and C the return value. The matrix B can be smaller as A; C will have the same size as A.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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