repl.txt (3308B)
1 2 {{alias}}( N, sum, x, strideX, y, strideY ) 3 Computes the cumulative sum of strided array elements using ordinary 4 recursive summation. 5 6 The `N` and `stride` parameters determine which elements in `x` and `y` are 7 accessed at 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 `y` unchanged. 13 14 Parameters 15 ---------- 16 N: integer 17 Number of indexed elements. 18 19 sum: number 20 Initial sum. 21 22 x: Array<number>|TypedArray 23 Input array. 24 25 strideX: integer 26 Index increment for `x`. 27 28 y: Array<number>|TypedArray 29 Output array. 30 31 strideY: integer 32 Index increment for `y`. 33 34 Returns 35 ------- 36 out: Array<number>|TypedArray 37 Output array. 38 39 Examples 40 -------- 41 // Standard Usage: 42 > var x = [ 1.0, -2.0, 2.0 ]; 43 > var y = [ 0.0, 0.0, 0.0 ]; 44 > {{alias}}( x.length, 0.0, x, 1, y, 1 ) 45 [ 1.0, -1.0, 1.0 ] 46 47 // Using `N` and `stride` parameters: 48 > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; 49 > y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; 50 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 51 > {{alias}}( N, 0.0, x, 2, y, 2 ) 52 [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] 53 54 // Using view offsets: 55 > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); 56 > var y0 = new {{alias:@stdlib/array/float64}}( x0.length ); 57 > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); 58 > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); 59 > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); 60 > {{alias}}( N, 0.0, x1, 2, y1, 1 ) 61 <Float64Array>[ -2.0, 0.0, -1.0 ] 62 > y0 63 <Float64Array>[ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] 64 65 {{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) 66 Computes the cumulative sum of strided array elements using ordinary 67 recursive summation and alternative indexing semantics. 68 69 While typed array views mandate a view offset based on the underlying 70 buffer, the `offset` parameter supports indexing semantics based on a 71 starting index. 72 73 Parameters 74 ---------- 75 N: integer 76 Number of indexed elements. 77 78 sum: number 79 Initial sum. 80 81 x: Array<number>|TypedArray 82 Input array. 83 84 strideX: integer 85 Index increment for `x`. 86 87 offsetX: integer 88 Starting index for `x`. 89 90 y: Array<number>|TypedArray 91 Output array. 92 93 strideY: integer 94 Index increment for `y`. 95 96 offsetY: integer 97 Starting index for `y`. 98 99 Returns 100 ------- 101 out: Array<number>|TypedArray 102 Output array. 103 104 Examples 105 -------- 106 // Standard Usage: 107 > var x = [ 1.0, -2.0, 2.0 ]; 108 > var y = [ 0.0, 0.0, 0.0 ]; 109 > {{alias}}.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ) 110 <Float64Array>[ 1.0, -1.0, 1.0 ] 111 112 // Advanced indexing: 113 > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; 114 > y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; 115 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 116 > {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ) 117 <Float64Array>[ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] 118 119 See Also 120 -------- 121