Skip to content

[linalg] Discrepancy between [linalg.algs.blas1.nrm2] and reference implementation #320

@MattStephanson

Description

@MattStephanson

Hello,

[linalg.algs.blas1.nrm2]/3 specifies the return value of vector_two_norm as "The square root of the sum of the square of init and the squares of the absolute values of the elements of v." (emphasis added). But the reference implementation provides

return init + ssq_res.scaling_factor * sqrt(ssq_res.scaled_sum_of_squares);

which pulls init out of the square-root-of-sum-of-squares. If the purpose is to be able to calculate a two-norm in stages, then the language in [linalg] is the correct way to do it, which is why I'm filing a bug instead of an LWG issue. But LMK if I have it the other way around.

As an aside, however, the Standard language is more difficult to implement robustly because init can be complex. That is, $\sqrt{z^2 +x^2}$, with $z\in ℂ,x\in ℝ$ is harder to compute than $\sqrt{x^2+y^2}$ with $\{ x,y \} \in ℝ$.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions