mat

package module
v0.0.0-...-451632e Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2018 License: Apache-2.0 Imports: 5 Imported by: 5

README

mat

A simple to use, not ready for production, matrix package

Documentation

Overview

The mat package provides an implementation of matrices and vectors that is completely immutable and focused on exposing a nice API rather than going for high performance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals

func Equals(a, b Matrix) bool

Equals returns whether two matrices are identical.

func Sum

func Sum(m Matrix) float64

Sum returns the sum of all of the elements in the matrix.

Types

type Matrix

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

Matrix is optimized for dense matrices.

func BlasProduct

func BlasProduct(a, b Matrix) Matrix

BlasProduct returns the product of two matrices performed with blas.

func ConcatenateCols

func ConcatenateCols(ms ...Matrix) Matrix

ConcatenateCols returns a matrix that contains the values of all of the given matrices side by side. All of the matrices need to have the same number of rows. The resulting matrix has as many columns as all of the given matrices combined, and as many rows as each one of them.

func ConcatenateRows

func ConcatenateRows(ms ...Matrix) Matrix

ConcatenateRows returns a matrix that contains the values of all of the given matrices stacked verticaly. All of the matrices need to have the same number of columns. The resulting matrix has as many rows as all of the given matrices combined, and as many cols as each one of them.

func Dot

func Dot(a, b Matrix) Matrix

Dot returns the dot product of two matrices.

func FromFunc

func FromFunc(rows, cols int, f func(i, j int) float64) Matrix

FromFunc returns a new Matrix with the contents initialized by calling f.

func FromSlice

func FromSlice(rows, cols int, data []float64) Matrix

FromSlice returns a new Matrix with the contents of the given slice.

func Map

func Map(f func(float64) float64, m Matrix) Matrix

Map returns a new Matrix where each value is the result of calling f with the value of that position in the original matrix.

func Minus

func Minus(a, b Matrix) Matrix

Minus returns the difference of the two matrices.

func New

func New(rows, cols int) Matrix

New returns a new matrix with the given dimensions and where all cells are zero.

func ParallelProduct

func ParallelProduct(a, b Matrix) Matrix

ParallelProduct returns the product of two matrices performed in parallel.

func Plus

func Plus(a, b Matrix) Matrix

Plus returns the sum of the two matrices.

func Product

func Product(a, b Matrix) Matrix

Product returns the product of two matrices.

func (Matrix) AddScalar

func (m Matrix) AddScalar(x float64) Matrix

AddScalar adds the given scalar to every cell in the receiver matrix.

func (Matrix) Apply

func (m Matrix) Apply(f func(i, j int) float64)

func (Matrix) At

func (m Matrix) At(i, j int) float64

At returns the value of the cell at the given position. It panics if the position is not valid.

func (Matrix) Clone

func (m Matrix) Clone() Matrix

Clone returns a copy of the current Matrix.

func (Matrix) Cols

func (m Matrix) Cols() int

Cols returns the number of cols in the matrix.

func (Matrix) FilterRows

func (m Matrix) FilterRows(f func(i int) bool) Matrix

FilterRows returns a matrix where only the rows with an index for which f returns true have been kept.

func (Matrix) Reduce

func (m Matrix) Reduce(zero float64, f func(x, cum float64) float64) float64

Reduce provides a functional way of reducing a function over the whole matrix. For instance: sum can be implemented as:

m.Reduce(0, func(x, cum float64) float64 {return x+cum})

func (Matrix) Rows

func (m Matrix) Rows() int

Rows returns the number of rows in the matrix.

func (Matrix) Scale

func (m Matrix) Scale(x float64) Matrix

Scale multiplies the receiver matrix by the given scalar.

func (Matrix) Set

func (m Matrix) Set(i, j int, x float64) Matrix

Set sets the value of the cell at the given position. It panics if the position is not valid.

func (Matrix) SliceCols

func (m Matrix) SliceCols(from, to int) Matrix

SliceCols returns a new matrix that contains only the columns in between from and to, without including to. Similar to slice[from:to].

func (Matrix) SliceRows

func (m Matrix) SliceRows(from, to int) Matrix

SliceRows returns a new matrix that contains only the rows in between from and to, without including to. Similar to slice[from:to].

func (Matrix) String

func (m Matrix) String() string

func (Matrix) Sum

func (m Matrix) Sum() float64

Sum returns the sum of all of the elements in the matrix.

func (Matrix) T

func (m Matrix) T() Matrix

T returns the transposed matrix.

func (Matrix) ToSlice

func (m Matrix) ToSlice() []float64

Jump to

Keyboard shortcuts

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