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