- Notifications
You must be signed in to change notification settings - Fork0
Calculate the sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm.
License
stdlib-js/blas-ext-base-dsumkbn
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!
Calculate the sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm.
npm install @stdlib/blas-ext-base-dsumkbn
Alternatively,
- To load the package in a website via a
script
tag without installation and bundlers, use theES Module available on theesm
branch (seeREADME). - If you are using Deno, visit the
deno
branch (seeREADME for usage intructions). - For use in Observable, or in browser/node environments, use theUniversal Module Definition (UMD) build available on the
umd
branch (seeREADME).
Thebranches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
vardsumkbn=require('@stdlib/blas-ext-base-dsumkbn');
Computes the sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm.
varFloat64Array=require('@stdlib/array-float64');varx=newFloat64Array([1.0,-2.0,2.0]);varv=dsumkbn(x.length,x,1);// returns 1.0
The function has the following parameters:
- N: number of indexed elements.
- x: input
Float64Array
. - strideX: stride length for
x
.
TheN
and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element:
varFloat64Array=require('@stdlib/array-float64');varx=newFloat64Array([1.0,2.0,2.0,-7.0,-2.0,3.0,4.0,2.0]);varv=dsumkbn(4,x,2);// returns 5.0
Note that indexing is relative to the first index. To introduce an offset, usetyped array
views.
varFloat64Array=require('@stdlib/array-float64');varx0=newFloat64Array([2.0,1.0,2.0,-2.0,-2.0,2.0,3.0,4.0]);varx1=newFloat64Array(x0.buffer,x0.BYTES_PER_ELEMENT*1);// start at 2nd elementvarv=dsumkbn(4,x1,2);// returns 5.0
Computes the sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm and alternative indexing semantics.
varFloat64Array=require('@stdlib/array-float64');varx=newFloat64Array([1.0,-2.0,2.0]);varv=dsumkbn.ndarray(3,x,1,0);// returns 1.0
The function has the following additional parameters:
- offsetX: starting index for
x
.
Whiletyped array
views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other element starting from the second element:
varFloat64Array=require('@stdlib/array-float64');varx=newFloat64Array([2.0,1.0,2.0,-2.0,-2.0,2.0,3.0,4.0]);varv=dsumkbn.ndarray(4,x,2,1);// returns 5.0
- If
N <= 0
, both functions return0.0
.
vardiscreteUniform=require('@stdlib/random-array-discrete-uniform');vardsumkbn=require('@stdlib/blas-ext-base-dsumkbn');varx=discreteUniform(10,-100,100,{'dtype':'float64'});console.log(x);varv=dsumkbn(x.length,x,1);console.log(v);
#include"stdlib/blas/ext/base/dsumkbn.h"
Computes the sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm.
constdoublex[]= {1.0,2.0,3.0,4.0 };doublev=stdlib_strided_dsumkbn(4,x,1 );// returns 10.0
The function accepts the following arguments:
- N:
[in] CBLAS_INT
number of indexed elements. - X:
[in] double*
input array. - strideX:
[in] CBLAS_INT
stride length forX
.
doublestdlib_strided_dsumkbn(constCBLAS_INTN,constdouble*X,constCBLAS_INTstrideX );
Computes the sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm and alternative indexing semantics.
constdoublex[]= {1.0,2.0,3.0,4.0 };doublev=stdlib_strided_dsumkbn_ndarray(4,x,1,0 );// returns 10.0
The function accepts the following arguments:
- N:
[in] CBLAS_INT
number of indexed elements. - X:
[in] double*
input array. - strideX:
[in] CBLAS_INT
stride length forX
. - offsetX:
[in] CBLAS_INT
starting index forX
.
doublestdlib_strided_dsumkbn_ndarray(constCBLAS_INTN,constdouble*X,constCBLAS_INTstrideX,constCBLAS_INToffsetX );
#include"stdlib/blas/ext/base/dsumkbn.h"#include<stdio.h>intmain(void ) {// Create a strided array:constdoublex[]= {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0 };// Specify the number of elements:constintN=4;// Specify the stride length:constintstrideX=2;// Compute the sum:doublev=stdlib_strided_dsumkbn(N,x,strideX );// Print the result:printf("sum: %lf\n",v );}
- Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums."Zeitschrift Für Angewandte Mathematik Und Mechanik 54 (1): 39–51. doi:10.1002/zamm.19740540106.
@stdlib/blas-ext/base/dnansumkbn
:calculate the sum of double-precision floating-point strided array elements, ignoring NaN values and using an improved Kahan–Babuška algorithm.@stdlib/blas-ext/base/dsum
:calculate the sum of double-precision floating-point strided array elements.@stdlib/blas-ext/base/dsumkbn2
:calculate the sum of double-precision floating-point strided array elements using a second-order iterative Kahan–Babuška algorithm.@stdlib/blas-ext/base/dsumors
:calculate the sum of double-precision floating-point strided array elements using ordinary recursive summation.@stdlib/blas-ext/base/dsumpw
:calculate the sum of double-precision floating-point strided array elements using pairwise summation.@stdlib/blas-ext/base/gsumkbn
:calculate the sum of strided array elements using an improved Kahan–Babuška algorithm.@stdlib/blas-ext/base/ssumkbn
:calculate the sum of single-precision floating-point strided array elements using an improved Kahan–Babuška algorithm.
This package is part ofstdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to developstdlib, see the main projectrepository.
SeeLICENSE.
Copyright © 2016-2025. The StdlibAuthors.
About
Calculate the sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm.