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

3.2 KiB
Raw Blame History

[linalg.algs.blas1.asum]

29 Numerics library [numerics]

29.9 Basic linear algebra algorithms [linalg]

29.9.13 BLAS 1 algorithms [linalg.algs.blas1]

29.9.13.10 Sum of absolute values of vector elements [linalg.algs.blas1.asum]

🔗

template<[in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec, class Scalar> Scalar vector_abs_sum(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_abs_sum(ExecutionPolicy&& exec, InVec v, Scalar init);

1

#

[Note 1:

These functions correspond to the BLAS functionsSASUM, DASUM, SCASUM, and DZASUM[bib].

— end note]

2

#

Mandates: decltype(init + abs-if-needed(real-if-needed(declval())) +abs-if-needed(imag-if-needed(declval()))) is convertible to Scalar.

3

#

Returns: Let N be v.extent(0).

init if N is zero;

otherwise, if InVec::value_type is an arithmetic type,GENERALIZED_SUM(plus<>(), init, abs-if-needed(v[0]), …, abs-if-needed(v[N-1]))

otherwise,GENERALIZED_SUM(plus<>(), init, abs-if-needed(real-if-needed(v[0])) + abs-if-needed(imag-if-needed(v[0])), …, abs-if-needed(real-if-needed(v[N-1])) + abs-if-needed(imag-if-needed(v[N-1])))

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.

🔗

template<[in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec> auto vector_abs_sum(InVec v); template<class ExecutionPolicy, [in-vector](linalg.helpers.concepts#concept:in-vector "29.9.7.5Argument concepts[linalg.helpers.concepts]") InVec> auto vector_abs_sum(ExecutionPolicy&& exec, InVec v);

5

#

Effects: Let T be typename InVec::value_type.

Then,

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

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