graphblas

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

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 8 Imported by: 4

README

GraphBLAS

Go Go Report Card Read the Docs

A sparse linear algebra library implementing may of the ideas from the GraphBLAS Forum in Go.

Sparse Matrix Formats: Compressed Sparse Row (CSR) Compressed Sparse Column (CSC) Sparse Vector

Supports bool | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64

array := [][]float64{
		[]float64{0, 0, 0, 1, 0, 0, 0},
		[]float64{1, 0, 0, 0, 0, 0, 0},
		[]float64{0, 0, 0, 1, 0, 1, 1},
		[]float64{1, 0, 0, 0, 0, 0, 1},
		[]float64{0, 1, 0, 0, 0, 0, 1},
		[]float64{0, 0, 1, 0, 1, 0, 0},
		[]float64{0, 1, 0, 0, 0, 0, 0},
    }

g := graphblas.NewDenseMatrixFromArrayN(array)

atx := breadthfirst.Search[float64](context.Background(), g, 3, func(i graphblas.Vector[float64]) bool {
    return i.AtVec(5) == 1
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[T constraints.Number](ctx context.Context, s, m Matrix[T], mask Mask, matrix Matrix[T])

Add addition of a matrix by another matrix

func Apply

func Apply[T constraints.Number](ctx context.Context, in Matrix[T], mask Mask, u unaryop.UnaryOp[T], matrix Matrix[T])

Apply modifies edge weights by the UnaryOperator

C ⊕= f(A)

func Compare

func Compare(ctx context.Context, s, m MatrixLogical[rune]) int

Compare returns an integer comparing two matrices lexicographically.

func Default

func Default[T any]() T

func DefaultMonoIDAddition

func DefaultMonoIDAddition[T constraints.Number]() binaryop.MonoID[T]

func DefaultMonoIDMaximum

func DefaultMonoIDMaximum[T constraints.Number]() binaryop.MonoID[T]

func ElementWiseMatrixAdd

func ElementWiseMatrixAdd[T constraints.Number](ctx context.Context, s, m Matrix[T], mask Mask, matrix Matrix[T])

ElementWiseMatrixAdd Element-wise addition on a matrix

eWiseMult

func ElementWiseMatrixMultiply

func ElementWiseMatrixMultiply[T constraints.Number](ctx context.Context, s, m Matrix[T], mask Mask, matrix Matrix[T])

ElementWiseMatrixMultiply Element-wise multiplication on a matrix

eWiseMult

func ElementWiseVectorAdd

func ElementWiseVectorAdd[T constraints.Number](ctx context.Context, s, m Vector[T], mask Mask, vector Vector[T])

ElementWiseVectorAdd Element-wise addition on a vector

eWiseMult

func ElementWiseVectorMultiply

func ElementWiseVectorMultiply[T constraints.Number](ctx context.Context, s, m Vector[T], mask Mask, vector Vector[T])

ElementWiseVectorMultiply Element-wise multiplication on a vector

eWiseMult

func Equal

func Equal[T constraints.Type](ctx context.Context, s, m MatrixLogical[T]) bool

Equal the two matrices are equal

func Greater

func Greater(ctx context.Context, s, m MatrixLogical[rune]) bool

func IsSparseMatrix

func IsSparseMatrix[T constraints.Type](s MatrixLogical[T]) bool

IsSparseMatrix is 's' a sparse matrix

func IsZero

func IsZero[T comparable](v T) bool

func Less

func Less(ctx context.Context, s, m MatrixLogical[rune]) bool

func MatrixMatrixMultiply

func MatrixMatrixMultiply[T constraints.Number](ctx context.Context, s, m Matrix[T], mask Mask, matrix Matrix[T])

MatrixMatrixMultiply multiplies a matrix by another matrix

mxm

func MatrixVectorMultiply

func MatrixVectorMultiply[T constraints.Number](ctx context.Context, s Matrix[T], m Vector[T], mask Mask, vector Vector[T])

MatrixVectorMultiply multiplies a matrix by a vector

mxv

func Negative

func Negative[T constraints.Number](ctx context.Context, s Matrix[T], mask Mask, matrix Matrix[T])

Negative the negative of a matrix

func NewContext

func NewContext(ctx context.Context, mode Mode) context.Context

NewContext returns a Context

func NotEqual

func NotEqual[T constraints.Type](ctx context.Context, s, m MatrixLogical[T]) bool

NotEqual the two matrices are not equal

func ReduceMatrixToScalar

func ReduceMatrixToScalar[T constraints.Number](ctx context.Context, s MatrixLogical[T], mask Mask) T

ReduceMatrixToScalar perform's a reduction on the Matrix

func ReduceMatrixToScalarWithMonoID

func ReduceMatrixToScalarWithMonoID[T constraints.Number](ctx context.Context, s MatrixLogical[T], monoID binaryop.MonoID[T], mask Mask) T

ReduceMatrixToScalarWithMonoID perform's a reduction on the Matrix monoid used in the element-wise reduction operation

func ReduceVectorToScalar

func ReduceVectorToScalar[T constraints.Number](ctx context.Context, s VectorLogial[T], mask Mask) T

ReduceVectorToScalar perform's a reduction on the Matrix

func ReduceVectorToScalarWithMonoID

func ReduceVectorToScalarWithMonoID[T constraints.Number](ctx context.Context, s VectorLogial[T], monoID binaryop.MonoID[T], mask Mask) T

ReduceVectorToScalarWithMonoID perform's a reduction on the Matrix monoid used in the element-wise reduction operation

func RegisterMatrix

func RegisterMatrix(matrix reflect.Type)

RegisterMatrix add's the sparse matrix to the registry

func String

func String(ctx context.Context, s MatrixLogical[rune]) string

func Subtract

func Subtract[T constraints.Number](ctx context.Context, s, m Matrix[T], mask Mask, matrix Matrix[T])

Subtract subtracts one matrix from another matrix

func Transpose

func Transpose[T constraints.Type](ctx context.Context, s MatrixLogical[T], mask Mask, matrix MatrixLogical[T])

Transpose swaps the rows and columns

C ⊕= Aᵀ

func VectorMatrixMultiply

func VectorMatrixMultiply[T constraints.Number](ctx context.Context, s Vector[T], m Matrix[T], mask Mask, vector Vector[T])

VectorMatrixMultiply multiplies a vector by a matrix

vxm

func Zero

func Zero[T any]() T

Types

type CSCMatrix

type CSCMatrix[T constraints.Number] struct {
	// contains filtered or unexported fields
}

CSCMatrix compressed storage by columns (CSC)

func NewCSCMatrix

func NewCSCMatrix[T constraints.Number](r, c int) *CSCMatrix[T]

NewCSCMatrix returns a CSCMatrix

func NewCSCMatrixFromArray

func NewCSCMatrixFromArray[T constraints.Number](data [][]T) *CSCMatrix[T]

NewCSCMatrixFromArray returns a CSCMatrix

func (*CSCMatrix[T]) Add

func (s *CSCMatrix[T]) Add(m Matrix[T]) Matrix[T]

Add addition of a matrix by another matrix

func (*CSCMatrix[T]) At

func (s *CSCMatrix[T]) At(r, c int) (value T)

At returns the value of a matrix element at r-th, c-th

func (*CSCMatrix[T]) Clear

func (s *CSCMatrix[T]) Clear()

Clear removes all elements from a matrix

func (*CSCMatrix[T]) Columns

func (s *CSCMatrix[T]) Columns() int

Columns the number of columns of the matrix

func (*CSCMatrix[T]) ColumnsAt

func (s *CSCMatrix[T]) ColumnsAt(c int) VectorLogial[T]

ColumnsAt return the columns at c-th

func (*CSCMatrix[T]) Copy

func (s *CSCMatrix[T]) Copy() Matrix[T]

func (*CSCMatrix[T]) CopyLogical

func (s *CSCMatrix[T]) CopyLogical() MatrixLogical[T]

Copy copies the matrix

func (*CSCMatrix[T]) Element

func (s *CSCMatrix[T]) Element(r, c int) (b bool)

Element of the mask for each tuple that exists in the matrix for which the value of the tuple cast to Boolean is true

func (*CSCMatrix[T]) Enumerate

func (s *CSCMatrix[T]) Enumerate() Enumerate[T]

Enumerate iterates through all non-zero elements, order is not guaranteed

func (*CSCMatrix[T]) Equal

func (s *CSCMatrix[T]) Equal(m MatrixLogical[T]) bool

Equal the two matrices are equal

func (*CSCMatrix[T]) Map

func (s *CSCMatrix[T]) Map() Map[T]

Map replace each element with the result of applying a function to its value

func (*CSCMatrix[T]) Multiply

func (s *CSCMatrix[T]) Multiply(m Matrix[T]) Matrix[T]

Multiply multiplies a matrix by another matrix

func (*CSCMatrix[T]) Negative

func (s *CSCMatrix[T]) Negative() MatrixLogical[T]

Negative the negative of a matrix

func (*CSCMatrix[T]) NotEqual

func (s *CSCMatrix[T]) NotEqual(m MatrixLogical[T]) bool

NotEqual the two matrices are not equal

func (*CSCMatrix[T]) Rows

func (s *CSCMatrix[T]) Rows() int

Rows the number of rows of the matrix

func (*CSCMatrix[T]) RowsAt

func (s *CSCMatrix[T]) RowsAt(r int) VectorLogial[T]

RowsAt return the rows at r-th

func (*CSCMatrix[T]) RowsAtToArray

func (s *CSCMatrix[T]) RowsAtToArray(r int) []T

RowsAtToArray return the rows at r-th

func (*CSCMatrix[T]) Scalar

func (s *CSCMatrix[T]) Scalar(alpha T) Matrix[T]

Scalar multiplication of a matrix by alpha

func (*CSCMatrix[T]) Set

func (s *CSCMatrix[T]) Set(r, c int, value T)

Set sets the value at r-th, c-th of the matrix

func (*CSCMatrix[T]) SetReturnPointer

func (s *CSCMatrix[T]) SetReturnPointer(r, c int, value T) (pointer int, start int)

func (*CSCMatrix[T]) Size

func (s *CSCMatrix[T]) Size() int

Size of the matrix

func (*CSCMatrix[T]) Subtract

func (s *CSCMatrix[T]) Subtract(m Matrix[T]) Matrix[T]

Subtract subtracts one matrix from another matrix

func (*CSCMatrix[T]) Transpose

func (s *CSCMatrix[T]) Transpose() MatrixLogical[T]

Transpose swaps the rows and columns

func (*CSCMatrix[T]) Update

func (s *CSCMatrix[T]) Update(r, c int, f func(T) T)

Update does a At and Set on the matrix element at r-th, c-th

func (*CSCMatrix[T]) UpdateReturnPointer

func (s *CSCMatrix[T]) UpdateReturnPointer(r, c int, f func(T) T) (pointer int, start int)

func (*CSCMatrix[T]) Values

func (s *CSCMatrix[T]) Values() int

Values the number of non-zero elements in the matrix

type CSRMatrix

type CSRMatrix[T constraints.Number] struct {
	// contains filtered or unexported fields
}

CSRMatrix compressed storage by rows (CSR)

func NewCSRMatrix

func NewCSRMatrix[T constraints.Number](r, c int) *CSRMatrix[T]

NewCSRMatrix returns a CSRMatrix

func NewCSRMatrixFromArray

func NewCSRMatrixFromArray[T constraints.Number](data [][]T) *CSRMatrix[T]

NewCSRMatrixFromArray returns a CSRMatrix

func (*CSRMatrix[T]) Add

func (s *CSRMatrix[T]) Add(m Matrix[T]) Matrix[T]

Add addition of a matrix by another matrix

func (*CSRMatrix[T]) At

func (s *CSRMatrix[T]) At(r, c int) (value T)

At returns the value of a matrix element at r-th, c-th

func (*CSRMatrix[T]) Clear

func (s *CSRMatrix[T]) Clear()

Clear removes all elements from a matrix

func (*CSRMatrix[T]) Columns

func (s *CSRMatrix[T]) Columns() int

Columns the number of columns of the matrix

func (*CSRMatrix[T]) ColumnsAt

func (s *CSRMatrix[T]) ColumnsAt(c int) VectorLogial[T]

ColumnsAt return the columns at c-th

func (*CSRMatrix[T]) Copy

func (s *CSRMatrix[T]) Copy() Matrix[T]

func (*CSRMatrix[T]) CopyLogical

func (s *CSRMatrix[T]) CopyLogical() MatrixLogical[T]

Copy copies the matrix

func (*CSRMatrix[T]) Element

func (s *CSRMatrix[T]) Element(r, c int) (b bool)

Element of the mask for each tuple that exists in the matrix for which the value of the tuple cast to Boolean is true

func (*CSRMatrix[T]) Enumerate

func (s *CSRMatrix[T]) Enumerate() Enumerate[T]

Enumerate iterates through all non-zero elements, order is not guaranteed

func (*CSRMatrix[T]) Equal

func (s *CSRMatrix[T]) Equal(m MatrixLogical[T]) bool

Equal the two matrices are equal

func (*CSRMatrix[T]) Map

func (s *CSRMatrix[T]) Map() Map[T]

Map replace each element with the result of applying a function to its value

func (*CSRMatrix[T]) Multiply

func (s *CSRMatrix[T]) Multiply(m Matrix[T]) Matrix[T]

Multiply multiplies a matrix by another matrix

func (*CSRMatrix[T]) Negative

func (s *CSRMatrix[T]) Negative() MatrixLogical[T]

Negative the negative of a matrix

func (*CSRMatrix[T]) NotEqual

func (s *CSRMatrix[T]) NotEqual(m MatrixLogical[T]) bool

NotEqual the two matrices are not equal

func (*CSRMatrix[T]) Rows

func (s *CSRMatrix[T]) Rows() int

Rows the number of rows of the matrix

func (*CSRMatrix[T]) RowsAt

func (s *CSRMatrix[T]) RowsAt(r int) VectorLogial[T]

RowsAt return the rows at r-th

func (*CSRMatrix[T]) RowsAtToArray

func (s *CSRMatrix[T]) RowsAtToArray(r int) []T

RowsAtToArray return the rows at r-th

func (*CSRMatrix[T]) Scalar

func (s *CSRMatrix[T]) Scalar(alpha T) Matrix[T]

Scalar multiplication of a matrix by alpha

func (*CSRMatrix[T]) Set

func (s *CSRMatrix[T]) Set(r, c int, value T)

Set sets the value at r-th, c-th of the matrix

func (*CSRMatrix[T]) SetReturnPointer

func (s *CSRMatrix[T]) SetReturnPointer(r, c int, value T) (pointer int, start int)

func (*CSRMatrix[T]) Size

func (s *CSRMatrix[T]) Size() int

Size of the matrix

func (*CSRMatrix[T]) Subtract

func (s *CSRMatrix[T]) Subtract(m Matrix[T]) Matrix[T]

Subtract subtracts one matrix from another matrix

func (*CSRMatrix[T]) Transpose

func (s *CSRMatrix[T]) Transpose() MatrixLogical[T]

Transpose swaps the rows and columns

func (*CSRMatrix[T]) Update

func (s *CSRMatrix[T]) Update(r, c int, f func(T) T)

Update does a At and Set on the matrix element at r-th, c-th

func (*CSRMatrix[T]) UpdateReturnPointer

func (s *CSRMatrix[T]) UpdateReturnPointer(r, c int, f func(T) T) (pointer int, start int)

func (*CSRMatrix[T]) Values

func (s *CSRMatrix[T]) Values() int

Values the number of non-zero elements in the matrix

type Context

type Context interface {
	context.Context
	Mode() Mode
}

Context exends the standard context to include Mode

type DenseMatrix

type DenseMatrix[T constraints.Type] struct {
	// contains filtered or unexported fields
}

DenseMatrix a dense matrix

func NewDenseMatrix

func NewDenseMatrix[T constraints.Type](r, c int) *DenseMatrix[T]

NewDenseMatrix returns a DenseMatrix

func NewDenseMatrixFromArray

func NewDenseMatrixFromArray[T constraints.Number](data [][]T) *DenseMatrix[T]

NewDenseMatrixFromArray returns a DenseMatrix

func (*DenseMatrix[T]) At

func (s *DenseMatrix[T]) At(r, c int) T

At returns the value of a matrix element at r-th, c-th

func (*DenseMatrix[T]) Clear

func (s *DenseMatrix[T]) Clear()

Clear removes all elements from a matrix

func (*DenseMatrix[T]) Columns

func (s *DenseMatrix[T]) Columns() int

Columns the number of columns of the matrix

func (*DenseMatrix[T]) ColumnsAt

func (s *DenseMatrix[T]) ColumnsAt(c int) VectorLogial[T]

ColumnsAt return the columns at c-th

func (*DenseMatrix[T]) CopyLogical

func (s *DenseMatrix[T]) CopyLogical() MatrixLogical[T]

Copy copies the matrix

func (*DenseMatrix[T]) Enumerate

func (s *DenseMatrix[T]) Enumerate() Enumerate[T]

Enumerate iterates through all non-zero elements, order is not guaranteed

func (*DenseMatrix[T]) Equal

func (s *DenseMatrix[T]) Equal(m MatrixLogical[T]) bool

Equal the two matrices are equal

func (*DenseMatrix[T]) NotEqual

func (s *DenseMatrix[T]) NotEqual(m MatrixLogical[T]) bool

NotEqual the two matrices are not equal

func (*DenseMatrix[T]) RawMatrix

func (s *DenseMatrix[T]) RawMatrix() [][]T

RawMatrix returns the raw matrix

func (*DenseMatrix[T]) Rows

func (s *DenseMatrix[T]) Rows() int

Rows the number of rows of the matrix

func (*DenseMatrix[T]) RowsAt

func (s *DenseMatrix[T]) RowsAt(r int) VectorLogial[T]

RowsAt return the rows at r-th

func (*DenseMatrix[T]) RowsAtToArray

func (s *DenseMatrix[T]) RowsAtToArray(r int) []T

RowsAtToArray return the rows at r-th

func (*DenseMatrix[T]) Set

func (s *DenseMatrix[T]) Set(r, c int, value T)

Set sets the value at r-th, c-th of the matrix

func (*DenseMatrix[T]) Size

func (s *DenseMatrix[T]) Size() int

Size of the matrix

func (*DenseMatrix[T]) Transpose

func (s *DenseMatrix[T]) Transpose() MatrixLogical[T]

Transpose swaps the rows and columns

func (*DenseMatrix[T]) Update

func (s *DenseMatrix[T]) Update(r, c int, f func(T) T)

Update does a At and Set on the matrix element at r-th, c-th

func (*DenseMatrix[T]) Values

func (s *DenseMatrix[T]) Values() int

Values the number of elements in the matrix

type DenseMatrixNumber

type DenseMatrixNumber[T constraints.Number] struct {
	DenseMatrix[T]
}

func NewDenseMatrixFromArrayN

func NewDenseMatrixFromArrayN[T constraints.Number](data [][]T) *DenseMatrixNumber[T]

NewDenseMatrixFromArray returns a DenseMatrix

func NewDenseMatrixN

func NewDenseMatrixN[T constraints.Number](r, c int) *DenseMatrixNumber[T]

func (*DenseMatrixNumber[T]) Add

func (s *DenseMatrixNumber[T]) Add(m Matrix[T]) Matrix[T]

Add addition of a matrix by another matrix

func (*DenseMatrixNumber[T]) Copy

func (s *DenseMatrixNumber[T]) Copy() Matrix[T]

func (*DenseMatrixNumber[T]) Element

func (s *DenseMatrixNumber[T]) Element(r, c int) bool

Element of the mask for each tuple that exists in the matrix for which the value of the tuple cast to Boolean is true

func (*DenseMatrixNumber[T]) Map

func (s *DenseMatrixNumber[T]) Map() Map[T]

Map replace each element with the result of applying a function to its value

func (*DenseMatrixNumber[T]) Multiply

func (s *DenseMatrixNumber[T]) Multiply(m Matrix[T]) Matrix[T]

Multiply multiplies a matrix by another matrix

func (*DenseMatrixNumber[T]) Negative

func (s *DenseMatrixNumber[T]) Negative() MatrixLogical[T]

Negative the negative of a matrix

func (*DenseMatrixNumber[T]) Scalar

func (s *DenseMatrixNumber[T]) Scalar(alpha T) Matrix[T]

Scalar multiplication of a matrix by alpha

func (*DenseMatrixNumber[T]) Subtract

func (s *DenseMatrixNumber[T]) Subtract(m Matrix[T]) Matrix[T]

Subtract subtracts one matrix from another matrix

type DenseVector

type DenseVector[T constraints.Type] struct {
	// contains filtered or unexported fields
}

DenseVector a vector

func NewDenseVector

func NewDenseVector[T constraints.Type](l int) *DenseVector[T]

NewDenseVector returns a DenseVector

func NewDenseVectorFromArray

func NewDenseVectorFromArray[T constraints.Type](data []T) *DenseVector[T]

NewDenseVectorFromArray returns a SparseVector

func (*DenseVector[T]) At

func (s *DenseVector[T]) At(r, c int) (value T)

At returns the value of a vector element at r-th, c-th

func (*DenseVector[T]) AtVec

func (s *DenseVector[T]) AtVec(i int) T

AtVec returns the value of a vector element at i-th

func (*DenseVector[T]) Clear

func (s *DenseVector[T]) Clear()

Clear removes all elements from a vector

func (*DenseVector[T]) Columns

func (s *DenseVector[T]) Columns() int

Columns the number of columns of the vector

func (*DenseVector[T]) ColumnsAt

func (s *DenseVector[T]) ColumnsAt(c int) VectorLogial[T]

ColumnsAt return the columns at c-th

func (*DenseVector[T]) CopyLogical

func (s *DenseVector[T]) CopyLogical() MatrixLogical[T]

Copy copies the vector

func (*DenseVector[T]) Enumerate

func (s *DenseVector[T]) Enumerate() Enumerate[T]

Enumerate iterates through all non-zero elements, order is not guaranteed

func (*DenseVector[T]) Equal

func (s *DenseVector[T]) Equal(m MatrixLogical[T]) bool

Equal the two vectors are equal

func (*DenseVector[T]) Length

func (s *DenseVector[T]) Length() int

Length of the vector

func (*DenseVector[T]) NotEqual

func (s *DenseVector[T]) NotEqual(m MatrixLogical[T]) bool

NotEqual the two vectors are not equal

func (*DenseVector[T]) ReSize

func (s *DenseVector[T]) ReSize(size int) int

Re-size the vector, will cut if the new size is smaller than the old size

func (*DenseVector[T]) Rows

func (s *DenseVector[T]) Rows() int

Rows the number of rows of the vector

func (*DenseVector[T]) RowsAt

func (s *DenseVector[T]) RowsAt(r int) VectorLogial[T]

RowsAt return the rows at r-th

func (*DenseVector[T]) RowsAtToArray

func (s *DenseVector[T]) RowsAtToArray(r int) []T

RowsAtToArray return the rows at r-th

func (*DenseVector[T]) Set

func (s *DenseVector[T]) Set(r, c int, value T)

Set sets the value at r-th, c-th of the vector

func (*DenseVector[T]) SetVec

func (s *DenseVector[T]) SetVec(i int, value T)

SetVec sets the value at i-th of the vector

func (*DenseVector[T]) Size

func (s *DenseVector[T]) Size() int

Size of the vector

func (*DenseVector[T]) Transpose

func (s *DenseVector[T]) Transpose() MatrixLogical[T]

Transpose swaps the rows and columns

func (*DenseVector[T]) Update

func (s *DenseVector[T]) Update(r, c int, f func(T) T)

Update does a At and Set on the vector element at r-th, c-th

func (*DenseVector[T]) Values

func (s *DenseVector[T]) Values() int

Values the number of elements in the vector

type DenseVectorNumber

type DenseVectorNumber[T constraints.Number] struct {
	DenseVector[T]
}

func NewDenseVectorFromArrayN

func NewDenseVectorFromArrayN[T constraints.Number](data []T) *DenseVectorNumber[T]

NewDenseVectorFromArray returns a SparseVector

func NewDenseVectorN

func NewDenseVectorN[T constraints.Number](l int) *DenseVectorNumber[T]

func (*DenseVectorNumber[T]) Add

func (s *DenseVectorNumber[T]) Add(m Matrix[T]) Matrix[T]

Add addition of a vector by another vector

func (*DenseVectorNumber[T]) Copy

func (s *DenseVectorNumber[T]) Copy() Matrix[T]

func (*DenseVectorNumber[T]) Element

func (s *DenseVectorNumber[T]) Element(r, c int) bool

Element of the mask for each tuple that exists in the matrix for which the value of the tuple cast to Boolean is true

func (*DenseVectorNumber[T]) Map

func (s *DenseVectorNumber[T]) Map() Map[T]

Map replace each element with the result of applying a function to its value

func (*DenseVectorNumber[T]) Multiply

func (s *DenseVectorNumber[T]) Multiply(m Matrix[T]) Matrix[T]

Multiply multiplies a vector by another vector

func (*DenseVectorNumber[T]) Negative

func (s *DenseVectorNumber[T]) Negative() MatrixLogical[T]

Negative the negative of a metrix

func (*DenseVectorNumber[T]) Scalar

func (s *DenseVectorNumber[T]) Scalar(alpha T) Matrix[T]

Scalar multiplication of a vector by alpha

func (*DenseVectorNumber[T]) Subtract

func (s *DenseVectorNumber[T]) Subtract(m Matrix[T]) Matrix[T]

Subtract subtracts one vector from another vector

type EmptyMask

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

EmptyMask is a mask with no elements but will always returns false

func NewEmptyMask

func NewEmptyMask(r, c int) *EmptyMask

NewEmptyMask returns a EmptyMask

func (*EmptyMask) Columns

func (s *EmptyMask) Columns() int

Columns the number of columns of the mask

func (*EmptyMask) Element

func (s *EmptyMask) Element(r, c int) bool

Element of the mask for each tuple that exists in the matrix for which the value of the tuple cast to Boolean is true

func (*EmptyMask) Rows

func (s *EmptyMask) Rows() int

Rows the number of rows of the mask

type Enumerate

type Enumerate[T constraints.Type] interface {
	// HasNext checks for the next element in the matrix
	HasNext() bool

	// Next move the iterator over the matrix
	Next() (r, c int, v T)
}

Enumerate iterates over the matrix

type Map

type Map[T constraints.Type] interface {
	// HasNext checks for the next element in the matrix
	HasNext() bool

	// Map move the iterator and uses a higher order function to changes the elements current value
	Map(func(r, c int, v T) T)
}

Map replace each element with the result of applying a function to its value

type Mask

type Mask interface {
	MaskLogical

	// Element of the mask for each tuple that exists in the matrix for which the value of the tuple cast to Boolean is true
	Element(r, c int) bool
}

type MaskLogical

type MaskLogical interface {
	// Columns the number of columns of the mask
	Columns() int

	// Rows the number of rows of the mask
	Rows() int
}

Mask is used to control how computed values are stored in the output from a method

type Matrix

type Matrix[T constraints.Number] interface {
	Mask
	MatrixLogical[T]

	// Copy copies the matrix
	Copy() Matrix[T]

	// Scalar multiplication of a matrix by alpha
	Scalar(alpha T) Matrix[T]

	// Multiply multiplies a matrix by another matrix
	//  C = AB
	Multiply(m Matrix[T]) Matrix[T]

	// Add addition of a matrix by another matrix
	Add(m Matrix[T]) Matrix[T]

	// Subtract subtracts one matrix from another matrix
	Subtract(m Matrix[T]) Matrix[T]

	// Negative the negative of a matrix
	Negative() MatrixLogical[T]

	// Map iterates and replace each element with the result of applying a function to its value
	Map() Map[T]
}

Matrix interface

func Scalar

func Scalar[T constraints.Number](ctx context.Context, s Matrix[T], alpha T) Matrix[T]

Scalar multiplication of a matrix by alpha

func TransposeToCSC

func TransposeToCSC[T constraints.Number](ctx context.Context, s Matrix[T]) Matrix[T]

TransposeToCSC swaps the rows and columns and returns a compressed storage by columns (CSC) matrix

func TransposeToCSR

func TransposeToCSR[T constraints.Number](ctx context.Context, s Matrix[T]) Matrix[T]

TransposeToCSR swaps the rows and columns and returns a compressed storage by rows (CSR) matrix

type MatrixCompressed

type MatrixCompressed[T constraints.Number] interface {
	Matrix[T]
	SetReturnPointer(r, c int, value T) (pointer int, start int)
	UpdateReturnPointer(r, c int, f func(T) T) (pointer int, start int)
}

type MatrixLogical

type MatrixLogical[T constraints.Type] interface {
	// contains filtered or unexported methods
}

type MatrixRune

type MatrixRune interface {
	// contains filtered or unexported methods
}

type Mode

type Mode = int

Mode for blocking

const (
	// Blocking until each method has completed
	Blocking Mode = iota
	// NonBlocking may execute methods in any order
	NonBlocking
)

func BlockingMode

func BlockingMode(ctx context.Context) (Mode, bool)

BlockingMode returns the Mode from the context

type MutexMatrix

type MutexMatrix[T constraints.Number] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MutexMatrix a matrix wrapper that has a mutex lock support

func NewMutexMatrix

func NewMutexMatrix[T constraints.Number](matrix Matrix[T]) *MutexMatrix[T]

NewMutexMatrix returns a MutexMatrix

func (*MutexMatrix[T]) Add

func (s *MutexMatrix[T]) Add(m Matrix[T]) Matrix[T]

Add addition of a matrix by another matrix

func (*MutexMatrix[T]) At

func (s *MutexMatrix[T]) At(r, c int) T

At returns the value of a matrix element at r-th, c-th

func (*MutexMatrix[T]) Clear

func (s *MutexMatrix[T]) Clear()

Clear removes all elements from a matrix

func (*MutexMatrix[T]) Columns

func (s *MutexMatrix[T]) Columns() int

Columns the number of columns of the matrix

func (*MutexMatrix[T]) ColumnsAt

func (s *MutexMatrix[T]) ColumnsAt(c int) VectorLogial[T]

ColumnsAt return the columns at c-th

func (*MutexMatrix[T]) Copy

func (s *MutexMatrix[T]) Copy() MatrixLogical[T]

Copy copies the matrix

func (*MutexMatrix[T]) Element

func (s *MutexMatrix[T]) Element(r, c int) bool

Element of the mask for each tuple that exists in the matrix for which the value of the tuple cast to Boolean is true

func (*MutexMatrix[T]) Enumerate

func (s *MutexMatrix[T]) Enumerate() Enumerate[T]

Enumerate iterates through all non-zero elements, order is not guaranteed

func (*MutexMatrix[T]) Equal

func (s *MutexMatrix[T]) Equal(m MatrixLogical[T]) bool

Equal the two matrices are equal

func (*MutexMatrix[T]) Map

func (s *MutexMatrix[T]) Map() Map[T]

Map replace each element with the result of applying a function to its value

func (*MutexMatrix[T]) Multiply

func (s *MutexMatrix[T]) Multiply(m Matrix[T]) Matrix[T]

Multiply multiplies a matrix by another matrix

func (*MutexMatrix[T]) Negative

func (s *MutexMatrix[T]) Negative() MatrixLogical[T]

Negative the negative of a matrix

func (*MutexMatrix[T]) NotEqual

func (s *MutexMatrix[T]) NotEqual(m MatrixLogical[T]) bool

NotEqual the two matrices are not equal

func (*MutexMatrix[T]) Rows

func (s *MutexMatrix[T]) Rows() int

Rows the number of rows of the matrix

func (*MutexMatrix[T]) RowsAt

func (s *MutexMatrix[T]) RowsAt(r int) VectorLogial[T]

RowsAt return the rows at r-th

func (*MutexMatrix[T]) RowsAtToArray

func (s *MutexMatrix[T]) RowsAtToArray(r int) []T

RowsAtToArray return the rows at r-th

func (*MutexMatrix[T]) Scalar

func (s *MutexMatrix[T]) Scalar(alpha T) Matrix[T]

Scalar multiplication of a matrix by alpha

func (*MutexMatrix[T]) Set

func (s *MutexMatrix[T]) Set(r, c int, value T)

Set sets the value at r-th, c-th of the matrix

func (*MutexMatrix[T]) Size

func (s *MutexMatrix[T]) Size() int

Size of the matrix

func (*MutexMatrix[T]) Subtract

func (s *MutexMatrix[T]) Subtract(m Matrix[T]) Matrix[T]

Subtract subtracts one matrix from another matrix

func (*MutexMatrix[T]) Transpose

func (s *MutexMatrix[T]) Transpose() MatrixLogical[T]

Transpose swaps the rows and columns

func (*MutexMatrix[T]) Update

func (s *MutexMatrix[T]) Update(r, c int, f func(T) T)

Update does a At and Set on the matrix element at r-th, c-th

func (*MutexMatrix[T]) Values

func (s *MutexMatrix[T]) Values() int

Values the number of elements in the matrix

type SparseVector

type SparseVector[T constraints.Number] struct {
	// contains filtered or unexported fields
}

SparseVector compressed storage by indices

func NewSparseVector

func NewSparseVector[T constraints.Number](l int) *SparseVector[T]

NewSparseVector returns a SparseVector

func NewSparseVectorFromArray

func NewSparseVectorFromArray[T constraints.Number](data []T) *SparseVector[T]

NewSparseVectorFromArray returns a SparseVector

func (*SparseVector[T]) Add

func (s *SparseVector[T]) Add(m Matrix[T]) Matrix[T]

Add addition of a metrix by another metrix

func (*SparseVector[T]) At

func (s *SparseVector[T]) At(r, c int) (value T)

At returns the value of a vector element at r-th, c-th

func (*SparseVector[T]) AtVec

func (s *SparseVector[T]) AtVec(i int) T

AtVec returns the value of a vector element at i-th

func (*SparseVector[T]) Clear

func (s *SparseVector[T]) Clear()

Clear removes all elements from a vector

func (*SparseVector[T]) Columns

func (s *SparseVector[T]) Columns() int

Columns the number of columns of the vector

func (*SparseVector[T]) ColumnsAt

func (s *SparseVector[T]) ColumnsAt(c int) VectorLogial[T]

ColumnsAt return the columns at c-th

func (*SparseVector[T]) Copy

func (s *SparseVector[T]) Copy() Matrix[T]

Copy copies the vector

func (*SparseVector[T]) CopyLogical

func (s *SparseVector[T]) CopyLogical() MatrixLogical[T]

func (*SparseVector[T]) Element

func (s *SparseVector[T]) Element(r, c int) bool

Element of the mask for each tuple that exists in the matrix for which the value of the tuple cast to Boolean is true

func (*SparseVector[T]) Enumerate

func (s *SparseVector[T]) Enumerate() Enumerate[T]

Enumerate iterates through all non-zero elements, order is not guaranteed

func (*SparseVector[T]) Equal

func (s *SparseVector[T]) Equal(m MatrixLogical[T]) bool

Equal the two metrics are equal

func (*SparseVector[T]) Length

func (s *SparseVector[T]) Length() int

Length of the vector

func (*SparseVector[T]) Map

func (s *SparseVector[T]) Map() Map[T]

Map replace each element with the result of applying a function to its value

func (*SparseVector[T]) Multiply

func (s *SparseVector[T]) Multiply(m Matrix[T]) Matrix[T]

Multiply multiplies a vector by another vector

func (*SparseVector[T]) Negative

func (s *SparseVector[T]) Negative() MatrixLogical[T]

Negative the negative of a metrix

func (*SparseVector[T]) NotEqual

func (s *SparseVector[T]) NotEqual(m MatrixLogical[T]) bool

NotEqual the two metrix are not equal

func (*SparseVector[T]) Rows

func (s *SparseVector[T]) Rows() int

Rows the number of rows of the vector

func (*SparseVector[T]) RowsAt

func (s *SparseVector[T]) RowsAt(r int) VectorLogial[T]

RowsAt return the rows at r-th

func (*SparseVector[T]) RowsAtToArray

func (s *SparseVector[T]) RowsAtToArray(r int) []T

RowsAtToArray return the rows at r-th

func (*SparseVector[T]) Scalar

func (s *SparseVector[T]) Scalar(alpha T) Matrix[T]

Scalar multiplication of a vector by alpha

func (*SparseVector[T]) Set

func (s *SparseVector[T]) Set(r, c int, value T)

Set sets the value at r-th, c-th of the vector

func (*SparseVector[T]) SetVec

func (s *SparseVector[T]) SetVec(i int, value T)

SetVec sets the value at i-th of the vector

func (*SparseVector[T]) Size

func (s *SparseVector[T]) Size() int

Size of the vector

func (*SparseVector[T]) Subtract

func (s *SparseVector[T]) Subtract(m Matrix[T]) Matrix[T]

Subtract subtracts one metrix from another metrix

func (*SparseVector[T]) Transpose

func (s *SparseVector[T]) Transpose() MatrixLogical[T]

Transpose swaps the rows and columns

func (*SparseVector[T]) Update

func (s *SparseVector[T]) Update(r, c int, f func(T) T)

Update does a At and Set on the vector element at r-th, c-th

func (*SparseVector[T]) Values

func (s *SparseVector[T]) Values() int

Values the number of non-zero elements in the Vector

type Vector

type Vector[T constraints.Number] interface {
	Matrix[T]
	// contains filtered or unexported methods
}

func ReduceMatrixToVector

func ReduceMatrixToVector[T constraints.Number](ctx context.Context, s Matrix[T]) Vector[T]

ReduceMatrixToVector perform's a reduction on the Matrix

func ReduceMatrixToVectorWithMonoID

func ReduceMatrixToVectorWithMonoID[T constraints.Number](ctx context.Context, s Matrix[T], monoID binaryop.MonoID[T], mask Mask) Vector[T]

ReduceMatrixToVectorWithMonoID perform's a reduction on the Matrix monoid used in the element-wise reduction operation

type VectorLogial

type VectorLogial[T constraints.Type] interface {
	MatrixLogical[T]
	// contains filtered or unexported methods
}

type VectorRune

type VectorRune interface {
	MatrixLogical[rune]

	Compare(v VectorRune) int
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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