Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Calculate the sum of single-precision floating-point strided array elements, ignoring NaN values and using pairwise summation with extended accumulation.

License

NotificationsYou must be signed in to change notification settings

stdlib-js/blas-ext-base-sdsnansumpw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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!

sdsnansumpw

NPM versionBuild StatusCoverage Status

Calculate the sum of single-precision floating-point strided array elements, ignoringNaN values and using pairwise summation with extended accumulation.

Installation

npm install @stdlib/blas-ext-base-sdsnansumpw

Alternatively,

  • To load the package in a website via ascript tag without installation and bundlers, use theES Module available on theesm branch (seeREADME).
  • If you are using Deno, visit thedeno branch (seeREADME for usage intructions).
  • For use in Observable, or in browser/node environments, use theUniversal Module Definition (UMD) build available on theumd 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.

Usage

varsdsnansumpw=require('@stdlib/blas-ext-base-sdsnansumpw');

sdsnansumpw( N, x, strideX )

Computes the sum of single-precision floating-point strided array elements, ignoringNaN values and using pairwise summation with extended accumulation.

varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([1.0,-2.0,NaN,2.0]);varv=sdsnansumpw(x.length,x,1);// returns 1.0

The function has the following parameters:

  • N: number of indexed elements.
  • x: inputFloat32Array.
  • strideX: stride length.

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:

varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([1.0,2.0,NaN,-7.0,NaN,3.0,4.0,2.0]);varv=sdsnansumpw(4,x,2);// returns 5.0

Note that indexing is relative to the first index. To introduce an offset, usetyped array views.

varFloat32Array=require('@stdlib/array-float32');varx0=newFloat32Array([2.0,1.0,NaN,-2.0,-2.0,2.0,3.0,4.0]);varx1=newFloat32Array(x0.buffer,x0.BYTES_PER_ELEMENT*1);// start at 2nd elementvarv=sdsnansumpw(4,x1,2);// returns 5.0

sdsnansumpw.ndarray( N, x, strideX, offsetX )

Computes the sum of single-precision floating-point strided array elements, ignoringNaN values and using pairwise summation with extended accumulation and alternative indexing semantics.

varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([1.0,-2.0,NaN,2.0]);varv=sdsnansumpw.ndarray(x.length,x,1,0);// returns 1.0

The function has the following additional parameters:

  • offsetX: starting index.

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:

varFloat32Array=require('@stdlib/array-float32');varx=newFloat32Array([2.0,1.0,NaN,-2.0,-2.0,2.0,3.0,4.0]);varv=sdsnansumpw.ndarray(4,x,2,1);// returns 5.0

Notes

  • IfN <= 0, both functions return0.0.
  • Accumulated intermediate values are stored as double-precision floating-point numbers.

Examples

vardiscreteUniform=require('@stdlib/random-base-discrete-uniform');varbernoulli=require('@stdlib/random-base-bernoulli');varfilledarrayBy=require('@stdlib/array-filled-by');varsdsnansumpw=require('@stdlib/blas-ext-base-sdsnansumpw');functionrand(){if(bernoulli(0.5)<1){returnNaN;}returndiscreteUniform(0,100);}varx=filledarrayBy(10,'float32',rand);console.log(x);varv=sdsnansumpw(x.length,x,1);console.log(v);

C APIs

Usage

#include"stdlib/blas/ext/base/sdsnansumpw.h"

stdlib_strided_sdsnansumpw( N, *X, strideX )

Computes the sum of single-precision floating-point strided array elements, ignoringNaN values and using pairwise summation with extended accumulation.

constfloatx[]= {1.0f,-2.0f,0.0f/0.0f,2.0f };floatv=stdlib_strided_sdsnansumpw(4,x,1 );// returns 1.0f

The function accepts the following arguments:

  • N:[in] CBLAS_INT number of indexed elements.
  • X:[in] float* input array.
  • strideX:[in] CBLAS_INT stride length.
floatstdlib_strided_sdsnansumpw(constCBLAS_INTN,constfloat*X,constCBLAS_INTstrideX );

stdlib_strided_sdsnansumpw_ndarray( N, *X, strideX, offsetX )

Computes the sum of single-precision floating-point strided array elements, ignoringNaN values and using pairwise summation with extended accumulation and alternative indexing semantics.

constfloatx[]= {1.0f,-2.0f,0.0f/0.0f,2.0f };floatv=stdlib_strided_sdsnansumpw_ndarray(4,x,1,0 );// returns 1.0f

The function accepts the following arguments:

  • N:[in] CBLAS_INT number of indexed elements.
  • X:[in] float* input array.
  • strideX:[in] CBLAS_INT stride length.
  • offsetX:[in] CBLAS_INT starting index.
floatstdlib_strided_sdsnansumpw_ndarray(constCBLAS_INTN,constfloat*X,constCBLAS_INTstrideX,constCBLAS_INToffsetX );

Examples

#include"stdlib/blas/ext/base/sdsnansumpw.h"#include<stdio.h>intmain(void ) {// Create a strided array:constfloatx[]= {1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f,0.0f/0.0f,0.0f/0.0f };// Specify the number of elements:constintN=5;// Specify the stride length:constintstrideX=2;// Compute the sum:floatv=stdlib_strided_sdsnansumpw(N,x,strideX );// Print the result:printf("Sum: %f\n",v );}

References

  • Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation."SIAM Journal on Scientific Computing 14 (4): 783–99. doi:10.1137/0914050.

See Also

  • @stdlib/blas-ext/base/dsnansumpw:calculate the sum of single-precision floating-point strided array elements, ignoring NaN values, using pairwise summation with extended accumulation, and returning an extended precision result.
  • @stdlib/blas-ext/base/dnansumpw:calculate the sum of double-precision floating-point strided array elements, ignoring NaN values and using pairwise summation.
  • @stdlib/blas-ext/base/gnansumpw:calculate the sum of strided array elements, ignoring NaN values and using pairwise summation.
  • @stdlib/blas-ext/base/sdsnansum:calculate the sum of single-precision floating-point strided array elements, ignoring NaN values and using extended accumulation.
  • @stdlib/blas-ext/base/sdssumpw:calculate the sum of single-precision floating-point strided array elements using pairwise summation with extended accumulation.
  • @stdlib/blas-ext/base/snansumpw:calculate the sum of single-precision floating-point strided array elements, ignoring NaN values and using pairwise summation.

Notice

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.

Community

Chat


License

SeeLICENSE.

Copyright

Copyright © 2016-2025. The StdlibAuthors.

About

Calculate the sum of single-precision floating-point strided array elements, ignoring NaN values and using pairwise summation with extended accumulation.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp