diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e0d2008..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T01:27:54.503Z diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ec8ec..a1b2314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,17 @@
-## Unreleased (2024-12-30) +## Unreleased (2025-01-03) + +
+ +### Features + +- [`da4697a`](https://github.com/stdlib-js/stdlib/commit/da4697a938cbd040e23e406a04c5c7dddf4e4a52) - add C ndarray interface and refactor implementation for `stats/base/sminsorted` [(#4492)](https://github.com/stdlib-js/stdlib/pull/4492) + +
+ +
@@ -12,6 +22,7 @@
+- [`da4697a`](https://github.com/stdlib-js/stdlib/commit/da4697a938cbd040e23e406a04c5c7dddf4e4a52) - **feat:** add C ndarray interface and refactor implementation for `stats/base/sminsorted` [(#4492)](https://github.com/stdlib-js/stdlib/pull/4492) _(by Aayush Khanna, stdlib-bot)_ - [`62364f6`](https://github.com/stdlib-js/stdlib/commit/62364f62ea823a3b52c2ad25660ecd80c71f8f36) - **style:** fix C comment alignment _(by Philipp Burckhardt)_ - [`9e689ff`](https://github.com/stdlib-js/stdlib/commit/9e689ffcb7c6223afc521f1e574b42f10921cf5e) - **chore:** fix indentation in manifest.json files _(by Philipp Burckhardt)_ - [`272ae7a`](https://github.com/stdlib-js/stdlib/commit/272ae7ac5c576c68cfab1b6e304c86407faa20cd) - **docs:** remove comment _(by Athan Reines)_ @@ -27,8 +38,9 @@ ### Contributors -A total of 2 people contributed to this release. Thank you to the following contributors: +A total of 3 people contributed to this release. Thank you to the following contributors: +- Aayush Khanna - Athan Reines - Philipp Burckhardt diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 173c07b..a5f7aba 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -27,6 +27,7 @@ Daniel Killenberger Daniel Yu <40680511+Daniel777y@users.noreply.github.com> Debashis Maharana Desh Deepak Kant <118960904+DeshDeepakKant@users.noreply.github.com> +Dhruv/ <154677013+DhruvArvindSingh@users.noreply.github.com> Divyansh Seth <59174836+sethdivyansh@users.noreply.github.com> Dominic Lim <46486515+domlimm@users.noreply.github.com> Dominik Moritz diff --git a/NOTICE b/NOTICE index e6e7482..cbd3a29 100644 --- a/NOTICE +++ b/NOTICE @@ -1 +1 @@ -Copyright (c) 2016-2024 The Stdlib Authors. +Copyright (c) 2016-2025 The Stdlib Authors. diff --git a/README.md b/README.md index b60f9bf..dd8ca2a 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ To view installation and usage instructions specific to each branch build, be su var sminsorted = require( '@stdlib/stats-base-sminsorted' ); ``` -#### sminsorted( N, x, stride ) +#### sminsorted( N, x, strideX ) Computes the minimum value of a sorted single-precision floating-point strided array `x`. @@ -77,15 +77,13 @@ Computes the minimum value of a sorted single-precision floating-point strided a var Float32Array = require( '@stdlib/array-float32' ); var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); -var N = x.length; -var v = sminsorted( N, x, 1 ); +var v = sminsorted( x.length, x, 1 ); // returns 1.0 x = new Float32Array( [ 3.0, 2.0, 1.0 ] ); -N = x.length; -v = sminsorted( N, x, 1 ); +v = sminsorted( x.length, x, 1 ); // returns 1.0 ``` @@ -93,18 +91,16 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: sorted input [`Float32Array`][@stdlib/array/float32]. -- **stride**: index increment for `x`. +- **strideX**: index increment for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the minimum value 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 minimum value of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array-float32' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, 3.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = sminsorted( N, x, 2 ); +var v = sminsorted( 4, x, 2 ); // returns 1.0 ``` @@ -114,18 +110,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array-float32' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, 2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = sminsorted( N, x1, 2 ); +var v = sminsorted( 4, x1, 2 ); // returns 1.0 ``` -#### sminsorted.ndarray( N, x, stride, offset ) +#### sminsorted.ndarray( N, x, strideX, offsetX ) Computes the minimum value of a sorted single-precision floating-point strided array using alternative indexing semantics. @@ -133,26 +126,23 @@ Computes the minimum value of a sorted single-precision floating-point strided a var Float32Array = require( '@stdlib/array-float32' ); var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); -var N = x.length; -var v = sminsorted.ndarray( N, x, 1, 0 ); +var v = sminsorted.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 minimum value for 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 minimum value for every other element in `x` starting from the second element ```javascript var Float32Array = require( '@stdlib/array-float32' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, 2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = sminsorted.ndarray( N, x, 2, 1 ); +var v = sminsorted.ndarray( 4, x, 2, 1 ); // returns 1.0 ``` @@ -178,16 +168,13 @@ var v = sminsorted.ndarray( N, x, 2, 1 ); ```javascript -var Float32Array = require( '@stdlib/array-float32' ); +var linspace = require( '@stdlib/array-linspace' ); var sminsorted = require( '@stdlib/stats-base-sminsorted' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = i - 5.0; -} +var options = { + 'dtype': 'float32' +}; +var x = linspace( -5.0, 5.0, 10, options ); console.log( x ); var v = sminsorted( x.length, x, 1 ); @@ -198,6 +185,123 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/sminsorted.h" +``` + +#### stdlib_strided_sminsorted( N, \*X, strideX ) + +Computes the minimum value of a sorted single-precision floating-point strided array. + +```c +const float x[] = { 1.0f, 2.0f, 3.0f }; + +float v = stdlib_strided_sminsorted( 3, x, 1 ); +// returns 1.0f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +float stdlib_strided_sminsorted( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_sminsorted_ndarray( N, \*X, strideX, offsetX ) + +Computes the minimum value of a sorted single-precision floating-point strided array using alternative indexing semantics. + +```c +const float x[] = { 1.0f, 2.0f, 3.0f }; + +float v = stdlib_strided_sminsorted_ndarray( 3, x, 1, 0 ); +// returns 1.0f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +float stdlib_strided_sminsorted_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/sminsorted.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the minimum value: + float v = stdlib_strided_sminsorted( N, x, strideX ); + + // Print the result: + printf( "min: %f\n", v ); +} +``` + +
+ + + +
+ + + diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 2f605ea..18b2b96 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -22,12 +22,19 @@ var bench = require( '@stdlib/bench-harness' ); var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); +var linspace = require( '@stdlib/array-linspace' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float32Array = require( '@stdlib/array-float32' ); var pkg = require( './../package.json' ).name; var sminsorted = require( './../lib/sminsorted.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var sminsorted = require( './../lib/sminsorted.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = i; - } + var x = linspace( -len/2, len/2, len, options ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.native.js b/benchmark/benchmark.native.js index 320cfe4..7e02873 100644 --- a/benchmark/benchmark.native.js +++ b/benchmark/benchmark.native.js @@ -23,8 +23,8 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench-harness' ); var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); +var linspace = require( '@stdlib/array-linspace' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float32Array = require( '@stdlib/array-float32' ); var tryRequire = require( '@stdlib/utils-try-require' ); var pkg = require( './../package.json' ).name; @@ -35,6 +35,9 @@ var sminsorted = tryRequire( resolve( __dirname, './../lib/sminsorted.native.js' var opts = { 'skip': ( sminsorted instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -47,13 +50,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = i; - } + var x = linspace( -len/2, len/2, len, options ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js index 947a50c..5b13dc0 100644 --- a/benchmark/benchmark.ndarray.js +++ b/benchmark/benchmark.ndarray.js @@ -22,12 +22,19 @@ var bench = require( '@stdlib/bench-harness' ); var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); +var linspace = require( '@stdlib/array-linspace' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float32Array = require( '@stdlib/array-float32' ); var pkg = require( './../package.json' ).name; var sminsorted = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var sminsorted = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = i; - } + var x = linspace( -len/2, len/2, len, options ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.ndarray.native.js b/benchmark/benchmark.ndarray.native.js index cdb8ff2..33f787e 100644 --- a/benchmark/benchmark.ndarray.native.js +++ b/benchmark/benchmark.ndarray.native.js @@ -23,8 +23,8 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench-harness' ); var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); +var linspace = require( '@stdlib/array-linspace' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float32Array = require( '@stdlib/array-float32' ); var tryRequire = require( '@stdlib/utils-try-require' ); var pkg = require( './../package.json' ).name; @@ -35,6 +35,9 @@ var sminsorted = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( sminsorted instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -47,13 +50,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = i; - } + var x = linspace( -len/2, len/2, len, options ); return benchmark; function benchmark( b ) { diff --git a/benchmark/c/benchmark.length.c b/benchmark/c/benchmark.length.c index 871fc4b..a78f92e 100644 --- a/benchmark/c/benchmark.length.c +++ b/benchmark/c/benchmark.length.c @@ -82,9 +82,9 @@ static double tic( void ) { * * @return random number */ -static double rand_double( void ) { +static float rand_float( void ) { int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); + return (float)r / ( (float)RAND_MAX + 1.0f ); } /** @@ -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; float x[ len ]; float v; @@ -107,6 +107,7 @@ static double benchmark( int iterations, int len ) { v = 0.0f; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_sminsorted( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +121,40 @@ 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; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = i; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_sminsorted_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. */ @@ -142,7 +177,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; + 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/dist/index.js b/dist/index.js index 304b407..1d91b3f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,9 +1,9 @@ -"use strict";var a=function(n,e){return function(){return e||n((e={exports:{}}).exports,e),e.exports}};var o=a(function(h,f){ -var s=require('@stdlib/math-base-assert-is-nanf/dist'),v=require('@stdlib/math-base-assert-is-negative-zerof/dist');function g(n,e,t){var i,r;return n<=0?NaN:n===1||t===0?e[0]:(t<0?(i=e[(1-n)*t],r=e[0]):(i=e[0],r=e[(n-1)*t]),s(i)||s(r)?NaN:i===r?v(i)||v(r)?-0:i:i {{alias}}( x.length, x, 1 ) 1.0 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ -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 ) -2.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, 3.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( 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 ) -2.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the minimum value of a sorted single-precision floating-point strided array using alternative indexing semantics. @@ -68,10 +65,10 @@ x: Float32Array Sorted input array. - stride: integer - Index increment. + strideX: integer + Stride Length. - offset: integer + offsetX: integer Starting index. Returns @@ -88,8 +85,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, 3.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) -2.0 See Also diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts index d668f0b..9ea0c18 100644 --- a/docs/types/index.d.ts +++ b/docs/types/index.d.ts @@ -27,7 +27,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - sorted input array - * @param stride - stride length + * @param strideX - stride length * @returns minimum value * * @example @@ -38,15 +38,15 @@ interface Routine { * var v = sminsorted( x.length, x, 1 ); * // returns 1.0 */ - ( N: number, x: Float32Array, stride: number ): number; + ( N: number, x: Float32Array, strideX: number ): number; /** * Computes the minimum value of a sorted single-precision floating-point strided array using alternative indexing semantics. * * @param N - number of indexed elements * @param x - sorted input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns minimum value * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = sminsorted.ndarray( x.length, x, 1, 0 ); * // returns 1.0 */ - ndarray( N: number, x: Float32Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float32Array, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - sorted input array -* @param stride - stride length +* @param strideX - stride length * @returns minimum value * * @example diff --git a/examples/c/example.c b/examples/c/example.c index 960eadf..7ba730c 100644 --- a/examples/c/example.c +++ b/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/sminsorted.h" -#include #include int main( void ) { // Create a strided array: - float x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; // Specify the number of elements: - int64_t N = 4; + const int N = 4; // Specify the stride length: - int64_t stride = 2; + const int strideX = 2; // Compute the minimum value: - float v = stdlib_strided_sminsorted( N, x, stride ); + float v = stdlib_strided_sminsorted( N, x, strideX ); // Print the result: printf( "min: %f\n", v ); diff --git a/examples/index.js b/examples/index.js index eced191..0577efc 100644 --- a/examples/index.js +++ b/examples/index.js @@ -18,16 +18,13 @@ 'use strict'; -var Float32Array = require( '@stdlib/array-float32' ); +var linspace = require( '@stdlib/array-linspace' ); var sminsorted = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = i - 5.0; -} +var options = { + 'dtype': 'float32' +}; +var x = linspace( -5.0, 5.0, 10, options ); console.log( x ); var v = sminsorted( x.length, x, 1 ); diff --git a/include.gypi b/include.gypi index 2fa318f..9212937 100644 --- a/include.gypi +++ b/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#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 minimum value of a sorted single-precision floating-point strided array. */ -float stdlib_strided_sminsorted( const int64_t N, const float *X, const int64_t stride ); +float API_SUFFIX(stdlib_strided_sminsorted)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); + +/** +* Computes the minimum value of a sorted single-precision floating-point strided array using alternative indexing semantics. +*/ +float API_SUFFIX(stdlib_strided_sminsorted_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/index.js b/lib/index.js index 774d8de..f37feda 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,20 +28,17 @@ * var sminsorted = require( '@stdlib/stats-base-sminsorted' ); * * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); -* var N = x.length; * -* var v = sminsorted( N, x, 1 ); +* var v = sminsorted( x.length, x, 1 ); * // returns 1.0 * * @example * var Float32Array = require( '@stdlib/array-float32' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * var sminsorted = require( '@stdlib/stats-base-sminsorted' ); * * var x = new Float32Array( [ 2.0, -3.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = sminsorted.ndarray( N, x, 2, 1 ); +* var v = sminsorted.ndarray( 4, x, 2, 1 ); * // returns -3.0 */ diff --git a/lib/ndarray.js b/lib/ndarray.js index d9477ea..c06442e 100644 --- a/lib/ndarray.js +++ b/lib/ndarray.js @@ -31,32 +31,30 @@ var isNegativeZerof = require( '@stdlib/math-base-assert-is-negative-zerof' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - sorted input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} minimum value * * @example * var Float32Array = require( '@stdlib/array-float32' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * * var x = new Float32Array( [ 2.0, -3.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = sminsorted( N, x, 2, 1 ); +* var v = sminsorted( 4, x, 2, 1 ); * // returns -3.0 */ -function sminsorted( N, x, stride, offset ) { +function sminsorted( N, x, strideX, offsetX ) { var v1; var v2; if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { + if ( N === 1 || strideX === 0 ) { return x[ 0 ]; } - v1 = x[ offset ]; - v2 = x[ offset + ((N-1)*stride) ]; + v1 = x[ offsetX ]; + v2 = x[ offsetX + ((N-1)*strideX) ]; if ( isnanf( v1 ) || isnanf( v2 ) ) { return NaN; } diff --git a/lib/ndarray.native.js b/lib/ndarray.native.js index 41afc6c..faf7884 100644 --- a/lib/ndarray.native.js +++ b/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float32Array = require( '@stdlib/array-float32' ); -var addon = require( './sminsorted.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -31,27 +30,20 @@ var addon = require( './sminsorted.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - sorted input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} minimum value * * @example * var Float32Array = require( '@stdlib/array-float32' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * * var x = new Float32Array( [ 2.0, -3.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = sminsorted( N, x, 2, 1 ); +* var v = sminsorted( 4, x, 2, 1 ); * // returns -3.0 */ -function sminsorted( N, x, stride, offset ) { - var view; - if ( stride < 0 ) { - offset += (N-1) * stride; - } - view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len - return addon( N, view, stride ); +function sminsorted( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/sminsorted.js b/lib/sminsorted.js index d23f004..4ca90df 100644 --- a/lib/sminsorted.js +++ b/lib/sminsorted.js @@ -20,8 +20,8 @@ // MODULES // -var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); -var isNegativeZerof = require( '@stdlib/math-base-assert-is-negative-zerof' ); +var stride2offset = require( '@stdlib/strided-base-stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -31,48 +31,19 @@ var isNegativeZerof = require( '@stdlib/math-base-assert-is-negative-zerof' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - sorted input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} minimum value * * @example * var Float32Array = require( '@stdlib/array-float32' ); * * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); -* var N = x.length; * -* var v = sminsorted( N, x, 1 ); +* var v = sminsorted( x.length, x, 1 ); * // returns 1.0 */ -function sminsorted( N, x, stride ) { - var v1; - var v2; - - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - if ( stride < 0 ) { - v1 = x[ (1-N) * stride ]; - v2 = x[ 0 ]; - } else { - v1 = x[ 0 ]; - v2 = x[ (N-1) * stride ]; - } - if ( isnanf( v1 ) || isnanf( v2 ) ) { - return NaN; - } - if ( v1 === v2 ) { - if ( isNegativeZerof( v1 ) || isNegativeZerof( v2 ) ) { - return -0.0; - } - return v1; - } - if ( v1 < v2 ) { - return v1; - } - return v2; +function sminsorted( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/sminsorted.native.js b/lib/sminsorted.native.js index db60f02..bace172 100644 --- a/lib/sminsorted.native.js +++ b/lib/sminsorted.native.js @@ -30,20 +30,19 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - sorted input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} minimum value * * @example * var Float32Array = require( '@stdlib/array-float32' ); * * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); -* var N = x.length; * -* var v = sminsorted( N, x, 1 ); +* var v = sminsorted( x.length, x, 1 ); * // returns 1.0 */ -function sminsorted( N, x, stride ) { - return addon( N, x, stride ); +function sminsorted( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/manifest.json b/manifest.json index b8d8cf2..dd8d91b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,8 @@ { - "options": {}, + "options": { + "task": "build", + "wasm": false + }, "fields": [ { "field": "src", @@ -24,19 +27,80 @@ ], "confs": [ { + "task": "build", + "wasm": false, "src": [ - "./src/sminsorted.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math-base-assert-is-nanf", + "@stdlib/math-base-assert-is-negative-zerof", + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset", + "@stdlib/napi-export", + "@stdlib/napi-argv", + "@stdlib/napi-argv-int64", + "@stdlib/napi-argv-strided-float32array", + "@stdlib/napi-create-double" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math-base-assert-is-nanf", + "@stdlib/math-base-assert-is-negative-zerof", + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math-base-assert-is-nanf", + "@stdlib/math-base-assert-is-negative-zerof", + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/math-base-assert-is-nanf", - "@stdlib/math-base-assert-is-negative-zerof" + "@stdlib/math-base-assert-is-negative-zerof", + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" ] } ] diff --git a/package.json b/package.json index 531a9e5..8d0364d 100644 --- a/package.json +++ b/package.json @@ -41,14 +41,21 @@ "url": "https://github.com/stdlib-js/stdlib/issues" }, "dependencies": { + "@stdlib/blas-base-shared": "^0.1.0", "@stdlib/math-base-assert-is-nanf": "^0.2.2", "@stdlib/math-base-assert-is-negative-zerof": "^0.1.3", + "@stdlib/napi-argv": "^0.2.2", + "@stdlib/napi-argv-int64": "^0.2.2", + "@stdlib/napi-argv-strided-float32array": "^0.2.2", + "@stdlib/napi-create-double": "^0.0.2", + "@stdlib/napi-export": "^0.2.2", + "@stdlib/strided-base-stride2offset": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-library-manifest": "^0.2.2" }, "devDependencies": { "@stdlib/array-float32": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", + "@stdlib/array-linspace": "^0.2.1", "@stdlib/math-base-special-pow": "^0.3.0", "@stdlib/utils-try-require": "^0.2.2", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", diff --git a/src/addon.c b/src/addon.c new file mode 100644 index 0000000..ed151bc --- /dev/null +++ b/src/addon.c @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/stats/base/sminsorted.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include "stdlib/napi/create_double.h" +#include + +/** +* 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( 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, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_sminsorted( N, X, strideX ), v ); + return v; +} + +/** +* 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_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_sminsorted_ndarray( N, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/src/addon.cpp b/src/addon.cpp deleted file mode 100644 index 6a69ec5..0000000 --- a/src/addon.cpp +++ /dev/null @@ -1,117 +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/stats/base/sminsorted.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_stats_base_sminsorted { - - /** - * Computes the minimum value of a sorted single-precision floating-point strided array. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: sorted input array - * - `stride`: stride length - */ - napi_value node_sminsorted( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, (double)stdlib_strided_sminsorted( N, (float *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_sminsorted, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_stats_base_sminsorted diff --git a/src/sminsorted.c b/src/main.c similarity index 54% rename from src/sminsorted.c rename to src/main.c index 010e8b4..5141b7d 100644 --- a/src/sminsorted.c +++ b/src/main.c @@ -19,33 +19,43 @@ #include "stdlib/stats/base/sminsorted.h" #include "stdlib/math/base/assert/is_nanf.h" #include "stdlib/math/base/assert/is_negative_zerof.h" -#include +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the minimum value of a sorted single-precision floating-point strided array. * -* @param N number of indexed elements -* @param X sorted input array -* @param stride stride length -* @return output value +* @param N number of indexed elements +* @param X sorted input array +* @param strideX stride length +* @return output value */ -float stdlib_strided_sminsorted( const int64_t N, const float *X, const int64_t stride ) { +float API_SUFFIX(stdlib_strided_sminsorted)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_sminsorted_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the minimum value of a sorted single-precision floating-point strided array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X sorted input array +* @param strideX stride length +* @param offsetX starting index for X +* @return output value +*/ +float API_SUFFIX(stdlib_strided_sminsorted_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { float v1; float v2; if ( N <= 0 ) { return 0.0f / 0.0f; // NaN } - if ( N == 1 || stride == 0 ) { + if ( N == 1 || strideX == 0 ) { return X[ 0 ]; } - if ( stride < 0 ) { - v1 = X[ (1-N) * stride ]; - v2 = X[ 0 ]; - } else { - v1 = X[ 0 ]; - v2 = X[ (N-1) * stride ]; - } + v1 = X[ offsetX ]; + v2 = X[ ( (N-1)*strideX ) + offsetX ]; if ( stdlib_base_is_nanf( v1 ) || stdlib_base_is_nanf( v2 ) ) { return 0.0f / 0.0f; // NaN } diff --git a/test/test.ndarray.js b/test/test.ndarray.js index 075ac18..b7e27da 100644 --- a/test/test.ndarray.js +++ b/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); var isNegativeZerof = require( '@stdlib/math-base-assert-is-negative-zerof' ); var Float32Array = require( '@stdlib/array-float32' ); @@ -116,7 +115,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; @@ -125,21 +123,19 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0, 2.0, // 1 -7.0, - 3.0, // 2 + 3.0, // 2 3.0, 4.0, // 3 2.0 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, 2, 0 ); + v = sminsorted( 4, x, 2, 0 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -154,8 +150,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, -2, 6 ); + v = sminsorted( 4, x, -2, 6 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); @@ -174,7 +169,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -188,9 +182,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, 2, 1 ); + v = sminsorted( 4, x, 2, 1 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); diff --git a/test/test.ndarray.native.js b/test/test.ndarray.native.js index 3c25af0..67924e1 100644 --- a/test/test.ndarray.native.js +++ b/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); var isNegativeZerof = require( '@stdlib/math-base-assert-is-negative-zerof' ); var Float32Array = require( '@stdlib/array-float32' ); @@ -125,7 +124,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -134,21 +132,19 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0, 2.0, // 1 -7.0, - 3.0, // 2 + 3.0, // 2 3.0, 4.0, // 3 2.0 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, 2, 0 ); + v = sminsorted( 4, x, 2, 0 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -163,8 +159,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, -2, 6 ); + v = sminsorted( 4, x, -2, 6 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); @@ -183,7 +178,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -197,9 +191,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, 2, 1 ); + v = sminsorted( 4, x, 2, 1 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); diff --git a/test/test.sminsorted.js b/test/test.sminsorted.js index 5f2ebdf..84c45af 100644 --- a/test/test.sminsorted.js +++ b/test/test.sminsorted.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); var isNegativeZerof = require( '@stdlib/math-base-assert-is-negative-zerof' ); var Float32Array = require( '@stdlib/array-float32' ); @@ -116,7 +115,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; @@ -131,15 +129,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, 2 ); + v = sminsorted( 4, x, 2 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -154,8 +150,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, -2 ); + v = sminsorted( 4, x, -2 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); @@ -176,7 +171,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 Float32Array([ @@ -192,9 +186,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = sminsorted( N, x1, 2 ); + v = sminsorted( 4, x1, 2 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); diff --git a/test/test.sminsorted.native.js b/test/test.sminsorted.native.js index a6b9851..3a0356c 100644 --- a/test/test.sminsorted.native.js +++ b/test/test.sminsorted.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math-base-special-floor' ); var isnanf = require( '@stdlib/math-base-assert-is-nanf' ); var isNegativeZerof = require( '@stdlib/math-base-assert-is-negative-zerof' ); var Float32Array = require( '@stdlib/array-float32' ); @@ -125,7 +124,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -140,15 +138,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, 2 ); + v = sminsorted( 4, x, 2 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -163,8 +159,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = sminsorted( N, x, -2 ); + v = sminsorted( 4, x, -2 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); @@ -185,7 +180,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -201,9 +195,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = sminsorted( N, x1, 2 ); + v = sminsorted( 4, x1, 2 ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end();