/rust/registry/src/index.crates.io-1949cf8c6b5b557f/hyperdual-1.4.0/src/linalg.rs
Line | Count | Source |
1 | | use na::allocator::Allocator; |
2 | | use na::{DefaultAllocator, DimName, OVector, SVector, Scalar}; |
3 | | |
4 | | use crate::{Float, Hyperdual, OHyperdual, Zero}; |
5 | | |
6 | | /// Computes the norm of a vector of Hyperdual. |
7 | 0 | pub fn norm<T: Scalar + Float, const M: usize, const N: usize>(v: &SVector<Hyperdual<T, N>, M>) -> Hyperdual<T, N> |
8 | 0 | where |
9 | 0 | Hyperdual<T, N>: Float, |
10 | | { |
11 | 0 | let mut val = Hyperdual::<T, N>::zero(); |
12 | | |
13 | 0 | for i in 0..M { |
14 | 0 | val += v[i].powi(2); |
15 | 0 | } |
16 | | |
17 | 0 | val.sqrt() |
18 | 0 | } |
19 | | |
20 | | /// Computes the norm of a vector of Hyperdual. |
21 | | pub fn norm_owned<T: Scalar + Float, M: DimName, N: DimName>(v: &OVector<OHyperdual<T, N>, M>) -> OHyperdual<T, N> |
22 | | where |
23 | | OHyperdual<T, N>: Float, |
24 | | DefaultAllocator: Allocator<M> + Allocator<N>, |
25 | | <DefaultAllocator as Allocator<N>>::Buffer<T>: Copy, |
26 | | { |
27 | | let mut val = OHyperdual::<T, N>::zero(); |
28 | | |
29 | | for i in 0..M::dim() { |
30 | | val += v[i].powi(2); |
31 | | } |
32 | | |
33 | | val.sqrt() |
34 | | } |