From 6f6753c54702f46f22ba5c29e8efecc2edde7346 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Tue, 31 Dec 2024 07:43:16 +0000 Subject: [PATCH 1/5] feat: add C ndarray interface and refactor implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/smskrange/README.md | 138 ++++++++++++++-- .../base/smskrange/benchmark/benchmark.js | 42 +++-- .../smskrange/benchmark/benchmark.native.js | 38 +++-- .../smskrange/benchmark/benchmark.ndarray.js | 42 +++-- .../benchmark/benchmark.ndarray.native.js | 38 +++-- .../smskrange/benchmark/c/benchmark.length.c | 56 ++++++- .../stats/base/smskrange/docs/repl.txt | 22 ++- .../stats/base/smskrange/examples/c/example.c | 10 +- .../@stdlib/stats/base/smskrange/include.gypi | 2 +- .../include/stdlib/stats/base/smskrange.h | 8 +- .../@stdlib/stats/base/smskrange/lib/index.js | 4 +- .../stats/base/smskrange/lib/ndarray.js | 4 +- .../base/smskrange/lib/ndarray.native.js | 21 +-- .../stats/base/smskrange/lib/smskrange.js | 60 +------ .../stats/base/smskrange/manifest.json | 70 +++++++- .../@stdlib/stats/base/smskrange/src/addon.c | 66 ++++++++ .../stats/base/smskrange/src/addon.cpp | 153 ------------------ .../smskrange/src/{smskrange.c => main.c} | 40 +++-- .../stats/base/smskrange/test/test.ndarray.js | 13 +- .../smskrange/test/test.ndarray.native.js | 15 +- .../base/smskrange/test/test.smskrange.js | 13 +- .../smskrange/test/test.smskrange.native.js | 13 +- 22 files changed, 475 insertions(+), 393 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/smskrange/src/addon.cpp rename lib/node_modules/@stdlib/stats/base/smskrange/src/{smskrange.c => main.c} (57%) diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/README.md b/lib/node_modules/@stdlib/stats/base/smskrange/README.md index b2816e520d9c..d20b5878ffdc 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/smskrange/README.md @@ -57,22 +57,20 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **strideX**: index increment for `x`. +- **strideX**: stride length for `x`. - **mask**: mask [`Uint8Array`][@stdlib/array/uint8]. If a `mask` array element is `0`, the corresponding element in `x` is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in `x` is considered invalid/missing and **excluded** from computation. -- **strideMask**: index increment for `mask`. +- **strideMask**: stride length for `mask`. -The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the [range][range] of every other element in `x`, +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the [range][range] of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); var Uint8Array = require( '@stdlib/array/uint8' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ] ); var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] ); -var N = floor( x.length / 2 ); -var v = smskrange( N, x, 2, mask, 2 ); +var v = smskrange( 4, x, 2, mask, 2 ); // returns 11.0 ``` @@ -83,7 +81,6 @@ Note that indexing is relative to the first index. To introduce offsets, use [`t ```javascript var Float32Array = require( '@stdlib/array/float32' ); var Uint8Array = require( '@stdlib/array/uint8' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element @@ -91,9 +88,7 @@ var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd var mask0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] ); var mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = smskrange( N, x1, 2, mask1, 2 ); +var v = smskrange( 4, x1, 2, mask1, 2 ); // returns 6.0 ``` @@ -117,18 +112,16 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetMask**: starting index for `mask`. -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 [range][range] 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 parameters support indexing semantics based on a starting index. For example, to calculate the [range][range] for every other value in `x` starting from the second value ```javascript var Float32Array = require( '@stdlib/array/float32' ); var Uint8Array = require( '@stdlib/array/uint8' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] ); var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] ); -var N = floor( x.length / 2 ); -var v = smskrange.ndarray( N, x, 2, 1, mask, 2, 1 ); +var v = smskrange.ndarray( 4, x, 2, 1, mask, 2, 1 ); // returns 6.0 ``` @@ -184,6 +177,123 @@ console.log( v ); + + +
+ +### Usage + +```c +#include "stdlib/stats/base/smskrange.h" +``` + +#### stdlib_strided_smskrange( N, \*X, strideX, Mask, strideMask ) + +Computes the [range][range] of a single-precision floating-point strided array `x` according to a `mask`. + +```c +#include + +const float x[] = { 1.0f, -2.0f, 2.0f }; +const uint_8 mask = { 0, 1, 0 }; + +float v = stdlib_strided_smskrange( 3, x, 1, mask, 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`. +- **Mask**: `[in] uint_8*`. If a `mask` array element is `0`, the corresponding element in `x` is considered valid and included in computation. If a `mask` array element is `1`, the corresponding element in `x` is considered invalid/missing and excluded from computation. +- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`. + +```c +float stdlib_strided_smskrange( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const uint8_t *Mask, const CBLAS_INT strideMask ); +``` + +#### stdlib_strided_smskrange_ndarray( N, \*X, strideX, offsetX ) + +Computes the [range][range] of a single-precision floating-point strided array according to a `mask` and using alternative indexing semantics. + +```c +#include + +const float x[] = { 1.0f, -2.0f, 2.0f }; +const uint_8 mask = { 0, 1, 0 }; + +float v = stdlib_strided_smskrange( 3, x, 1, 0, mask, 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`. +- **Mask**: `[in] uint_8*`. If a `mask` array element is `0`, the corresponding element in `x` is considered valid and included in computation. If a `mask` array element is `1`, the corresponding element in `x` is considered invalid/missing and excluded from computation. +- **strideMask**: `[in] CBLAS_INT` stride length for `Mask`. +- **offsetMask**: `[in] CBLAS_INT` starting index for `Mask`. + +```c +float stdlib_strided_smskrange_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const uint8_t *Mask, const CBLAS_INT strideMask , const CBLAS_INT offsetMask ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/smskrange.h" +#include +#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, 9.0f, 10.0f }; + + // Create a mask array: + uint8_t mask[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; + + // Specify the number of elements: + const int N = 5; + + // Specify the stride lengths: + const int strideX = 2; + const int strideMask = 2; + + // Compute the minimum value: + float v = stdlib_strided_smskrange( N, x, strideX, mask, strideMask ); + + // Print the result: + printf( "min: %f\n", v ); +} +``` + +
+ + + + + + + @@ -278,11 +280,11 @@ int main( void ) { const int strideX = 2; const int strideMask = 2; - // Compute the minimum value: + // Compute the range: float v = stdlib_strided_smskrange( N, x, strideX, mask, strideMask ); // Print the result: - printf( "min: %f\n", v ); + printf( "range: %f\n", v ); } ``` diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/include/stdlib/stats/base/smskrange.h b/lib/node_modules/@stdlib/stats/base/smskrange/include/stdlib/stats/base/smskrange.h index cb5425e4d94f..7dbc1b899814 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/include/stdlib/stats/base/smskrange.h +++ b/lib/node_modules/@stdlib/stats/base/smskrange/include/stdlib/stats/base/smskrange.h @@ -37,7 +37,7 @@ float API_SUFFIX(stdlib_strided_smskrange)( const CBLAS_INT N, const float *X, c /** * Computes the range of a single-precision floating-point strided array according to a mask and using alternative indexing semantics. */ -float API_SUFFIX(stdlib_strided_smskrange_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const uint8_t *Mask, const CBLAS_INT strideMask , const CBLAS_INT offsetMask ); +float API_SUFFIX(stdlib_strided_smskrange_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const uint8_t *Mask, const CBLAS_INT strideMask, const CBLAS_INT offsetMask ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/smskrange/lib/ndarray.native.js index 8efbf91bdf49..a78caef56b78 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/smskrange/lib/ndarray.native.js @@ -48,8 +48,7 @@ var addon = require( './../src/addon.node' ); * // returns 6.0 */ function smskrange( N, x, strideX, offsetX, mask, strideMask, offsetMask ) { - // TODO-add eslint comment to disable max len warning(if needed) - return addon.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ); + return addon.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ); // eslint-disable-line max-len } From 829cd0792390b180445fbf42ffafcc36a21f56f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Wed, 1 Jan 2025 05:38:32 +0000 Subject: [PATCH 3/5] chore: update copyright years --- lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c b/lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c index 35c002769f4b..929825c11d79 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* 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. From a9d957014873095902366ffe503e5709c5eb90e9 Mon Sep 17 00:00:00 2001 From: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Date: Thu, 2 Jan 2025 14:35:37 +0530 Subject: [PATCH 4/5] feat: update benchmarks and examples --- .../@stdlib/stats/base/smskrange/README.md | 37 ++++++++----------- .../base/smskrange/benchmark/benchmark.js | 25 ++++--------- .../smskrange/benchmark/benchmark.native.js | 25 ++++--------- .../smskrange/benchmark/benchmark.ndarray.js | 25 ++++--------- .../benchmark/benchmark.ndarray.native.js | 25 ++++--------- .../stats/base/smskrange/docs/repl.txt | 2 +- .../stats/base/smskrange/examples/index.js | 27 +++++--------- 7 files changed, 54 insertions(+), 112 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/README.md b/lib/node_modules/@stdlib/stats/base/smskrange/README.md index f323f70c487e..e63c44af60bb 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/smskrange/README.md @@ -112,7 +112,7 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetMask**: starting index for `mask`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on a starting index. For example, to calculate the [range][range] 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 parameters support indexing semantics based on a starting indices. For example, to calculate the [range][range] for every other element in `x` starting from the second element ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -146,26 +146,19 @@ var v = smskrange.ndarray( 4, x, 2, 1, mask, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); -var Uint8Array = require( '@stdlib/array/uint8' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var smskrange = require( '@stdlib/stats/base/smskrange' ); -var mask; -var x; -var i; - -x = new Float32Array( 10 ); -mask = new Uint8Array( x.length ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - mask[ i ] = 1; - } else { - mask[ i ] = 0; - } - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var uniformOptions = { + 'dtype': 'float32' +}; +var bernoulliOptions = { + 'dtype': 'uint8' +}; + +var x = uniform( 10, -50.0, 50.0, uniformOptions ); +var mask = bernoulli( x.length, 0.2, bernoulliOptions ); console.log( x ); console.log( mask ); @@ -195,7 +188,7 @@ Computes the [range][range] of a single-precision floating-point strided array a #include const float x[] = { 1.0f, -2.0f, 2.0f }; -const uint8_t mask = { 0, 1, 0 }; +const uint8_t mask[] = { 0, 1, 0 }; float v = stdlib_strided_smskrange( 3, x, 1, mask, 1 ); // returns 1.0f @@ -223,7 +216,7 @@ Computes the [range][range] of a single-precision floating-point strided array a #include const float x[] = { 1.0f, -2.0f, 2.0f }; -const uint8_t mask = { 0, 1, 0 }; +const uint8_t mask[] = { 0, 1, 0 }; float v = stdlib_strided_smskrange( 3, x, 1, 0, mask, 1, 0 ); // returns 1.0f @@ -271,7 +264,7 @@ int main( void ) { const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }; // Create a mask array: - uint8_t mask[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; + const uint8_t mask[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; // Specify the number of elements: const int N = 5; diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.js index a26a52c62ffb..62f5bb0783f6 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.js @@ -22,8 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -32,26 +31,16 @@ var smskrange = require( './../lib/smskrange.js' ); // VARIABLES // -var options = { +var uniformOptions = { 'dtype': 'float32' }; +var bernoulliOptions = { + 'dtype': 'uint8' +}; // FUNCTIONS // -/** -* Returns either one or zero. -* -* @private -* @returns {number} one or zero -*/ -function rand() { - if ( bernoulli( 0.2 ) ) { - return 1; - } - return 0; -} - /** * Creates a benchmark function. * @@ -60,8 +49,8 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var mask = filledarrayBy( len, 'uint8', rand ); - var x = uniform( len, -10.0, 10.0, options ); + var mask = bernoulli( len, 0.2, bernoulliOptions ); + var x = uniform( len, -10.0, 10.0, uniformOptions ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.native.js index 00bd7b9d77e6..f88173beb42d 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.native.js @@ -23,8 +23,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -37,26 +36,16 @@ var smskrange = tryRequire( resolve( __dirname, './../lib/smskrange.native.js' ) var opts = { 'skip': ( smskrange instanceof Error ) }; -var options = { +var uniformOptions = { 'dtype': 'float32' }; +var bernoulliOptions = { + 'dtype': 'uint8' +}; // FUNCTIONS // -/** -* Returns either one or zero. -* -* @private -* @returns {number} one or zero -*/ -function rand() { - if ( bernoulli( 0.2 ) ) { - return 1; - } - return 0; -} - /** * Creates a benchmark function. * @@ -65,8 +54,8 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var mask = filledarrayBy( len, 'uint8', rand ); - var x = uniform( len, -10.0, 10.0, options ); + var mask = bernoulli( len, 0.2, bernoulliOptions ); + var x = uniform( len, -10.0, 10.0, uniformOptions ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.ndarray.js index cb5ed131ad9a..7a4187e30aec 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.ndarray.js @@ -22,8 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -32,26 +31,16 @@ var smskrange = require( './../lib/ndarray.js' ); // VARIABLES // -var options = { +var uniformOptions = { 'dtype': 'float32' }; +var bernoulliOptions = { + 'dtype': 'uint8' +}; // FUNCTIONS // -/** -* Returns either one or zero. -* -* @private -* @returns {number} one or zero -*/ -function rand() { - if ( bernoulli( 0.2 ) ) { - return 1; - } - return 0; -} - /** * Creates a benchmark function. * @@ -60,8 +49,8 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var mask = filledarrayBy( len, 'uint8', rand ); - var x = uniform( len, -10.0, 10.0, options ); + var mask = bernoulli( len, 0.2, bernoulliOptions ); + var x = uniform( len, -10.0, 10.0, uniformOptions ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.ndarray.native.js index 54cef57fe91f..2dbfb2c311fe 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/smskrange/benchmark/benchmark.ndarray.native.js @@ -23,8 +23,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -37,26 +36,16 @@ var smskrange = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ) var opts = { 'skip': ( smskrange instanceof Error ) }; -var options = { +var uniformOptions = { 'dtype': 'float32' }; +var bernoulliOptions = { + 'dtype': 'uint8' +}; // FUNCTIONS // -/** -* Returns either one or zero. -* -* @private -* @returns {number} one or zero -*/ -function rand() { - if ( bernoulli( 0.2 ) ) { - return 1; - } - return 0; -} - /** * Creates a benchmark function. * @@ -65,8 +54,8 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var mask = filledarrayBy( len, 'uint8', rand ); - var x = uniform( len, -10.0, 10.0, options ); + var mask = bernoulli( len, 0.2, bernoulliOptions ); + var x = uniform( len, -10.0, 10.0, uniformOptions ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/smskrange/docs/repl.txt index 2c1550c0f7cc..7eeccb40a7a7 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/smskrange/docs/repl.txt @@ -3,7 +3,7 @@ Computes the range of a single-precision floating-point strided array according to a mask. - The `N` and stride parameters determine which elements in the strided array + The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. Indexing is relative to the first index. To introduce offsets, use a typed diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/examples/index.js b/lib/node_modules/@stdlib/stats/base/smskrange/examples/index.js index 4d2c7d22f6dc..f39eab3a7777 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/smskrange/examples/index.js @@ -18,26 +18,19 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); -var Uint8Array = require( '@stdlib/array/uint8' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); var smskrange = require( './../lib' ); -var mask; -var x; -var i; +var uniformOptions = { + 'dtype': 'float32' +}; +var bernoulliOptions = { + 'dtype': 'uint8' +}; -x = new Float32Array( 10 ); -mask = new Uint8Array( x.length ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - mask[ i ] = 1; - } else { - mask[ i ] = 0; - } - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = uniform( 10, -50.0, 50.0, uniformOptions ); +var mask = bernoulli( x.length, 0.2, bernoulliOptions ); console.log( x ); console.log( mask ); From 159e57edc1e0c672955521715072a934e0a4be58 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 2 Jan 2025 02:14:59 -0800 Subject: [PATCH 5/5] style: fix indentation Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c b/lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c index 929825c11d79..2763cecc3def 100644 --- a/lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/smskrange/src/addon.c @@ -54,9 +54,9 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 7 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_INT64( env, strideMask, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, strideMask, argv, 5 ); STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); - STDLIB_NAPI_ARGV_INT64( env, offsetMask, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, offsetMask, argv, 6 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); STDLIB_NAPI_ARGV_STRIDED_UINT8ARRAY( env, Mask, N, strideMask, argv, 4 ); STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_smskrange_ndarray( N, X, strideX, offsetX, Mask, strideMask, offsetMask ), v );