From 456053e706883cf2a2692f81f5e6090a345eb0ad Mon Sep 17 00:00:00 2001
From: Sahil Goyal <87982509+sahil20021008@users.noreply.github.com>
Date: Tue, 6 May 2025 21:47:36 +0000
Subject: [PATCH 1/4] feat: add C implementation of
stdlib/math/base/special/minn
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: passed
- task: lint_package_json
status: passed
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: passed
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: passed
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
.../@stdlib/math/base/special/minn/README.md | 96 ++++++++++
.../minn/benchmark/benchmark.native.js | 63 +++++++
.../base/special/minn/benchmark/c/benchmark.c | 10 +-
.../math/base/special/minn/binding.gyp | 170 ++++++++++++++++++
.../base/special/minn/examples/c/Makefile | 146 +++++++++++++++
.../base/special/minn/examples/c/example.c | 36 ++++
.../math/base/special/minn/include.gypi | 53 ++++++
.../include/stdlib/math/base/special/minn.h | 38 ++++
.../math/base/special/minn/lib/native.js | 66 +++++++
.../math/base/special/minn/manifest.json | 74 ++++++++
.../math/base/special/minn/package.json | 3 +
.../math/base/special/minn/src/Makefile | 70 ++++++++
.../math/base/special/minn/src/addon.c | 62 +++++++
.../@stdlib/math/base/special/minn/src/main.c | 73 ++++++++
.../base/special/minn/test/test.native.js | 140 +++++++++++++++
15 files changed, 1097 insertions(+), 3 deletions(-)
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/benchmark/benchmark.native.js
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/binding.gyp
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/examples/c/Makefile
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/examples/c/example.c
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/include.gypi
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/include/stdlib/math/base/special/minn.h
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/lib/native.js
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/manifest.json
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/src/Makefile
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/src/addon.c
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/src/main.c
create mode 100644 lib/node_modules/@stdlib/math/base/special/minn/test/test.native.js
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/README.md b/lib/node_modules/@stdlib/math/base/special/minn/README.md
index 459d61d55fe3..af35b33ce9d5 100644
--- a/lib/node_modules/@stdlib/math/base/special/minn/README.md
+++ b/lib/node_modules/@stdlib/math/base/special/minn/README.md
@@ -117,6 +117,102 @@ for ( i = 0; i < 100; i++ ) {
+
+
+* * *
+
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/math/base/special/minn.h"
+```
+
+#### stdlib_base_minn( count, values )
+
+Returns the minimum value.
+
+```c
+double vals1[] = {4.2};
+double v = stdlib_base_minn( 1, vals1 );
+// returns 4.2
+
+double vals2[] = {3.14, 4.2};
+v = stdlib_base_minn( 2, vals2 );
+// returns 3.14
+```
+
+The function accepts the following arguments:
+
+- **count**: `[in] int` input value.
+- **values**: `[in] doubles*` input value.
+
+```c
+float stdlib_base_minn( int count, const double* values );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/math/base/special/minn.h"
+#include
+#include
+
+int main( void ) {
+ double values[ 2 ];
+ double v;
+ int i;
+
+ for ( i = 0; i < 100; i++ ) {
+ values[0] = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0;
+ values[1] = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0;
+ v = stdlib_base_minn( 2, values );
+ printf( "x: %f, y: %f, minn(x, y): %f\n", values[0], values[1], v );
+ }
+
+ return 0;
+}
+```
+
+
+
+
+
+
+
+
+
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/minn/benchmark/benchmark.native.js
new file mode 100644
index 000000000000..d239e745ec05
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/minn/benchmark/benchmark.native.js
@@ -0,0 +1,63 @@
+/**
+* @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 resolve = require( 'path' ).resolve;
+var bench = require( '@stdlib/bench' );
+var uniform = require( '@stdlib/random/array/uniform' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var tryRequire = require( '@stdlib/utils/try-require' );
+var pkg = require( './../package.json' ).name;
+
+
+// VARIABLES //
+
+var minn = tryRequire( resolve( __dirname, './../lib/native.js' ) );
+var opts = {
+ 'skip': ( minn instanceof Error )
+};
+
+
+// MAIN //
+
+bench( pkg+'::native', opts, function benchmark( b ) {
+ var x;
+ var y;
+ var z;
+ var i;
+
+ x = uniform( 100, -500.0, 500.0 );
+ y = uniform( 100, -500.0, 500.0 );
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ z = minn( x[ i%x.length ], y[ i%y.length ] );
+ if ( isnan( z ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( z ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/benchmark.c
index 7cac1bab2c1b..6ba746abd917 100644
--- a/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/benchmark.c
+++ b/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/benchmark.c
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2018 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.
@@ -16,13 +16,14 @@
* limitations under the License.
*/
+#include "stdlib/math/base/special/minn.h"
#include
#include
#include
#include
#include
-#define NAME "min"
+#define NAME "minn"
#define ITERATIONS 1000000
#define REPEATS 3
@@ -92,6 +93,7 @@ static double benchmark( void ) {
double elapsed;
double x[ 100 ];
double y[ 100 ];
+ double v[ 2 ];
double z;
double t;
int i;
@@ -103,7 +105,9 @@ static double benchmark( void ) {
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
- z = fmin( x[ i%100 ], y[ i%100 ] );
+ v[ 0 ] = x[ i%100 ];
+ v[ 1 ] = y[ i%100 ];
+ z = stdlib_base_minn( 2, v );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/binding.gyp b/lib/node_modules/@stdlib/math/base/special/minn/binding.gyp
new file mode 100644
index 000000000000..68a1ca11d160
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/minn/binding.gyp
@@ -0,0 +1,170 @@
+# @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.
+
+# 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/math/base/special/minn/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/minn/examples/c/Makefile
new file mode 100644
index 000000000000..25ced822f96a
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/minn/examples/c/Makefile
@@ -0,0 +1,146 @@
+#/
+# @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.
+#/
+
+# 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/math/base/special/minn/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/minn/examples/c/example.c
new file mode 100644
index 000000000000..9ac673a2d032
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/minn/examples/c/example.c
@@ -0,0 +1,36 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "stdlib/math/base/special/minn.h"
+#include
+#include
+
+int main( void ) {
+ double values[ 2 ];
+ double v;
+ int i;
+
+ for ( i = 0; i < 100; i++ ) {
+ values[0] = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0;
+ values[1] = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0;
+ v = stdlib_base_minn( 2, values );
+ printf( "x: %f, y: %f, minn(x, y): %f\n", values[0], values[1], v );
+ }
+
+ return 0;
+}
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/include.gypi b/lib/node_modules/@stdlib/math/base/special/minn/include.gypi
new file mode 100644
index 000000000000..ecfaf82a3279
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/minn/include.gypi
@@ -0,0 +1,53 @@
+# @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.
+
+# 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': [
+ '
+
+/**
+* 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 ){
+ napi_status status;
+
+ // Parse arguments
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 2 );
+ STDLIB_NAPI_ARGV_INT32( env, x, argv, 0 ); // Number of elements
+
+ // Parse Float64Array
+ STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, values, values_length, argv, 1 );
+
+ // Sanity check: x must not differ from values_length
+ if (x < 0 || ( int64_t )x != values_length) {
+ napi_throw_range_error( env, NULL, "Invalid array length" );
+ return NULL;
+ }
+
+ // Call the C function
+ double out = stdlib_base_minn( x, values );
+
+ // Return the result as a JavaScript number
+ napi_value result;
+ status = napi_create_double( env, out, &result );
+ if ( status != napi_ok ) {
+ return NULL;
+ }
+
+ return result;
+}
+
+STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/src/main.c b/lib/node_modules/@stdlib/math/base/special/minn/src/main.c
new file mode 100644
index 000000000000..0f7004687e63
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/minn/src/main.c
@@ -0,0 +1,73 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "stdlib/math/base/special/minn.h"
+#include "stdlib/math/base/assert/is_nan.h"
+#include "stdlib/constants/float64/ninf.h"
+#include "stdlib/constants/float64/pinf.h"
+#include "stdlib/math/base/assert/is_negative_zero.h"
+#include
+
+/**
+* Returns the minimum value.
+*
+* @param count number of elements
+* @param values pointer to array of doubles
+* @returns minimum value
+*
+* @example
+* double vals[] = {4.2};
+* double v = stdlib_base_minn( 1, vals );
+* // returns 4.2
+*
+* @example
+* double vals[] = {3.14, 4.2};
+* double v = stdlib_base_minn( 2, vals );
+* // returns 3.14
+*
+* @example
+* double vals[] = {NaN};
+* double v = stdlib_base_minn( 1, vals );
+* // returns NaN
+*
+* @example
+* double vals[] = {-0.0};
+* double v = stdlib_base_minn( 1, vals );
+* // returns -0.0
+*/
+double stdlib_base_minn(int count, const double* values ) {
+ if ( count <= 0 || values == NULL) {
+ return STDLIB_CONSTANT_FLOAT64_PINF;
+ }
+
+ double m = STDLIB_CONSTANT_FLOAT64_PINF;
+
+ for ( int i = 0; i < count; i++ ) {
+ double val = values[ i ];
+ if ( stdlib_base_is_nan( val ) || val == STDLIB_CONSTANT_FLOAT64_NINF ) {
+ return val;
+ }
+ if ( val < m ) {
+ m = val;
+ } else if ( val == m && val == 0.0 && stdlib_base_is_negative_zero( val ) ) {
+ // cppcheck-suppress redundantAssignment
+ m = val;
+ }
+ }
+ return m;
+}
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/minn/test/test.native.js
new file mode 100644
index 000000000000..be1d7dc17d45
--- /dev/null
+++ b/lib/node_modules/@stdlib/math/base/special/minn/test/test.native.js
@@ -0,0 +1,140 @@
+/**
+* @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 resolve = require( 'path' ).resolve;
+var tape = require( 'tape' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
+var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
+var PINF = require( '@stdlib/constants/float64/pinf' );
+var NINF = require( '@stdlib/constants/float64/ninf' );
+var tryRequire = require( '@stdlib/utils/try-require' );
+
+
+// VARIABLES //
+
+var minn = tryRequire( resolve( __dirname, './../lib/native.js' ) );
+var opts = {
+ 'skip': ( minn instanceof Error )
+};
+
+
+// TESTS //
+
+tape( 'main export is a function', opts, function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof minn, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) {
+ var v;
+
+ v = minn( NaN, 3.14 );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ v = minn( 3.14, NaN );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ v = minn( NaN );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ v = minn( 3.14, 4.2, NaN );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns `-Infinity` if provided `-Infinity`', opts, function test( t ) {
+ var v;
+
+ v = minn( NINF, 3.14 );
+ t.strictEqual( v, NINF, 'returns expected value' );
+
+ v = minn( 3.14, NINF );
+ t.strictEqual( v, NINF, 'returns expected value' );
+
+ v = minn( NINF );
+ t.strictEqual( v, NINF, 'returns expected value' );
+
+ v = minn( 3.14, 4.2, NINF );
+ t.strictEqual( v, NINF, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns `+infinity` if not provided any arguments', opts, function test( t ) {
+ var v = minn();
+ t.strictEqual( v, PINF, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns a correctly signed zero', opts, function test( t ) {
+ var v;
+
+ v = minn( +0.0, -0.0 );
+ t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
+
+ v = minn( -0.0, +0.0 );
+ t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
+
+ v = minn( -0.0, -0.0 );
+ t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
+
+ v = minn( +0.0, +0.0 );
+ t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
+
+ v = minn( -0.0 );
+ t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
+
+ v = minn( +0.0 );
+ t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
+
+ v = minn( +0.0, -0.0, +0.0 );
+ t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns the minimum value', opts, function test( t ) {
+ var v;
+
+ v = minn( 4.2, 3.14 );
+ t.strictEqual( v, 3.14, 'returns expected value' );
+
+ v = minn( -4.2, 3.14 );
+ t.strictEqual( v, -4.2, 'returns expected value' );
+
+ v = minn( 3.14 );
+ t.strictEqual( v, 3.14, 'returns expected value' );
+
+ v = minn( PINF );
+ t.strictEqual( v, PINF, 'returns expected value' );
+
+ v = minn( 4.2, 3.14, -1.0 );
+ t.strictEqual( v, -1.0, 'returns expected value' );
+
+ v = minn( 4.2, 3.14, -1.0, -3.14 );
+ t.strictEqual( v, -3.14, 'returns expected value' );
+
+ t.end();
+});
From e6d9266126499f3ae339c5f888cd7bee96f10099 Mon Sep 17 00:00:00 2001
From: Sahil Goyal <87982509+sahil20021008@users.noreply.github.com>
Date: Tue, 6 May 2025 21:55:30 +0000
Subject: [PATCH 2/4] feat: add C implementation of
stdlib/math/base/special/minn
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
.../@stdlib/math/base/special/minn/manifest.json | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/manifest.json b/lib/node_modules/@stdlib/math/base/special/minn/manifest.json
index 15a7bb8c1f32..cd1d6cd420f2 100644
--- a/lib/node_modules/@stdlib/math/base/special/minn/manifest.json
+++ b/lib/node_modules/@stdlib/math/base/special/minn/manifest.json
@@ -56,7 +56,12 @@
],
"libraries": [],
"libpath": [],
- "dependencies": []
+ "dependencies": [
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/assert/is-negative-zero",
+ "@stdlib/constants/float64/ninf",
+ "@stdlib/constants/float64/pinf"
+ ]
},
{
"task": "examples",
@@ -68,7 +73,12 @@
],
"libraries": [],
"libpath": [],
- "dependencies": []
+ "dependencies": [
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/assert/is-negative-zero",
+ "@stdlib/constants/float64/ninf",
+ "@stdlib/constants/float64/pinf"
+ ]
}
]
}
From 9cbb6064ae6643a6b2c16f0cd28fcf1d23f615cf Mon Sep 17 00:00:00 2001
From: Sahil Goyal <87982509+sahil20021008@users.noreply.github.com>
Date: Tue, 6 May 2025 22:01:04 +0000
Subject: [PATCH 3/4] feat: add C implementation of
stdlib/math/base/special/minn
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: passed
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
.../@stdlib/math/base/special/minn/README.md | 2 +-
.../base/special/minn/benchmark/c/Makefile | 43 +++++++++++++------
2 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/README.md b/lib/node_modules/@stdlib/math/base/special/minn/README.md
index af35b33ce9d5..589e8de6990e 100644
--- a/lib/node_modules/@stdlib/math/base/special/minn/README.md
+++ b/lib/node_modules/@stdlib/math/base/special/minn/README.md
@@ -2,7 +2,7 @@
@license Apache-2.0
-Copyright (c) 2018 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.
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/Makefile
index e64c0050f3da..25ced822f96a 100644
--- a/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/Makefile
+++ b/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/Makefile
@@ -1,7 +1,7 @@
#/
# @license Apache-2.0
#
-# Copyright (c) 2018 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.
@@ -16,7 +16,6 @@
# limitations under the License.
#/
-
# VARIABLES #
ifndef VERBOSE
@@ -70,18 +69,34 @@ 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.out
+c_targets := example.out
# RULES #
#/
-# Compiles C source files.
+# Compiles source files.
#
-# @param {string} [C_COMPILER] - C compiler
-# @param {string} [CFLAGS] - C compiler flags
-# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code
+# @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
@@ -97,15 +112,19 @@ all: $(c_targets)
# Compiles C source files.
#
# @private
-# @param {string} CC - C compiler
-# @param {string} CFLAGS - C compiler flags
-# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
+# @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) -o $@ $< -lm
+ $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
#/
-# Runs compiled benchmarks.
+# Runs compiled examples.
#
# @example
# make run
From 24f511d98016f1473fcf52140cbcb4cc81ea9e2c Mon Sep 17 00:00:00 2001
From: Sahil Goyal <87982509+sahil20021008@users.noreply.github.com>
Date: Tue, 6 May 2025 22:06:07 +0000
Subject: [PATCH 4/4] feat: add C implementation of
stdlib/math/base/special/minn
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
.../@stdlib/math/base/special/minn/benchmark/c/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/Makefile
index 25ced822f96a..87e582eafead 100644
--- a/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/Makefile
+++ b/lib/node_modules/@stdlib/math/base/special/minn/benchmark/c/Makefile
@@ -82,13 +82,13 @@ LIBRARIES ?=
LIBPATH ?=
# List of C targets:
-c_targets := example.out
+c_targets := benchmark.out
# RULES #
#/
-# Compiles source files.
+# Compiles C source files.
#
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
# @param {string} [CFLAGS] - C compiler options
@@ -124,7 +124,7 @@ $(c_targets): %.out: %.c
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
#/
-# Runs compiled examples.
+# Runs compiled benchmarks.
#
# @example
# make run