sum (Descriptive Statistics)


Import

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

Synopsis

 float archr_stats_sum_f32(const float *first, size_t nbelem);
(1)
 double archr_stats_sum_f64(const double *first, size_t nbelem);
(2)
 int8_t archr_stats_sum_i8(const int8_t *first, size_t nbelem);
(3)
 int16_t archr_stats_sum_i16(const int16_t *first, size_t nbelem);
(4)
 int32_t archr_stats_sum_i32(const int32_t *first, size_t nbelem);
(5)
 int64_t archr_stats_sum_i64(const int64_t *first, size_t nbelem);
(6)
 uint8_t archr_stats_sum_u8(const uint8_t *first, size_t nbelem);
(7)
 uint16_t archr_stats_sum_u16(const uint16_t *first, size_t nbelem);
(8)
 uint32_t archr_stats_sum_u32(const uint32_t *first, size_t nbelem);
(9)
 uint64_t archr_stats_sum_u64(const uint64_t *first, size_t nbelem);
(10)
 float sum(const float *first, size_t nbelem);
(1)
 double sum(const double *first, size_t nbelem);
(2)
 int8_t sum(const int8_t *first, size_t nbelem);
(3)
 int16_t sum(const int16_t *first, size_t nbelem);
(4)
 int32_t sum(const int32_t *first, size_t nbelem);
(5)
 int64_t sum(const int64_t *first, size_t nbelem);
(6)
 uint8_t sum(const uint8_t *first, size_t nbelem);
(7)
 uint16_t sum(const uint16_t *first, size_t nbelem);
(8)
 uint32_t sum(const uint32_t *first, size_t nbelem);
(9)
 uint64_t sum(const uint64_t *first, size_t nbelem);
(10)
 float sum(const float *first, const float *last);
(11)
 double sum(const double *first, const double *last);
(12)
 int8_t sum(const int8_t *first, const int8_t *last);
(13)
 int16_t sum(const int16_t *first, const int16_t *last);
(14)
 int32_t sum(const int32_t *first, const int32_t *last);
(15)
 int64_t sum(const int64_t *first, const int64_t *last);
(16)
 uint8_t sum(const uint8_t *first, const uint8_t *last);
(17)
 uint16_t sum(const uint16_t *first, const uint16_t *last);
(18)
 uint32_t sum(const uint32_t *first, const uint32_t *last);
(19)
 uint64_t sum(const uint64_t *first, const uint64_t *last);
(20)
template <typename Range> typename Range::value_type sum(const Range& data);
(21)
subroutine archr_stats_sum_f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(1)
subroutine archr_stats_sum_f64(real(8) :: r, real(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(2)
subroutine archr_stats_sum_i8(integer(1) :: r, integer(1), dimension(*), parameter :: first, integer(4) :: nbelem)
(3)
subroutine archr_stats_sum_i16(integer(2) :: r, integer(2), dimension(*), parameter :: first, integer(4) :: nbelem)
(4)
subroutine archr_stats_sum_i32(integer(4) :: r, integer(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(5)
subroutine archr_stats_sum_i64(integer(8) :: r, integer(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(6)
subroutine archr_stats_sum_u8(integer(1) :: r, integer(1), dimension(*), parameter :: first, integer(4) :: nbelem)
(7)
subroutine archr_stats_sum_u16(integer(2) :: r, integer(2), dimension(*), parameter :: first, integer(4) :: nbelem)
(8)
subroutine archr_stats_sum_u32(integer(4) :: r, integer(4), dimension(*), parameter :: first, integer(4) :: nbelem)
(9)
subroutine archr_stats_sum_u64(integer(8) :: r, integer(8), dimension(*), parameter :: first, integer(4) :: nbelem)
(10)
def sum(first):
    return r
(1)
function r = archr_stats_sum(first)
(1)

Description

This function computes the 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.

Example

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

int main()
{
  float v[] = {1,2,3,4,5,6};

  printf("sum(1,2,3,4,5,6) = %f\n", archr_stats_sum_f32(&v[0],6) );

  return 0;
}

Possible Output

sum(1,2,3,4,5,6) = 21.000000
sum(1,2,3,4)     = 10.000000
#include <archr/stats/sum.hpp>
#include <iostream>
#include <vector>

int main()
{
 std::vector<float> v{1,2,3,4,5,6};

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

  return 0;
}

Possible Output

sum(1,2,3,4,5,6) = 21
sum(1,2,3,4,5)   = 15
sum(1,2,3,4)     = 10

Possible Output