Files
cppdraft_translate/cppdraft/linalg/algs/blas1/nrm2.md
2025-10-25 03:02:53 +03:00

3.2 KiB
Raw Blame History

[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.5Argument 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.5Argument concepts[linalg.helpers.concepts]") InVec, class Scalar> Scalar vector_two_norm(ExecutionPolicy&& exec, InVec v, Scalar init);

1

#

[Note 1:

These functions correspond to the BLAS function xNRM2[bib].

— end note]

2

#

Mandates: Let a beabs-if-needed(declval<typename InVec::value_type>()).

Then, decltype(init + a * a is convertible to Scalar.

3

#

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]

4

#

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.5Argument 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.5Argument concepts[linalg.helpers.concepts]") InVec> auto vector_two_norm(ExecutionPolicy&& exec, InVec v);

5

#

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{});