|  | 
|  | 1 | +<!-- | 
|  | 2 | +
 | 
|  | 3 | +@license Apache-2.0 | 
|  | 4 | +
 | 
|  | 5 | +Copyright (c) 2020 The Stdlib Authors. | 
|  | 6 | +
 | 
|  | 7 | +Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 8 | +you may not use this file except in compliance with the License. | 
|  | 9 | +You may obtain a copy of the License at | 
|  | 10 | +
 | 
|  | 11 | +   http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 12 | +
 | 
|  | 13 | +Unless required by applicable law or agreed to in writing, software | 
|  | 14 | +distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 16 | +See the License for the specific language governing permissions and | 
|  | 17 | +limitations under the License. | 
|  | 18 | +
 | 
|  | 19 | +--> | 
|  | 20 | + | 
|  | 21 | +# dnancusumkbn2 | 
|  | 22 | + | 
|  | 23 | +> Calculate the cumulative sum of double-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm. | 
|  | 24 | +
 | 
|  | 25 | +<section class="intro"> | 
|  | 26 | + | 
|  | 27 | +</section> | 
|  | 28 | + | 
|  | 29 | +<!-- /.intro --> | 
|  | 30 | + | 
|  | 31 | +<section class="usage"> | 
|  | 32 | + | 
|  | 33 | +## Usage | 
|  | 34 | + | 
|  | 35 | +```javascript | 
|  | 36 | +var dnancusumkbn2 = require( '@stdlib/blas/ext/base/dnancusumkbn2' ); | 
|  | 37 | +``` | 
|  | 38 | + | 
|  | 39 | +#### dnancusumkbn2( N, sum, x, strideX, y, strideY ) | 
|  | 40 | + | 
|  | 41 | +Computes the cumulative sum of double-precision floating-point strided array elements,ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm. | 
|  | 42 | + | 
|  | 43 | +```javascript | 
|  | 44 | +var Float64Array = require( '@stdlib/array/float64' ); | 
|  | 45 | + | 
|  | 46 | +var x = new Float64Array( [ 1.0, -2.0, NaN ] ); | 
|  | 47 | +var y = new Float64Array( x.length ); | 
|  | 48 | + | 
|  | 49 | +dnancusumkbn2( x.length, 0.0, x, 1, y, 1 ); | 
|  | 50 | +// y => <Float64Array>[ 1.0, -1.0, -1.0 ] | 
|  | 51 | + | 
|  | 52 | +x = new Float64Array( [ 1.0, -2.0, NaN ] ); | 
|  | 53 | +y = new Float64Array( x.length ); | 
|  | 54 | + | 
|  | 55 | +dnancusumkbn2( x.length, 10.0, x, 1, y, 1 ); | 
|  | 56 | +// y => <Float64Array>[ 11.0, 9.0, 9.0 ] | 
|  | 57 | +``` | 
|  | 58 | + | 
|  | 59 | +The function has the following parameters: | 
|  | 60 | + | 
|  | 61 | +-   **N**: number of indexed elements. | 
|  | 62 | +-   **sum**: initial sum. | 
|  | 63 | +-   **x**: input [`Float64Array`][@stdlib/array/float64]. | 
|  | 64 | +-   **strideX**: stride length for `x`. | 
|  | 65 | +-   **y**: output [`Float64Array`][@stdlib/array/float64]. | 
|  | 66 | +-   **strideY**: stride length for `y`. | 
|  | 67 | + | 
|  | 68 | +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element: | 
|  | 69 | + | 
|  | 70 | +```javascript | 
|  | 71 | +var Float64Array = require( '@stdlib/array/float64' ); | 
|  | 72 | + | 
|  | 73 | +var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, NaN, 3.0, 4.0, 2.0 ] ); | 
|  | 74 | +var y = new Float64Array( x.length ); | 
|  | 75 | + | 
|  | 76 | +var v = dnancusumkbn2( 4, 0.0, x, 2, y, 1 ); | 
|  | 77 | +// y => <Float64Array>[ 1.0, 3.0, 3.0, 7.0, 0.0, 0.0, 0.0, 0.0 ] | 
|  | 78 | +``` | 
|  | 79 | + | 
|  | 80 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. | 
|  | 81 | + | 
|  | 82 | +<!-- eslint-disable stdlib/capitalized-comments --> | 
|  | 83 | + | 
|  | 84 | +```javascript | 
|  | 85 | +var Float64Array = require( '@stdlib/array/float64' ); | 
|  | 86 | + | 
|  | 87 | +// Initial arrays... | 
|  | 88 | +var x0 = new Float64Array( [ 2.0, NaN, 2.0, NaN, -2.0, 2.0, 3.0, 4.0 ] ); | 
|  | 89 | +var y0 = new Float64Array( x0.length ); | 
|  | 90 | + | 
|  | 91 | +// Create offset views... | 
|  | 92 | +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | 
|  | 93 | +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element | 
|  | 94 | + | 
|  | 95 | +dnancusumkbn2( 4, 0.0, x1, -2, y1, 1 ); | 
|  | 96 | +// y0 => <Float64Array>[ 0.0, 0.0, 0.0, 4.0, 6.0, 6.0, 6.0, 0.0 ] | 
|  | 97 | +``` | 
|  | 98 | + | 
|  | 99 | +#### dnancusumkbn2.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) | 
|  | 100 | + | 
|  | 101 | +Computes the cumulative sum of double-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. | 
|  | 102 | + | 
|  | 103 | +```javascript | 
|  | 104 | +var Float64Array = require( '@stdlib/array/float64' ); | 
|  | 105 | + | 
|  | 106 | +var x = new Float64Array( [ 1.0, -2.0, NaN ] ); | 
|  | 107 | +var y = new Float64Array( x.length ); | 
|  | 108 | + | 
|  | 109 | +dnancusumkbn2.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ); | 
|  | 110 | +// y => <Float64Array>[ 1.0, -1.0, -1.0 ] | 
|  | 111 | +``` | 
|  | 112 | + | 
|  | 113 | +The function has the following additional parameters: | 
|  | 114 | + | 
|  | 115 | +-   **offsetX**: starting index for `x`. | 
|  | 116 | +-   **offsetY**: starting index for `y`. | 
|  | 117 | + | 
|  | 118 | +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element: | 
|  | 119 | + | 
|  | 120 | +```javascript | 
|  | 121 | +var Float64Array = require( '@stdlib/array/float64' ); | 
|  | 122 | + | 
|  | 123 | +var x = new Float64Array( [ 2.0, 1.0, 2.0, NaN, -2.0, 2.0, 3.0, NaN ] ); | 
|  | 124 | +var y = new Float64Array( x.length ); | 
|  | 125 | + | 
|  | 126 | +dnancusumkbn2.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); | 
|  | 127 | +// y => <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 1.0, 1.0 ] | 
|  | 128 | +``` | 
|  | 129 | + | 
|  | 130 | +</section> | 
|  | 131 | + | 
|  | 132 | +<!-- /.usage --> | 
|  | 133 | + | 
|  | 134 | +<section class="notes"> | 
|  | 135 | + | 
|  | 136 | +## Notes | 
|  | 137 | + | 
|  | 138 | +-   If `N <= 0`, both functions return `y` unchanged. | 
|  | 139 | + | 
|  | 140 | +</section> | 
|  | 141 | + | 
|  | 142 | +<!-- /.notes --> | 
|  | 143 | + | 
|  | 144 | +<section class="examples"> | 
|  | 145 | + | 
|  | 146 | +## Examples | 
|  | 147 | + | 
|  | 148 | +<!-- eslint no-undef: "error" --> | 
|  | 149 | + | 
|  | 150 | +```javascript | 
|  | 151 | +var bernoulli = require( '@stdlib/random/base/bernoulli' ); | 
|  | 152 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); | 
|  | 153 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); | 
|  | 154 | +var Float64Array = require( '@stdlib/array/float64' ); | 
|  | 155 | +var dnancusumkbn2 = require( '@stdlib/blas/ext/base/dnancusumkbn2' ); | 
|  | 156 | + | 
|  | 157 | +function rand() { | 
|  | 158 | +    if ( bernoulli( 0.5 ) < 1 ) { | 
|  | 159 | +        return discreteUniform( 0, 100 ); | 
|  | 160 | +    } | 
|  | 161 | +    return NaN; | 
|  | 162 | +} | 
|  | 163 | + | 
|  | 164 | +var x = filledarrayBy( 10, 'float64', rand ); | 
|  | 165 | +console.log( x ); | 
|  | 166 | + | 
|  | 167 | +var y = new Float64Array( x.length ); | 
|  | 168 | +console.log( y ); | 
|  | 169 | + | 
|  | 170 | +dnancusumkbn2( x.length, 0.0, x, 1, y, 1 ); | 
|  | 171 | +console.log( y ); | 
|  | 172 | +``` | 
|  | 173 | + | 
|  | 174 | +</section> | 
|  | 175 | + | 
|  | 176 | +<!-- /.examples --> | 
|  | 177 | + | 
|  | 178 | +<!-- C interface documentation. --> | 
|  | 179 | + | 
|  | 180 | +* * * | 
|  | 181 | + | 
|  | 182 | +<section class="c"> | 
|  | 183 | + | 
|  | 184 | +## C APIs | 
|  | 185 | + | 
|  | 186 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | 
|  | 187 | + | 
|  | 188 | +<section class="intro"> | 
|  | 189 | + | 
|  | 190 | +</section> | 
|  | 191 | + | 
|  | 192 | +<!-- /.intro --> | 
|  | 193 | + | 
|  | 194 | +<!-- C usage documentation. --> | 
|  | 195 | + | 
|  | 196 | +<section class="usage"> | 
|  | 197 | + | 
|  | 198 | +### Usage | 
|  | 199 | + | 
|  | 200 | +```c | 
|  | 201 | +#include "stdlib/blas/ext/base/dnancusumkbn2.h" | 
|  | 202 | +``` | 
|  | 203 | + | 
|  | 204 | +#### stdlib_strided_dnancusumkbn2( N, sum, \*X, strideX, \*Y, strideY ) | 
|  | 205 | + | 
|  | 206 | +Computes the cumulative sum of double-precision floating-point strided array elements, ingoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm. | 
|  | 207 | + | 
|  | 208 | +```c | 
|  | 209 | +const double x[] = { 1.0, 2.0, 3.0, 0.0/0.0 } | 
|  | 210 | +double y[] = { 0.0, 0.0, 0.0, 0.0 } | 
|  | 211 | + | 
|  | 212 | +stdlib_strided_dnancusumkbn2( 4, 0.0, x, 1, y, 1 ); | 
|  | 213 | +``` | 
|  | 214 | +
 | 
|  | 215 | +The function accepts the following arguments: | 
|  | 216 | +
 | 
|  | 217 | +-   **N**: `[in] CBLAS_INT` number of indexed elements. | 
|  | 218 | +-   **sum**: `[in] double` initial sum. | 
|  | 219 | +-   **X**: `[in] double*` input array. | 
|  | 220 | +-   **strideX**: `[in] CBLAS_INT` stride length for `X`. | 
|  | 221 | +-   **Y**: `[out] double*` output array. | 
|  | 222 | +-   **strideY**: `[in] CBLAS_INT` stride length for `Y`. | 
|  | 223 | +
 | 
|  | 224 | +```c | 
|  | 225 | +void stdlib_strided_dnancusumkbn2( const CBLAS_INT N, const double sum, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY ); | 
|  | 226 | +``` | 
|  | 227 | + | 
|  | 228 | +<!-- lint disable maximum-heading-length --> | 
|  | 229 | + | 
|  | 230 | +#### stdlib_strided_dnancusumkbn2_ndarray( N, sum, \*X, strideX, offsetX, \*Y, strideY, offsetY ) | 
|  | 231 | + | 
|  | 232 | +<!-- lint enable maximum-heading-length --> | 
|  | 233 | + | 
|  | 234 | +Computes the cumulative sum of double-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. | 
|  | 235 | + | 
|  | 236 | +```c | 
|  | 237 | +const double x[] = { 1.0, 2.0, 3.0, 0.0/0.0 } | 
|  | 238 | +double y[] = { 0.0, 0.0, 0.0, 0.0 } | 
|  | 239 | + | 
|  | 240 | +stdlib_strided_dnancusumkbn2_ndarray( 4, 0.0, x, 1, 0, y, 1, 0 ); | 
|  | 241 | +``` | 
|  | 242 | +
 | 
|  | 243 | +The function accepts the following arguments: | 
|  | 244 | +
 | 
|  | 245 | +-   **N**: `[in] CBLAS_INT` number of indexed elements. | 
|  | 246 | +-   **sum**: `[in] double` initial sum. | 
|  | 247 | +-   **X**: `[in] double*` input array. | 
|  | 248 | +-   **strideX**: `[in] CBLAS_INT` stride length for `X`. | 
|  | 249 | +-   **offsetX**: `[in] CBLAS_INT` starting index for `X`. | 
|  | 250 | +-   **Y**: `[out] double*` output array. | 
|  | 251 | +-   **strideY**: `[in] CBLAS_INT` stride length for `Y`. | 
|  | 252 | +-   **offsetY**: `[in] CBLAS_INT` starting index for `Y`. | 
|  | 253 | +
 | 
|  | 254 | +```c | 
|  | 255 | +void stdlib_strided_dnancusumkbn2_ndarray( const CBLAS_INT N, const double sum, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); | 
|  | 256 | +``` | 
|  | 257 | + | 
|  | 258 | +</section> | 
|  | 259 | + | 
|  | 260 | +<!-- /.usage --> | 
|  | 261 | + | 
|  | 262 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | 
|  | 263 | + | 
|  | 264 | +<section class="notes"> | 
|  | 265 | + | 
|  | 266 | +</section> | 
|  | 267 | + | 
|  | 268 | +<!-- /.notes --> | 
|  | 269 | + | 
|  | 270 | +<!-- C API usage examples. --> | 
|  | 271 | + | 
|  | 272 | +<section class="examples"> | 
|  | 273 | + | 
|  | 274 | +### Examples | 
|  | 275 | + | 
|  | 276 | +```c | 
|  | 277 | +#include "stdlib/blas/ext/base/dnancusumkbn2.h" | 
|  | 278 | + | 
|  | 279 | +int main( void ) { | 
|  | 280 | +    // Create strided arrays: | 
|  | 281 | +    const double x[] = { 1.0, 2.0, 3.0, 0.0/0.0, 5.0, 6.0, 7.0, 0.0/0.0 }; | 
|  | 282 | +    double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; | 
|  | 283 | + | 
|  | 284 | +    // Specify the number of elements: | 
|  | 285 | +    const int N = 4; | 
|  | 286 | + | 
|  | 287 | +    // Specify stride lengths: | 
|  | 288 | +    const int strideX = 2; | 
|  | 289 | +    const int strideY = -2; | 
|  | 290 | + | 
|  | 291 | +    // Compute the cumulative sum: | 
|  | 292 | +    stdlib_strided_dnancusumkbn2( N, 0.0, x, strideX, y, strideY ); | 
|  | 293 | + | 
|  | 294 | +    // Print the result: | 
|  | 295 | +    for ( int i = 0; i < 8; i++ ) { | 
|  | 296 | +        printf( "y[ %d ] = %lf\n", i, y[ i ] ); | 
|  | 297 | +    } | 
|  | 298 | +} | 
|  | 299 | +``` | 
|  | 300 | +
 | 
|  | 301 | +</section> | 
|  | 302 | +
 | 
|  | 303 | +<!-- /.examples --> | 
|  | 304 | +
 | 
|  | 305 | +</section> | 
|  | 306 | +
 | 
|  | 307 | +<!-- /.c --> | 
|  | 308 | +
 | 
|  | 309 | +<section class="references"> | 
|  | 310 | +
 | 
|  | 311 | +## References | 
|  | 312 | +
 | 
|  | 313 | +-   Klein, Andreas. 2005. "A Generalized Kahan-Babuška-Summation-Algorithm." _Computing_ 76 (3): 279–93. doi:[10.1007/s00607-005-0139-x][@klein:2005a]. | 
|  | 314 | +
 | 
|  | 315 | +</section> | 
|  | 316 | +
 | 
|  | 317 | +<!-- /.references --> | 
|  | 318 | +
 | 
|  | 319 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | 
|  | 320 | +
 | 
|  | 321 | +<section class="related"> | 
|  | 322 | +
 | 
|  | 323 | +* * * | 
|  | 324 | +
 | 
|  | 325 | +## See Also | 
|  | 326 | +
 | 
|  | 327 | +-   <span class="package-name">[`@stdlib/blas/ext/base/dcusum`][@stdlib/blas/ext/base/dcusum]</span><span class="delimiter">: </span><span class="description">calculate the cumulative sum of double-precision floating-point strided array elements.</span> | 
|  | 328 | +-   <span class="package-name">[`@stdlib/blas/ext/base/gcusumkbn2`][@stdlib/blas/ext/base/gcusumkbn2]</span><span class="delimiter">: </span><span class="description">calculate the cumulative sum of strided array elements using a second-order iterative Kahan–Babuška algorithm.</span> | 
|  | 329 | +-   <span class="package-name">[`@stdlib/blas/ext/base/scusumkbn2`][@stdlib/blas/ext/base/scusumkbn2]</span><span class="delimiter">: </span><span class="description">calculate the cumulative sum of single-precision floating-point strided array elements using a second-order iterative Kahan–Babuška algorithm.</span> | 
|  | 330 | +
 | 
|  | 331 | +</section> | 
|  | 332 | +
 | 
|  | 333 | +<!-- /.related --> | 
|  | 334 | +
 | 
|  | 335 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | 
|  | 336 | +
 | 
|  | 337 | +<section class="links"> | 
|  | 338 | +
 | 
|  | 339 | +[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64 | 
|  | 340 | +
 | 
|  | 341 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | 
|  | 342 | +
 | 
|  | 343 | +[@klein:2005a]: https://doi.org/10.1007/s00607-005-0139-x | 
|  | 344 | +
 | 
|  | 345 | +<!-- <related-links> --> | 
|  | 346 | +
 | 
|  | 347 | +[@stdlib/blas/ext/base/dcusum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/dcusum | 
|  | 348 | +
 | 
|  | 349 | +[@stdlib/blas/ext/base/gcusumkbn2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/gcusumkbn2 | 
|  | 350 | +
 | 
|  | 351 | +[@stdlib/blas/ext/base/scusumkbn2]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/scusumkbn2 | 
|  | 352 | +
 | 
|  | 353 | +<!-- </related-links> --> | 
|  | 354 | +
 | 
|  | 355 | +</section> | 
|  | 356 | +
 | 
|  | 357 | +<!-- /.links --> | 
0 commit comments