Skip to main content

apply_resolution_with_matrix

Function apply_resolution_with_matrix 

Source
pub fn apply_resolution_with_matrix(
    energies: &[f64],
    matrix: &ResolutionMatrix,
    spectrum: &[f64],
) -> Result<Vec<f64>, ResolutionError>
Expand description

Checked variant of apply_r that validates the matrix was compiled for energies before applying.

Returns ResolutionError::LengthMismatch when either energies or spectrum has a length that disagrees with the matrix grid size. For the spectrum check, the energies field of the returned error holds the matrix grid length (the required length) so callers can read it as “expected vs got”. Returns ResolutionError::MatrixGridMismatch when the lengths match but the grid contents differ (per-element to_bits() compare).

Unlike apply_resolution_with_plan, this entrypoint does not enforce an ascending energies grid through the crate’s internal validate_inputs helper. That check is redundant here: the plan that produced the matrix was itself built on a sorted grid (via TabulatedResolution::plan, which validates sortedness), and the stored target_energies copy is used in the to_bits() grid-identity check above. Any energies slice that is not bit-identical to the matrix’s stored copy — including an unsorted permutation of the same values — fails with ResolutionError::MatrixGridMismatch.