Skip to content

float32 #

Compensated (double-double) sums and dot products for f32 inputs, the f32 counterpart of the float64 dd API. Every f32 is exact in f64 and every product of two f32 values is exact in f64 (24 + 24 mantissa bits fit in 53), so accumulating the f64 values with error-free transformations keeps roughly 106 bits of precision: the results stay accurate on inputs where naive f32 evaluation cancels catastrophically, and the compensated variants are correctly rounded in practice (see vlang/vsl#65).

fn acos #

fn acos(x f32) f32

acos returns arccos(x).

fn argmax_unitary #

fn argmax_unitary(x []f32) int

argmax_unitary returns the index of the first largest element of x, or the index of the first NaN when x contains one. It panics when x is empty.

fn argmin_unitary #

fn argmin_unitary(x []f32) int

argmin_unitary returns the index of the first smallest element of x, or the index of the first NaN when x contains one. It panics when x is empty.

fn arrays_tolerance #

fn arrays_tolerance(data1 []f32, data2 []f32, tol f32) bool

arrays_tolerance exposes this operation as part of the public API.

fn asin #

fn asin(x f32) f32

asin returns arcsin(x).

fn atan #

fn atan(x f32) f32

atan returns arctan(x).

fn axpy_inc #

fn axpy_inc(alpha f32, x []f32, mut y []f32, n u32, incX u32, incY u32, ix u32, iy u32)

axpy_inc

fn axpy_inc_to #

fn axpy_inc_to(mut dst []f32, incdst u32, idst u32, alpha f32, x []f32, y []f32, n u32, incX u32, incY u32, ix u32, iy u32)

axpy_inc_to

fn axpy_unitary #

@[direct_array_access]
fn axpy_unitary(alpha f32, x []f32, mut y []f32)

axpy_unitary Length validation allows direct indexed access in the hot loop.

fn axpy_unitary_to #

@[direct_array_access]
fn axpy_unitary_to(mut dst []f32, alpha f32, x []f32, y []f32)

axpy_unitary_to Length validation allows direct indexed access in the hot loop.

fn cos #

fn cos(x f32) f32

cos returns cos(x).

fn cosh #

fn cosh(x f32) f32

cosh returns cosh(x).

fn dot_compensated #

fn dot_compensated(x []f32, y []f32) f32

dot_compensated returns the dot product of x and y rounded once to f32 from the double-double result: correctly rounded in practice.

fn dot_dd #

@[direct_array_access]
fn dot_dd(x []f32, y []f32) (f64, f64)

dot_dd returns the double-double dot product (hi, lo) of x and y. Each product is exact in f64, so no product splitting is needed before the compensated accumulation.

fn dot_inc #

fn dot_inc(x []f32, y []f32, n u32, incX u32, incY u32, ix u32, iy u32) f32

dot_inc

fn dot_unitary #

@[direct_array_access]
fn dot_unitary(x []f32, y []f32) f32

dot_unitary returns the f32 dot product, accumulating rounded f32 products in f64 so low-order terms are retained until the final f32 result. Length validation allows direct indexed access in the hot loop.

fn exp #

fn exp(x f32) f32

exp returns e^x, correctly rounded in practice (see module comment).

fn exp2 #

fn exp2(x f32) f32

exp2 returns 2^x.

fn exp_unitary_to #

fn exp_unitary_to(mut dst []f32, x []f32)

exp_unitary_to sets dst[i] = e^x[i] for every element of x.

fn expm1 #

fn expm1(x f32) f32

expm1 returns e^x - 1, accurate for x near zero.

fn expm1_unitary_to #

fn expm1_unitary_to(mut dst []f32, x []f32)

expm1_unitary_to sets dst[i] = e^x[i] - 1, accurate for small |x[i]|.

fn gemv_n #

fn gemv_n(m u32, n u32, alpha f32, a []f32, lda u32, x []f32, incx int, beta f32, mut y []f32, incy int)

gemv_n computes y = alpha * A * x + beta * y where A is an m×n dense matrix, x and y are vectors, and alpha and beta are scalars.

fn gemv_t #

fn gemv_t(m u32, n u32, alpha f32, a []f32, lda u32, x []f32, incx int, beta f32, mut y []f32, incy int)

gemv_t computes y = alpha * Aᵀ * x + beta * y where A is an m×n dense matrix, x and y are vectors, and alpha and beta are scalars.

fn ger #

fn ger(m u32, n u32, alpha f32, x []f32, incx u32, y []f32, incy u32, mut a []f32, lda u32)

ger performs the rank-one operation A += alpha * x * yᵀ where A is an m×n dense matrix, x and y are vectors, and alpha is a scalar.

fn l2_distance_unitary #

fn l2_distance_unitary(x []f32, y []f32) f32

l2_distance_unitary returns the L2-norm of x-y.

fn l2_norm_inc #

fn l2_norm_inc(x []f32, n u32, incx u32) f32

l2_norm_inc returns the L2-norm of x.

fn l2_norm_unitary #

fn l2_norm_unitary(x []f32) f32

l2_norm_unitary returns the L2-norm of x.

fn log #

fn log(x f32) f32

log returns the natural logarithm of x.

fn log10 #

fn log10(x f32) f32

log10 returns the base-10 logarithm of x.

fn log1p #

fn log1p(x f32) f32

log1p returns log(1 + x), accurate for x near zero.

fn log1p_unitary_to #

fn log1p_unitary_to(mut dst []f32, x []f32)

log1p_unitary_to sets dst[i] = ln(1 + x[i]), accurate for small |x[i]|.

fn log2 #

fn log2(x f32) f32

log2 returns the base-2 logarithm of x.

fn log_unitary_to #

fn log_unitary_to(mut dst []f32, x []f32)

log_unitary_to sets dst[i] = ln(x[i]); negative inputs give NaN and zero gives -Inf.

fn max_unitary #

fn max_unitary(x []f32) f32

max_unitary returns the largest element of x (NaN if x contains a NaN). It panics when x is empty.

fn min_unitary #

fn min_unitary(x []f32) f32

min_unitary returns the smallest element of x (NaN if x contains a NaN). It panics when x is empty.

fn minmax_unitary #

fn minmax_unitary(x []f32) (f32, f32)

minmax_unitary returns (min, max) of x in one pass, so ptp is mx - mn. Any NaN in x makes both results NaN. It panics when x is empty.

fn reduce_vectorized #

fn reduce_vectorized() bool

reduce_vectorized reports whether the reductions in this file run the AVX2 kernels on this machine (false means the pure-V fallback is used).

fn scal_inc #

fn scal_inc(alpha f32, mut x []f32, n u32, incx u32)

scal_inc

fn scal_inc_to #

fn scal_inc_to(mut dst []f32, incdst u32, alpha f32, x []f32, n u32, incx u32)

scal_inc_to

fn scal_unitary #

fn scal_unitary(alpha f32, mut x []f32)

scal_unitary

fn scal_unitary_to #

fn scal_unitary_to(mut dst []f32, alpha f32, x []f32)

scal_unitary_to

fn sigmoid_unitary_to #

fn sigmoid_unitary_to(mut dst []f32, x []f32)

sigmoid_unitary_to sets dst[i] = 1 / (1 + e^-x[i]) without overflow for large negative inputs.

fn sin #

fn sin(x f32) f32

sin returns sin(x). Accuracy for very large |x| is bounded by the libm argument reduction beyond 1e15, as in float64.

fn sinh #

fn sinh(x f32) f32

sinh returns sinh(x).

fn sum_compensated #

fn sum_compensated(x []f32) f32

sum_compensated returns the sum of x rounded once to f32 from the double-double sum: correctly rounded in practice.

fn sum_dd #

fn sum_dd(x []f32) (f64, f64)

sum_dd returns the double-double sum (hi, lo) of x: hi + lo approximates the true sum with roughly 106 bits of precision.

fn sum_unitary #

fn sum_unitary(x []f32) f32

sum_unitary returns the sum of x using pairwise summation, so the rounding error grows like O(log n * eps) instead of O(n * eps) for a left-to-right loop (the same family of algorithm as NumPy's np.sum). The AVX2 kernel sums blocks of up to 1024 elements with 32 independent lanes and adds larger inputs by recursive halving; the pure-V fallback follows NumPy's pairwise_sum (blocks of 128 with 8 accumulators). Accumulation is in f32. The two paths round differently in the last bits; the result for a given path and length is deterministic. For a compensated or double-double sum use sum_compensated or sum_dd. An empty slice sums to 0.

fn tan #

fn tan(x f32) f32

tan returns tan(x).

fn tanh #

fn tanh(x f32) f32

tanh returns tanh(x).

fn tanh_unitary_to #

fn tanh_unitary_to(mut dst []f32, x []f32)

tanh_unitary_to sets dst[i] = tanh(x[i]); the result saturates to +-1 for large |x[i]|.

fn vmath_vectorized #

fn vmath_vectorized() bool

vmath_vectorized reports whether the *_unitary_to functions run the AVX2 kernels on this machine (false means the pure-V math fallback is used).