pub fn map_error(op: Op, error: Error) -> ErrorExpand description
Rebuild tenferro’s error from a tlinalg (faer route) failure.
This is the translation tenferro’s own linalg entries apply to every tlinalg failure. A
caller that runs tlinalg factorizations itself, for example on the bundle
tenferro_cpu::CpuEngine::with_exec lends, calls it to report
exactly the error tenferro would have reported for the same failure. The types are those of the
tlinalg build this crate links, so a caller names them through a tlinalg dependency of the
same semver-compatible version.
§Contract
The mapping is total and never panics. It is decided in two steps:
- Operation name. Every error it builds names
op.as_str()from theopargument. Theopfield stored insideerroris not consulted, so when the two disagree the argument wins. The only place the inneropsurvives is the typed source ofInsufficientWorkspace, which is the provider error itself. - Variant. One
matchon thetlinalg::Errorvariant. The arms are disjoint, so their order does not change the result; the catch-all arm is last and fires only for a variant no arm names.
tlinalg::Error | tenferro error | ErrorKind | Downcastable source |
|---|---|---|---|
NonConvergence | Extension (linalg family) | NumericalFailure | Error::NonConvergence { op } |
NonFinite { role } | Extension (linalg family) | NumericalFailure | Error::NonFinite { op, role: role.as_str() } |
Singular | Extension (linalg family) | NumericalFailure | Error::Singular { op } |
InvalidArgument { role, detail } | Validation | Validation(InvalidArgument) | ValidationError::InvalidArgument { argument: role, message: detail } |
InvalidWorkspace { library, routine, detail } | BackendSource | BackendFailure | crate-private; library, routine and detail are in the message |
Inconsistent { detail } | Internal("{op}: {detail}") | Internal | none |
InsufficientWorkspace | RuntimeStateSource | RuntimeState | the tlinalg::Error itself, op, needed and have included |
| any other variant | Internal("{op}: unmapped linalg provider error {error:?}") | Internal | none |
The last row is the case that cannot be represented. tlinalg::Error is
#[non_exhaustive], so a later tlinalg may add a variant this crate does not know. The
mapping does not guess a kind for it: it returns the generic Internal variant with the
provider error’s Debug text, so the failure stays visible and is never misclassified as a
numerical or caller error. Against the tlinalg this crate links, every variant has its own
row and the last row is unreachable.
§Examples
use std::error::Error as _;
use tenferro_tensor::ErrorKind;
let error = tenferro_linalg::error::map_error(
tlinalg::Op::Svd,
tlinalg::Error::NonConvergence { op: tlinalg::Op::Svd },
);
assert_eq!(error.kind(), ErrorKind::NumericalFailure);
assert!(matches!(
error.source().and_then(|source| source.downcast_ref()),
Some(tenferro_linalg::Error::NonConvergence { op: "svd" })
));