pub struct QuadratureBatch { /* private fields */ }Expand description
A batch of N quadrature outcomes, in the same order as the intervals handed
in.
Lane i of the result corresponds to intervals[i], always — the parallel
path preserves order.
§Getting values out
Self::values— all-or-nothing.Ok(Vec<f64>)only when every lane ran to completion; otherwiseErr(QuadratureBatchFailure).Self::solutions— per-lane, when the caller wants to handle failures individually.
§Units
See QuadratureSolution.
Implementations§
Source§impl QuadratureBatch
impl QuadratureBatch
Sourcepub fn solutions(&self) -> &[QuadratureSolution]
pub fn solutions(&self) -> &[QuadratureSolution]
Every lane’s outcome, in input order.
Sourcepub fn into_solutions(self) -> Vec<QuadratureSolution>
pub fn into_solutions(self) -> Vec<QuadratureSolution>
Consume the batch and take the outcomes.
Sourcepub fn get(&self, i: usize) -> Option<QuadratureSolution>
pub fn get(&self, i: usize) -> Option<QuadratureSolution>
Lane i’s outcome, or None if i is out of range.
Sourcepub fn all_evaluated(&self) -> bool
pub fn all_evaluated(&self) -> bool
Whether every lane ran to completion. Vacuously true when empty.
Sourcepub fn failure_count(&self) -> usize
pub fn failure_count(&self) -> usize
How many lanes failed, dimensionless.
Sourcepub fn first_failure(&self) -> Option<(usize, QuadratureSolution)>
pub fn first_failure(&self) -> Option<(usize, QuadratureSolution)>
The first failing lane and its outcome, if any.
Sourcepub fn failures(&self) -> Vec<(usize, QuadratureSolution)>
pub fn failures(&self) -> Vec<(usize, QuadratureSolution)>
Every failing lane, as (index, outcome) pairs.
Allocates, so prefer Self::first_failure on a hot path.
Sourcepub fn total_evaluations(&self) -> u64
pub fn total_evaluations(&self) -> u64
Total integrand evaluations over every lane, dimensionless.
Sourcepub fn values(&self) -> Result<Vec<f64>, QuadratureBatchFailure>
pub fn values(&self) -> Result<Vec<f64>, QuadratureBatchFailure>
All integrals, or an error naming the failures — the all-or-nothing path.
§Returns
Ok(v) with v[i] the integral over intervals[i], in the integral’s
units, when every lane ran to completion. Otherwise
Err(QuadratureBatchFailure). No Vec of plausible-looking
numbers is ever returned for a batch that contained a failure.
An empty batch returns Ok(vec![]).
§Errors
QuadratureBatchFailure when one or more lanes failed.
§Example
use outram_foam_basic_lib::compute::ComputeBackend;
use outram_foam_basic_lib::ode::parallel::{
quadrature_batch, QuadratureInterval, QuadratureRule, QuadratureStatus,
};
// Lane 1's upper limit is not finite.
let intervals = [
QuadratureInterval::new(0.0, 1.0),
QuadratureInterval::new(0.0, f64::INFINITY),
];
let batch = quadrature_batch(
&intervals,
QuadratureRule::Simpson { panels: 8 },
ComputeBackend::Serial,
|_, x| x * x,
);
let err = batch.values().expect_err("lane 1 has no finite interval");
assert_eq!(err.failure_count, 1);
assert_eq!(err.first_index, 1);
assert_eq!(err.first_status, QuadratureStatus::InvalidInterval);
// The good lane is still individually readable, and Simpson is exact
// for x^2.
let v = batch.solutions()[0].value().unwrap();
assert!((v - 1.0 / 3.0).abs() < 1e-15);
assert!(batch.solutions()[1].value().is_none());