1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
#ifndef HPC_MATVEC_ASUM_H
#define HPC_MATVEC_ASUM_H 1

#include <cassert>
#include <cmath>
#include <type_traits>
#include <hpc/aux/primitive_type.h>
#include <hpc/ulmblas/geaxpy.h>
#include <hpc/matvec/isgematrix.h>

namespace hpc { namespace matvec {

template <typename MA>
typename hpc::aux::PrimitiveType<typename MA::ElementType>::Type
asum(const MA &A)
{
    typedef typename MA::Index                        Index;
    typedef typename MA::ElementType                  T;
    typedef typename hpc::aux::PrimitiveType<T>::Type PT;

    PT result = 0;
    apply(A, [&result](T val, Index, Index)
             {
                 result += std::abs(val);
             });
    return result;
}

} } // namespace matvec, hpc

#endif // HPC_MATVEC_ASUM_H