[linalg.algs.blas1.nrm2]

# 29 Numerics library [[numerics]](./#numerics)

## 29.9 Basic linear algebra algorithms [[linalg]](linalg#algs.blas1.nrm2)

### 29.9.13 BLAS 1 algorithms [[linalg.algs.blas1]](linalg.algs.blas1#nrm2)

#### 29.9.13.9 Euclidean norm of a vector [linalg.algs.blas1.nrm2]

[ð](#lib:vector_two_norm)

`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);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13796)

[*Note [1](#note-1)*:

These functions correspond to the BLAS function xNRM2[[bib]](bibliography#bib:blas1 "Bibliography")[.](#1.sentence-1)

â *end note*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13801)

*Mandates*: Let a be*abs-if-needed*(declval<typename InVec​::​value_type>())[.](#2.sentence-1)

Then, decltype(init + a * a is convertible to Scalar[.](#2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13807)

*Returns*: The square root of the sum of the square of init and the squares of the absolute values of the elements of v[.](#3.sentence-1)

[*Note [2](#note-2)*:

For init equal to zero, this is the Euclidean norm
(also called 2-norm) of the vector v[.](#3.sentence-2)

â *end note*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13815)

*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[.](#4.sentence-1)

[*Note [3](#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})[.](#4.sentence-2)

â *end note*]

[ð](#lib:vector_two_norm_)

`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);
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L13838)

*Effects*: Let a be*abs-if-needed*(declval<typename InVec​::​value_type>())[.](#5.sentence-1)

Let T be decltype(a * a)[.](#5.sentence-2)

Then,

- [(5.1)](#5.1)

the one-parameter overload is equivalent to:return vector_two_norm(v, T{}); and

- [(5.2)](#5.2)

the two-parameter overload is equivalent to:return vector_two_norm(std::forward<ExecutionPolicy>(exec), v, T{});
