filtered_sum (Descriptive Statistics)


Import

#include <archr/stats/filtered_sum.h>
#include <archr/stats/filtered_sum.hpp>
import archr.stats
atomsLoads('archr')

Synopsis

 float archr_stats_filtered_sum_f32(const float *first, size_t nbelem);
(1)
 double archr_stats_filtered_sum_f64(const double *first, size_t nbelem);
(2)
 float filtered_sum(const float *first, size_t nbelem);
(1)
 double filtered_sum(const double *first, size_t nbelem);
(2)
 float filtered_sum(const float *first, const float *last);
(3)
 double filtered_sum(const double *first, const double *last);
(4)
template <typename Range> typename Range::value_type filtered_sum(const Range& data);
(5)
subroutine archr_stats_filtered_sum_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(1)
subroutine archr_stats_filtered_sum_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(2)
def filtered_sum(first):
    return r
(1)
function r = archr_stats_filtered_sum(first)
(1)

Description

This function computes the filtered sum of the elements stored in:

Parameters

first

the beginning of the range of elements to sum.

last

the end of the range of elements to sum.

nbelem

the number of elements to sum.

Return value

The sum of the elements in the given range or container in which any NaN elements are ignored.

Example

#include <archr/stats/filtered_sum.h>
#include <stdio.h>

int main()
{
  float fnan = 0.f/0.f;
  float v[] = {1,fnan,3,4,fnan,6};

  printf("filtered_sum(1,NaN,3,4,NaN,6) = %f\n", archr_stats_filtered_sum_f32(&v[0],6) );

  return 0;
}

Possible Output

filtered_sum(1,NaN,3,4,NaN,6) = 14.000000
filtered_sum(1,NaN,3,4)       = 8.000000
#include <archr/stats/filtered_sum.hpp>
#include <iostream>
#include <vector>

int main()
{
  float fnan = 0.f/0.f;
  std::vector<float> v{1,fnan,3,4,fnan,6};

  std::cout << "filtered_sum(1,NaN,3,4,NaN,6) = " << archr::stats::filtered_sum(v) << "\n";
  std::cout << "filtered_sum(1,NaN,3,4,NaN)   = " << archr::stats::filtered_sum(v.data(), 5) << "\n";
  std::cout << "filtered_sum(1,NaN,3,4)       = " << archr::stats::filtered_sum(v.data(), v.data() + 4) << "\n";

  return 0;
}

Possible Output

filtered_sum(1,NaN,3,4,NaN,6) = 14
filtered_sum(1,NaN,3,4,NaN)   = 8
filtered_sum(1,NaN,3,4)       = 8

Possible Output