blas

package
v0.0.0-...-495ee4f Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 2 Imported by: 5 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Sparse matrix formats

GoDoc Sourcegraph

Implementation of sparse BLAS (Basic Linear Algebra Subprograms) routines in Go for sparse matrix arithmetic. See http://www.netlib.org/blas/blast-forum/chapter3.pdf for more details. Includes optimised assembler implementations of key kernel operations (vector dot product and Axpy operations).

Indicative Benchmarks

Operation Pure Go Assembler
Dusdot (with increment/stride) 1340 ns/op 978 ns/op
Dusdot (unitary) 1215 ns/op 662 ns/op
Dusaxpy (with increment/stride) 1944 ns/op 1769 ns/op
Dusaxpy (unitary) 1091 ns/op 979 ns/op

Documentation

Overview

Package blas provides implementations of sparse BLAS (Basic Linear Algebra Subprograms) routines for sparse matrix arithmetic and solving sparse linear systems.

See http://www.netlib.org/blas/blast-forum/chapter3.pdf for further information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dusaxpy

func Dusaxpy(alpha float64, x []float64, indx []int, y []float64, incy int)

Dusaxpy (Sparse update (y <- alpha * x + y)) scales the sparse vector x by alpha and adds the result to the dense vector y. indx is used as the index values to gather and incy as the stride for y.

func Dusdot

func Dusdot(x []float64, indx []int, y []float64, incy int) (dot float64)

Dusdot (Sparse dot product (r <- x^T * y)) calculates the dot product of sparse vector x and dense vector y. indx is used as the index values to gather and incy as the stride for y.

func Dusga

func Dusga(y []float64, incy int, x []float64, indx []int)

Dusga (Sparse gather (x <- y|x)) gathers entries from the dense vector y into the sparse vector x using indx as the index values to gather and incy as the stride for y.

func Dusgz

func Dusgz(y []float64, incy int, x []float64, indx []int)

Dusgz (Sparse gather and zero (x <- y|x, y|x <- 0)) gathers entries from the dense vector y into the sparse vector x (as Usga()) and then sets the corresponding elements of y (y[indx[i]]) to 0. indx is used as the index values to gather and incy as the stride for y.

func Dusmm

func Dusmm(transA bool, k int, alpha float64, a *SparseMatrix, b []float64, ldb int, c []float64, ldc int)

Dusmm (Sparse matrix multiply (C <- alpha * A * B + C Or C <- alpha * A^T * B + C)) multiplies a dense matrix B by a sparse matrix A (or its transpose), and adds it to a dense matrix operand C. C is modified to hold the result of operation. k Represents the number of columns in matrices B and C and ldb and ldc are the spans to be used for indexing into matrices B and C respectively.

func Dusmv

func Dusmv(transA bool, alpha float64, a *SparseMatrix, x []float64, incx int, y []float64, incy int)

Dusmv (sparse matrix / vector multiply (y <- alpha * A * x + y Or y <- alpha * A^T * x + y)) multiplies a dense vector x by sparse matrix a (or its transpose), and adds it to the dense vector y. transA is a boolean indicating whether to transpose (true) a. alpha is used to scale a and incx and incy represent the span to be used for indexing into vectors x and y respectively.

func Dussc

func Dussc(x []float64, y []float64, incy int, indx []int)

Dussc (Sparse scatter (y|x <- x)) scatters enries into the dense vector y from the sparse vector x using indx as the index values to scatter to and incy as the stride for y. The function will panic if x and idx are different lengths.

Types

type SparseMatrix

type SparseMatrix struct {
	I, J   int
	Indptr []int
	Ind    []int
	Data   []float64
}

SparseMatrix represents the common structure for representing compressed sparse matrix formats e.g. CSR (Compressed Sparse Row) or CSC (Compressed Sparse Column)

func (*SparseMatrix) At

func (m *SparseMatrix) At(i, j int) float64

At returns the element of the matrix located at coordinate i, j.

func (*SparseMatrix) Cull

func (m *SparseMatrix) Cull(epsilon float64) *SparseMatrix

Cull returns a new SparseMatrix with all entries within epsilon of 0 removed.

func (*SparseMatrix) Set

func (m *SparseMatrix) Set(i, j int, v float64)

Set is a generic method to set a matrix element. Note: setting a non-zero element to zero does not remove the element from the sparcity pattern but will actually store a zero value.

Jump to

Keyboard shortcuts

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