From 0e54830b664aa7c681f0fd2177bad518a4e6b7bc Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Wed, 26 Aug 2026 02:41:56 +0530 Subject: [PATCH 01/10] feat(stats/base/ndarray/smskmin): add C implementation Signed-off-by: Aryan Sharma --- .../stats/base/ndarray/smskmin/README.md | 120 ++++++++ .../ndarray/smskmin/benchmark/benchmark.c | 150 ++++++++++ .../smskmin/benchmark/benchmark.native.js | 116 ++++++++ .../stats/base/ndarray/smskmin/binding.gyp | 170 ++++++++++++ .../stats/base/ndarray/smskmin/include.gypi | 53 ++++ .../stdlib/stats/base/ndarray/smskmin.h | 43 +++ .../stats/base/ndarray/smskmin/lib/index.js | 18 +- .../stats/base/ndarray/smskmin/lib/native.js | 65 +++++ .../stats/base/ndarray/smskmin/manifest.json | 110 ++++++++ .../stats/base/ndarray/smskmin/package.json | 8 +- .../stats/base/ndarray/smskmin/src/Makefile | 70 +++++ .../stats/base/ndarray/smskmin/src/addon.c | 46 ++++ .../stats/base/ndarray/smskmin/src/main.c | 35 +++ .../stats/base/ndarray/smskmin/test/test.js | 234 ++-------------- .../base/ndarray/smskmin/test/test.main.js | 253 +++++++++++++++++ .../base/ndarray/smskmin/test/test.native.js | 257 ++++++++++++++++++ 16 files changed, 1539 insertions(+), 209 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/include/stdlib/stats/base/ndarray/smskmin.h create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md index 3bb870022903..55507fe2429d 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md @@ -118,3 +118,123 @@ console.log( v ); + +## C APIs + + + +### Usage + +```c +#include "stdlib/stats/base/ndarray/smskmin.h" +``` + +#### stdlib_stats_smskmin( arrays ) + +Computes the minimum value of a single-precision floating-point ndarray according to a mask. + +```c +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/dtypes.h" +#include + +// Define arrays: +float x[] = { 1.0f, -2.0f, 4.0f, 2.0f }; +uint8_t mask[] = { 0, 0, 1, 0 }; + +// Define ndarray meta data: +int64_t shape[] = { 4 }; +int64_t stridesX[] = { 1 }; +int64_t stridesMask[] = { 1 }; +int64_t offset = 0; + +// Allocate ndarrays: +struct ndarray *arrX = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, x, 1, shape, stridesX, offset, STDLIB_NDARRAY_ROW_MAJOR ); +struct ndarray *arrMask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mask, 1, shape, stridesMask, offset, STDLIB_NDARRAY_ROW_MAJOR ); + +// Set up arguments: +const struct ndarray *arrays[] = { arrX, arrMask }; + +// Compute the masked minimum: +float v = stdlib_stats_smskmin( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( arrX ); +stdlib_ndarray_free( arrMask ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` array containing an input ndarray and a mask ndarray. + +```c +float stdlib_stats_smskmin( const struct ndarray *arrays[] ); +``` + + + + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/ndarray/smskmin.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/dtypes.h" +#include +#include + +int main( void ) { + // Define arrays: + float x[] = { 1.0f, -2.0f, 4.0f, 2.0f }; + uint8_t mask[] = { 0, 0, 1, 0 }; + + // Define ndarray meta data: + int64_t shape[] = { 4 }; + int64_t stridesX[] = { 1 }; + int64_t stridesMask[] = { 1 }; + int64_t offset = 0; + + // Allocate ndarrays: + struct ndarray *arrX = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, x, 1, shape, stridesX, offset, STDLIB_NDARRAY_ROW_MAJOR ); + struct ndarray *arrMask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mask, 1, shape, stridesMask, offset, STDLIB_NDARRAY_ROW_MAJOR ); + + // Set up arguments: + const struct ndarray *arrays[] = { arrX, arrMask }; + + // Compute the masked minimum: + float v = stdlib_stats_smskmin( arrays ); + + printf( "smskmin = %f\n", v ); + + // Free allocated memory: + stdlib_ndarray_free( arrX ); + stdlib_ndarray_free( arrMask ); + + return 0; +} +``` + +
+ + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.c new file mode 100644 index 000000000000..864055487340 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.c @@ -0,0 +1,150 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/ndarray/smskmin.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include "stdlib/ndarray/ctor.h" +#include +#include +#include +#include +#include + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %g\n", elapsed ); + printf( " rate: %g\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_double( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double t; + float x[ 100 ]; + uint8_t mask[ 100 ]; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_double() * 100.0f ) - 50.0f; + mask[ i ] = ( rand_double() < 0.2 ) ? 1 : 0; + } + + int64_t shape[] = { 100 }; + int64_t stridesX[] = { 1 }; + int64_t stridesMask[] = { 1 }; + int64_t offset = 0; + + struct ndarray *arrX = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, x, 1, shape, stridesX, offset, STDLIB_NDARRAY_ROW_MAJOR ); + struct ndarray *arrMask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mask, 1, shape, stridesMask, offset, STDLIB_NDARRAY_ROW_MAJOR ); + + const struct ndarray *arrays[] = { arrX, arrMask }; + + int iterations = 1000000; + float v; + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_stats_smskmin( arrays ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + stdlib_ndarray_free( arrX ); + stdlib_ndarray_free( arrMask ); + + print_results( iterations, elapsed ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + + count = 0; + print_version(); + printf( "# c::%s\n", "smskmin" ); + elapsed = benchmark(); + print_results( 1000000, elapsed ); + printf( "ok %d benchmark finished\n", ++count ); + print_summary( count, count ); + return 0; +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js new file mode 100644 index 000000000000..435b7111090e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js @@ -0,0 +1,116 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/uniform' ); +var bernoulli = require( '@stdlib/random/bernoulli' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var tryRequire = require( '@stdlib/utils/try-require' ); +var resolve = require( 'path' ).resolve; +var smskmin = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { 'skip': ( smskmin instanceof Error ) }; + + +// VARIABLES // + +var xoptions = { + 'dtype': 'float32' +}; +var moptions = { + 'dtype': 'uint8' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask; + var x; + + x = uniform( [ len ], -100.0, 100.0, xoptions ); + mask = bernoulli( [ len ], 0.2, moptions ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x.set( i%len, i ); + v = smskmin( [ x, mask ] ); + if ( isnanf( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/binding.gyp b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/include.gypi b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '} arrays - array-like object containing ndarrays +* @returns {number} minimum value +* +* @example +* var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); +* var Uint8Vector = require( '@stdlib/ndarray/vector/uint8' ); +* +* var x = new Float32Vector( [ 1.0, -2.0, 4.0, 2.0 ] ); +* var mask = new Uint8Vector( [ 0, 0, 1, 0 ] ); +* +* var v = smskmin( [ x, mask ] ); +* // returns -2.0 +*/ +function smskmin( arrays ) { + var mask; + var x; + + x = arrays[ 0 ]; + mask = arrays[ 1 ]; + return addon( getData( x ), serialize( x ), getData( mask ), serialize( mask ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = smskmin; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/manifest.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/manifest.json new file mode 100644 index 000000000000..4763a882f3f6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/manifest.json @@ -0,0 +1,110 @@ +{ + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/stats/strided/smskmin", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/base/napi/addon-arguments", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/create-double" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/stats/strided/smskmin", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/dtypes", + "@stdlib/ndarray/index-modes", + "@stdlib/ndarray/orders", + "@stdlib/ndarray/base/bytes-per-element" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/stats/strided/smskmin", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/dtypes", + "@stdlib/ndarray/index-modes", + "@stdlib/ndarray/orders", + "@stdlib/ndarray/base/bytes-per-element" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/stats/strided/smskmin", + "@stdlib/ndarray/ctor" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json index b5a31a67c58a..2333b0419ab6 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json @@ -19,7 +19,9 @@ "doc": "./docs", "example": "./examples", "lib": "./lib", - "test": "./test" + "test": "./test", + "src": "./src", + "include": "./include" }, "types": "./docs/types", "scripts": {}, @@ -63,5 +65,7 @@ "single-precision", "ndarray" ], - "__stdlib__": {} + "__stdlib__": {}, + "gypfile": true, + "browser": "./lib/main.js" } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/addon.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/addon.c new file mode 100644 index 000000000000..beb67c70b19e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/addon.c @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/ndarray/smskmin.h" +#include "stdlib/ndarray/base/napi/addon_arguments.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.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 ) { + struct ndarray *arrays[ 2 ]; + napi_value v; + napi_status status; + + status = stdlib_ndarray_napi_addon_arguments( env, info, arrays, 2, "smskmin" ); + if ( status != napi_ok ) { + return NULL; + } + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_stats_smskmin( (const struct ndarray **)arrays ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c new file mode 100644 index 000000000000..0ec95da79018 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/ndarray/smskmin.h" +#include "stdlib/stats/strided/smskmin.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/blas/base/shared.h" +#include + +/** +* Computes the minimum value of a single-precision floating-point ndarray according to a mask. +* +* @param arrays list containing an input ndarray and a mask ndarray +* @return minimum value +*/ +float stdlib_stats_smskmin( const struct ndarray *arrays[] ) { + const struct ndarray *x = arrays[ 0 ]; + const struct ndarray *mask = arrays[ 1 ]; + return API_SUFFIX(stdlib_strided_smskmin_ndarray)( stdlib_ndarray_dimension( x, 0 ), (const float *)stdlib_ndarray_data( x ), stdlib_ndarray_stride_elements( x, 0 ), stdlib_ndarray_offset_elements( x ), (const uint8_t *)stdlib_ndarray_data( mask ), stdlib_ndarray_stride_elements( mask, 0 ), stdlib_ndarray_offset_elements( mask ) ); +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js index 58e0ea796b5c..2578d2c1f2e2 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. @@ -21,30 +21,16 @@ // MODULES // var tape = require( 'tape' ); -var Float32Array = require( '@stdlib/array/float32' ); -var Uint8Array = require( '@stdlib/array/uint8' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); var smskmin = require( './../lib' ); -// FUNCTIONS // +// VARIABLES // -/** -* Returns a one-dimensional ndarray. -* -* @private -* @param {string} dtype - data type -* @param {Collection} buffer - underlying data buffer -* @param {NonNegativeInteger} length - number of indexed elements -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - index offset -* @returns {ndarray} one-dimensional ndarray -*/ -function vector( dtype, buffer, length, stride, offset ) { - return new ndarray( dtype, buffer, [ length ], [ stride ], offset, 'row-major' ); -} +var opts = { + 'skip': IS_BROWSER +}; // TESTS // @@ -55,199 +41,37 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 1', function test( t ) { - t.strictEqual( smskmin.length, 1, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the minimum value of a one-dimensional ndarray according to a mask', function test( t ) { - var mask; - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ] ); - mask = new Uint8Array( [ 0, 0, 0, 1, 0, 0, 0 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( v, -4.0, 'returns expected value' ); - - x = new Float32Array( [ -4.0, NaN, -5.0 ] ); - mask = new Uint8Array( [ 0, 1, 0 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( v, -5.0, 'returns expected value' ); - - x = new Float32Array( [ -0.0, 0.0, NaN, -0.0 ] ); - mask = new Uint8Array( [ 0, 0, 1, 0 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); - - x = new Float32Array( [ -4.0, 0.0, NaN, 5.0 ] ); - mask = new Uint8Array( [ 0, 0, 0, 0 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - x = new Float32Array( [ NaN ] ); - mask = new Uint8Array( [ 0 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - x = new Float32Array( [ NaN ] ); - mask = new Uint8Array( [ 1 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - x = new Float32Array( [ NaN, NaN ] ); - mask = new Uint8Array( [ 1, 1 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - x = new Float32Array( [ NaN, NaN ] ); - mask = new Uint8Array( [ 1, 0 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - x = new Float32Array( [ NaN, NaN ] ); - mask = new Uint8Array( [ 0, 1 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - x = new Float32Array( [ NaN, NaN ] ); - mask = new Uint8Array( [ 0, 0 ] ); - v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var smskmin = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + t.strictEqual( smskmin, mock, 'returns expected value' ); t.end(); -}); - -tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t ) { - var mask; - var x; - var v; - x = new Float32Array( [] ); - mask = new Uint8Array( [] ); + function tryRequire() { + return mock; + } - v = smskmin( [ vector( 'float32', x, 0, 1, 0 ), vector( 'uint8', mask, 0, 1, 0 ) ] ); - t.strictEqual( isnanf( v ), true, 'returns expected value' ); - - t.end(); + function mock() { + // Mock... + } }); -tape( 'if provided an ndarray containing a single element, the function returns the first element', function test( t ) { - var mask; - var x; - var v; +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var smskmin; + var main; - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - mask = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); + main = require( './../lib/main.js' ); - v = smskmin( [ vector( 'float32', x, 1, 1, 0 ), vector( 'uint8', mask, 1, 1, 0 ) ] ); - t.strictEqual( v, 1.0, 'returns expected value' ); + smskmin = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + t.strictEqual( smskmin, main, 'returns expected value' ); t.end(); -}); -tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { - var mask; - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0, - 5.0, // 4 - 6.0 - ]); - mask = new Uint8Array([ - 0, // 0 - 0, - 0, // 1 - 0, - 0, // 2 - 0, - 0, // 3 - 0, - 1, // 4 - 1 - ]); - - v = smskmin( [ vector( 'float32', x, 5, 2, 0 ), vector( 'uint8', mask, 5, 2, 0 ) ] ); - t.strictEqual( v, -2.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { - var mask; - var x; - var v; - - x = new Float32Array([ - 5.0, // 4 - 6.0, - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - mask = new Uint8Array([ - 1, // 4 - 1, - 0, // 3 - 0, - 0, // 2 - 0, - 0, // 1 - 0, - 0, // 0 - 0 - ]); - - v = smskmin( [ vector( 'float32', x, 5, -2, 8 ), vector( 'uint8', mask, 5, -2, 8 ) ] ); - t.strictEqual( v, -2.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { - var mask; - var x; - var v; - - x = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 5.0, - 6.0 // 4 - ]); - mask = new Uint8Array([ - 0, - 0, // 0 - 0, - 0, // 1 - 0, - 0, // 2 - 0, - 0, // 3 - 1, - 1 // 4 - ]); - - v = smskmin( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); - t.strictEqual( v, -2.0, 'returns expected value' ); - - t.end(); + function tryRequire() { + return new Error( 'Cannot find module' ); + } }); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.main.js new file mode 100644 index 000000000000..126d348ae6c3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.main.js @@ -0,0 +1,253 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var smskmin = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {string} dtype - data type +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( dtype, buffer, length, stride, offset ) { + return new ndarray( dtype, buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof smskmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( smskmin.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the minimum value of a one-dimensional ndarray according to a mask', function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 1, 0, 0, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = new Float32Array( [ -4.0, NaN, -5.0 ] ); + mask = new Uint8Array( [ 0, 1, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, -5.0, 'returns expected value' ); + + x = new Float32Array( [ -0.0, 0.0, NaN, -0.0 ] ); + mask = new Uint8Array( [ 0, 0, 1, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + + x = new Float32Array( [ -4.0, 0.0, NaN, 5.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + mask = new Uint8Array( [ 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + mask = new Uint8Array( [ 1 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 1, 1 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 1, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 0, 1 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 0, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array( [] ); + mask = new Uint8Array( [] ); + + v = smskmin( [ vector( 'float32', x, 0, 1, 0 ), vector( 'uint8', mask, 0, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an ndarray containing a single element, the function returns the first element', function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); + + v = smskmin( [ vector( 'float32', x, 1, 1, 0 ), vector( 'uint8', mask, 1, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + 5.0, // 4 + 6.0 + ]); + mask = new Uint8Array([ + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]); + + v = smskmin( [ vector( 'float32', x, 5, 2, 0 ), vector( 'uint8', mask, 5, 2, 0 ) ] ); + t.strictEqual( v, -2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array([ + 5.0, // 4 + 6.0, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + mask = new Uint8Array([ + 1, // 4 + 1, + 0, // 3 + 0, + 0, // 2 + 0, + 0, // 1 + 0, + 0, // 0 + 0 + ]); + + v = smskmin( [ vector( 'float32', x, 5, -2, 8 ), vector( 'uint8', mask, 5, -2, 8 ) ] ); + t.strictEqual( v, -2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 5.0, + 6.0 // 4 + ]); + mask = new Uint8Array([ + 0, + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 1, + 1 // 4 + ]); + + v = smskmin( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); + t.strictEqual( v, -2.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js new file mode 100644 index 000000000000..ecf52ce53905 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js @@ -0,0 +1,257 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var resolve = require( 'path' ).resolve; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var smskmin = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { 'skip': isError( smskmin ) }; + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {string} dtype - data type +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( dtype, buffer, length, stride, offset ) { + return new ndarray( dtype, buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof smskmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', opts, function test( t ) { + t.strictEqual( smskmin.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the minimum value of a one-dimensional ndarray according to a mask', opts, function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 1, 0, 0, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = new Float32Array( [ -4.0, NaN, -5.0 ] ); + mask = new Uint8Array( [ 0, 1, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, -5.0, 'returns expected value' ); + + x = new Float32Array( [ -0.0, 0.0, NaN, -0.0 ] ); + mask = new Uint8Array( [ 0, 0, 1, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + + x = new Float32Array( [ -4.0, 0.0, NaN, 5.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + mask = new Uint8Array( [ 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + mask = new Uint8Array( [ 1 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 1, 1 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 1, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 0, 1 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 0, 0 ] ); + v = smskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns `NaN`', opts, function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array( [] ); + mask = new Uint8Array( [] ); + + v = smskmin( [ vector( 'float32', x, 0, 1, 0 ), vector( 'uint8', mask, 0, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an ndarray containing a single element, the function returns the first element', opts, function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); + + v = smskmin( [ vector( 'float32', x, 1, 1, 0 ), vector( 'uint8', mask, 1, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', opts, function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + 5.0, // 4 + 6.0 + ]); + mask = new Uint8Array([ + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]); + + v = smskmin( [ vector( 'float32', x, 5, 2, 0 ), vector( 'uint8', mask, 5, 2, 0 ) ] ); + t.strictEqual( v, -2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', opts, function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array([ + 5.0, // 4 + 6.0, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + mask = new Uint8Array([ + 1, // 4 + 1, + 0, // 3 + 0, + 0, // 2 + 0, + 0, // 1 + 0, + 0, // 0 + 0 + ]); + + v = smskmin( [ vector( 'float32', x, 5, -2, 8 ), vector( 'uint8', mask, 5, -2, 8 ) ] ); + t.strictEqual( v, -2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', opts, function test( t ) { + var mask; + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 5.0, + 6.0 // 4 + ]); + mask = new Uint8Array([ + 0, + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 1, + 1 // 4 + ]); + + v = smskmin( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); + t.strictEqual( v, -2.0, 'returns expected value' ); + + t.end(); +}); From 1c6faed30245cb37f5cdc9e3c956c5144809d549 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Wed, 26 Aug 2026 03:10:43 +0530 Subject: [PATCH 02/10] chore(stats/base/ndarray/smskmin): fix lint and format issues for native bindings Signed-off-by: Aryan Sharma --- .../smskmin/benchmark/benchmark.native.js | 19 ++++++------ .../stats/base/ndarray/smskmin/src/addon.c | 31 +++++++++++++++---- .../base/ndarray/smskmin/test/test.native.js | 13 ++++---- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js index 435b7111090e..948b608bc66a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. @@ -20,17 +20,18 @@ // MODULES // -var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/uniform' ); -var bernoulli = require( '@stdlib/random/bernoulli' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var format = require( '@stdlib/string/format' ); -var pkg = require( './../package.json' ).name; var tryRequire = require( '@stdlib/utils/try-require' ); +var bernoulli = require( '@stdlib/random/bernoulli' ); var resolve = require( 'path' ).resolve; var smskmin = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var uniform = require( '@stdlib/random/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var bench = require( '@stdlib/bench' ); var opts = { 'skip': ( smskmin instanceof Error ) }; +var pkg = require( './../package.json' ).name; +var pow = require( '@stdlib/math/base/special/pow' ); + // VARIABLES // @@ -109,7 +110,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( format( '%s:len=%d', pkg, len ), f ); + bench( format( '%s::native:len=%d', pkg, len ), opts, f ); } } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/addon.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/addon.c index beb67c70b19e..ddfccad15d30 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/addon.c @@ -17,11 +17,13 @@ */ #include "stdlib/stats/base/ndarray/smskmin.h" +#include "stdlib/ndarray/ctor.h" #include "stdlib/ndarray/base/napi/addon_arguments.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/create_double.h" #include +#include /** * Receives JavaScript callback invocation data. @@ -31,15 +33,32 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - struct ndarray *arrays[ 2 ]; - napi_value v; - napi_status status; + STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - status = stdlib_ndarray_napi_addon_arguments( env, info, arrays, 2, "smskmin" ); - if ( status != napi_ok ) { + // Process provided arguments: + struct ndarray *arrays[ 2 ]; + napi_value err; + napi_status status = stdlib_ndarray_napi_addon_arguments( env, argv, 4, 2, arrays, &err ); + assert( status == napi_ok ); + if ( err != NULL ) { + status = napi_throw( env, err ); + assert( status == napi_ok ); return NULL; } - STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_stats_smskmin( (const struct ndarray **)arrays ), v ); + // Create a const-qualified view of the argument pointer list: + const struct ndarray *arr[ 2 ] = { + arrays[ 0 ], + arrays[ 1 ] + }; + // Perform computation: + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_stats_smskmin( arr ), v ); + + // Free allocated memory: + stdlib_ndarray_free( arrays[ 0 ] ); + arrays[ 0 ] = NULL; + stdlib_ndarray_free( arrays[ 1 ] ); + arrays[ 1 ] = NULL; + return v; } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js index ecf52ce53905..32487e14859b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. @@ -20,17 +20,18 @@ // MODULES // -var tape = require( 'tape' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); var Uint8Array = require( '@stdlib/array/uint8' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var isError = require( '@stdlib/assert/is-error' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var resolve = require( 'path' ).resolve; -var tryRequire = require( '@stdlib/utils/try-require' ); -var isError = require( '@stdlib/assert/is-error' ); var smskmin = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var opts = { 'skip': isError( smskmin ) }; +var tape = require( 'tape' ); + // FUNCTIONS // From daf85f7be2ecb4d86cd4de71142ce6d31b3cff15 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Wed, 26 Aug 2026 03:27:50 +0530 Subject: [PATCH 03/10] fix: resolve README sections, package.json ordering, and jsdoc verbs Signed-off-by: Aryan Sharma --- .../stats/base/ndarray/smskmin/README.md | 14 ++++++++++- .../ndarray/smskmin/docs/types/index.d.ts | 2 +- .../stats/base/ndarray/smskmin/lib/index.js | 4 ++-- .../stats/base/ndarray/smskmin/lib/main.js | 2 +- .../stats/base/ndarray/smskmin/lib/native.js | 2 +- .../stats/base/ndarray/smskmin/package.json | 24 +++++++++---------- .../base/ndarray/smskmin/test/test.main.js | 2 +- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md index 55507fe2429d..05f49f7c041b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md @@ -119,9 +119,21 @@ console.log( v ); +
+ ## C APIs - + + +
+ +
+ + + + + +
### Usage diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts index 51bf8ebfad87..5b6b4298d0d3 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { float32ndarray, uint8ndarray } from '@stdlib/types/ndarray'; /** -* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* Compute the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * ## Notes * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js index beabadbbc94e..9d432adb379a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. @@ -19,7 +19,7 @@ 'use strict'; /** -* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* Compute the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * @module @stdlib/stats/base/ndarray/smskmin * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js index 569acf5696d8..166e0c70c3e4 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js @@ -30,7 +30,7 @@ var strided = require( '@stdlib/stats/strided/smskmin' ).ndarray; // MAIN // /** -* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* Compute the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * ## Notes * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js index a39944f7bc15..4da0bebcd910 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js @@ -28,7 +28,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* Compute the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * ## Notes * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json index 2333b0419ab6..1f83186c475d 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json @@ -14,15 +14,6 @@ } ], "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test", - "src": "./src", - "include": "./include" - }, "types": "./docs/types", "scripts": {}, "homepage": "https://github.com/stdlib-js/stdlib", @@ -65,7 +56,16 @@ "single-precision", "ndarray" ], - "__stdlib__": {}, + "browser": "./lib/main.js", "gypfile": true, - "browser": "./lib/main.js" -} + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "__stdlib__": {} +}\n \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.main.js index 126d348ae6c3..98c9e14907dc 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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 2939f46ce86de3a519d2a558fe7028d649ab1830 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Wed, 26 Aug 2026 03:34:54 +0530 Subject: [PATCH 04/10] fix: resolve package.json json parsing and readme sections Signed-off-by: Aryan Sharma --- .../@stdlib/stats/base/ndarray/smskmin/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json index 1f83186c475d..368e0b523499 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json @@ -68,4 +68,4 @@ "test": "./test" }, "__stdlib__": {} -}\n \ No newline at end of file +} From 745b87952d3f4c84b103f31ba13e7683313e8684 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Wed, 26 Aug 2026 03:44:01 +0530 Subject: [PATCH 05/10] fix: resolve test.native.js linting errors Signed-off-by: Aryan Sharma --- .../base/ndarray/smskmin/test/test.native.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js index 32487e14859b..7724a945d42b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.native.js @@ -20,19 +20,24 @@ // MODULES // -var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); -var tryRequire = require( '@stdlib/utils/try-require' ); var Uint8Array = require( '@stdlib/array/uint8' ); var isError = require( '@stdlib/assert/is-error' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var resolve = require( 'path' ).resolve; -var smskmin = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var opts = { 'skip': isError( smskmin ) }; -var tape = require( 'tape' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +// VARIABLES // + +var smskmin = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': isError( smskmin ) +}; + // FUNCTIONS // From 84391579747876107507a0a62be6dc91e76ad319 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Wed, 26 Aug 2026 03:54:48 +0530 Subject: [PATCH 06/10] fix: resolve benchmark lint errors and package.json field order Signed-off-by: Aryan Sharma --- .../smskmin/benchmark/benchmark.native.js | 18 ++++++++------- .../stats/base/ndarray/smskmin/package.json | 22 +++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js index 948b608bc66a..4037bb7ff028 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.native.js @@ -20,22 +20,24 @@ // MODULES // -var tryRequire = require( '@stdlib/utils/try-require' ); -var bernoulli = require( '@stdlib/random/bernoulli' ); var resolve = require( 'path' ).resolve; -var smskmin = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var bench = require( '@stdlib/bench' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var bernoulli = require( '@stdlib/random/bernoulli' ); var uniform = require( '@stdlib/random/uniform' ); var format = require( '@stdlib/string/format' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var bench = require( '@stdlib/bench' ); -var opts = { 'skip': ( smskmin instanceof Error ) }; +var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; -var pow = require( '@stdlib/math/base/special/pow' ); - // VARIABLES // +var smskmin = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( smskmin instanceof Error ) +}; + var xoptions = { 'dtype': 'float32' }; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json index 368e0b523499..e25937ad5b6d 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json @@ -14,6 +14,17 @@ } ], "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, "types": "./docs/types", "scripts": {}, "homepage": "https://github.com/stdlib-js/stdlib", @@ -56,16 +67,5 @@ "single-precision", "ndarray" ], - "browser": "./lib/main.js", - "gypfile": true, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, "__stdlib__": {} } From e35a621c48bb44565eab4f321d916e9bc61c492d Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sat, 29 Aug 2026 20:10:16 +0530 Subject: [PATCH 07/10] Applied code suggestions from review Signed-off-by: Aryan Sharma --- .../stats/base/ndarray/smskmin/README.md | 149 +++++++++++------- .../base/ndarray/smskmin/benchmark/c/Makefile | 146 +++++++++++++++++ .../{benchmark.c => c/benchmark.length.c} | 111 +++++++++---- .../ndarray/smskmin/docs/types/index.d.ts | 2 +- .../base/ndarray/smskmin/examples/c/Makefile | 146 +++++++++++++++++ .../base/ndarray/smskmin/examples/c/example.c | 84 ++++++++++ .../stats/base/ndarray/smskmin/lib/index.js | 4 +- .../stats/base/ndarray/smskmin/lib/main.js | 2 +- .../stats/base/ndarray/smskmin/lib/native.js | 10 +- .../stats/base/ndarray/smskmin/src/main.c | 11 +- 10 files changed, 565 insertions(+), 100 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/Makefile rename lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/{benchmark.c => c/benchmark.length.c} (54%) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/c/example.c diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md index 05f49f7c041b..29bc5b008a0c 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md @@ -103,21 +103,9 @@ console.log( v ); - - - - - - - - - + - +* * *
@@ -143,43 +131,46 @@ console.log( v ); #### stdlib_stats_smskmin( arrays ) -Computes the minimum value of a single-precision floating-point ndarray according to a mask. +Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. ```c #include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" #include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" #include -// Define arrays: -float x[] = { 1.0f, -2.0f, 4.0f, 2.0f }; -uint8_t mask[] = { 0, 0, 1, 0 }; - -// Define ndarray meta data: +// Create an ndarray: +const float data[] = { 1.0f, -2.0f, 4.0f, 2.0f }; int64_t shape[] = { 4 }; -int64_t stridesX[] = { 1 }; -int64_t stridesMask[] = { 1 }; -int64_t offset = 0; +int64_t strides[] = { STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); -// Allocate ndarrays: -struct ndarray *arrX = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, x, 1, shape, stridesX, offset, STDLIB_NDARRAY_ROW_MAJOR ); -struct ndarray *arrMask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mask, 1, shape, stridesMask, offset, STDLIB_NDARRAY_ROW_MAJOR ); +// Create a mask ndarray: +const uint8_t mdata[] = { 0, 0, 1, 0 }; +int64_t mstrides[] = { STDLIB_NDARRAY_UINT8_BYTES_PER_ELEMENT }; -// Set up arguments: -const struct ndarray *arrays[] = { arrX, arrMask }; +struct ndarray *mask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mdata, 1, shape, mstrides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); -// Compute the masked minimum: +// Compute the minimum value: +const struct ndarray *arrays[] = { x, mask }; float v = stdlib_stats_smskmin( arrays ); +// returns -2.0f // Free allocated memory: -stdlib_ndarray_free( arrX ); -stdlib_ndarray_free( arrMask ); +stdlib_ndarray_free( x ); +stdlib_ndarray_free( mask ); ``` The function accepts the following arguments: -- **arrays**: `[in] struct ndarray**` array containing an input ndarray and a mask ndarray. +- **arrays**: `[in] struct ndarray**` list containing the following ndarrays: + + - `[in] struct ndarray*` a one-dimensional input ndarray. + - `[in] struct ndarray*` a one-dimensional mask ndarray. ```c float stdlib_stats_smskmin( const struct ndarray *arrays[] ); @@ -189,7 +180,7 @@ float stdlib_stats_smskmin( const struct ndarray *arrays[] ); - +
@@ -206,40 +197,68 @@ float stdlib_stats_smskmin( const struct ndarray *arrays[] ); ```c #include "stdlib/stats/base/ndarray/smskmin.h" #include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/index_modes.h" #include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" #include +#include #include int main( void ) { - // Define arrays: - float x[] = { 1.0f, -2.0f, 4.0f, 2.0f }; - uint8_t mask[] = { 0, 0, 1, 0 }; + // Create a data buffer: + const float data[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 4 }; + + // Specify the array strides: + int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; + + // Specify the byte offset: + const int64_t offset = 0; - // Define ndarray meta data: - int64_t shape[] = { 4 }; - int64_t stridesX[] = { 1 }; - int64_t stridesMask[] = { 1 }; - int64_t offset = 0; + // Specify the array order: + const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; - // Allocate ndarrays: - struct ndarray *arrX = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, x, 1, shape, stridesX, offset, STDLIB_NDARRAY_ROW_MAJOR ); - struct ndarray *arrMask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mask, 1, shape, stridesMask, offset, STDLIB_NDARRAY_ROW_MAJOR ); + // Specify the index mode: + const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; - // Set up arguments: - const struct ndarray *arrays[] = { arrX, arrMask }; + // Specify the subscript index modes: + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + const int64_t nsubmodes = 1; - // Compute the masked minimum: - float v = stdlib_stats_smskmin( arrays ); + // Create an ndarray: + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( x == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } - printf( "smskmin = %f\n", v ); + // Create a mask ndarray: + const uint8_t mdata[] = { 0, 0, 1, 0 }; + int64_t mstrides[] = { STDLIB_NDARRAY_UINT8_BYTES_PER_ELEMENT }; + struct ndarray *mask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mdata, ndims, shape, mstrides, offset, order, imode, nsubmodes, submodes ); + if ( mask == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } - // Free allocated memory: - stdlib_ndarray_free( arrX ); - stdlib_ndarray_free( arrMask ); + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, mask }; - return 0; + // Compute the minimum value: + float v = stdlib_stats_smskmin( arrays ); + + // Print the result: + printf( "min: %f\n", v ); + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( mask ); } ``` @@ -250,3 +269,19 @@ int main( void ) {
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c similarity index 54% rename from lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.c rename to lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c index 864055487340..518fe59aae7e 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c @@ -17,14 +17,24 @@ */ #include "stdlib/stats/base/ndarray/smskmin.h" -#include "stdlib/ndarray/base/bytes_per_element.h" #include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include #include #include -#include #include +#include #include +#define NAME "smskmin" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + /** * Prints the TAP version. */ @@ -40,7 +50,7 @@ static void print_version( void ) { */ static void print_summary( int total, int passing ) { printf( "#\n" ); - printf( "1..%d\n", total ); + printf( "1..%d\n", total ); // TAP plan printf( "# total %d\n", total ); printf( "# pass %d\n", passing ); printf( "#\n" ); @@ -57,15 +67,15 @@ static void print_results( int iterations, double elapsed ) { double rate = (double)iterations / elapsed; printf( " ---\n" ); printf( " iterations: %d\n", iterations ); - printf( " elapsed: %g\n", elapsed ); - printf( " rate: %g\n", rate ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); printf( " ...\n" ); } /** * Returns a clock time. * -* @return time +* @return clock time */ static double tic( void ) { struct timeval now; @@ -78,7 +88,7 @@ static double tic( void ) { * * @return random number */ -static float rand_double( void ) { +static float rand_float( void ) { int r = rand(); return (float)r / ( (float)RAND_MAX + 1.0f ); } @@ -86,32 +96,51 @@ static float rand_double( void ) { /** * Runs a benchmark. * -* @return elapsed time in seconds +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds */ -static double benchmark( void ) { +static double benchmark( int iterations, int len ) { + enum STDLIB_NDARRAY_INDEX_MODE imode; + const struct ndarray *arrays[ 2 ]; + enum STDLIB_NDARRAY_ORDER order; + struct ndarray *mask; + int8_t submodes[ 1 ]; + int64_t strides[ 1 ]; + int64_t shape[ 1 ]; + int64_t nsubmodes; + struct ndarray *x; + int64_t offset; double elapsed; + uint8_t *mdata; + int64_t ndims; + float *xdata; + float v; double t; - float x[ 100 ]; - uint8_t mask[ 100 ]; int i; - for ( i = 0; i < 100; i++ ) { - x[ i ] = ( rand_double() * 100.0f ) - 50.0f; - mask[ i ] = ( rand_double() < 0.2 ) ? 1 : 0; + ndims = 1; + shape[ 0 ] = len; + strides[ 0 ] = STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT; + offset = 0; + order = STDLIB_NDARRAY_ROW_MAJOR; + imode = STDLIB_NDARRAY_INDEX_ERROR; + submodes[ 0 ] = imode; + nsubmodes = 1; + + xdata = (float *) malloc( len * sizeof( float ) ); + mdata = (uint8_t *) malloc( len * sizeof( uint8_t ) ); + for( i = 0; i < len; i++ ) { + xdata[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + mdata[ i ] = 0; } + // cppcheck-suppress invalidPointerCast + x = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mdata, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); - int64_t shape[] = { 100 }; - int64_t stridesX[] = { 1 }; - int64_t stridesMask[] = { 1 }; - int64_t offset = 0; - - struct ndarray *arrX = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, x, 1, shape, stridesX, offset, STDLIB_NDARRAY_ROW_MAJOR ); - struct ndarray *arrMask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mask, 1, shape, stridesMask, offset, STDLIB_NDARRAY_ROW_MAJOR ); + arrays[ 0 ] = x; + arrays[ 1 ] = mask; - const struct ndarray *arrays[] = { arrX, arrMask }; - - int iterations = 1000000; - float v; + v = 0.0f; t = tic(); for ( i = 0; i < iterations; i++ ) { @@ -129,6 +158,13 @@ static double benchmark( void ) { stdlib_ndarray_free( arrMask ); print_results( iterations, elapsed ); + stdlib_ndarray_free( x ); + stdlib_ndarray_free( mask ); + free( xdata ); + free( mdata ); + arrays[ 0 ] = NULL; + arrays[ 1 ] = NULL; + return elapsed; } @@ -138,13 +174,26 @@ static double benchmark( void ) { int main( void ) { double elapsed; int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); - count = 0; print_version(); - printf( "# c::%s\n", "smskmin" ); - elapsed = benchmark(); - print_results( 1000000, elapsed ); - printf( "ok %d benchmark finished\n", ++count ); + count = 0; + 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:len=%d\n", NAME, len ); + elapsed = benchmark( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } print_summary( count, count ); - return 0; } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts index 5b6b4298d0d3..51bf8ebfad87 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { float32ndarray, uint8ndarray } from '@stdlib/types/ndarray'; /** -* Compute the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * ## Notes * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/c/example.c new file mode 100644 index 000000000000..3ea10e226a04 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/c/example.c @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/ndarray/smskmin.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include +#include +#include + +int main( void ) { + // Create a data buffer: + const float data[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 4 }; + + // Specify the array strides: + int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; + + // Specify the byte offset: + const int64_t offset = 0; + + // Specify the array order: + const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; + + // Specify the index mode: + const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; + + // Specify the subscript index modes: + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + const int64_t nsubmodes = 1; + + // Create an ndarray: + // cppcheck-suppress invalidPointerCast + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( x == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Create a mask ndarray: + const uint8_t mdata[] = { 0, 0, 1, 0 }; + int64_t mstrides[] = { STDLIB_NDARRAY_UINT8_BYTES_PER_ELEMENT }; + struct ndarray *mask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mdata, ndims, shape, mstrides, offset, order, imode, nsubmodes, submodes ); + if ( mask == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, mask }; + + // Compute the minimum value: + float v = stdlib_stats_smskmin( arrays ); + + // Print the result: + printf( "min: %f\n", v ); + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( mask ); +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js index 9d432adb379a..a6d179599925 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 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. @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* Calculate the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * @module @stdlib/stats/base/ndarray/smskmin * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js index 166e0c70c3e4..569acf5696d8 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js @@ -30,7 +30,7 @@ var strided = require( '@stdlib/stats/strided/smskmin' ).ndarray; // MAIN // /** -* Compute the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * ## Notes * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js index 4da0bebcd910..b2fc69cd534e 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js @@ -28,7 +28,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Compute the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * ## Notes * @@ -37,6 +37,7 @@ var addon = require( './../src/addon.node' ); * - a one-dimensional input ndarray. * - a one-dimensional mask ndarray. * +* @private * @param {ArrayLikeObject} arrays - array-like object containing ndarrays * @returns {number} minimum value * @@ -51,11 +52,8 @@ var addon = require( './../src/addon.node' ); * // returns -2.0 */ function smskmin( arrays ) { - var mask; - var x; - - x = arrays[ 0 ]; - mask = arrays[ 1 ]; + var x = arrays[ 0 ]; + var mask = arrays[ 1 ]; return addon( getData( x ), serialize( x ), getData( mask ), serialize( mask ) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c index 0ec95da79018..89bd4da6cc6b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c @@ -23,9 +23,16 @@ #include /** -* Computes the minimum value of a single-precision floating-point ndarray according to a mask. +* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * -* @param arrays list containing an input ndarray and a mask ndarray +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional mask ndarray. +* +* @param arrays list containing ndarrays * @return minimum value */ float stdlib_stats_smskmin( const struct ndarray *arrays[] ) { From f5e3bf56f45c0e37211181842ab55836a4d8e294 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sat, 29 Aug 2026 20:22:22 +0530 Subject: [PATCH 08/10] fix: editor and linting errors Signed-off-by: Aryan Sharma --- .../ndarray/smskmin/benchmark/c/benchmark.length.c | 10 ++++++---- .../@stdlib/stats/base/ndarray/smskmin/lib/native.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c index 518fe59aae7e..a762babc5650 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c @@ -106,6 +106,7 @@ static double benchmark( int iterations, int len ) { enum STDLIB_NDARRAY_ORDER order; struct ndarray *mask; int8_t submodes[ 1 ]; + int64_t mstrides[ 1 ]; int64_t strides[ 1 ]; int64_t shape[ 1 ]; int64_t nsubmodes; @@ -135,7 +136,10 @@ static double benchmark( int iterations, int len ) { mdata[ i ] = 0; } // cppcheck-suppress invalidPointerCast - x = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mdata, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)xdata, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + + mstrides[ 0 ] = STDLIB_NDARRAY_UINT8_BYTES_PER_ELEMENT; + mask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, mdata, ndims, shape, mstrides, offset, order, imode, nsubmodes, submodes ); arrays[ 0 ] = x; arrays[ 1 ] = mask; @@ -154,8 +158,6 @@ static double benchmark( int iterations, int len ) { if ( v != v ) { printf( "should not return NaN\n" ); } - stdlib_ndarray_free( arrX ); - stdlib_ndarray_free( arrMask ); print_results( iterations, elapsed ); stdlib_ndarray_free( x ); @@ -164,7 +166,7 @@ static double benchmark( int iterations, int len ) { free( mdata ); arrays[ 0 ] = NULL; arrays[ 1 ] = NULL; - + return elapsed; } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js index b2fc69cd534e..ea9f7072d816 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/native.js @@ -52,8 +52,8 @@ var addon = require( './../src/addon.node' ); * // returns -2.0 */ function smskmin( arrays ) { - var x = arrays[ 0 ]; var mask = arrays[ 1 ]; + var x = arrays[ 0 ]; return addon( getData( x ), serialize( x ), getData( mask ), serialize( mask ) ); // eslint-disable-line max-len } From 2e336527e0fd5f6c2a426e389eb71c17be65073e Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sat, 29 Aug 2026 20:31:01 +0530 Subject: [PATCH 09/10] fix: trailing whitespace error Signed-off-by: Aryan Sharma --- lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c index 89bd4da6cc6b..b2e7f2d09b7c 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/src/main.c @@ -28,7 +28,7 @@ * ## Notes * * - The function expects the following ndarrays: -* +* * - a one-dimensional input ndarray. * - a one-dimensional mask ndarray. * From 41b87469ad69fbe43e7c9eb5547ecfb6c4c119d5 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sun, 30 Aug 2026 11:20:29 +0530 Subject: [PATCH 10/10] Apply batched suggestions from code review Co-authored-by: Ujjwal Verma Signed-off-by: Aryan Sharma --- .../stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c | 2 +- .../@stdlib/stats/base/ndarray/smskmin/test/test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c index a762babc5650..658a4b26c9ad 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/c/benchmark.length.c @@ -80,7 +80,7 @@ static void print_results( int iterations, double elapsed ) { static double tic( void ) { struct timeval now; gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; } /** diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js index 2578d2c1f2e2..4a4593170b41 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 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.