include/vecmat/reduce.h file

Compensated reductions and extrema on contiguous buffers.

Sum and dot use Neumaier compensation in the accumulation type. vm_sum_f32f64 and vm_dot_f32f64 are fixed names, compiled once, and are not remapped in abi.h. The mixed dot widens each factor to f64 before the multiply. n <= 0 returns +0 and does not read.

Functions

auto vm_sum_compensated(const vm_float_t* x, int n) -> vm_float_t
Neumaier sum of x[0..n).
auto vm_dot_compensated(const vm_float_t* a, const vm_float_t* b, int n) -> vm_float_t
Neumaier dot product of a and b.
auto vm_sum_f32f64(const vm_float32_t* x, int n) -> vm_float64_t
f64 Neumaier sum of f32 values.
auto vm_dot_f32f64(const vm_float32_t* a, const vm_float32_t* b, int n) -> vm_float64_t
f64 Neumaier dot of f32 values, widened before the multiply.
auto vm_array_minmax(vm_float_t* min_value, vm_float_t* max_value, const vm_float_t* x, int n) -> bool
Minimum and maximum, ignoring NaNs.

Function documentation

vm_float_t vm_sum_compensated(const vm_float_t* x, int n)

Neumaier sum of x[0..n).

Returns Compensated sum, or +0 when n <= 0.

n <= 0 returns +0 and does not read. On finite non-overflow inputs with n <= 10^6, the absolute error is at most 16 eps × sum(|terms|). The same binary and input repeat.

vm_float_t vm_dot_compensated(const vm_float_t* a, const vm_float_t* b, int n)

Neumaier dot product of a and b.

Parameters
a Left input; length n. Ignored when n <= 0.
b Right input; length n. May exactly alias a.
n
Returns Compensated dot, or +0 when n <= 0.

The product is formed in vm_float_t, then compensated. a may exactly alias b. n <= 0 returns +0 and does not read. The absolute-error target matches vm_sum_compensated.

vm_float64_t vm_sum_f32f64(const vm_float32_t* x, int n)

f64 Neumaier sum of f32 values.

Returns Compensated f64 sum, or +0 when n <= 0.

Each term is widened before it is accumulated. Compiled once; the name is not remapped. n <= 0 returns +0 and does not read.

vm_float64_t vm_dot_f32f64(const vm_float32_t* a, const vm_float32_t* b, int n)

f64 Neumaier dot of f32 values, widened before the multiply.

Parameters
a Left input; length n. Ignored when n <= 0.
b Right input; length n. May exactly alias a.
n
Returns Compensated f64 dot, or +0 when n <= 0.

a[i] and b[i] are converted to f64, then multiplied. Compiled once; the name is not remapped. a may exactly alias b. n <= 0 returns +0 and does not read.

bool vm_array_minmax(vm_float_t* min_value, vm_float_t* max_value, const vm_float_t* x, int n)

Minimum and maximum, ignoring NaNs.

Parameters
min_value Output minimum. Unchanged on failure.
max_value Output maximum. Unchanged on failure.
x
n
Returns true when at least one non-NaN value was seen.

n <= 0, a missing pointer, or an all-NaN input returns false and leaves *min_value and *max_value unchanged. Infinities count. The minimum of ±0 is −0 and the maximum is +0. A selected finite or infinite value is exact.