diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c9ac7b05..a13d85686 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@
-## Unreleased (2025-01-09) +## Unreleased (2025-01-10)
@@ -1357,6 +1357,7 @@ A total of 8 people contributed to this release. Thank you to the following cont
+- [`dbade8e`](https://github.com/stdlib-js/stdlib/commit/dbade8ed06df1ad8cef3ecf6c1f1f729ad62a53c) - **refactor:** update `blas/ext/base/gsumpw` to follow current project conventions [(#4680)](https://github.com/stdlib-js/stdlib/pull/4680) _(by Muhammad Haris)_ - [`76642bf`](https://github.com/stdlib-js/stdlib/commit/76642bf477c7431527bdeef8b979e92e8d93e6bb) - **docs:** update namespace table of contents [(#4658)](https://github.com/stdlib-js/stdlib/pull/4658) _(by stdlib-bot)_ - [`1d7a2df`](https://github.com/stdlib-js/stdlib/commit/1d7a2dfcb1cb9bae13f6ecd63aca3c4741433d29) - **docs:** update namespace TypeScript declarations [(#4656)](https://github.com/stdlib-js/stdlib/pull/4656) _(by stdlib-bot)_ - [`074b9a1`](https://github.com/stdlib-js/stdlib/commit/074b9a191c77d297bab5cb51cf82a727a650fe58) - **feat:** add C `ndarray` API and refactor `blas/ext/base/dsumpw` [(#4329)](https://github.com/stdlib-js/stdlib/pull/4329) _(by Muhammad Haris)_ diff --git a/ext/base/gsumpw/README.md b/ext/base/gsumpw/README.md index 826629cfb..bfdcd11b6 100644 --- a/ext/base/gsumpw/README.md +++ b/ext/base/gsumpw/README.md @@ -36,15 +36,14 @@ limitations under the License. var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); ``` -#### gsumpw( N, x, stride ) +#### gsumpw( N, x, strideX ) Computes the sum of strided array elements using pairwise summation. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gsumpw( N, x, 1 ); +var v = gsumpw( x.length, x, 1 ); // returns 1.0 ``` @@ -52,17 +51,14 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **stride**: index increment for `x`. +- **strideX**: stride length. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the gsumpw of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element: ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; -var N = floor( x.length / 2 ); -var v = gsumpw( N, x, 2 ); +var v = gsumpw( 4, x, 2 ); // returns 5.0 ``` @@ -72,42 +68,35 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = gsumpw( N, x1, 2 ); +var v = gsumpw( 4, x1, 2 ); // returns 5.0 ``` -#### gsumpw.ndarray( N, x, stride, offset ) +#### gsumpw.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements using pairwise summation and alternative indexing semantics. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gsumpw.ndarray( N, x, 1, 0 ); +var v = gsumpw.ndarray( x.length, x, 1, 0 ); // returns 1.0 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other element starting from the second element: ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -var N = floor( x.length / 2 ); -var v = gsumpw.ndarray( N, x, 2, 1 ); +var v = gsumpw.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -134,18 +123,12 @@ var v = gsumpw.ndarray( N, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = gsumpw( x.length, x, 1 ); diff --git a/ext/base/gsumpw/benchmark/benchmark.js b/ext/base/gsumpw/benchmark/benchmark.js index 0cbbdae1f..1d11248c7 100644 --- a/ext/base/gsumpw/benchmark/benchmark.js +++ b/ext/base/gsumpw/benchmark/benchmark.js @@ -21,13 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; var gsumpw = require( './../lib/main.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gsumpw = require( './../lib/main.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*10.0 ) - 20.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/ext/base/gsumpw/benchmark/benchmark.ndarray.js b/ext/base/gsumpw/benchmark/benchmark.ndarray.js index 3d59be8f2..8fe3f267e 100644 --- a/ext/base/gsumpw/benchmark/benchmark.ndarray.js +++ b/ext/base/gsumpw/benchmark/benchmark.ndarray.js @@ -21,13 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; var gsumpw = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gsumpw = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*10.0 ) - 20.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/ext/base/gsumpw/docs/repl.txt b/ext/base/gsumpw/docs/repl.txt index 2defa985e..822329805 100644 --- a/ext/base/gsumpw/docs/repl.txt +++ b/ext/base/gsumpw/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of strided array elements using pairwise summation. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -18,8 +18,8 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -33,27 +33,24 @@ > {{alias}}( x.length, x, 1 ) 1.0 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, x, 2 ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 3, x1, 2 ) -1.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements using pairwise summation and alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -64,10 +61,10 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -84,8 +81,7 @@ // Using offset parameter: > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) -1.0 See Also diff --git a/ext/base/gsumpw/docs/types/index.d.ts b/ext/base/gsumpw/docs/types/index.d.ts index ba4683be6..aad0cc753 100644 --- a/ext/base/gsumpw/docs/types/index.d.ts +++ b/ext/base/gsumpw/docs/types/index.d.ts @@ -31,7 +31,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -40,15 +40,15 @@ interface Routine { * var v = gsumpw( x.length, x, 1 ); * // returns 1.0 */ - ( N: number, x: NumericArray, stride: number ): number; + ( N: number, x: NumericArray, strideX: number ): number; /** * Computes the sum of strided array elements using pairwise summation and alternative indexing semantics. * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = gsumpw.ndarray( x.length, x, 1, 0 ); * // returns 1.0 */ - ndarray( N: number, x: NumericArray, stride: number, offset: number ): number; + ndarray( N: number, x: NumericArray, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns sum * * @example diff --git a/ext/base/gsumpw/examples/index.js b/ext/base/gsumpw/examples/index.js index 77e2022e8..e24743192 100644 --- a/ext/base/gsumpw/examples/index.js +++ b/ext/base/gsumpw/examples/index.js @@ -18,18 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); -var gsumpw = require( './../lib' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gsumpw = require( './../../../../ext/base/gsumpw' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = gsumpw( x.length, x, 1 ); diff --git a/ext/base/gsumpw/lib/index.js b/ext/base/gsumpw/lib/index.js index c62ccbdee..229a4b11a 100644 --- a/ext/base/gsumpw/lib/index.js +++ b/ext/base/gsumpw/lib/index.js @@ -27,19 +27,16 @@ * var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); * * var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; * -* var v = gsumpw( N, x, 1 ); +* var v = gsumpw( x.length, x, 1 ); * // returns 1.0 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); * * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* var N = floor( x.length / 2 ); * -* var v = gsumpw.ndarray( N, x, 2, 1 ); +* var v = gsumpw.ndarray( 4, x, 2, 1 ); * // returns 5.0 */ diff --git a/ext/base/gsumpw/lib/main.js b/ext/base/gsumpw/lib/main.js index a82cda55a..da5e4fbbc 100644 --- a/ext/base/gsumpw/lib/main.js +++ b/ext/base/gsumpw/lib/main.js @@ -20,7 +20,8 @@ // MODULES // -var sum = require( './ndarray.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -38,42 +39,17 @@ var sum = require( './ndarray.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {NumericArray} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example * var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; * -* var v = gsumpw( N, x, 1 ); +* var v = gsumpw( x.length, x, 1 ); * // returns 1.0 */ -function gsumpw( N, x, stride ) { - var ix; - var s; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - if ( N < 8 ) { - // Use simple summation... - s = 0.0; - for ( i = 0; i < N; i++ ) { - s += x[ ix ]; - ix += stride; - } - return s; - } - return sum( N, x, stride, ix ); +function gsumpw( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/ext/base/gsumpw/lib/ndarray.js b/ext/base/gsumpw/lib/ndarray.js index 04c36cde0..6c433c5d6 100644 --- a/ext/base/gsumpw/lib/ndarray.js +++ b/ext/base/gsumpw/lib/ndarray.js @@ -44,20 +44,17 @@ var BLOCKSIZE = 128; * * @param {PositiveInteger} N - number of indexed elements * @param {NumericArray} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); -* * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* var N = floor( x.length / 2 ); * -* var v = gsumpw( N, x, 2, 1 ); +* var v = gsumpw( 4, x, 2, 1 ); * // returns 5.0 */ -function gsumpw( N, x, stride, offset ) { +function gsumpw( N, x, strideX, offsetX ) { var ix; var s0; var s1; @@ -75,57 +72,57 @@ function gsumpw( N, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - return x[ offset ]; + ix = offsetX; + if ( strideX === 0 ) { + return N * x[ ix ]; } - ix = offset; if ( N < 8 ) { // Use simple summation... s = 0.0; for ( i = 0; i < N; i++ ) { s += x[ ix ]; - ix += stride; + ix += strideX; } return s; } if ( N <= BLOCKSIZE ) { // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... s0 = x[ ix ]; - s1 = x[ ix+stride ]; - s2 = x[ ix+(2*stride) ]; - s3 = x[ ix+(3*stride) ]; - s4 = x[ ix+(4*stride) ]; - s5 = x[ ix+(5*stride) ]; - s6 = x[ ix+(6*stride) ]; - s7 = x[ ix+(7*stride) ]; - ix += 8 * stride; + s1 = x[ ix+strideX ]; + s2 = x[ ix+(2*strideX) ]; + s3 = x[ ix+(3*strideX) ]; + s4 = x[ ix+(4*strideX) ]; + s5 = x[ ix+(5*strideX) ]; + s6 = x[ ix+(6*strideX) ]; + s7 = x[ ix+(7*strideX) ]; + ix += 8 * strideX; M = N % 8; for ( i = 8; i < N-M; i += 8 ) { s0 += x[ ix ]; - s1 += x[ ix+stride ]; - s2 += x[ ix+(2*stride) ]; - s3 += x[ ix+(3*stride) ]; - s4 += x[ ix+(4*stride) ]; - s5 += x[ ix+(5*stride) ]; - s6 += x[ ix+(6*stride) ]; - s7 += x[ ix+(7*stride) ]; - ix += 8 * stride; + s1 += x[ ix+strideX ]; + s2 += x[ ix+(2*strideX) ]; + s3 += x[ ix+(3*strideX) ]; + s4 += x[ ix+(4*strideX) ]; + s5 += x[ ix+(5*strideX) ]; + s6 += x[ ix+(6*strideX) ]; + s7 += x[ ix+(7*strideX) ]; + ix += 8 * strideX; } // Pairwise sum the accumulators: - s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + s = ( (s0+s1) + (s2+s3) ) + ( (s4+s5) + (s6+s7) ); // Clean-up loop... for ( i; i < N; i++ ) { s += x[ ix ]; - ix += stride; + ix += strideX; } return s; } // Recurse by dividing by two, but avoiding non-multiples of unroll factor... n = floor( N/2 ); n -= n % 8; - return gsumpw( n, x, stride, ix ) + gsumpw( N-n, x, stride, ix+(n*stride) ); + return gsumpw( n, x, strideX, ix ) + gsumpw( N-n, x, strideX, ix+(n*strideX) ); // eslint-disable-line max-len } diff --git a/ext/base/gsumpw/test/test.main.js b/ext/base/gsumpw/test/test.main.js index ff9f6391d..2aea27f8a 100644 --- a/ext/base/gsumpw/test/test.main.js +++ b/ext/base/gsumpw/test/test.main.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var gsumpw = require( './../lib' ); @@ -103,7 +102,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -118,15 +116,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, 2 ); + v = gsumpw( 4, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -141,21 +137,20 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, -2 ); + v = gsumpw( 4, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; v = gsumpw( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); @@ -163,7 +158,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -179,9 +173,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = gsumpw( N, x1, 2 ); + v = gsumpw( 4, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/ext/base/gsumpw/test/test.ndarray.js b/ext/base/gsumpw/test/test.ndarray.js index ce8a24431..021815a2a 100644 --- a/ext/base/gsumpw/test/test.ndarray.js +++ b/ext/base/gsumpw/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var gsumpw = require( './../lib/ndarray.js' ); @@ -102,7 +101,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -117,15 +115,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, 2, 0 ); + v = gsumpw( 4, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -140,27 +136,25 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, -2, 6 ); + v = gsumpw( 4, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; v = gsumpw( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -174,9 +168,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, 2, 1 ); + v = gsumpw( 4, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end();