diff --git a/src/preprocessing/data_traits.rs b/src/preprocessing/data_traits.rs new file mode 100644 index 0000000..04b534e --- /dev/null +++ b/src/preprocessing/data_traits.rs @@ -0,0 +1,43 @@ +//! Traits to indicate that float variables can be viewed as categorical +//! This module assumes + +pub type CategoricalFloat = u16; + +// pub struct CategoricalFloat(u16); + +pub trait Categorizable { + type A; + + fn to_category(self) -> CategoricalFloat; + + fn is_valid(self) -> bool; + +} + +impl Categorizable for f32 { + + type A = CategoricalFloat; + + fn to_category(self) -> CategoricalFloat { + self as CategoricalFloat + } + + fn is_valid(self) -> bool { + let a = self.to_category(); + a as f32 == self + } +} + +impl Categorizable for f64 { + + type A = CategoricalFloat; + + fn to_category(self) ->CategoricalFloat { + self as CategoricalFloat + } + + fn is_valid(self) -> bool { + let a = self.to_category(); + a as f64 == self + } +} \ No newline at end of file