Skip to content

Publicize internal traits to let users write generic fns #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ pub use crate::statistics::*;
mod statistics;

#[cfg(feature = "core")]
pub use crate::util::{FloatingPoint, ComplexFloating, RealFloating, RealNumber};
pub use crate::util::{get_size, HasAfEnum, ImplicitPromote};
pub use crate::util::{GrayRGBConvertible, ImageFilterType, ImageNativeType, Scanable};
pub use crate::util::{CovarianceComputable, EdgeComputable, MedianComputable, MomentsComputable};
#[cfg(feature = "core")]
mod util;

Expand Down
16 changes: 16 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ impl Zero for Complex32 {
}
}

///Trait qualifier to accept either real or complex typed data
pub trait FloatingPoint {
fn is_real() -> bool {
false
Expand Down Expand Up @@ -638,16 +639,19 @@ impl FloatingPoint for f32 {
}
}

///Trait qualifier to accept real data(numbers)
pub trait RealFloating {}

impl RealFloating for f64 {}
impl RealFloating for f32 {}

///Trait qualifier to accept complex data(numbers)
pub trait ComplexFloating {}

impl ComplexFloating for Complex64 {}
impl ComplexFloating for Complex32 {}

///Trait qualifier indicating it can hold real numbers only
pub trait RealNumber {}

impl RealNumber for f64 {}
Expand All @@ -661,19 +665,24 @@ impl RealNumber for bool {}
impl RealNumber for u64 {}
impl RealNumber for i64 {}

///Trait qualifier for the type of Arrays accepted by scan operations
pub trait Scanable {}

impl Scanable for i32 {}
impl Scanable for u32 {}
impl Scanable for u64 {}
impl Scanable for i64 {}

/// Trait qualifier for type of Array's that are accepted
/// by native image load/save functions.
pub trait ImageNativeType {}

impl ImageNativeType for f32 {}
impl ImageNativeType for u16 {}
impl ImageNativeType for u8 {}

/// Trait qualifier for type of Array's that are accepted
/// by image processing functions especially filtering algorithms
pub trait ImageFilterType {}

impl ImageFilterType for f64 {}
Expand All @@ -686,6 +695,8 @@ impl ImageFilterType for u8 {}
impl ImageFilterType for bool {}

// TODO Rust haven't stabilized trait aliases yet
/// Trait qualifier for given type indicating conversion capability between
/// grayscale and RGB triplets of data
pub trait GrayRGBConvertible {}

impl GrayRGBConvertible for f64 {}
Expand All @@ -697,6 +708,7 @@ impl GrayRGBConvertible for u16 {}
impl GrayRGBConvertible for u8 {}

// TODO Rust haven't stabilized trait aliases yet
/// Trait qualifier for given type indicating computability of Moments
pub trait MomentsComputable {}

impl MomentsComputable for f64 {}
Expand All @@ -708,6 +720,7 @@ impl MomentsComputable for u16 {}
impl MomentsComputable for u8 {}

// TODO Rust haven't stabilized trait aliases yet
/// Trait qualifier for given type indicating computability of Median
pub trait MedianComputable {}

impl MedianComputable for f64 {}
Expand All @@ -719,6 +732,8 @@ impl MedianComputable for u16 {}
impl MedianComputable for u8 {}

// TODO Rust haven't stabilized trait aliases yet
/// Trait qualifier for given type indicating if edge calculations such as
/// derivates etc. can be performed
pub trait EdgeComputable {}

impl EdgeComputable for f64 {}
Expand All @@ -729,6 +744,7 @@ impl EdgeComputable for i16 {}
impl EdgeComputable for u16 {}
impl EdgeComputable for u8 {}

/// Trait qualifier for given type indicating computability of covariance
pub trait CovarianceComputable {}

impl CovarianceComputable for f64 {}
Expand Down