Skip to content

Commit d202d75

Browse files
committed
Rename Absolute::squared() to Absolute::abs_sqr()
For complex numbers, the result of this function is actually the square of the absolute value of the number, not the square of the number. |a + bi|^2 == a^2 + b^2 == (a + bi)(a - bi) != (a + bi)^2
1 parent 57fc75c commit d202d75

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/norm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
self.iter().map(|x| x.abs()).sum()
3434
}
3535
fn norm_l2(&self) -> Self::Output {
36-
self.iter().map(|x| x.squared()).sum::<A::Real>().sqrt()
36+
self.iter().map(|x| x.abs_sqr()).sum::<A::Real>().sqrt()
3737
}
3838
fn norm_max(&self) -> Self::Output {
3939
self.iter().fold(A::Real::zero(), |f, &val| {

src/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use num_complex::Complex64 as c64;
1818
/// You can use the following operations with `A: Scalar`:
1919
///
2020
/// - [abs](trait.Absolute.html#method.abs)
21-
/// - [squared](trait.Absolute.html#tymethod.squared)
21+
/// - [abs_sqr](trait.Absolute.html#tymethod.abs_sqr)
2222
/// - [sqrt](trait.SquareRoot.html#tymethod.sqrt)
2323
/// - [exp](trait.Exponential.html#tymethod.exp)
2424
/// - [conj](trait.Conjugate.html#tymethod.conj)
@@ -100,9 +100,9 @@ pub trait AssociatedComplex: Sized {
100100

101101
/// Define `abs()` more generally
102102
pub trait Absolute: AssociatedReal {
103-
fn squared(&self) -> Self::Real;
103+
fn abs_sqr(&self) -> Self::Real;
104104
fn abs(&self) -> Self::Real {
105-
self.squared().sqrt()
105+
self.abs_sqr().sqrt()
106106
}
107107
}
108108

@@ -164,7 +164,7 @@ impl AssociatedComplex for $complex {
164164
}
165165

166166
impl Absolute for $real {
167-
fn squared(&self) -> Self::Real {
167+
fn abs_sqr(&self) -> Self::Real {
168168
*self * *self
169169
}
170170
fn abs(&self) -> Self::Real{
@@ -173,7 +173,7 @@ impl Absolute for $real {
173173
}
174174

175175
impl Absolute for $complex {
176-
fn squared(&self) -> Self::Real {
176+
fn abs_sqr(&self) -> Self::Real {
177177
self.norm_sqr()
178178
}
179179
fn abs(&self) -> Self::Real {

0 commit comments

Comments
 (0)