-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtraits.rs
47 lines (42 loc) · 1.26 KB
/
traits.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use almost::AlmostEqual;
use ndarray::NdFloat;
use num_traits::{Float, MulAdd, Num};
use std::ops::{Add, Mul};
/// Floating-point element types `f32` and `f64`.
///
/// Trait `Real` is only implemented for `f32` and `f64`, including the traits
/// needed for computing smoothing splines, manipulating n-d arrays and sparse matrices and also
/// checking almost equality.
///
/// This trait can only be implemented by `f32` and `f64`.
pub trait Real<T>:
Num
+ NdFloat
+ Default
+ AlmostEqual
+ Float
+ for<'r> std::ops::DivAssign<&'r T>
+ MulAdd<Output = T>
{
}
pub trait RealRef<S, T>: Add<S, Output = T> + Mul<S, Output = T> {}
impl Real<f32> for f32 {}
impl Real<f64> for f64 {}
impl RealRef<&f32, f32> for &f32 {}
impl RealRef<&f64, f64> for &f64 {}
// fn test<T>(
// a: &CsMatBase<T, usize, Vec<usize>, Vec<usize>, Vec<T>, usize>,
// b: &CsMatBase<T, usize, Vec<usize>, Vec<usize>, Vec<T>, usize>,
// ) where
// T: Real<T>,
// // for<'r> &'r T: Add<&'r T, Output = T>,
// for<'r> &'r T: RealRef<&'r T, T>
// {
// let c = a + b;
// }
// fn test2(
// a: &CsMatBase<f64, usize, Vec<usize>, Vec<usize>, Vec<f64>, usize>,
// b: &CsMatBase<f64, usize, Vec<usize>, Vec<usize>, Vec<f64>, usize>,
// ) {
// let c = a + b;
// }