Skip to content

Commit

Permalink
Remove NdFloatCore also make tests f32 not NdFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
xd009642 committed Dec 14, 2020
1 parent 668bae7 commit 2d6f045
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -135,7 +135,7 @@ use crate::iterators::{ElementsBase, ElementsBaseMut, Iter, IterMut, Lanes, Lane
pub use crate::arraytraits::AsArray;
#[cfg(feature = "std")]
pub use crate::linalg_traits::NdFloat;
pub use crate::linalg_traits::{LinalgScalar, NdFloatCore};
pub use crate::linalg_traits::LinalgScalar;

pub use crate::stacking::{concatenate, stack, stack_new_axis};

Expand Down
30 changes: 1 addition & 29 deletions src/linalg_traits.rs
Expand Up @@ -8,7 +8,7 @@
use crate::ScalarOperand;
#[cfg(feature = "std")]
use num_traits::Float;
use num_traits::{float::FloatCore, One, Zero};
use num_traits::{One, Zero};
use std::fmt;
use std::ops::{Add, Div, Mul, Sub};
use std::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign};
Expand Down Expand Up @@ -73,31 +73,3 @@ impl NdFloat for f32 {}
#[cfg(feature = "std")]
impl NdFloat for f64 {}

/// A no_std floating-point element type represented by `f32` and `f64`.
///
/// Trait `NdFloatCore` is only implemented for `f32` and `f64` and encompasses
/// much float-relevant ndarray functionality as possible, while working for no_std
/// code, including the traits needed for linear algebra and for *right hand side* scalar
/// operations (`ScalarOperand`).
///
/// This trait can only be implemented by `f32` and `f64`.
pub trait NdFloatCore:
FloatCore
+ AddAssign
+ SubAssign
+ MulAssign
+ DivAssign
+ RemAssign
+ fmt::Display
+ fmt::Debug
+ fmt::LowerExp
+ fmt::UpperExp
+ ScalarOperand
+ LinalgScalar
+ Send
+ Sync
{
}

impl NdFloatCore for f32 {}
impl NdFloatCore for f64 {}
2 changes: 1 addition & 1 deletion src/prelude.rs
Expand Up @@ -51,7 +51,7 @@ pub use crate::{array, azip, s};
pub use crate::ShapeBuilder;

#[doc(no_inline)]
pub use crate::{AsArray, NdFloatCore};
pub use crate::AsArray;

#[doc(no_inline)]
#[cfg(feature = "std")]
Expand Down
21 changes: 6 additions & 15 deletions tests/oper.rs
Expand Up @@ -10,6 +10,7 @@ use ndarray::prelude::*;
use ndarray::{rcarr1, rcarr2};
use ndarray::{Data, LinalgScalar};
use ndarray::{Ix, Ixs};
use num_traits::Zero;
use std::iter::FromIterator;

use approx::assert_abs_diff_eq;
Expand All @@ -33,18 +34,9 @@ fn test_oper(op: &str, a: &[f32], b: &[f32], c: &[f32]) {
test_oper_arr::<f32, _>(op, aa.clone(), bb.clone(), cc.clone());
}

#[cfg(feature = "std")]
trait TestFloat: NdFloat {}

#[cfg(not(feature = "std"))]
trait TestFloat: NdFloatCore {}

impl TestFloat for f32 {}

fn test_oper_arr<A, D>(op: &str, mut aa: ArcArray<A, D>, bb: ArcArray<A, D>, cc: ArcArray<A, D>)
fn test_oper_arr<A, D>(op: &str, mut aa: ArcArray<f32, D>, bb: ArcArray<f32, D>, cc: ArcArray<f32, D>)
where
A: TestFloat,
for<'a> &'a A: Neg<Output = A>,
D: Dimension,
{
match op {
Expand Down Expand Up @@ -155,17 +147,16 @@ fn scalar_operations() {
}
}

fn reference_dot<'a, A, V1, V2>(a: V1, b: V2) -> A
fn reference_dot<'a, V1, V2>(a: V1, b: V2) -> f32
where
A: TestFloat,
V1: AsArray<'a, A>,
V2: AsArray<'a, A>,
V1: AsArray<'a, f32>,
V2: AsArray<'a, f32>,
{
let a = a.into();
let b = b.into();
a.iter()
.zip(b.iter())
.fold(A::zero(), |acc, (&x, &y)| acc + x * y)
.fold(f32::zero(), |acc, (&x, &y)| acc + x * y)
}

#[test]
Expand Down

0 comments on commit 2d6f045

Please sign in to comment.