From 2771718f98a5968d7bc1e02cba076854d561d122 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Fri, 3 Jan 2025 09:53:49 +0000 Subject: [PATCH 1/2] 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: passed - 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/sminsorted/README.md | 164 ++++++++++++++---- .../base/sminsorted/benchmark/benchmark.js | 17 +- .../sminsorted/benchmark/benchmark.native.js | 13 +- .../sminsorted/benchmark/benchmark.ndarray.js | 17 +- .../benchmark/benchmark.ndarray.native.js | 13 +- .../sminsorted/benchmark/c/benchmark.length.c | 54 +++++- .../stats/base/sminsorted/docs/repl.txt | 32 ++-- .../base/sminsorted/docs/types/index.d.ts | 12 +- .../base/sminsorted/examples/c/example.c | 9 +- .../stats/base/sminsorted/examples/index.js | 13 +- .../stats/base/sminsorted/include.gypi | 2 +- .../include/stdlib/stats/base/sminsorted.h | 9 +- .../stats/base/sminsorted/lib/index.js | 7 +- .../stats/base/sminsorted/lib/ndarray.js | 16 +- .../base/sminsorted/lib/ndarray.native.js | 20 +-- .../stats/base/sminsorted/lib/sminsorted.js | 41 +---- .../base/sminsorted/lib/sminsorted.native.js | 9 +- .../stats/base/sminsorted/manifest.json | 74 +++++++- .../@stdlib/stats/base/sminsorted/src/addon.c | 60 +++++++ .../stats/base/sminsorted/src/addon.cpp | 117 ------------- .../sminsorted/src/{sminsorted.c => main.c} | 38 ++-- .../base/sminsorted/test/test.ndarray.js | 15 +- .../sminsorted/test/test.ndarray.native.js | 15 +- .../base/sminsorted/test/test.sminsorted.js | 13 +- .../sminsorted/test/test.sminsorted.native.js | 13 +- 25 files changed, 441 insertions(+), 352 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/sminsorted/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/sminsorted/src/addon.cpp rename lib/node_modules/@stdlib/stats/base/sminsorted/src/{sminsorted.c => main.c} (54%) diff --git a/lib/node_modules/@stdlib/stats/base/sminsorted/README.md b/lib/node_modules/@stdlib/stats/base/sminsorted/README.md index 2d988bb3a57e..0b8552e30be4 100644 --- a/lib/node_modules/@stdlib/stats/base/sminsorted/README.md +++ b/lib/node_modules/@stdlib/stats/base/sminsorted/README.md @@ -36,7 +36,7 @@ limitations under the License. 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`. @@ -44,15 +44,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 ``` @@ -60,18 +58,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 ``` @@ -81,18 +77,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. @@ -100,26 +93,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 ``` @@ -145,16 +135,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 ); @@ -165,6 +152,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 ); +} +``` + +
+ + + +
+ + +