3.2 KiB
[linalg.algs.blas1.nrm2]
29 Numerics library [numerics]
29.9 Basic linear algebra algorithms [linalg]
29.9.13 BLAS 1 algorithms [linalg.algs.blas1]
29.9.13.9 Euclidean norm of a vector [linalg.algs.blas1.nrm2]
template<[in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InVec, class Scalar> Scalar vector_two_norm(InVec v, Scalar init); template<class ExecutionPolicy, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InVec, class Scalar> Scalar vector_two_norm(ExecutionPolicy&& exec, InVec v, Scalar init);
[Note 1:
These functions correspond to the BLAS function xNRM2[bib].
â end note]
Mandates: Let a beabs-if-needed(declval<typename InVec::value_type>()).
Then, decltype(init + a * a is convertible to Scalar.
Returns: The square root of the sum of the square of init and the squares of the absolute values of the elements of v.
[Note 2:
For init equal to zero, this is the Euclidean norm (also called 2-norm) of the vector v.
â end note]
Remarks: If InVec::value_type, and Scalar are all floating-point types or specializations of complex, and if Scalar has higher precision than InVec::value_type, then intermediate terms in the sum use Scalar's precision or greater.
[Note 3:
An implementation of this function for floating-point types T can use the scaled_sum_of_squares result fromvector_sum_of_squares(x, {.scaling_factor=1.0, .scaled_sum_of_squares=init}).
â end note]
template<[in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InVec> auto vector_two_norm(InVec v); template<class ExecutionPolicy, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5 Argument concepts [linalg.helpers.concepts]") InVec> auto vector_two_norm(ExecutionPolicy&& exec, InVec v);
Effects: Let a beabs-if-needed(declval<typename InVec::value_type>()).
Let T be decltype(a * a).
Then,
the one-parameter overload is equivalent to:return vector_two_norm(v, T{}); and
the two-parameter overload is equivalent to:return vector_two_norm(std::forward(exec), v, T{});