From f248299246fab90057e99463edafff2b107266c1 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 1 Nov 2024 12:36:58 +0500 Subject: [PATCH] feat: add C ndarray API and refactor --- .../@stdlib/blas/ext/base/dnansum/README.md | 134 ++++++++++++++++-- .../ext/base/dnansum/benchmark/benchmark.js | 22 +-- .../dnansum/benchmark/benchmark.native.js | 22 +-- .../dnansum/benchmark/benchmark.ndarray.js | 22 +-- .../benchmark/benchmark.ndarray.native.js | 22 +-- .../dnansum/benchmark/c/benchmark.length.c | 52 ++++++- .../blas/ext/base/dnansum/docs/repl.txt | 20 +-- .../ext/base/dnansum/docs/types/index.d.ts | 10 +- .../ext/base/dnansum/examples/c/example.c | 7 +- .../include/stdlib/blas/ext/base/dnansum.h | 9 +- .../blas/ext/base/dnansum/lib/dnansum.js | 11 +- .../ext/base/dnansum/lib/dnansum.native.js | 8 +- .../blas/ext/base/dnansum/lib/index.js | 2 +- .../blas/ext/base/dnansum/lib/ndarray.js | 8 +- .../ext/base/dnansum/lib/ndarray.native.js | 17 +-- .../blas/ext/base/dnansum/manifest.json | 18 ++- .../@stdlib/blas/ext/base/dnansum/src/addon.c | 26 +++- .../blas/ext/base/dnansum/src/dnansum.c | 33 ----- .../@stdlib/blas/ext/base/dnansum/src/main.c | 48 +++++++ .../ext/base/dnansum/test/test.dnansum.js | 4 +- .../base/dnansum/test/test.dnansum.native.js | 4 +- .../ext/base/dnansum/test/test.ndarray.js | 4 +- .../base/dnansum/test/test.ndarray.native.js | 4 +- 23 files changed, 366 insertions(+), 141 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dnansum/src/dnansum.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dnansum/src/main.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnansum/README.md index 65d2e16fc99..1f73db2bc34 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/README.md @@ -36,7 +36,7 @@ limitations under the License. var dnansum = require( '@stdlib/blas/ext/base/dnansum' ); ``` -#### dnansum( N, x, stride ) +#### dnansum( N, x, strideX ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values. @@ -44,9 +44,8 @@ Computes the sum of double-precision floating-point strided array elements, igno var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = dnansum( N, x, 1 ); +var v = dnansum( x.length, x, 1 ); // returns 1.0 ``` @@ -54,9 +53,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: stride length for `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 in the strided array, +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 in the strided array, ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -81,7 +80,7 @@ var v = dnansum( 4, x1, 2 ); // returns 5.0 ``` -#### dnansum.ndarray( N, x, stride, offset ) +#### dnansum.ndarray( N, x, strideX, offsetX ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. @@ -90,15 +89,15 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var v = dnansum.ndarray( 4, x, 1, 0 ); +var v = dnansum.ndarray( x.length, x, 1, 0 ); // returns 1.0 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. -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 the strided array 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 Float64Array = require( '@stdlib/array/float64' ); @@ -154,6 +153,123 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dnansum.h" +``` + +#### stdlib_strided_dnansum( N, \*X, strideX ) + +Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; + +double v = stdlib_strided_dnansum( 4, x, 1 ); +// returns 7.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +double stdlib_strided_dnansum( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnansum_ndarray( N, \*X, strideX, offsetX ) + +Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; + +double v = stdlib_strided_dnansum_ndarray( 4, x, 1, 0 ); +// returns 7.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dnansum_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dnansum.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 }; + + // Specify the number of elements: + const int N = 5; + + // Specify the stride length: + const int strideX = 2; + + // Compute the sum: + double v = stdlib_strided_dnansum( N, x, strideX ); + + // Print the result: + printf( "sum: %lf\n", v ); +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.js index 0fcbb379f7e..ed8e2e24cfd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.js @@ -32,6 +32,19 @@ var dnansum = require( './../lib/dnansum.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -40,16 +53,9 @@ var dnansum = require( './../lib/dnansum.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', clbk ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; - function clbk() { - if ( bernoulli( 0.7 ) > 0 ) { - return discreteUniform( -10, 10 ); - } - return NaN; - } - function benchmark( b ) { var v; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.native.js index 4105b34fb5a..9ca95fff724 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.native.js @@ -41,6 +41,19 @@ var opts = { // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -49,16 +62,9 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', clbk ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; - function clbk() { - if ( bernoulli( 0.7 ) > 0 ) { - return discreteUniform( -10, 10 ); - } - return NaN; - } - function benchmark( b ) { var v; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.js index a9a8301bca1..43d27ead092 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.js @@ -32,6 +32,19 @@ var dnansum = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -40,16 +53,9 @@ var dnansum = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', clbk ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; - function clbk() { - if ( bernoulli( 0.7 ) > 0 ) { - return discreteUniform( -10, 10 ); - } - return NaN; - } - function benchmark( b ) { var v; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.native.js index 4555fee4066..36f5f596a05 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/benchmark.ndarray.native.js @@ -41,6 +41,19 @@ var opts = { // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -49,16 +62,9 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', clbk ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; - function clbk() { - if ( bernoulli( 0.7 ) > 0 ) { - return discreteUniform( -10, 10 ); - } - return NaN; - } - function benchmark( b ) { var v; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/c/benchmark.length.c index 102b348d744..dfe0d8719db 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double v; @@ -124,6 +124,43 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + if ( rand_double() < 0.2 ) { + x[ i ] = 0.0 / 0.0; // NaN + } else { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_strided_dnansum_ndarray( len, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -146,7 +183,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/repl.txt index 74ea39830ed..a3845b34b7c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values. - The `N` and `stride` parameters determine which elements in the strided + 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 @@ -19,8 +19,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -34,7 +34,7 @@ > {{alias}}( x.length, x, 1 ) 1.0 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] ); > {{alias}}( 4, x, 2 ) 1.0 @@ -46,12 +46,12 @@ -1.0 -{{alias}}.ndarray( N, x, stride, offset ) +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using 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 @@ -62,10 +62,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/types/index.d.ts index 547c8571344..4b3b201498b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/docs/types/index.d.ts @@ -27,7 +27,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -45,8 +45,8 @@ interface Routine { * * @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 = dnansum.ndarray( x.length, x, 1, 0 ); * // returns 1.0 */ - ndarray( N: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float64Array, 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/lib/node_modules/@stdlib/blas/ext/base/dnansum/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dnansum/examples/c/example.c index 0389a136c58..2d33fbc55e3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/examples/c/example.c @@ -17,7 +17,6 @@ */ #include "stdlib/blas/ext/base/dnansum.h" -#include #include int main( void ) { @@ -25,13 +24,13 @@ int main( void ) { const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 }; // Specify the number of elements: - const int64_t N = 5; + const int N = 5; // Specify the stride length: - const int64_t stride = 2; + const int strideX = 2; // Compute the sum: - double v = stdlib_strided_dnansum( N, x, stride ); + double v = stdlib_strided_dnansum( N, x, strideX ); // Print the result: printf( "sum: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/include/stdlib/blas/ext/base/dnansum.h b/lib/node_modules/@stdlib/blas/ext/base/dnansum/include/stdlib/blas/ext/base/dnansum.h index dfad80a8226..9b5b73e432d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/include/stdlib/blas/ext/base/dnansum.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/include/stdlib/blas/ext/base/dnansum.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DNANSUM_H #define STDLIB_BLAS_EXT_BASE_DNANSUM_H -#include +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,12 @@ extern "C" { /** * Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values. */ -double stdlib_strided_dnansum( const int64_t N, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnansum)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnansum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/dnansum.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/dnansum.js index 33916506453..6f7bb6226a5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/dnansum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/dnansum.js @@ -20,7 +20,8 @@ // MODULES // -var dnansumkbn = require( '@stdlib/blas/ext/base/dnansumkbn' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -30,7 +31,7 @@ var dnansumkbn = require( '@stdlib/blas/ext/base/dnansumkbn' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -38,11 +39,11 @@ var dnansumkbn = require( '@stdlib/blas/ext/base/dnansumkbn' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); * -* var v = dnansum( 4, x, 1 ); +* var v = dnansum( x.length, x, 1 ); * // returns 1.0 */ -function dnansum( N, x, stride ) { - return dnansumkbn( N, x, stride ); +function dnansum( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/dnansum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/dnansum.native.js index 22b5ee028ff..e36390f5ea1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/dnansum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/dnansum.native.js @@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -38,11 +38,11 @@ var addon = require( './../src/addon.node' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); * -* var v = dnansum( 4, x, 1 ); +* var v = dnansum( x.length, x, 1 ); * // returns 1.0 */ -function dnansum( N, x, stride ) { - return addon( N, x, stride ); +function dnansum( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/index.js index e2e09263373..1f09c8bbac7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/index.js @@ -29,7 +29,7 @@ * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); * -* var v = dnansum( 4, x, 1 ); +* var v = dnansum( x.length, x, 1 ); * // returns 1.0 * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/ndarray.js index 3a36203ef21..ee8518d60fe 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/ndarray.js @@ -30,8 +30,8 @@ var dnansumkbn = require( '@stdlib/blas/ext/base/dnansumkbn' ).ndarray; * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} 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 @@ -42,8 +42,8 @@ var dnansumkbn = require( '@stdlib/blas/ext/base/dnansumkbn' ).ndarray; * var v = dnansum( 5, x, 2, 1 ); * // returns 5.0 */ -function dnansum( N, x, stride, offset ) { - return dnansumkbn( N, x, stride, offset ); +function dnansum( N, x, strideX, offsetX ) { + return dnansumkbn( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/ndarray.native.js index 7a814a92317..0772dc6b16b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dnansum.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,8 +30,8 @@ var addon = require( './dnansum.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} 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 @@ -44,13 +42,8 @@ var addon = require( './dnansum.native.js' ); * var v = dnansum( 5, x, 2, 1 ); * // returns 5.0 */ -function dnansum( N, x, stride, offset ) { - var view; - - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - - return addon( N, view, stride ); +function dnansum( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dnansum/manifest.json index e7ac8b6cfd3..f77dd65aa66 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/manifest.json @@ -28,7 +28,7 @@ { "task": "build", "src": [ - "./src/dnansum.c" + "./src/main.c" ], "include": [ "./include" @@ -41,13 +41,15 @@ "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", "@stdlib/napi/create-double", - "@stdlib/blas/ext/base/dnansumkbn" + "@stdlib/blas/ext/base/dnansumkbn", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] }, { "task": "benchmark", "src": [ - "./src/dnansum.c" + "./src/main.c" ], "include": [ "./include" @@ -55,13 +57,15 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dnansumkbn" + "@stdlib/blas/ext/base/dnansumkbn", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] }, { "task": "examples", "src": [ - "./src/dnansum.c" + "./src/main.c" ], "include": [ "./include" @@ -69,7 +73,9 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dnansumkbn" + "@stdlib/blas/ext/base/dnansumkbn", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/addon.c index 7a812db5c5c..7ea4cef2598 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/blas/ext/base/dnansum.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -34,10 +35,27 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnansum( N, (double *)X, stride ), v ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnansum)( N, X, strideX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnansum_ndarray)( N, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/dnansum.c b/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/dnansum.c deleted file mode 100644 index 8eb445101ce..00000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/dnansum.c +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/blas/ext/base/dnansum.h" -#include "stdlib/blas/ext/base/dnansumkbn.h" -#include - -/** -* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values. -* -* @param N number of indexed elements -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dnansum( const int64_t N, const double *X, const int64_t stride ) { - return stdlib_strided_dnansumkbn( N, X, stride ); -} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/main.c new file mode 100644 index 00000000000..62b94212bd0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/src/main.c @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/dnansum.h" +#include "stdlib/blas/ext/base/dnansumkbn.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnansum)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnansum_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @param offsetX starting index +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnansum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + return API_SUFFIX(stdlib_strided_dnansumkbn_ndarray)( N, X, strideX, offsetX ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.js index e25debdc7b4..9db461d13e2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.js @@ -150,14 +150,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 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 = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnansum( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.native.js index 03cda2e6e3c..0540421f502 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.dnansum.native.js @@ -241,14 +241,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', opts, function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnansum( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.js index 48ca7508619..05ad8d8f1d9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.js @@ -150,14 +150,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 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 = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnansum( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.native.js index b8dfd12b141..ccaf5bb5a71 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansum/test/test.ndarray.native.js @@ -159,14 +159,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', opts, function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnansum( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); });