use num_complex::Complex;
pub type Complex32 = Complex<f32>;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Dtype {
F32,
F16,
}
impl Dtype {
pub const fn size(self) -> usize {
match self {
Dtype::F32 => 4,
Dtype::F16 => 2,
}
}
pub const fn as_str(self) -> &'static str {
match self {
Dtype::F32 => "float32",
Dtype::F16 => "float16",
}
}
}
pub trait Element: Copy + Send + Sync + 'static {
const DTYPE: Dtype;
fn zero() -> Self;
}
impl Element for f32 {
const DTYPE: Dtype = Dtype::F32;
fn zero() -> Self {
0.0
}
}
impl Element for half::f16 {
const DTYPE: Dtype = Dtype::F16;
fn zero() -> Self {
half::f16::from_f32_const(0.0)
}
}