MCPcopy Create free account
hub / github.com/Axect/Peroxide / norm

Method norm

src/complex/matrix.rs:875–930  ·  view source on GitHub ↗
(&self, kind: Norm)

Source from the content-addressed store, hash-verified

873 type UnsignedScalar = f64;
874
875 fn norm(&self, kind: Norm) -> Self::UnsignedScalar {
876 match kind {
877 Norm::F => {
878 let mut s = Complex::zero();
879 for i in 0..self.data.len() {
880 s += self.data[i].powi(2);
881 }
882 s.sqrt().re
883 }
884 Norm::Lpq(p, q) => {
885 let mut s = Complex::zero();
886 for j in 0..self.col {
887 let mut s_row = Complex::zero();
888 for i in 0..self.row {
889 s_row += self[(i, j)].powi(p as i32);
890 }
891 s += s_row.powf(q / p);
892 }
893 s.powf(1f64 / q).re
894 }
895 Norm::L1 => {
896 let mut m = Complex::zero();
897 match self.shape {
898 Shape::Row => self.change_shape().norm(Norm::L1),
899 Shape::Col => {
900 for c in 0..self.col {
901 let s: C64 = self.col(c).iter().sum();
902 if s.re > m.re {
903 m = s;
904 }
905 }
906 m.re
907 }
908 }
909 }
910 Norm::LInf => {
911 let mut m = Complex::zero();
912 match self.shape {
913 Shape::Col => self.change_shape().norm(Norm::LInf),
914 Shape::Row => {
915 for r in 0..self.row {
916 let s: C64 = self.row(r).iter().sum();
917 if s.re > m.re {
918 m = s;
919 }
920 }
921 m.re
922 }
923 }
924 }
925 Norm::L2 => {
926 unimplemented!()
927 }
928 Norm::Lp(_) => unimplemented!(),
929 }
930 }
931
932 fn normalize(&self, _kind: Norm) -> Self

Callers 3

gk_normMethod · 0.45
geppFunction · 0.45
gecpFunction · 0.45

Calls 9

iterMethod · 0.80
lenMethod · 0.45
powiMethod · 0.45
sqrtMethod · 0.45
powfMethod · 0.45
change_shapeMethod · 0.45
sumMethod · 0.45
colMethod · 0.45
rowMethod · 0.45

Tested by

no test coverage detected