sparse

package module
v0.0.0-...-896b79b Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2015 License: BSD-3-Clause Imports: 3 Imported by: 0

README

sparse

Sparse matrices and vectors in Go remotely based on Sparse BLAS.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Axpy

func Axpy(y *mat64.Vector, alpha float64, x *Vector)

Axpy scales the sparse vector x by alpha and adds the result to the dense vector y. If alpha is zero, y is not modified.

func Dot

func Dot(x *Vector, y *mat64.Vector) (dot float64)

Dot computes the dot product of the sparse vector x with the dense vector y. The vectors must have the same dimension.

func Gather

func Gather(x *Vector, y *mat64.Vector, indices []int)

Gather gathers entries given by indices of the dense vector y into the sparse vector x. Indices must not be nil.

func GatherZero

func GatherZero(x *Vector, y *mat64.Vector, indices []int)

Gather gathers entries given by indices of the dense vector y into the sparse vector x and sets the corresponding values of y to zero.

func MulMatVec

func MulMatVec(y *mat64.Vector, alpha float64, transA bool, a Matrix, x *mat64.Vector)

MulMatVec multiplies the dense vector x by a sparse matrix A (or its transpose) and adds the result to the dense vector y, i.e., it computes

y += alpha * op(A) * x,

where op(A) is either A or Aᵀ.

func Scatter

func Scatter(y *mat64.Vector, x *Vector)

Scatter copies the values of x into the corresponding locations in the dense vector y. Both vectors must have the same dimension.

Types

type CSR

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

func NewCSR

func NewCSR(dok *DOK) *CSR

func (*CSR) At

func (m *CSR) At(r, c int) float64

func (*CSR) Dims

func (m *CSR) Dims() (r, c int)

type DOK

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

func NewDOK

func NewDOK(r, c int) *DOK

func (*DOK) At

func (m *DOK) At(r, c int) float64

func (*DOK) Dims

func (m *DOK) Dims() (r, c int)

func (*DOK) InsertEntry

func (m *DOK) InsertEntry(r, c int, v float64)

func (*DOK) Properties

func (m *DOK) Properties() MatrixProperties

func (*DOK) SetSparse

func (m *DOK) SetSparse(r, c int, v float64)

func (*DOK) Triplets

func (m *DOK) Triplets() []Triplet

type Index

type Index [2]int

type Matrix

type Matrix interface {
	// Dims returns the dimensions of the matrix.
	Dims() (r, c int)

	// At returns the value of the matrix entry at (r, c). It will panic if r
	// or c are out of bounds for the matrix.
	At(r, c int) float64
}

Matrix is a sparse matrix.

type MatrixBuilder

type MatrixBuilder interface {
	Begin()
	InsertEntry(r, c int, v float64)
	InsertEntries()
	InsertClique()
	End()
}

MatrixBuilder can build a sparse matrix by modifying its sparsity structure.

type MatrixProperties

type MatrixProperties struct {
	Symmetric       bool
	LowerTriangular bool
	UpperTriangular bool
}

type MutableMatrix

type MutableMatrix interface {
	Matrix

	// SetSparse sets the entry at (r, c) to v. It will panic if r or c are out
	// of bounds for the matrix.
	// Whether SetSparse panics if the entry does not already exist in the
	// matrix is implementation-specific.
	SetSparse(r, c int, v float64)
}

MutableMatrix is a matrix that can modify its non-zero entries without changing its sparsity structure.

type Triplet

type Triplet struct {
	Row, Col int
	Value    float64
}

type Vector

type Vector struct {
	N       int       // Dimension of the vector.
	Data    []float64 // Non-zero values.
	Indices []int     // Indices of values in Data. Must be zero-based and unique.
}

Vector is a sparse vector represented by a slice of non-zero values and a slice denoting their indices.

func NewVector

func NewVector(n int, data []float64, indices []int) *Vector

NewVector returns a new Vector of dimension n with non-zero elements given by data and indices. Both data and indices must have the same length smaller than n, otherwise NewVector will panic. Indices must be unique, although no checking is done.

func (*Vector) InsertEntry

func (v *Vector) InsertEntry(val float64, i int)

InsertEntry appends the value v with index i to the Vector.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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