Created on 2026-01-28.00:00:00 last changed 1 week ago
Proposed resolution:
This wording is relative to N5032.
Modify [linalg.algs.blas1.nrm2] as indicated:
[Drafting note: As a drive-by fix the missing closing parenthesis of the decltype form has been added.]
template<in-vector InVec, scalar Scalar> Scalar vector_two_norm(InVec v, Scalar init); template<class ExecutionPolicy, in-vector InVec, scalar Scalar> Scalar vector_two_norm(ExecutionPolicy&& exec, InVec v, Scalar init);-1- [Note 1: These functions correspond to the BLAS function xNRM2[17]. — end note]
-2- Mandates: `InVec::value_type` and `Scalar` are either a floating-point type, or a specialization of `complex`. Let `a` be abs-if-needed(declval<typename InVec::value_type>()) and let `init_abs` be abs-if-needed(init). Then, decltype(init_abs * init_abs + a * a) is convertible to `Scalar`. -3- Returns: The square root of the sumof the square of `init` and the squares of the absolute values of the elements of `v`.whose terms are the following:
(3.1) — the square of the absolute value of `init`, and
(3.2) — 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 `Scalar` has higher precision than `InVec::value_type`, then intermediate terms in the sum use `Scalar`'s precision or greater.
Modify [linalg.algs.blas1.matfrobnorm] as indicated:
[Drafting note: As a drive-by fix one spurious `InVec` has been changed to `InMat`]
template<in-matrix InMat, scalar Scalar> Scalar matrix_frob_norm(InMat A, Scalar init); template<class ExecutionPolicy, in-matrix InMat, scalar Scalar> Scalar matrix_frob_norm(ExecutionPolicy&& exec, InMat A, Scalar init);-2- Mandates:
-3- Returns: The square root of the sumInVecInMat::value_type and `Scalar` are either a floating-point type, or a specialization of `complex`. Let `a` be abs-if-needed(declval<typename InMat::value_type>()) and let `init_abs` be abs-if-needed(init). Then, decltype(init_abs * init_abs + a * a) is convertible to `Scalar`.of the squares of `init` and the absolute values of the elements of `A`.whose terms are the following:
(3.1) — the square of the absolute value of `init`, and
(3.2) — the squares of the absolute values of the elements of `A`.
[Note 2: For `init` equal to zero, this is the Frobenius norm of the matrix `A`. — end note]
-4- Remarks: If `Scalar` has higher precision than `InMat::value_type`, then intermediate terms in the sum use `Scalar`'s precision or greater.
This pull request discussion points out two issues with the current wording of `vector_two_norm`:
If `Scalar` is the complex number `1 + i`, then the current wording would make `vector_two_norm` return sqrt(2i + nonnegative_real_number). This would have nonzero imaginary part.
If `Scalar` is the real number `-1.0`, then the current wording would make `vector_two_norm` return sqrt(-1.0 + nonnegative_real_number). If nonnegative_real_number is less than `1`, then the result would be imaginary.
The analogous issues would also apply to `matrix_frob_norm`.
It's acceptable for the return type `Scalar` to be `complex`. However, the point of letting `init` be nonzero is to support computing the 2-norm of a vector (or the Frobenius norm of a matrix) in multiple steps. The value of `init` should thus always represent a valid 2-norm (or Frobenius norm) result. There are two ways to fix this:Impose a precondition on `init`, that it have nonnegative real part and zero imaginary part.
Change the Returns element to take the absolute value of `init`. (The [linalg] clause generally uses "absolute value" to mean the magnitude of a complex number, or the absolute value of a non-complex number.)
We offer (2) as the Proposed Fix, as it is consistent with the approach we took for fixing LWG 4136.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2026-01-31 13:55:36 | admin | set | messages: + msg15913 |
| 2026-01-31 13:55:36 | admin | set | messages: + msg15912 |
| 2026-01-31 13:55:36 | admin | restored | |
| 2026-01-30 17:52:35 | admin | retired | |
| 2026-01-30 17:52:35 | admin | set | messages: - msg15901, msg15902 |
| 2026-01-28 17:44:46 | admin | set | messages: + msg15902 |
| 2026-01-28 00:00:00 | admin | create | |