ndarray.js (1936B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2020 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MAIN // 22 23 /** 24 * Computes the cumulative sum of double-precision floating-point strided array elements using ordinary recursive summation. 25 * 26 * @param {PositiveInteger} N - number of indexed elements 27 * @param {number} sum - initial sum 28 * @param {Float64Array} x - input array 29 * @param {integer} strideX - `x` stride length 30 * @param {NonNegativeInteger} offsetX - starting index for `x` 31 * @param {Float64Array} y - output array 32 * @param {integer} strideY - `y` stride length 33 * @param {NonNegativeInteger} offsetY - starting index for `y` 34 * @returns {Float64Array} output array 35 * 36 * @example 37 * var Float64Array = require( '@stdlib/array/float64' ); 38 * var floor = require( '@stdlib/math/base/special/floor' ); 39 * 40 * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); 41 * var y = new Float64Array( x.length ); 42 * var N = floor( x.length / 2 ); 43 * 44 * var v = dcusumors( N, 0.0, x, 2, 1, y, 1, 0 ); 45 * // returns <Float64Array>[ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] 46 */ 47 function dcusumors( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { 48 var ix; 49 var iy; 50 var i; 51 52 if ( N <= 0 ) { 53 return y; 54 } 55 ix = offsetX; 56 iy = offsetY; 57 for ( i = 0; i < N; i++ ) { 58 sum += x[ ix ]; 59 y[ iy ] = sum; 60 ix += strideX; 61 iy += strideY; 62 } 63 return y; 64 } 65 66 67 // EXPORTS // 68 69 module.exports = dcusumors;