blas

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 6 Imported by: 3 modules, 0 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

blas

Pure-Go BLAS with the Fortran reference signatures, column-major: real (float32/float64) level 1, gemv and level 3 (gemm, trsm, trmm, syrk, syr2k, symm), with a SIMD GEMM on six architectures, and the first LAPACK routines (LU and Cholesky with their solves since v0.4.0; QR since v0.5.0), error bounds stated per routine, and a netlib-exact option. Complex (c/z) BLAS and the rest of LAPACK are next.

import "github.com/go-blas/blas"

// C := alpha*op(A)*op(B) + beta*C, column-major, as DGEMM. a is m x k, b is
// k x n, c is m x n, with leading dimensions lda, ldb, ldc.
err := blas.Dgemm(blas.NoTrans, blas.NoTrans, m, n, k, 1, a, lda, b, ldb, 0, c, ldc)

Status

First release line, real routines only (the LAPACK rows since v0.4.0, v0.5.0 and v0.6.0):

Level Routines (S and D)
LAPACK (package lapack, v0.4.0) Sgetrf/Dgetrf, Sgetrs/Dgetrs, Spotrf/Dpotrf, Spotrs/Dpotrs: LU with partial pivoting and Cholesky, and their solves, recursive and blocked over the packed GEMM, TRSM and SYRK; a factorization returns (info, err), a positive info being a result (see docs/design.md decision 10)
LAPACK, QR (package lapack, v0.5.0) Sgeqrf/Dgeqrf, Sormqr/Dormqr, Sorgqr/Dorgqr: Householder QR, multiplication by Q or Q**T, and generation of Q, the reference's blocked algorithms over the packed GEMM and TRMM; the bound's constant is tested, not proved (see docs/design.md decision 11)
LAPACK, symmetric eigenproblem (package lapack, v0.6.0) Ssyev/Dsyev: tridiagonal reduction (sytrd), orgtr, implicit QL/QR (steqr) and root-free QL (sterf), with Ssymv/Dsymv, Ssyr2/Dsyr2, Srot/Drot, Sswap/Dswap, Scopy/Dcopy; bounds are tested constants (see docs/design.md decision 12)
3 Strsm/Dtrsm, Strmm/Dtrmm, Ssyrk/Dsyrk, Ssyr2k/Dsyr2k, Ssymm/Dsymm, blocked on the packed GEMM (a residual bound for trsm, see docs/design.md decision 9)
3 Sgemm, Dgemm; SgemmStrided, DgemmStrided (row and column stride per operand, as BLIS's bli_?gemm, no copy of a sliced or transposed view); HasSgemmKernel
2 Sgemv, Dgemv
1 Sdot/Ddot, Saxpy/Daxpy, Sscal/Dscal, Snrm2/Dnrm2, Sasum/Dasum, Isamax/Idamax

The signatures are the reference's, parameter for parameter, so that a Fortran ABI shim (julia's libblastrampoline, for one) can call them exactly: column-major storage, leading dimensions, increments (negative ones included), beta = 0 never reads C, alpha = 0 never reads A or B, the reference's quick returns. Idamax and Isamax return the 1-based Fortran index.

No routine panics

Each routine returns an error: nil, or a *blas.ArgError{Routine, Param} carrying xerbla's parameter number (Info() is LAPACK's -Param). Beyond the reference's own tests, every slice is checked against the length the call needs, lda*(cols-1)+rows for a matrix and 1+(n-1)*|inc| for a vector, with overflow-safe arithmetic that also holds on 32-bit targets; a slice that is too short is reported against its own parameter number.

The contract is an error bound, not bit identity

Each routine states an elementwise error bound, asserted in the tests against a math/big oracle of 256 bits (for Dgemm, with u the unit roundoff and gamma_k = ku/(1-ku): |C^ - C| <= gamma_{k+2} (|alpha||op(A)||op(B)| + |beta||C|); the others are in the package comment). Inside the bound, FMA, packing, blocking and reordered sums are all used. Bit identity with netlib is not promised.

Dgemm and Sgemm run on a packed, cache-blocked, multicore SIMD kernel (AVX2/FMA on amd64, NEON on arm64, VSX on ppc64le, LASX on loong64, RVV on riscv64, the vector facility on s390x), moved here from go-ndarray/ndarray. The column-major product is the row-major product C^T = op(B)^T op(A)^T, so the one strided kernel serves both layouts and no operand is copied beyond the kernel's own packing.

netlib, the exact option

github.com/go-blas/blas/netlib has the same routines as plain-Go ports of reference BLAS 3.12 (dgemm.f, sgemm.f, dgemv.f, sgemv.f, ddot.f, daxpy.f, dscal.f, dnrm2.f90, dasum.f, idamax.f, dtrsm.f, dtrmm.f, dsyrk.f, dsyr2k.f, dsymm.f and their single precision twins), in the reference's loop order and without fused multiply-add, so the results are the same on every architecture. They are the equality oracle of the tests and a public option for callers who need the reference's exact rounding. They are not fast.

LAPACK: LU and Cholesky (since v0.4.0)

import "github.com/go-blas/blas/lapack"

// A = P*L*U, in place; ipiv is 1-based as in LAPACK. info > 0 means U(info,info)
// is exactly zero: a result, not an error. err is non-nil only when info < 0.
info, err := lapack.Dgetrf(n, n, a, lda, ipiv)
err = lapack.Dgetrs(blas.NoTrans, n, nrhs, a, lda, ipiv, b, ldb)

// A = L*L**T; info > 0 means the leading minor of order info is not positive definite.
info, err = lapack.Dpotrf(blas.Lower, n, a, lda)
err = lapack.Dpotrs(blas.Lower, n, nrhs, a, lda, b, ldb)

The reference LAPACK 3.12 signatures and xerbla numbering, column-major, the same conventions as the BLAS above. Each routine states a backward-error bound (|P A - L U| <= gamma_{3r+2} |L||U| for getrf, and so on, in the package comment of lapack), asserted against the 256-bit oracle. netlib has ports of dgetrf.f, dgetrf2.f, dgetrs.f, dlaswp.f, dpotrf.f, dpotrf2.f, dpotrs.f and their single precision twins as the exact option.

QR (since v0.5.0)
// A = Q*R: R in the upper triangle of a, the reflectors below it, tau their scalars.
err := lapack.Dgeqrf(m, n, a, lda, tau)
// C := Q**T * C, with Q taken from the reflectors in a (k of them).
err = lapack.Dormqr(blas.Left, blas.Trans, m, nrhs, k, a, lda, tau, c, ldc)
// Overwrite the first n columns of a with the m x n matrix Q.
err = lapack.Dorgqr(m, n, k, a, lda, tau)

The workspace arguments of the reference (WORK, LWORK) do not exist: the workspace is allocated. The bound is per column against the exact product of the stored reflectors, gamma_{8(m+n)+16}, a tested constant (LAWN 22 shows the blocked form keeps the Householder analysis, with changed constants); netlib has dgeqrf.f, dgeqr2.f, dlarfg.f, dlarf.f, dlarft.f, dlarfb.f, dorgqr.f, dorg2r.f, dormqr.f, dorm2r.f ports.

Symmetric eigensolver (v0.6.0)
// Eigenvalues of the symmetric matrix in the uplo triangle of a, ascending in w;
// with lapack.EigenvaluesAndVectors a holds the orthonormal eigenvectors on return.
info, err := lapack.Dsyev(lapack.EigenvaluesAndVectors, blas.Upper, n, a, lda, w)

Ssyev/Dsyev (reference LAPACK 3.12's xsyev: xsytrd, xorgtr, xsteqr, xsterf) and the routines they need are ported exactly: Ssymv/Dsymv, Ssyr2/Dsyr2, Srot/Drot, Sswap/Dswap, Scopy/Dcopy in the root package; lamch, lartg, lae2, laev2, lasr, lasrt, lascl, laset, lanst, lansy, sytd2, latrd, sytrd, steqr, sterf, org2l, orgql, orgtr in lapack. A positive info (an eigenvalue iteration that did not converge) is a result, as for the factorizations. The bounds (reduction, orthogonality, residual, eigenvalues) are tested constants, not proofs; they are listed with their measured worst cases in docs/design.md decision 12. netlib has the eigenvalue routines' ports (not the BLAS ones).

Next

Complex BLAS (Cgemm, Zgemm, Zgemv, Zdotc/Zdotu, ... on complex64 and complex128 slices), then the rest of LAPACK (zgetrf, zheevd, zgesdd, ...), under the same naming and error conventions; see docs/design.md.

Flags

Transpose flags are case-insensitive, as in netlib (blas.Transpose(n) is NoTrans).

Testing

  • Per-architecture kernel tests (one worker, bit equality, packing, fences that fault on a one-element overrun), run natively on amd64 and arm64 and under qemu on riscv64, loong64, ppc64le, s390x and 32-bit arm.
  • API tests over every transpose combination, odd leading dimensions, zero dimensions, the scalar rules, every argument error, and the bound of every routine against the oracle.
  • A fuzz target per routine (go test -fuzz): no panic, and either an error or a result within the bound, with a committed corpus in testdata/fuzz.
  • 100% block coverage, and internal/cmd/guardmut, which disables each argument guard in turn and requires the tests to fail by an assertion.

Regenerating the assembly

The kernels' assembly is generated by go-asmgen (internal/kernels/asmgen/<arch>/gen.go, a module of its own):

go generate ./internal/kernels         # every architecture, whatever the host
cd internal/kernels/asmgen && go run ./regen   # the same, without a shell

License

BSD-3-Clause, see LICENSE.

Documentation

Overview

Package blas is a pure-Go BLAS with the reference (netlib) signatures and semantics: column-major matrices, leading dimensions, increments, and the scalar rules of the reference routines (beta = 0 never reads C, alpha = 0 never reads A or B, the quick returns). Go's bounds checks cannot protect a caller that binds this package to Fortran, so no routine panics on its arguments: each returns an error, nil or a *ArgError.

Scope

This release has the real routines in single and double precision: the level 3 routines Sgemm/Dgemm, Strsm/Dtrsm, Strmm/Dtrmm, Ssyrk/Dsyrk, Ssyr2k/Dsyr2k and Ssymm/Dsymm, Sgemv, Dgemv and the level 1 routines Sdot/Ddot, Saxpy/Daxpy, Sscal/Dscal, Snrm2/Dnrm2, Sasum/Dasum and Isamax/Idamax. Complex routines (Cgemm, Zgemm, Zdotc, ...) and the rest of LAPACK follow (the LU and Cholesky factorizations and solves are in package lapack since v0.4.0, the QR factorization since v0.5.0), under the same naming convention, with complex64 and complex128 slices; nothing here will have to change for them. ConjTrans is in Transpose from the start: for real types it means Trans, as in netlib.

Contract

The contract of each routine is a stated error bound, asserted against a math/big oracle of at least 256 bits, and not equality with another float64 code. With u the unit roundoff (2^-53, or 2^-24 for float32) and gamma_k = k*u/(1-k*u):

Gemm   |C^ - C| <= gamma_{k+2} (|alpha| |op(A)| |op(B)| + |beta| |C0|)   elementwise
Trsm   |op(A) X^ - alpha B| <= gamma_{s+4} (|op(A)| |X^| + |alpha B|)   elementwise, s the order of A: a residual (backward error) bound
Trmm   |B^ - alpha op(A) B| <= gamma_{s+3} |alpha| |op(A)| |B|          elementwise
Syrk   |C^ - C| <= gamma_{k+2} (|alpha| |op(A)| |op(A)^T| + |beta| |C0|)   elementwise, on the triangle written
Syr2k  |C^ - C| <= gamma_{2k+2} (|alpha| (|op(A)||op(B)^T| + |op(B)||op(A)^T|) + |beta| |C0|)   likewise
Symm   |C^ - C| <= gamma_{s+2} (|alpha| |A| |B| + |beta| |C0|)           elementwise (|B| |A| for side Right)
Gemv   |y^ - y| <= gamma_{r+2} (|alpha| |op(A)| |x|      + |beta| |y0|)   elementwise, r the length of the sum
Dot    |d^ - d| <= gamma_n |x|.|y|
Axpy   |y^ - y| <= gamma_2 (|alpha x| + |y0|)             elementwise
Scal   |x^ - x| <= gamma_1 |alpha x|                     elementwise
Nrm2   |s^ - s| <= gamma_{n+2} s
Asum   |s^ - s| <= gamma_n sum|x|
Iamax  exact: the first index of the largest |x|

FMA, blocking, packing and reordered sums are all allowed inside that bound, and are used: Dgemm and Sgemm run on the packed, cache-blocked, multicore SIMD kernel moved from go-ndarray/ndarray (AVX2/FMA on amd64, NEON on arm64, VSX on ppc64le, LASX on loong64, RVV on riscv64, the vector facility on s390x). Bit identity with netlib is not part of the contract; package netlib is the option for callers who want it: plain-Go ports of the reference routines, in the reference's loop order, without FMA.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dasum

func Dasum(n int, x []float64, incx int) (float64, error)

Dasum returns the sum of the absolute values of x (DASUM), 0 for n <= 0 or incx <= 0.

func Daxpy

func Daxpy(n int, alpha float64, x []float64, incx int, y []float64, incy int) error

Daxpy computes y := alpha*x + y (DAXPY). With unit increments it is go-simd/floats.Axpy, one rounding per element. n <= 0 and alpha = 0 return at once, without reading x or y.

func Dcopy added in v0.6.0

func Dcopy(n int, x []float64, incx int, y []float64, incy int) error

Dcopy copies the n elements of x to y (DCOPY). n <= 0 returns at once; a slice too short is an *ArgError on parameter 2 (x) or 4 (y).

func Ddot

func Ddot(n int, x []float64, incx int, y []float64, incy int) (float64, error)

Ddot returns the dot product of x and y (DDOT). With unit increments it is go-simd/floats.Dot, within gamma_n|x|.|y| of the exact value; otherwise the reference loop.

func Dgemm

func Dgemm(tA, tB Transpose, m, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) error

Dgemm computes C := alpha*op(A)*op(B) + beta*C, where op(X) is X, or X**T for Trans and ConjTrans. op(A) is m x k, op(B) is k x n and C is m x n, all stored column-major: element (i, j) of A is a[i+j*lda]. It is DGEMM of the reference BLAS, parameter for parameter.

With beta = 0, C is not read (it may hold NaN); with alpha = 0, A and B are not read (they may be empty); m = 0 or n = 0, and alpha = 0 or k = 0 with beta = 1, return at once. An invalid argument returns a *ArgError numbered like xerbla's, among them a slice too short for the call: a is checked against lda*(cols-1)+rows, and likewise b and c (parameters 7, 9 and 12).

The product runs on a packed, cache-blocked, multicore SIMD kernel: it is within gamma_{k+2}(|alpha||op(A)||op(B)| + |beta||C|) elementwise of the exact result (see the package comment), not bit-identical to netlib.Dgemm. The beta term sits inside the k+2 because C is scaled first and the product accumulated into it, as in netlib's own loops and in every blocked BLAS. It is not safe to call with c overlapping a or b.

func DgemmStrided added in v0.2.0

func DgemmStrided(m, n, k int, alpha float64, a []float64, rsa, csa int, b []float64, rsb, csb int, beta float64, c []float64, rsc, csc int) error

DgemmStrided computes C := alpha*A*B + beta*C for an m x k matrix A, a k x n matrix B and an m x n matrix C, each given with a row stride and a column stride: element (i, j) of A is a[i*rsa+j*csa], and likewise B and C. It is the general-stride form of BLIS's bli_dgemm (see docs/design.md), without the transpose flags, which a stride swap expresses: a transposed operand is the same data with rs and cs exchanged. A row-major matrix has csa = 1, a column-major one rsa = 1, a sliced or decimated view anything else, and none of them is copied: the packing of the kernel reads the operands through their strides, as Dgemm's does through lda.

The parameters are numbered as in the signature, from 1: m, n, k, alpha (4), a (5), rsa (6), csa (7), b (8), rsb (9), csb (10), beta (11), c (12), rsc (13), csc (14). Every stride is at least 1. C must be row-major (csc = 1, rsc >= n) or column-major (rsc = 1, csc >= m): a C with both strides above 1 has no kernel form and is refused as parameter 13, and a column-major C whose csc is below m as 14. An invalid argument returns an *ArgError with Routine "DGEMMSTRIDED"; a slice is too short when it holds less than 1+(rows-1)*rs+(cols-1)*cs elements, reported against the slice's own number (5, 8, 12), the length being computed without overflow.

Beta, alpha, the quick returns, the error bound and the aliasing rule (C must not overlap A or B) are those of Dgemm; the product runs on the same packed, multicore kernel. The elements of the slices that are not elements of a matrix are never read or written.

func Dgemv

func Dgemv(t Transpose, m, n int, alpha float64, a []float64, lda int, x []float64, incx int, beta float64, y []float64, incy int) error

Dgemv computes y := alpha*op(A)*x + beta*y, where A is m x n column-major and op(A) is A, or A**T for Trans and ConjTrans. x has n elements for NoTrans and m otherwise, y the other; both are spaced by their increment, which may be negative (the vector is then traversed from its far end) but not zero. It is DGEMV of the reference BLAS, parameter for parameter, with the same rules for beta = 0 (y is not read), alpha = 0 (A and x are not read) and the quick returns; a slice too short for the call is an *ArgError on its own parameter (5, 7 and 10).

With unit increments each column is one go-simd/floats Axpy or Dot, so the result is within gamma_{r+2}(|alpha||op(A)||x| + |beta||y|) of the exact one, r being the length of the sums.

func Dnrm2

func Dnrm2(n int, x []float64, incx int) (float64, error)

Dnrm2 returns the Euclidean norm of x (DNRM2), by the 3.10 reference algorithm that neither overflows nor underflows when the result is representable, within gamma_{n+2} of the exact norm. The increment may be negative; n <= 0 returns 0.

func Drot added in v0.6.0

func Drot(n int, x []float64, incx int, y []float64, incy int, c, s float64) error

Drot applies the plane rotation x := c*x + s*y, y := c*y - s*x to the n elements of x and y (DROT). n <= 0 returns at once; a slice too short is an *ArgError on parameter 2 (x) or 4 (y). Increments may be negative, as in the reference; they are not tested for zero (the reference does not either).

func Dscal

func Dscal(n int, alpha float64, x []float64, incx int) error

Dscal computes x := alpha*x (DSCAL). n <= 0, incx <= 0 and alpha = 1 return at once; alpha = 0 stores 0*x, so a NaN stays one, as in the reference.

func Dswap added in v0.6.0

func Dswap(n int, x []float64, incx int, y []float64, incy int) error

Dswap exchanges the n elements of x and y (DSWAP). n <= 0 returns at once; a slice too short is an *ArgError on parameter 2 (x) or 4 (y).

func Dsymm added in v0.3.0

func Dsymm(side Side, uplo Uplo, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) error

Dsymm multiplies by a symmetric matrix: C := alpha*A*B + beta*C for side Left, C := alpha*B*A + beta*C for side Right. A is symmetric, m x m for Left and n x n for Right, of which only the triangle uplo names is referenced; B and C are m x n. All matrices are column-major. It is DSYMM of the reference BLAS, parameter for parameter: side 1, uplo 2, m 3, n 4, alpha 5, a 6, lda 7, b 8, ldb 9, beta 10, c 11, ldc 12.

With beta = 0, C is not read (it may hold NaN); with alpha = 0, A and B are not read (they may be empty); m = 0 or n = 0, and alpha = 0 with beta = 1, return at once. An invalid argument returns a *ArgError numbered like xerbla's, among them a slice too short for the call: a is checked against lda*(s-1)+s, s the order of A, b and c against ldb*(n-1)+m and ldc*(n-1)+m (parameters 6, 8 and 11).

The referenced triangle is copied, exactly, into a dense s x s scratch matrix (at most the size of A) and the product is one GEMM of the packed kernel, so the result is within the bound of Dgemm, with k = s,

|C^ - C| <= gamma_{s+2} (|alpha| |A| |B| + |beta| |C0|)   elementwise (|B| |A| for Right)

of the exact result, not bit-identical to netlib.Dsymm. It is not safe to call with c overlapping a or b.

func Dsymv added in v0.6.0

func Dsymv(uplo Uplo, n int, alpha float64, a []float64, lda int, x []float64, incx int, beta float64, y []float64, incy int) error

Dsymv computes y := alpha*A*x + beta*y for the n x n symmetric column-major matrix A, of which only the triangle uplo names is referenced (DSYMV, parameter for parameter: uplo 1, n 2, alpha 3, a 4, lda 5, x 6, incx 7, beta 8, y 9, incy 10). The increments may be negative but not zero. The quick returns are the reference's (n = 0, or alpha = 0 and beta = 1); with alpha = 0, a and x are not read, with beta = 0, y is not read. It is the reference loop, within gamma_{n+2}(|alpha||A||x| + |beta||y|) of the exact result.

func Dsyr2 added in v0.6.0

func Dsyr2(uplo Uplo, n int, alpha float64, x []float64, incx int, y []float64, incy int, a []float64, lda int) error

Dsyr2 computes the symmetric rank-2 update A := alpha*x*y**T + alpha*y*x**T + A on the triangle uplo names of the n x n matrix A (DSYR2: uplo 1, n 2, alpha 3, x 4, incx 5, y 6, incy 7, a 8, lda 9). The increments may be negative but not zero. n = 0 or alpha = 0 return at once. It is the reference loop, within gamma_4 (|A| + |alpha|(|x||y|^T + |y||x|^T)) of the exact result per element.

func Dsyr2k added in v0.3.0

func Dsyr2k(uplo Uplo, trans Transpose, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) error

Dsyr2k is the symmetric rank-2k update C := alpha*A*B**T + alpha*B*A**T + beta*C for trans NoTrans, C := alpha*A**T*B + alpha*B**T*A + beta*C for Trans and ConjTrans. C is n x n symmetric and only the triangle uplo names is referenced and written; A and B are n x k for NoTrans, k x n otherwise. All matrices are column-major. It is DSYR2K of the reference BLAS, parameter for parameter: uplo 1, trans 2, n 3, k 4, alpha 5, a 6, lda 7, b 8, ldb 9, beta 10, c 11, ldc 12.

The scalar rules, the quick returns and the slice checks are those of Dsyrk, with b checked like a (parameter 8). Blocked like Dsyrk, with two GEMMs per block off the diagonal, and on the diagonal one tile product A B**T of which the triangle of the sum with its transpose is merged into C. The result is within

|C^ - C| <= gamma_{2k+2} (|alpha| (|op(A)| |op(B)**T| + |op(B)| |op(A)**T|) + |beta| |C0|)   elementwise, on the triangle

of the exact result, not bit-identical to netlib.Dsyr2k. It is not safe to call with c overlapping a or b.

func Dsyrk added in v0.3.0

func Dsyrk(uplo Uplo, trans Transpose, n, k int, alpha float64, a []float64, lda int, beta float64, c []float64, ldc int) error

Dsyrk is the symmetric rank-k update C := alpha*A*A**T + beta*C for trans NoTrans, C := alpha*A**T*A + beta*C for Trans and ConjTrans (the same for real types). C is n x n symmetric and only the triangle uplo names is referenced and written (the other one is left as it was); A is n x k for NoTrans, k x n otherwise. All matrices are column-major. It is DSYRK of the reference BLAS, parameter for parameter: uplo 1, trans 2, n 3, k 4, alpha 5, a 6, lda 7, beta 8, c 9, ldc 10.

With beta = 0, C is not read (it may hold NaN); with alpha = 0, A is not read (it may be empty); n = 0, and alpha = 0 or k = 0 with beta = 1, return at once. An invalid argument returns a *ArgError numbered like xerbla's, among them a slice too short for the call: a is checked against lda*(cols-1)+rows, and c against ldc*(n-1)+n (parameters 6 and 9).

The triangle is cut into blocks of blockSize: GEMM on the blocks off the diagonal, and on each diagonal block a GEMM into a small scratch tile of which the triangle is merged into C. The result is within

|C^ - C| <= gamma_{k+2} (|alpha| |op(A)| |op(A)**T| + |beta| |C0|)   elementwise, on the triangle

of the exact result, the bound of Dgemm, not bit-identical to netlib.Dsyrk. It is not safe to call with c overlapping a.

func Dtrmm added in v0.3.0

func Dtrmm(side Side, uplo Uplo, tA Transpose, diag Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) error

Dtrmm multiplies by a triangular matrix, in place: B := alpha*op(A)*B for side Left, B := alpha*B*op(A) for side Right, where op(A) is A, or A**T for Trans and ConjTrans, and B is m x n. A is triangular, m x m for Left and n x n for Right, of which only the triangle uplo names is referenced, and with diag Unit its diagonal is not read and taken to be one. All matrices are column-major. It is DTRMM of the reference BLAS, parameter for parameter, with the parameters, the quick returns and the slice checks of Dtrsm: side 1, uplo 2, transA 3, diag 4, m 5, n 6, alpha 7, a 8, lda 9, b 10, ldb 11. With alpha = 0, B is set to zero and A is not read.

The product is blocked: GEMM updates on the packed kernel, and the reference's loops on diagonal blocks of blockSize rows. With s the order of A, it is within

|B^ - alpha op(A) B| <= gamma_{s+3} |alpha| |op(A)| |B|   elementwise (B op(A) for Right)

of the exact result, not bit-identical to netlib.Dtrmm. It is not safe to call with b overlapping a.

func Dtrsm added in v0.3.0

func Dtrsm(side Side, uplo Uplo, tA Transpose, diag Diag, m, n int, alpha float64, a []float64, lda int, b []float64, ldb int) error

Dtrsm solves a triangular system with m x n right-hand sides B, in place: B := alpha*inv(op(A))*B for side Left, B := alpha*B*inv(op(A)) for side Right, where op(A) is A, or A**T for Trans and ConjTrans. A is triangular, m x m for Left and n x n for Right, of which only the triangle uplo names is referenced, and with diag Unit its diagonal is not read and taken to be one. All matrices are column-major. It is DTRSM of the reference BLAS, parameter for parameter: side 1, uplo 2, transA 3, diag 4, m 5, n 6, alpha 7, a 8, lda 9, b 10, ldb 11.

With alpha = 0, B is set to zero and A is not read (it may be empty); m = 0 or n = 0 returns at once. As in the reference there is no singularity test: a zero on the diagonal of A gives infinities and NaNs in B. An invalid argument returns a *ArgError numbered like xerbla's, among them a slice too short for the call: a is checked against lda*(s-1)+s, s the order of A, and b against ldb*(n-1)+m (parameters 8 and 10).

The solve is blocked: GEMM updates on the packed kernel, and the reference's substitution on diagonal blocks of blockSize rows. Its contract is the backward error of substitution, of Higham's Theorem 8.5 (see docs/design.md), stated as a residual: with s the order of A and X the computed solution,

|op(A) X - alpha B| <= gamma_{s+4} (|op(A)| |X| + |alpha B|)   elementwise (Left; X op(A) for Right)

It is not bit-identical to netlib.Dtrsm. It is not safe to call with b overlapping a.

func HasSgemmKernel added in v0.2.0

func HasSgemmKernel() bool

HasSgemmKernel reports whether Sgemm runs on a SIMD kernel on this CPU. When it is false Sgemm runs the reference loops, which a caller with a faster fallback (widening to float64, say) may prefer to avoid.

func Idamax

func Idamax(n int, x []float64, incx int) (int, error)

Idamax returns the Fortran, 1-based, index of the first element of largest absolute value (IDAMAX), and 0 for n < 1 or incx <= 0. A NaN never compares larger, so it is skipped unless it comes first.

func Isamax

func Isamax(n int, x []float32, incx int) (int, error)

Isamax is Idamax in single precision (ISAMAX).

func Sasum

func Sasum(n int, x []float32, incx int) (float32, error)

Sasum is Dasum in single precision (SASUM).

func Saxpy

func Saxpy(n int, alpha float32, x []float32, incx int, y []float32, incy int) error

Saxpy is Daxpy in single precision (SAXPY).

func Scopy added in v0.6.0

func Scopy(n int, x []float32, incx int, y []float32, incy int) error

Scopy is Dcopy in single precision (SCOPY).

func Sdot

func Sdot(n int, x []float32, incx int, y []float32, incy int) (float32, error)

Sdot is Ddot in single precision (SDOT).

func Sgemm

func Sgemm(tA, tB Transpose, m, n, k int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) error

Sgemm is Dgemm in single precision (SGEMM). Without a float32 kernel on the running CPU it runs the reference loops of netlib.Sgemm.

func SgemmStrided added in v0.2.0

func SgemmStrided(m, n, k int, alpha float32, a []float32, rsa, csa int, b []float32, rsb, csb int, beta float32, c []float32, rsc, csc int) error

SgemmStrided is DgemmStrided in single precision (SGEMMSTRIDED). Without a float32 kernel on the running CPU it runs plain loops.

func Sgemv

func Sgemv(t Transpose, m, n int, alpha float32, a []float32, lda int, x []float32, incx int, beta float32, y []float32, incy int) error

Sgemv is Dgemv in single precision (SGEMV).

func Snrm2

func Snrm2(n int, x []float32, incx int) (float32, error)

Snrm2 is Dnrm2 in single precision (SNRM2).

func Srot added in v0.6.0

func Srot(n int, x []float32, incx int, y []float32, incy int, c, s float32) error

Srot is Drot in single precision (SROT).

func Sscal

func Sscal(n int, alpha float32, x []float32, incx int) error

Sscal is Dscal in single precision (SSCAL).

func Sswap added in v0.6.0

func Sswap(n int, x []float32, incx int, y []float32, incy int) error

Sswap is Dswap in single precision (SSWAP).

func Ssymm added in v0.3.0

func Ssymm(side Side, uplo Uplo, m, n int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) error

Ssymm is Dsymm in single precision (SSYMM). Without a float32 kernel on the running CPU it runs the reference loops of netlib.Ssymm.

func Ssymv added in v0.6.0

func Ssymv(uplo Uplo, n int, alpha float32, a []float32, lda int, x []float32, incx int, beta float32, y []float32, incy int) error

Ssymv is Dsymv in single precision (SSYMV).

func Ssyr2 added in v0.6.0

func Ssyr2(uplo Uplo, n int, alpha float32, x []float32, incx int, y []float32, incy int, a []float32, lda int) error

Ssyr2 is Dsyr2 in single precision (SSYR2).

func Ssyr2k added in v0.3.0

func Ssyr2k(uplo Uplo, trans Transpose, n, k int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) error

Ssyr2k is Dsyr2k in single precision (SSYR2K). Without a float32 kernel on the running CPU it runs the reference loops of netlib.Ssyr2k.

func Ssyrk added in v0.3.0

func Ssyrk(uplo Uplo, trans Transpose, n, k int, alpha float32, a []float32, lda int, beta float32, c []float32, ldc int) error

Ssyrk is Dsyrk in single precision (SSYRK). Without a float32 kernel on the running CPU it runs the reference loops of netlib.Ssyrk.

func Strmm added in v0.3.0

func Strmm(side Side, uplo Uplo, tA Transpose, diag Diag, m, n int, alpha float32, a []float32, lda int, b []float32, ldb int) error

Strmm is Dtrmm in single precision (STRMM). Without a float32 kernel on the running CPU it runs the reference loops of netlib.Strmm.

func Strsm added in v0.3.0

func Strsm(side Side, uplo Uplo, tA Transpose, diag Diag, m, n int, alpha float32, a []float32, lda int, b []float32, ldb int) error

Strsm is Dtrsm in single precision (STRSM). Without a float32 kernel on the running CPU it runs the reference loops of netlib.Strsm.

Types

type ArgError

type ArgError struct {
	Routine string // upper case, as xerbla prints it: "DGEMM"
	Param   int
}

ArgError reports an invalid argument the way the reference's xerbla does: by the routine and the number of the parameter, counted from 1 in the reference signature (so Param is 8 for the LDA of DGEMM). LAPACK's info is -Param.

Where the reference has no test, because Fortran cannot know the length of an array, a slice too short for what the call reads or writes is reported against the slice's own parameter number.

func (*ArgError) Error

func (e *ArgError) Error() string

func (*ArgError) Info

func (e *ArgError) Info() int

Info is the LAPACK convention for the same fact: -Param.

type Diag

type Diag byte

Diag says whether a triangular matrix has a unit diagonal.

const (
	NonUnit Diag = 'N'
	Unit    Diag = 'U'
)

type Side

type Side byte

Side says on which side of a product a matrix operand stands.

const (
	Left  Side = 'L'
	Right Side = 'R'
)

type Transpose

type Transpose byte

Transpose says whether a matrix operand is used as is, transposed, or conjugate-transposed. The values are the characters the Fortran routines take.

const (
	NoTrans   Transpose = 'N'
	Trans     Transpose = 'T'
	ConjTrans Transpose = 'C' // for real types, the same as Trans
)

type Uplo

type Uplo byte

Uplo says which triangle of a symmetric, Hermitian or triangular matrix is referenced. It is type-independent, like Diag and Side, and is taken by the level 3 routines Trsm, Trmm, Syrk, Syr2k and Symm.

const (
	Upper Uplo = 'U'
	Lower Uplo = 'L'
)

Directories

Path Synopsis
internal
check
Package check validates BLAS arguments the way the reference routines do, plus the one thing the reference cannot: that each slice is long enough for what the call reads or writes.
Package check validates BLAS arguments the way the reference routines do, plus the one thing the reference cannot: that each slice is long enough for what the call reads or writes.
oracle
Package oracle computes BLAS results exactly, in math/big floating point of 256 bits, together with the magnitudes the error bounds of package blas are stated against.
Package oracle computes BLAS results exactly, in math/big floating point of 256 bits, together with the magnitudes the error bounds of package blas are stated against.
ref
Package ref holds plain-Go ports of the reference BLAS 3.12 routines this module ships (Reference-LAPACK/lapack, tag v3.12.0, BLAS/SRC): dgemm.f, sgemm.f, dgemv.f, sgemv.f, ddot.f, sdot.f, daxpy.f, saxpy.f, dscal.f, sscal.f, dnrm2.f90, snrm2.f90, dasum.f, sasum.f, idamax.f and isamax.f (and, in level3.go, dtrsm.f, dtrmm.f, dsyrk.f, dsyr2k.f, dsymm.f and their single precision twins).
Package ref holds plain-Go ports of the reference BLAS 3.12 routines this module ships (Reference-LAPACK/lapack, tag v3.12.0, BLAS/SRC): dgemm.f, sgemm.f, dgemv.f, sgemv.f, ddot.f, sdot.f, daxpy.f, saxpy.f, dscal.f, sscal.f, dnrm2.f90, snrm2.f90, dasum.f, sasum.f, idamax.f and isamax.f (and, in level3.go, dtrsm.f, dtrmm.f, dsyrk.f, dsyr2k.f, dsymm.f and their single precision twins).
cmd module
Package lapack is the first LAPACK of the pure-Go BLAS of go-blas: the LU, Cholesky and QR factorizations and their solves, in single and double precision, with the reference (netlib, LAPACK 3.12) signatures, column-major, so that a Fortran ABI shim (julia's libblastrampoline, for one) can call them exactly:
Package lapack is the first LAPACK of the pure-Go BLAS of go-blas: the LU, Cholesky and QR factorizations and their solves, in single and double precision, with the reference (netlib, LAPACK 3.12) signatures, column-major, so that a Fortran ABI shim (julia's libblastrampoline, for one) can call them exactly:
Package netlib is the exact option: plain-Go ports of the reference BLAS 3.12 routines (Reference-LAPACK/lapack, tag v3.12.0, BLAS/SRC: dgemm.f, sgemm.f, dgemv.f, sgemv.f, ddot.f, sdot.f, daxpy.f, saxpy.f, dscal.f, sscal.f, dnrm2.f90, snrm2.f90, dasum.f, sasum.f, idamax.f, isamax.f, and the level 3 dtrsm.f, dtrmm.f, dsyrk.f, dsyr2k.f, dsymm.f with their single precision twins), in the reference's loop order and without fused multiply-add.
Package netlib is the exact option: plain-Go ports of the reference BLAS 3.12 routines (Reference-LAPACK/lapack, tag v3.12.0, BLAS/SRC: dgemm.f, sgemm.f, dgemv.f, sgemv.f, ddot.f, sdot.f, daxpy.f, saxpy.f, dscal.f, sscal.f, dnrm2.f90, snrm2.f90, dasum.f, sasum.f, idamax.f, isamax.f, and the level 3 dtrsm.f, dtrmm.f, dsyrk.f, dsyr2k.f, dsymm.f with their single precision twins), in the reference's loop order and without fused multiply-add.

Jump to

Keyboard shortcuts

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