macro_rules! scalar_type {
($(#[$outer:meta])* $name:ident, $repr:ty) => {
#[derive(Copy, Clone, Debug, Default)]
#[repr(transparent)]
$(#[$outer])*
pub struct $name($repr);
impl $name {
#[doc = concat!("Creates a new `", stringify!($name), "` from its raw bit representation.")]
pub const fn from_bits(bits: $repr) -> Self {
Self(bits)
}
#[doc = concat!("Get the raw bit representation of the `", stringify!($name), "`.")]
pub const fn to_bits(&self) -> $repr {
self.0
}
}
};
}
cfg_if::cfg_if! { if #[cfg(feature = "half")] {
pub use half::f16;
pub use half::bf16;
} else {
scalar_type!(
#[allow(non_camel_case_types)]
f16, u16
);
scalar_type!(
#[allow(non_camel_case_types)]
bf16, u16
);
} }
cfg_if::cfg_if! { if #[cfg(feature = "num-complex")] {
pub use num_complex::Complex;
} else {
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
#[repr(C)]
pub struct Complex<T> {
pub re: T,
pub im: T,
}
} }
scalar_type!(
QInt8, u8
);
scalar_type!(
QUInt8, u8
);
scalar_type!(
QInt32, u32
);
scalar_type!(
QUInt4x2, u8
);
scalar_type!(
QUInt2x4, u8
);
scalar_type!(
Bits1x8, u8
);
scalar_type!(
Bits2x4, u8
);
scalar_type!(
Bits4x2, u8
);
scalar_type!(
Bits8, u8
);
scalar_type!(
Bits16, u16
);
scalar_type!(
#[allow(non_camel_case_types)]
Float8_e5m2, u8
);
scalar_type!(
#[allow(non_camel_case_types)]
Float8_e4m3fn, u8
);
scalar_type!(
#[allow(non_camel_case_types)]
Float8_e5m2fnuz, u8
);
scalar_type!(
#[allow(non_camel_case_types)]
Float8_e4m3fnuz, u8
);