Crate xsum

Crate xsum 

Source
Expand description

This crate implments xsum algorithm by Radford M. Neal (https://arxiv.org/abs/1505.05571).

xsum is able to calculate fast exact summation

⚠️ Currently, xsum supports f64 calculation only.

§Usage

§add_list() to take vector or array

Calculates the sum of a small-sized vector or array.

use xsum::{Xsum, XsumSmall};

let mut xsmall = XsumSmall::new();
xsmall.add_list(&vec![1.0, 2.0, 3.0]);
assert_eq!(xsmall.sum(), 6.0);

Calculates the sum of a large-sized vector or array (more than 1,000 elements).

use xsum::{Xsum, XsumLarge};

let mut xlarge = XsumLarge::new();
xlarge.add_list(&vec![1.0; 1_000]);
assert_eq!(xlarge.sum(), 1000.0);

Calculates the sum of a unknown-sized vector or array.

use xsum::{Xsum, XsumAuto};

let mut xauto = XsumAuto::new();
xauto.add_list(&vec![1.0; 1_000]);
assert_eq!(xauto.sum(), 1000.0);

§add() to take a floating point number

use xsum::{Xsum, XsumSmall};

let mut xsmall = XsumSmall::new();
let vec = vec![1.0, 2.0, 3.0];
for v in vec {
    xsmall.add(v);
}
assert_eq!(xsmall.sum(), 6.0);

§Chaining Method

use xsum::{Xsum, XsumExt};

let vec = vec![1.0, 2.0, 3.0];
assert_eq!(vec.xsum(), 6.0);

Modules§

constants

Structs§

XsumAuto
XsumAuto is efficient when vector or array size is unknown
XsumLarge
XsumLarge is efficient when vector or array size is more than 1,000
XsumSmall
XsumSmall is efficient when vector or array size is less than or equal to 1,000

Enums§

XsumVariant
XsumVariant provides an easy way to manage multiple xsum variants.

Traits§

Xsum
Xsum trait
XsumExt
XsumExt selects either XsumSmall or XsumLarge based on the number of elements of vector or array