repl.txt (3166B)
1 2 {{alias}}( N, x, strideX, out, strideOut ) 3 Computes the sum of strided array elements, ignoring `NaN` values and using 4 an improved Kahan–Babuška algorithm. 5 6 The `N` and `stride` parameters determine which elements are accessed at 7 runtime. 8 9 Indexing is relative to the first index. To introduce an offset, use a typed 10 array view. 11 12 If `N <= 0`, the function returns a sum equal to `0.0`. 13 14 Parameters 15 ---------- 16 N: integer 17 Number of indexed elements. 18 19 x: Array<number>|TypedArray 20 Input array. 21 22 strideX: integer 23 Index increment for `x`. 24 25 out: Array<number>|TypedArray 26 Output array. 27 28 strideOut: integer 29 Index increment for `out`. 30 31 Returns 32 ------- 33 out: Array<number>|TypedArray 34 Output array whose first element is the sum and whose second element is 35 the number of non-NaN elements. 36 37 Examples 38 -------- 39 // Standard Usage: 40 > var x = [ 1.0, -2.0, NaN, 2.0 ]; 41 > var out = [ 0.0, 0 ]; 42 > {{alias}}( x.length, x, 1, out, 1 ) 43 [ 1.0, 3 ] 44 45 // Using `N` and `stride` parameters: 46 > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ]; 47 > out = [ 0.0, 0 ]; 48 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 49 > {{alias}}( N, x, 2, out, 1 ) 50 [ 1.0, 3 ] 51 52 // Using view offsets: 53 > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, 1.0, NaN, NaN ] ); 54 > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); 55 > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); 56 > out = [ 0.0, 0 ]; 57 > {{alias}}( N, x1, 2, out, 1 ) 58 <Float64Array>[ 1.0, 3 ] 59 60 {{alias}}.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut ) 61 Computes the sum of strided array elements, ignoring `NaN` values and using 62 an improved Kahan–Babuška algorithm and alternative indexing semantics. 63 64 While typed array views mandate a view offset based on the underlying 65 buffer, the `offset` parameter supports indexing semantics based on a 66 starting index. 67 68 Parameters 69 ---------- 70 N: integer 71 Number of indexed elements. 72 73 x: Array<number>|TypedArray 74 Input array. 75 76 strideX: integer 77 Index increment for `x`. 78 79 offsetX: integer 80 Starting index for `x`. 81 82 out: Array<number>|TypedArray 83 Output array. 84 85 strideOut: integer 86 Index increment for `out`. 87 88 offsetOut: integer 89 Starting index for `out`. 90 91 Returns 92 ------- 93 out: Array<number>|TypedArray 94 Output array whose first element is the sum and whose second element is 95 the number of non-NaN elements. 96 97 Examples 98 -------- 99 // Standard Usage: 100 > var x = [ 1.0, -2.0, NaN, 2.0 ]; 101 > var out = [ 0.0, 0 ]; 102 > {{alias}}.ndarray( x.length, x, 1, 0, out, 1, 0 ) 103 [ 1.0, 3 ] 104 105 // Using offset parameter: 106 > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, 1.0, NaN, NaN ]; 107 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 108 > out = [ 0.0, 0 ]; 109 > {{alias}}.ndarray( N, x, 2, 1, out, 1, 0 ) 110 [ 1.0, 3 ] 111 112 See Also 113 -------- 114