diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/binding.gyp b/lib/node_modules/@stdlib/math/base/special/heaviside/binding.gyp new file mode 100644 index 000000000000..6a161f876587 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/binding.gyp @@ -0,0 +1,166 @@ +# @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. + +{ + # 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/heaviside/include.gypi b/lib/node_modules/@stdlib/math/base/special/heaviside/include.gypi new file mode 100644 index 000000000000..ca7df2628e2c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/include.gypi @@ -0,0 +1,47 @@ +# @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. + +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' +*/ +function enumeration() { + return { + // Half-maximum: + 'half-maximum': 0, + + // Left-continuous: + 'left-continuous': 1, + + // Right-continuous: + 'right-continuous': 2, + + // Discontinuous: + 'discontinuous': 3 + }; +} + + +// EXPORTS // + +module.exports = enumeration; diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js index 9f6e92a627cb..e2678af8168a 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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. diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js new file mode 100644 index 000000000000..6b649b6686e3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js @@ -0,0 +1,72 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); +var str2enum = require( './str2enum.js' ); + + +// MAIN // + +/** +* Evaluates the Heaviside function. +* +* @private +* @param {number} x - input value +* @param {string} [continuity] - continuity option +* @returns {number} function value +* +* @example +* var v = heaviside( 3.14 ); +* // returns 1.0 +* +* @example +* var v = heaviside( -3.14 ); +* // returns 0.0 +* +* @example +* var v = heaviside( 0.0, 'half-maximum' ); +* // returns 0.5 +* +* @example +* var v = heaviside( 0.0, 'left-continuous' ); +* // returns 0.0 +* +* @example +* var v = heaviside( 0.0, 'right-continuous' ); +* // returns 1.0 +* +* @example +* var v = heaviside( 0.0, 'discontinuous' ); +* // returns NaN +* +* @example +* var v = heaviside( NaN, 'right-continuous' ); +* // returns NaN +*/ +function heaviside( x, continuity ) { + return addon( x, str2enum( continuity ) ); +} + + +// EXPORTS // + +module.exports = heaviside; diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js new file mode 100644 index 000000000000..3f297c824223 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/lib/str2enum.js @@ -0,0 +1,52 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var enumeration = require( './enum.js' ); + + +// VARIABLES // + +var ENUM = enumeration(); + + +// MAIN // + +/** +* Returns the enumeration constant associated with a function continuity type string. +* +* @private +* @param {string} ctype - function continuity type string +* @returns {(integer|null)} integer value or null +* +* @example +* var v = str2enum( 'left-continuous' ); +* // returns +*/ +function str2enum( ctype ) { + var v = ENUM[ ctype ]; + return ( typeof v === 'number' ) ? v : -1; // note: we include this guard to prevent walking the prototype chain +} + + +// EXPORTS // + +module.exports = str2enum; diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/manifest.json b/lib/node_modules/@stdlib/math/base/special/heaviside/manifest.json new file mode 100644 index 000000000000..fc10ca525d4b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/manifest.json @@ -0,0 +1,76 @@ +{ + "options": { + "task": "build" + }, + "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", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/create-double", + "@stdlib/math/base/assert/is-nan" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan" + ] + } + ] +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/package.json b/lib/node_modules/@stdlib/math/base/special/heaviside/package.json index dc806c9b66c1..26e70c2fcff7 100644 --- a/lib/node_modules/@stdlib/math/base/special/heaviside/package.json +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/package.json @@ -14,11 +14,14 @@ } ], "main": "./lib", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/src/Makefile b/lib/node_modules/@stdlib/math/base/special/heaviside/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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 + + +# 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/math/base/special/heaviside/src/addon.c b/lib/node_modules/@stdlib/math/base/special/heaviside/src/addon.c new file mode 100644 index 000000000000..4fc6623d4762 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/src/addon.c @@ -0,0 +1,42 @@ +/** +* @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/math/base/special/heaviside.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int32.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/create_double.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 2 ); + STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 ); + STDLIB_NAPI_ARGV_INT32( env, continuity, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_base_heaviside( x, (enum STDLIB_BASE_HEAVISIDE_CONTINUITY)continuity ), out ); + return out; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/src/main.c b/lib/node_modules/@stdlib/math/base/special/heaviside/src/main.c new file mode 100644 index 000000000000..4827d43530f3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/src/main.c @@ -0,0 +1,56 @@ +/** +* @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/math/base/special/heaviside.h" +#include "stdlib/math/base/assert/is_nan.h" + +/** +* Evaluates the Heaviside function for a double-precision floating-point number. +* +* @param x input value +* @param continuity continuity option +* @return function value +* +* @example +* double y = stdlib_base_heaviside( 0.0, STDLIB_BASE_HEAVISIDE_CONTINUITY_HALF_MAXIMUM ); +* // returns 0.5 +*/ +double stdlib_base_heaviside( const double x, const enum STDLIB_BASE_HEAVISIDE_CONTINUITY continuity ) { + if ( stdlib_base_is_nan( x ) ) { + return 0.0 / 0.0; // NaN + } + if ( x > 0.0 ) { + return 1.0; + } + // Handle `+-0`... + if ( x == 0.0 ) { + switch ( continuity ) { + case STDLIB_BASE_HEAVISIDE_CONTINUITY_HALF_MAXIMUM: + return 0.5; + case STDLIB_BASE_HEAVISIDE_CONTINUITY_LEFT_CONTINUOUS: + return 0.0; + case STDLIB_BASE_HEAVISIDE_CONTINUITY_RIGHT_CONTINUOUS: + return 1.0; + case STDLIB_BASE_HEAVISIDE_CONTINUITY_DISCONTINUOUS: + return 0.0 / 0.0; // NaN + default: + return 0.0 / 0.0; // NaN + } + } + return 0.0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js new file mode 100644 index 000000000000..f2539842ad3e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/heaviside/test/test.native.js @@ -0,0 +1,164 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +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 EPS = require( '@stdlib/constants/float64/eps' ); +var randu = require( '@stdlib/random/base/randu' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var heaviside = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': (heaviside instanceof Error) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof heaviside, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `0` if `x` is negative', opts, function test( t ) { + var x; + var v; + var i; + + for ( i = 0; i < 1e3; i++ ) { + x = -( randu() * 100.0 ) - EPS; + v = heaviside( x ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value when provided ' + x ); + } + t.end(); +}); + +tape( 'the function returns `1` if `x` is positive', opts, function test( t ) { + var x; + var v; + var i; + + for ( i = 0; i < 1e3; i++ ) { + x = ( randu() * 100.0 ) + EPS; + v = heaviside( x ); + t.strictEqual( v, 1.0, 'returns expected value when provided ' + x ); + } + t.end(); +}); + +tape( 'by default, the function returns `NaN` if provided `+-0`', opts, function test( t ) { + var v; + + v = heaviside( -0.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = heaviside( +0.0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `continuity` option is `discontinuous`, the function returns `NaN` if provided `+-0`', opts, function test( t ) { + var v; + + v = heaviside( -0.0, 'discontinuous' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = heaviside( +0.0, 'discontinuous' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `continuity` option is `half-maximum`, the function returns `0.5` if provided `+-0`', opts, function test( t ) { + var v; + + v = heaviside( -0.0, 'half-maximum' ); + t.strictEqual( v, 0.5, 'returns expected value' ); + + v = heaviside( +0.0, 'half-maximum' ); + t.strictEqual( v, 0.5, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `continuity` option is `left-continuous`, the function returns `0.0` if provided `+-0`', opts, function test( t ) { + var v; + + v = heaviside( -0.0, 'left-continuous' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + v = heaviside( +0.0, 'left-continuous' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `continuity` option is `right-continuous`, the function returns `1` if provided `+-0`', opts, function test( t ) { + var v; + + v = heaviside( -0.0, 'right-continuous' ); + t.strictEqual( v, 1, 'returns expected value' ); + + v = heaviside( +0.0, 'right-continuous' ); + t.strictEqual( v, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'if the `continuity` option is not valid, the function returns `NaN` if provided `+-0`', opts, function test( t ) { + var v; + + v = heaviside( -0.0, 'foo' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = heaviside( +0.0, 'bar' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { + var v = heaviside( NaN, 'left-continuous' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0` if provided `-infinity`', opts, function test( t ) { + var v = heaviside( NINF, 'left-continuous' ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `+1` if provided `+infinity`', opts, function test( t ) { + var v = heaviside( PINF, 'left-continuous' ); + t.strictEqual( v, 1.0, 'returns expected value' ); + t.end(); +});