use std::fmt;
use crate::symbolic::View::bvp_codegen::PreparedSparseAtomBvpCodegen;
use crate::symbolic::bvp::atom_aot::{AtomAotPlanError, AtomAotPreparedPlan};
use crate::symbolic::codegen::codegen_manifest::PreparedProblemManifest;
use crate::symbolic::codegen::codegen_provider_api::MatrixBackend;
use crate::symbolic::symbolic_engine::Expr;
#[derive(Clone, Copy, Debug)]
pub(crate) struct ExprLegacyAotAdapter<'a> {
pub residuals: &'a [Expr],
pub sparse_entries: &'a [(usize, usize, Expr)],
pub shape: (usize, usize),
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct AtomViewAotAdapter<'a> {
pub codegen: &'a PreparedSparseAtomBvpCodegen,
pub plan: &'a AtomAotPreparedPlan,
}
impl<'a> AtomViewAotAdapter<'a> {
pub(crate) fn prepared_manifest(
&self,
matrix_backend: MatrixBackend,
) -> Result<PreparedProblemManifest, AtomAotPlanError> {
self.codegen
.prepared_aot_manifest_from_plan(matrix_backend, self.plan)
}
}
#[derive(Clone, Copy, Debug)]
pub(crate) enum BvpAotAdapter<'a> {
ExprLegacy(ExprLegacyAotAdapter<'a>),
AtomView(AtomViewAotAdapter<'a>),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum BvpAotAdapterError {
AtomViewPlanMissing,
AtomViewCodegenMissing,
}
impl fmt::Display for BvpAotAdapterError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::AtomViewPlanMissing => {
f.write_str("AtomView AOT adapter has no validated prepared plan")
}
Self::AtomViewCodegenMissing => {
f.write_str("AtomView AOT adapter has no codegen payload")
}
}
}
}
impl std::error::Error for BvpAotAdapterError {}