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
32
33
34
35
36
37
38
39
40
|
#ifndef PYTHONIC_NUMPY_NANSUM_HPP
#define PYTHONIC_NUMPY_NANSUM_HPP
#include "pythonic/include/numpy/nansum.hpp"
#include "pythonic/utils/functor.hpp"
#include "pythonic/types/ndarray.hpp"
#include "pythonic/numpy/isnan.hpp"
PYTHONIC_NS_BEGIN
namespace numpy
{
template <class E, class F>
void _nansum(E begin, E end, F &sum, utils::int_<1>)
{
for (; begin != end; ++begin) {
auto curr = *begin;
if (!functor::isnan()(curr))
sum += curr;
}
}
template <class E, class F, size_t N>
void _nansum(E begin, E end, F &sum, utils::int_<N>)
{
for (; begin != end; ++begin)
_nansum((*begin).begin(), (*begin).end(), sum, utils::int_<N - 1>());
}
template <class E>
typename E::dtype nansum(E const &expr)
{
typename E::dtype s = 0;
_nansum(expr.begin(), expr.end(), s, utils::int_<E::value>());
return s;
}
}
PYTHONIC_NS_END
#endif
|