repl.txt (2426B)
1 2 {{alias}}( N, alpha, x, stride ) 3 Adds a constant to each strided array element and computes the sum using 4 ordinary recursive summation. 5 6 The `N` and `stride` parameters determine which elements in `x` are accessed 7 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 `0.0`. 13 14 Parameters 15 ---------- 16 N: integer 17 Number of indexed elements. 18 19 alpha: number 20 Constant. 21 22 x: Array<number>|TypedArray 23 Input array. 24 25 stride: integer 26 Index increment. 27 28 Returns 29 ------- 30 out: number 31 Sum. 32 33 Examples 34 -------- 35 // Standard Usage: 36 > var x = [ 1.0, -2.0, 2.0 ]; 37 > {{alias}}( x.length, 5.0, x, 1 ) 38 16.0 39 40 // Using `N` and `stride` parameters: 41 > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; 42 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 43 > var stride = 2; 44 > {{alias}}( N, 5.0, x, stride ) 45 16.0 46 47 // Using view offsets: 48 > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); 49 > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); 50 > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); 51 > stride = 2; 52 > {{alias}}( N, 5.0, x1, stride ) 53 14.0 54 55 {{alias}}.ndarray( N, alpha, x, stride, offset ) 56 Adds a constant to each strided array element and computes the sum using 57 ordinary recursive summation and alternative indexing semantics. 58 59 While typed array views mandate a view offset based on the underlying 60 buffer, the `offset` parameter supports indexing semantics based on a 61 starting index. 62 63 Parameters 64 ---------- 65 N: integer 66 Number of indexed elements. 67 68 alpha: number 69 Constant. 70 71 x: Array<number>|TypedArray 72 Input array. 73 74 stride: integer 75 Index increment. 76 77 offset: integer 78 Starting index. 79 80 Returns 81 ------- 82 out: number 83 Sum. 84 85 Examples 86 -------- 87 // Standard Usage: 88 > var x = [ 1.0, -2.0, 2.0 ]; 89 > {{alias}}.ndarray( x.length, 5.0, x, 1, 0 ) 90 16.0 91 92 // Using offset parameter: 93 > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; 94 > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); 95 > {{alias}}.ndarray( N, 5.0, x, 2, 1 ) 96 14.0 97 98 See Also 99 -------- 100