File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -5,26 +5,38 @@ use super::ArrayPartialMulDot;
55#[ const_trait]
66pub trait ArrayPartialMagnitude < T , const N : usize > : ArrayPartialMulDot < T , N >
77{
8- fn try_magnitude_squared ( self ) -> Option < <T as Mul < T > >:: Output >
8+ fn try_magnitude_squared ( & self ) -> Option < <T as Mul < T > >:: Output >
99 where
1010 T : Mul < T , Output : AddAssign > + Copy ;
11- async fn try_magnitude_squared_async ( self ) -> Option < <T as Mul < T > >:: Output >
11+ async fn try_magnitude_squared_async ( & self ) -> Option < <T as Mul < T > >:: Output >
1212 where
1313 T : Mul < T , Output : AddAssign > + Copy ;
1414}
1515
1616impl < T , const N : usize > ArrayPartialMagnitude < T , N > for [ T ; N ]
1717{
18- fn try_magnitude_squared ( self ) -> Option < <T as Mul < T > >:: Output >
18+ fn try_magnitude_squared ( & self ) -> Option < <T as Mul < T > >:: Output >
1919 where
2020 T : Mul < T , Output : AddAssign > + Copy
2121 {
22- self . try_mul_dot ( self )
22+ if N == 0
23+ {
24+ return None ;
25+ }
26+
27+ let mut y = self [ 0 ] * self [ 0 ] ;
28+ let mut i = 1 ;
29+ while i < N
30+ {
31+ y += self [ i] * self [ i] ;
32+ i += 1
33+ }
34+ Some ( y)
2335 }
24- async fn try_magnitude_squared_async ( self ) -> Option < <T as Mul < T > >:: Output >
36+ async fn try_magnitude_squared_async ( & self ) -> Option < <T as Mul < T > >:: Output >
2537 where
2638 T : Mul < T , Output : AddAssign > + Copy
2739 {
28- self . try_mul_dot_async ( self ) . await
40+ self . try_mul_dot_async ( * self ) . await
2941 }
3042}
You can’t perform that action at this time.
0 commit comments