1use diffsol::{FaerScalar, Matrix, NalgebraScalar};
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
13#[serde(rename_all = "snake_case")]
14pub enum MatrixType {
15 NalgebraDense,
16 FaerDense,
17 FaerSparse,
18}
19
20pub(crate) trait MatrixKind {
22 const MATRIX_TYPE: MatrixType;
23}
24
25impl<T: NalgebraScalar> MatrixKind for diffsol::NalgebraMat<T> {
26 const MATRIX_TYPE: MatrixType = MatrixType::NalgebraDense;
27}
28
29impl<T: FaerScalar> MatrixKind for diffsol::FaerMat<T> {
30 const MATRIX_TYPE: MatrixType = MatrixType::FaerDense;
31}
32
33impl<T: FaerScalar> MatrixKind for diffsol::FaerSparseMat<T> {
34 const MATRIX_TYPE: MatrixType = MatrixType::FaerSparse;
35}
36
37impl MatrixType {
38 pub(crate) fn get_name(&self) -> &str {
39 match self {
40 MatrixType::NalgebraDense => "nalgebra_dense",
41 MatrixType::FaerDense => "faer_dense",
42 MatrixType::FaerSparse => "faer_sparse",
43 }
44 }
45
46 pub(crate) fn from_diffsol<M: Matrix + MatrixKind>() -> Self {
48 M::MATRIX_TYPE
49 }
50}