[linalg.algs.blas1.asum]

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

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

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

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

[ð](#lib:vector_abs_sum)

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

[1](#1)

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

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

These functions correspond to the BLAS functionsSASUM, DASUM, SCASUM, and DZASUM[[bib]](bibliography#bib:blas1 "Bibliography")[.](#1.sentence-1)

â *end note*]

[2](#2)

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

*Mandates*: decltype(init + *abs-if-needed*(*real-if-needed*(declval<typename InVec::value_type>())) +*abs-if-needed*(*imag-if-needed*(declval<typename InVec::value_type>()))) is convertible to Scalar[.](#2.sentence-1)

[3](#3)

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

*Returns*: Let N be v.extent(0)[.](#3.sentence-1)

- [(3.1)](#3.1)

init if N is zero;

- [(3.2)](#3.2)

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

- [(3.3)](#3.3)

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](#4)

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

*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)

[ð](#lib:vector_abs_sum_)

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

[5](#5)

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

*Effects*: Let T be typename InVec​::​value_type[.](#5.sentence-1)

Then,

- [(5.1)](#5.1)

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

- [(5.2)](#5.2)

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