#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DeviceId(pub String);
impl DeviceId {
pub fn cpu() -> Self {
Self("cpu".to_string())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RepresentationId(pub String);
impl RepresentationId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Layout {
Scalar,
Contiguous,
Strided(Vec<isize>),
Blocked { block_shape: Vec<usize> },
CoverIndexed,
PadicLimbArray,
PadicBall,
Symbolic,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Representation {
DenseTensor { layout: Layout, device: DeviceId },
SparseTensor { layout: Layout, device: DeviceId },
LazyExpression,
CoverIndexedSection { device: DeviceId },
PadicScalar,
Symbolic,
}
impl Representation {
pub fn dense_cpu() -> Self {
Self::DenseTensor {
layout: Layout::Contiguous,
device: DeviceId::cpu(),
}
}
pub fn id(&self) -> RepresentationId {
match self {
Self::DenseTensor { layout, device } => {
RepresentationId::new(format!("dense_tensor:{}:{}", layout.id(), device.0))
}
Self::SparseTensor { layout, device } => {
RepresentationId::new(format!("sparse_tensor:{}:{}", layout.id(), device.0))
}
Self::LazyExpression => RepresentationId::new("lazy_expression"),
Self::CoverIndexedSection { device } => {
RepresentationId::new(format!("cover_indexed_section:{}", device.0))
}
Self::PadicScalar => RepresentationId::new("padic_scalar"),
Self::Symbolic => RepresentationId::new("symbolic"),
}
}
}
impl Layout {
pub fn id(&self) -> String {
match self {
Self::Scalar => "scalar".to_string(),
Self::Contiguous => "contiguous".to_string(),
Self::Strided(strides) => format!("strided:{strides:?}"),
Self::Blocked { block_shape } => format!("blocked:{block_shape:?}"),
Self::CoverIndexed => "cover_indexed".to_string(),
Self::PadicLimbArray => "padic_limb_array".to_string(),
Self::PadicBall => "padic_ball".to_string(),
Self::Symbolic => "symbolic".to_string(),
}
}
}