std/blas

March 17, 2026 · View on GitHub

SIMD-optimized Basic Linear Algebra Subprograms (BLAS) implementation.

Import

import <std/blas>

Notes

  • Experimental implementation with 16-byte alignment requirement
  • Automatically uses SIMD instructions (SSE, AVX) when available
  • Falls back to scalar operations on unsupported platforms

Vector Operations

abs

void abs<T>(usize n, T* x)

Computes absolute value of vector elements in-place.

sqrt

void sqrt<T>(usize n, T* x)

Computes square root of vector elements in-place.

asum

T asum<T>(usize n, T* x)

Returns sum of absolute values: Σ|x[i]|

axpy

void axpy<T>(usize n, T alpha, T* x, T* y)

Vector addition: y[i] += alpha * x[i]

axpby

void axpby<T>(usize n, T alpha, T* x, T beta, T* y)

Scaled vector addition: y[i] = alpha * x[i] + beta * y[i]

dot

T dot<T>(usize n, T* x, T* y)

Dot product: Σ(x[i] * y[i])

scale

void scale<T>(usize n, T* x, T alpha)

Scalar multiplication: x[i] *= alpha

norm

T norm<T>(usize n, T* x)

Euclidean norm: sqrt(Σ(x[i]²))

max

usize max<T>(usize n, T* x)

Returns index of maximum element.

min

usize min<T>(usize n, T* x)

Returns index of minimum element.

Matrix Operations

transpose

void transpose<T>(usize rows, usize columns, T* matrix, T* target)

Matrix transpose with SIMD optimization.

matmul

void matmul<T>(usize rows, usize columns, usize inners, T* mat1, T* mat2, T* result)
``$
\text{Matrix} \text{multiplication}: \text{result} = \text{mat1}  \times  \text{mat2}

### \text{vecmatmul}
$``d
void vecmatmul<T>(usize rows, usize columns, T* vector, T* matrix, T* result)

Vector-matrix multiplication.

Example

import <std/blas>

float[4] vec1 = [1.0, 2.0, 3.0, 4.0];
float[4] vec2 = [5.0, 6.0, 7.0, 8.0];

float dotProduct = std::blas::dot<float>(4, &vec1, &vec2);
std::blas::scale<float>(4, &vec1, 2.0);
std::blas::axpy<float>(4, 1.5, &vec1, &vec2);