Skip to main content

linear_roots_batch

Function linear_roots_batch 

Source
pub fn linear_roots_batch(
    eqns: &[LinearEqn],
    backend: ComputeBackend,
) -> Vec<Roots<1>>
Expand description

Roots of N independent linear equations a x + b = 0, on the chosen backend.

A batched wrapper over LinearEqn::roots — the per-equation closed-form solver is unchanged and is not reimplemented here. Each lane is an independent handful of floating-point operations, so this is the branch-lightest kernel in the module.

§Arguments

§Returns

One Roots<1> per equation, in input order. Degenerate cases are tagged rather than hidden: |a| < VSMALL yields a Nan-tagged root and an overflowing quotient yields PosInf/NegInf, exactly as the scalar solver does.

§Determinism

Bit-for-bit identical to calling LinearEqn::roots in a loop, on every backend and at any thread count: each lane is one independent closed-form evaluation.

§Example

use outram_foam_basic_lib::compute::ComputeBackend;
use outram_foam_basic_lib::math::parallel::linear_roots_batch;
use outram_foam_basic_lib::polynomial::{LinearEqn, RootType};

// 2x - 4 = 0  and  3x + 9 = 0
let eqns = [LinearEqn::new(2.0, -4.0), LinearEqn::new(3.0, 9.0)];
let roots = linear_roots_batch(&eqns, ComputeBackend::CpuMulti);

assert_eq!(roots[0].root_type(0), RootType::Real);
assert_eq!(roots[0].get(0), 2.0);
assert_eq!(roots[1].get(0), -3.0);