Skip to content

Commit 2fba371

Browse files
committed
Merge Absolute traint into types.rs
1 parent 1bc8a41 commit 2fba371

File tree

2 files changed

+38
-41
lines changed

2 files changed

+38
-41
lines changed

src/types.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,55 @@ pub trait AssociatedComplex: Sized {
1111
type Complex;
1212
}
1313

14-
macro_rules! impl_assoc {
14+
/// Field with norm
15+
pub trait Absolute {
16+
type Output: Float;
17+
fn squared(&self) -> Self::Output;
18+
fn abs(&self) -> Self::Output {
19+
self.squared().sqrt()
20+
}
21+
}
22+
23+
macro_rules! impl_traits {
1524
($real:ty, $complex:ty) => {
25+
1626
impl AssociatedReal for $real {
1727
type Real = $real;
1828
}
29+
1930
impl AssociatedReal for $complex {
2031
type Real = $real;
2132
}
33+
2234
impl AssociatedComplex for $real {
2335
type Complex = $complex;
2436
}
37+
2538
impl AssociatedComplex for $complex {
2639
type Complex = $complex;
2740
}
28-
}} // impl_assoc!
2941

30-
impl_assoc!(f64, c64);
31-
impl_assoc!(f32, c32);
42+
impl Absolute for $real {
43+
type Output = Self;
44+
fn squared(&self) -> Self::Output {
45+
*self * *self
46+
}
47+
fn abs(&self) -> Self::Output {
48+
Float::abs(*self)
49+
}
50+
}
51+
52+
impl Absolute for $complex {
53+
type Output = $real;
54+
fn squared(&self) -> Self::Output {
55+
self.norm_sqr()
56+
}
57+
fn abs(&self) -> Self::Output {
58+
self.norm()
59+
}
60+
}
61+
62+
}} // impl_traits!
63+
64+
impl_traits!(f64, c64);
65+
impl_traits!(f32, c32);

src/vector.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,3 @@ impl<A, S, D, T> Norm for ArrayBase<S, D>
4343
})
4444
}
4545
}
46-
47-
/// Field with norm
48-
pub trait Absolute {
49-
type Output: Float;
50-
fn squared(&self) -> Self::Output;
51-
fn abs(&self) -> Self::Output {
52-
self.squared().sqrt()
53-
}
54-
}
55-
56-
macro_rules! impl_abs {
57-
($f:ty, $c:ty) => {
58-
59-
impl Absolute for $f {
60-
type Output = Self;
61-
fn squared(&self) -> Self::Output {
62-
*self * *self
63-
}
64-
fn abs(&self) -> Self::Output {
65-
Float::abs(*self)
66-
}
67-
}
68-
69-
impl Absolute for $c {
70-
type Output = $f;
71-
fn squared(&self) -> Self::Output {
72-
self.norm_sqr()
73-
}
74-
fn abs(&self) -> Self::Output {
75-
self.norm()
76-
}
77-
}
78-
79-
}} // impl_abs!
80-
81-
impl_abs!(f64, c64);
82-
impl_abs!(f32, c32);

0 commit comments

Comments
 (0)