From 82cc765c8de1d1add338792850f2794134e21cff Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sun, 18 Oct 2026 04:39:25 +0530 Subject: [PATCH 1/2] feat: add `math/base/special/silu` Signed-off-by: Aryan Sharma --- .../@stdlib/math/base/special/silu/README.md | 216 ++++++++++++++++++ .../base/special/silu/benchmark/benchmark.js | 52 +++++ .../silu/benchmark/benchmark.native.js | 62 +++++ .../special/silu/benchmark/c/native/Makefile | 146 ++++++++++++ .../silu/benchmark/c/native/benchmark.c | 136 +++++++++++ .../math/base/special/silu/binding.gyp | 170 ++++++++++++++ .../math/base/special/silu/docs/repl.txt | 29 +++ .../base/special/silu/docs/types/index.d.ts | 52 +++++ .../math/base/special/silu/docs/types/test.ts | 44 ++++ .../base/special/silu/examples/c/Makefile | 146 ++++++++++++ .../base/special/silu/examples/c/example.c | 31 +++ .../math/base/special/silu/examples/index.js | 30 +++ .../math/base/special/silu/include.gypi | 53 +++++ .../include/stdlib/math/base/special/silu.h | 38 +++ .../math/base/special/silu/lib/index.js | 52 +++++ .../math/base/special/silu/lib/main.js | 69 ++++++ .../math/base/special/silu/lib/native.js | 62 +++++ .../math/base/special/silu/manifest.json | 81 +++++++ .../math/base/special/silu/package.json | 144 ++++++++++++ .../math/base/special/silu/src/Makefile | 70 ++++++ .../math/base/special/silu/src/addon.c | 22 ++ .../@stdlib/math/base/special/silu/src/main.c | 43 ++++ .../silu/test/fixtures/python/runner.py | 71 ++++++ .../fixtures/python/silu_large_negative.json | 1 + .../fixtures/python/silu_large_positive.json | 1 + .../test/fixtures/python/silu_medium.json | 1 + .../test/fixtures/python/silu_near_zero.json | 1 + .../test/fixtures/python/silu_special.json | 1 + .../math/base/special/silu/test/test.js | 171 ++++++++++++++ .../base/special/silu/test/test.native.js | 180 +++++++++++++++ 30 files changed, 2175 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/include/stdlib/math/base/special/silu.h create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/runner.py create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_large_negative.json create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_large_positive.json create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_medium.json create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_near_zero.json create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_special.json create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/silu/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/silu/README.md b/lib/node_modules/@stdlib/math/base/special/silu/README.md new file mode 100644 index 000000000000..341e3329ef48 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/README.md @@ -0,0 +1,216 @@ + + +# silu + +> Evaluate the [sigmoid linear unit][silu] (SiLU). + +
+ +The [sigmoid linear unit][silu] (SiLU), also known as the Swish activation function, is defined as: + + + +```math +\mathrm{silu}(x) = x \cdot \sigma(x) = \frac{x}{1 + e^{-x}} +``` + + + +where $\sigma(x)$ is the [standard logistic function][@stdlib/math/base/special/expit]. + +
+ + + +
+ +## Usage + +```javascript +var silu = require( '@stdlib/math/base/special/silu' ); +``` + +#### silu( x ) + +Evaluates the Sigmoid Linear Unit (SiLU) activation function. + +```javascript +var v = silu( 0.0 ); +// returns 0.0 + +v = silu( 1.0 ); +// returns ~0.7311 + +v = silu( -Infinity ); +// returns -0.0 + +v = silu( Infinity ); +// returns Infinity + +v = silu( NaN ); +// returns NaN +``` + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var silu = require( '@stdlib/math/base/special/silu' ); + +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -5.0, 5.0, opts ); + +logEachMap( 'silu(%0.4f) = %0.4f', x, silu ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/silu.h" +``` + +#### stdlib_base_silu( x ) + +Evaluates the Sigmoid Linear Unit (SiLU) activation function. + +```c +double y = stdlib_base_silu( 0.0 ); +// returns 0.0 + +y = stdlib_base_silu( 1.0 ); +// returns ~0.7311 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. + +```c +double stdlib_base_silu( const double x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/silu.h" +#include + +int main( void ) { + const double x[] = { -5.0, -3.89, -2.78, -1.67, -0.56, 0.56, 1.67, 2.78, 3.89, 5.0 }; + + double v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_silu( x[ i ] ); + printf( "silu(%lf) = %lf\n", x[ i ], v ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/silu/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/silu/benchmark/benchmark.js new file mode 100644 index 000000000000..9d97787411bc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/benchmark/benchmark.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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var silu = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -10.0, 10.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = silu( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/silu/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/silu/benchmark/benchmark.native.js new file mode 100644 index 000000000000..8ead96fc23ba --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/benchmark/benchmark.native.js @@ -0,0 +1,62 @@ +/** +* @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 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var silu = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( silu instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -10.0, 10.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = silu( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/silu/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/silu/benchmark/c/native/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/benchmark/c/native/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.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/math/base/special/silu/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/silu/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..ee40051756ff --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/benchmark/c/native/benchmark.c @@ -0,0 +1,136 @@ +/** +* @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/silu.h" +#include +#include +#include +#include +#include + +#define NAME "silu" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* 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 ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock 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 double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double x[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_double()*20.0 ) - 10.0; + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_silu( x[ i % 100 ] ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::native::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i + 1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/binding.gyp b/lib/node_modules/@stdlib/math/base/special/silu/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/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/math/base/special/silu/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/silu/docs/repl.txt new file mode 100644 index 000000000000..0ced98f4d205 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( x ) + Evaluates the Sigmoid Linear Unit (SiLU) activation function. + + Parameters + ---------- + x: number + Input value. + + Returns + ------- + y: number + Function value. + + Examples + -------- + > var y = {{alias}}( 0.0 ) + 0.0 + > y = {{alias}}( 1.0 ) + ~0.7311 + > y = {{alias}}( -Infinity ) + -0.0 + > y = {{alias}}( Infinity ) + Infinity + > y = {{alias}}( NaN ) + NaN + + See Also + -------- diff --git a/lib/node_modules/@stdlib/math/base/special/silu/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/silu/docs/types/index.d.ts new file mode 100644 index 000000000000..c2635bdeada1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/** +* Evaluates the Sigmoid Linear Unit (SiLU) activation function. +* +* @param x - input value +* @returns function value +* +* @example +* var y = silu( 0.0 ); +* // returns 0.0 +* +* @example +* var y = silu( 1.0 ); +* // returns ~0.7311 +* +* @example +* var y = silu( -Infinity ); +* // returns -0.0 +* +* @example +* var y = silu( Infinity ); +* // returns Infinity +* +* @example +* var y = silu( NaN ); +* // returns NaN +*/ +declare function silu( x: number ): number; + + +// EXPORTS // + +export = silu; diff --git a/lib/node_modules/@stdlib/math/base/special/silu/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/silu/docs/types/test.ts new file mode 100644 index 000000000000..ff9ba9b179d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @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. +*/ + +import silu = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + silu( 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a number... +{ + silu( true ); // $ExpectError + silu( false ); // $ExpectError + silu( null ); // $ExpectError + silu( undefined ); // $ExpectError + silu( '5' ); // $ExpectError + silu( [] ); // $ExpectError + silu( {} ); // $ExpectError + silu( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + silu(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/silu/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/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/math/base/special/silu/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/silu/examples/c/example.c new file mode 100644 index 000000000000..6e0239588b6e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/examples/c/example.c @@ -0,0 +1,31 @@ +/** +* @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/silu.h" +#include + +int main( void ) { + const double x[] = { -5.0, -3.89, -2.78, -1.67, -0.56, 0.56, 1.67, 2.78, 3.89, 5.0 }; + + double v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_silu( x[ i ] ); + printf( "silu(%lf) = %lf\n", x[ i ], v ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/examples/index.js b/lib/node_modules/@stdlib/math/base/special/silu/examples/index.js new file mode 100644 index 000000000000..7f135adcede1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var silu = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 100, -5.0, 5.0, opts ); + +logEachMap( 'silu(%0.4f) = %0.4f', x, silu ); diff --git a/lib/node_modules/@stdlib/math/base/special/silu/include.gypi b/lib/node_modules/@stdlib/math/base/special/silu/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/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': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "silu", + "swish", + "activation", + "sigmoid", + "sigmoid linear unit", + "neural", + "deep learning" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "silu", + "alias": "silu", + "pkg_desc": "evaluate the Sigmoid Linear Unit (SiLU) for a double-precision floating-point number", + "desc": "evaluates the Sigmoid Linear Unit (SiLU) for a double-precision floating-point number", + "short_desc": "sigmoid linear unit", + "parameters": [ + { + "name": "x", + "desc": "input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/uniform", + "parameters": [ + -5, + 5 + ] + }, + "example_values": [ + 3.28, + -3.04, + -0.06, + -4.23, + 4.84, + 2.62, + -4.89, + -1.56, + 4.25, + 0.33, + -0.49, + 0.48, + 3.91, + -4.82, + -3.7, + 4.14, + -1.61, + 0.32, + 4.51, + -1.55 + ] + } + ], + "output_policy": "real_floating_point_and_generic", + "returns": { + "desc": "evaluated SiLU", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "double", + "dtype": "float64" + } + }, + "keywords": [ + "silu", + "swish", + "activation", + "sigmoid", + "neural", + "deep learning", + "sigmoid linear unit" + ], + "extra_keywords": [] + } + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/src/Makefile b/lib/node_modules/@stdlib/math/base/special/silu/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/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/math/base/special/silu/src/addon.c b/lib/node_modules/@stdlib/math/base/special/silu/src/addon.c new file mode 100644 index 000000000000..b8f2f896ded2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/src/addon.c @@ -0,0 +1,22 @@ +/** +* @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/silu.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_silu ) diff --git a/lib/node_modules/@stdlib/math/base/special/silu/src/main.c b/lib/node_modules/@stdlib/math/base/special/silu/src/main.c new file mode 100644 index 000000000000..cda4962dfbaf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/src/main.c @@ -0,0 +1,43 @@ +/** +* @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/silu.h" +#include "stdlib/math/base/special/expit.h" +#include "stdlib/constants/float64/nan.h" +#include "stdlib/constants/float64/ninf.h" +#include "stdlib/math/base/assert/is_nan.h" + +/** +* Evaluates the Sigmoid Linear Unit (SiLU) activation function. +* +* @param x input value +* @return function value +* +* @example +* double y = stdlib_base_silu( 0.0 ); +* // returns 0.0 +*/ +double stdlib_base_silu( const double x ) { + if ( stdlib_base_is_nan( x ) ) { + return STDLIB_CONSTANT_FLOAT64_NAN; + } + if ( x == STDLIB_CONSTANT_FLOAT64_NINF ) { + return -0.0; + } + return x * stdlib_base_expit( x ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/runner.py b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/runner.py new file mode 100644 index 000000000000..535c9ac2bd2b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/runner.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# @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. + +"""Generate fixtures.""" + +import os +import json +import numpy as np +from scipy.special import expit + +# Get the file path: +FILE = os.path.realpath(__file__) + +# Extract the directory in which this file resides: +DIR = os.path.dirname(FILE) + + +def gen(x, name): + """Generate fixture data and writes them to file. + + # Arguments + + * `x`: domain + * `name::str`: output filename + """ + x_arr = np.array(x, dtype=np.float64) + y_arr = x_arr * expit(x_arr) + data = { + "x": x_arr.tolist(), + "expected": y_arr.tolist() + } + filepath = os.path.join(DIR, name) + with open(filepath, "w", encoding="utf-8") as outfile: + json.dump(data, outfile) + + +def main(): + """Generate fixture data.""" + x = [round(float(v), 4) for v in np.linspace(-1.0, 1.0, 101)] + gen(x, "silu_near_zero.json") + + x = [round(float(v), 4) for v in np.linspace(-5.0, 5.0, 201)] + gen(x, "silu_medium.json") + + x = [round(float(v), 2) for v in np.linspace(5.0, 50.0, 91)] + gen(x, "silu_large_positive.json") + + x = [round(float(v), 2) for v in np.linspace(-35.0, -5.0, 121)] + gen(x, "silu_large_negative.json") + + x = [-50.0, -25.0, -22.0, -2.0, -1.0, 0.0, 1.0, 2.0, 10.0, 50.0] + gen(x, "silu_special.json") + + +if __name__ == "__main__": + main() diff --git a/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_large_negative.json b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_large_negative.json new file mode 100644 index 000000000000..16b060f2d28d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_large_negative.json @@ -0,0 +1 @@ +{"x": [-35.0, -34.75, -34.5, -34.25, -34.0, -33.75, -33.5, -33.25, -33.0, -32.75, -32.5, -32.25, -32.0, -31.75, -31.5, -31.25, -31.0, -30.75, -30.5, -30.25, -30.0, -29.75, -29.5, -29.25, -29.0, -28.75, -28.5, -28.25, -28.0, -27.75, -27.5, -27.25, -27.0, -26.75, -26.5, -26.25, -26.0, -25.75, -25.5, -25.25, -25.0, -24.75, -24.5, -24.25, -24.0, -23.75, -23.5, -23.25, -23.0, -22.75, -22.5, -22.25, -22.0, -21.75, -21.5, -21.25, -21.0, -20.75, -20.5, -20.25, -20.0, -19.75, -19.5, -19.25, -19.0, -18.75, -18.5, -18.25, -18.0, -17.75, -17.5, -17.25, -17.0, -16.75, -16.5, -16.25, -16.0, -15.75, -15.5, -15.25, -15.0, -14.75, -14.5, -14.25, -14.0, -13.75, -13.5, -13.25, -13.0, -12.75, -12.5, -12.25, -12.0, -11.75, -11.5, -11.25, -11.0, -10.75, -10.5, -10.25, -10.0, -9.75, -9.5, -9.25, -9.0, -8.75, -8.5, -8.25, -8.0, -7.75, -7.5, -7.25, -7.0, -6.75, -6.5, -6.25, -6.0, -5.75, -5.5, -5.25, -5.0], "expected": [-2.206790866051445e-14, -2.8133357358863766e-14, -3.586406140262262e-14, -4.571666807946785e-14, -5.827288667242834e-14, -7.427369209416846e-14, -9.466286911837271e-14, -1.206424439200638e-13, -1.5374324278841139e-13, -1.9591469932837252e-13, -2.4963915226906613e-13, -3.1807730100221645e-13, -4.052532975710085e-13, -5.162902566661491e-13, -6.577098921684554e-13, -8.378137086817911e-13, -1.067167903625656e-12, -1.3592201418696006e-12, -1.731083995952882e-12, -2.2045365389852963e-12, -2.8072868906517896e-12, -3.5745891552016767e-12, -4.5512930494153665e-12, -5.794450734292118e-12, -7.3766303773912e-12, -9.390127610510844e-12, -1.1952317626376691e-11, -1.5212456115146958e-11, -1.9360320299419183e-11, -2.4637186702703678e-11, -3.1349775958684035e-11, -3.988796450987263e-11, -5.074727804645987e-11, -6.455745414638267e-11, -8.21187071758739e-11, -1.0444776656531196e-10, -1.3283631472896776e-10, -1.689251543288516e-10, -2.1479832573714116e-10, -2.731025243185099e-10, -3.471985966192786e-10, -4.413537044687527e-10, -5.609850371703154e-10, -7.129688517555228e-10, -9.060322905927796e-10, -1.1512500676833804e-09, -1.46267398629229e-09, -1.8581306749632882e-09, -2.3602323150492304e-09, -2.9976569960517326e-09, -3.8067703252399764e-09, -4.833678854500725e-09, -6.136829802599786e-09, -7.79030174557563e-09, -9.88796905955495e-09, -1.2548770990345654e-08, -1.592337688654101e-08, -2.0202615629825177e-08, -2.5628133728889135e-08, -3.2505868065329306e-08, -4.122307236380407e-08, -5.226982923011911e-08, -6.626622225496353e-08, -8.399664800265004e-08, -1.0645313171677286e-07, -1.348899933481844e-07, -1.7089281716784222e-07, -2.164654401945023e-07, -2.741396312296863e-07, -3.4711333252130866e-07, -4.3942484122124277e-07, -5.561721942447564e-07, -7.037893830570362e-07, -8.903939827846585e-07, -1.1262244802236372e-06, -1.4241902108400256e-06, -1.80056259288152e-06, -2.2758435587671617e-06, -2.875856078470913e-06, -3.6331128773984807e-06, -4.5885334038843705e-06, -5.793596453938902e-06, -7.313037418921049e-06, -9.228225874420207e-06, -1.164139238729785e-05, -1.4680914463107021e-05, -1.8507922292580904e-05, -2.3324547576787934e-05, -2.9384215872746472e-05, -3.700447781144149e-05, -4.658299105233201e-05, -5.8617407562403956e-05, -7.373009522657661e-05, -9.269883538837914e-05, -0.0001164948962800501, -0.00014633019524785536, -0.000183715640329047, -0.00023053319552482498, -0.00028912475670312646, -0.0003624015701028792, -0.00045397868702434395, -0.0005683398401961019, -0.0007110391613508066, -0.0008889473433701341, -0.0011105511838760856, -0.0013863169171471018, -0.0017291293134692556, -0.0021548201325396854, -0.002682801043731825, -0.0033368173802657652, -0.004145839776926997, -0.0051451103934792635, -0.006377358360804518, -0.007894194289124724, -0.009757684668790446, -0.012042091645796723, -0.014835738939808645, -0.01824292634428984, -0.022385757437428704, -0.027405659891181586, -0.03346425462142428]} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_large_positive.json b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_large_positive.json new file mode 100644 index 000000000000..f71fcd9d8980 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_large_positive.json @@ -0,0 +1 @@ +{"x": [5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0, 14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0, 19.5, 20.0, 20.5, 21.0, 21.5, 22.0, 22.5, 23.0, 23.5, 24.0, 24.5, 25.0, 25.5, 26.0, 26.5, 27.0, 27.5, 28.0, 28.5, 29.0, 29.5, 30.0, 30.5, 31.0, 31.5, 32.0, 32.5, 33.0, 33.5, 34.0, 34.5, 35.0, 35.5, 36.0, 36.5, 37.0, 37.5, 38.0, 38.5, 39.0, 39.5, 40.0, 40.5, 41.0, 41.5, 42.0, 42.5, 43.0, 43.5, 44.0, 44.5, 45.0, 45.5, 46.0, 46.5, 47.0, 47.5, 48.0, 48.5, 49.0, 49.5, 50.0], "expected": [4.966535745378576, 5.477614242562572, 5.985164261060192, 6.490242315331209, 6.993622641639195, 7.495854160223073, 7.997317198956269, 8.49827087068653, 8.998889448816124, 9.49928896083865, 9.999546021312977, 10.499710875243295, 10.999816284359673, 11.499883505103721, 11.999926269904773, 12.499953417008948, 12.999970615784127, 13.499981492077707, 13.999988358607611, 14.499992686962582, 14.999995411466594, 15.49999712414392, 15.999998199437407, 16.49999887377552, 16.999999296210614, 17.49999956057516, 17.99999972586037, 18.499999829107182, 18.999999893546867, 19.499999933733775, 19.999999958776925, 20.499999974371867, 20.99999998407662, 21.499999990112034, 21.99999999386317, 22.49999999619323, 22.99999999763977, 23.499999998537323, 23.999999999093966, 24.49999999943902, 24.9999999996528, 25.499999999785203, 25.999999999867164, 26.49999999991788, 26.99999999994925, 27.49999999996865, 27.999999999980638, 28.499999999988045, 28.99999999999262, 29.49999999999545, 29.999999999997197, 30.499999999998266, 30.999999999998934, 31.499999999999343, 31.999999999999595, 32.499999999999744, 32.999999999999844, 33.4999999999999, 33.99999999999994, 34.499999999999964, 34.99999999999998, 35.499999999999986, 35.99999999999999, 36.49999999999999, 37.0, 37.5, 38.0, 38.5, 39.0, 39.5, 40.0, 40.5, 41.0, 41.5, 42.0, 42.5, 43.0, 43.5, 44.0, 44.5, 45.0, 45.5, 46.0, 46.5, 47.0, 47.5, 48.0, 48.5, 49.0, 49.5, 50.0]} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_medium.json b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_medium.json new file mode 100644 index 000000000000..7c517a164495 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_medium.json @@ -0,0 +1 @@ +{"x": [-5.0, -4.95, -4.9, -4.85, -4.8, -4.75, -4.7, -4.65, -4.6, -4.55, -4.5, -4.45, -4.4, -4.35, -4.3, -4.25, -4.2, -4.15, -4.1, -4.05, -4.0, -3.95, -3.9, -3.85, -3.8, -3.75, -3.7, -3.65, -3.6, -3.55, -3.5, -3.45, -3.4, -3.35, -3.3, -3.25, -3.2, -3.15, -3.1, -3.05, -3.0, -2.95, -2.9, -2.85, -2.8, -2.75, -2.7, -2.65, -2.6, -2.55, -2.5, -2.45, -2.4, -2.35, -2.3, -2.25, -2.2, -2.15, -2.1, -2.05, -2.0, -1.95, -1.9, -1.85, -1.8, -1.75, -1.7, -1.65, -1.6, -1.55, -1.5, -1.45, -1.4, -1.35, -1.3, -1.25, -1.2, -1.15, -1.1, -1.05, -1.0, -0.95, -0.9, -0.85, -0.8, -0.75, -0.7, -0.65, -0.6, -0.55, -0.5, -0.45, -0.4, -0.35, -0.3, -0.25, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2.0, 2.05, 2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7, 2.75, 2.8, 2.85, 2.9, 2.95, 3.0, 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4, 3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4.0, 4.05, 4.1, 4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75, 4.8, 4.85, 4.9, 4.95, 5.0], "expected": [-0.03346425462142428, -0.034816256417226035, -0.03621855258698165, -0.03767271487837277, -0.0391803415351675, -0.040743055715131926, -0.04236250366838477, -0.04404035265604941, -0.04577828858775989, -0.047578013355227225, -0.049441241837669306, -0.051369698553454184, -0.053365113930806646, -0.055429220168885476, -0.057563746658958546, -0.05977041493379327, -0.06205093311174684, -0.06440698980039689, -0.06684024742290787, -0.06935233492869733, -0.07194483984836622, -0.07461929965130423, -0.07737719236290228, -0.08021992639691963, -0.0831488295572958, -0.08616513716259605, -0.08926997924537602, -0.09246436677808181, -0.09574917687671707, -0.09912513693345923, -0.10259280762974712, -0.1061525647821606, -0.10980457997473175, -0.11354879993324678, -0.11738492459969939, -0.12131238386842073, -0.12533031294964592, -0.1294375263314648, -0.13363249031736696, -0.13791329412402684, -0.14227761953270035, -0.14672270909774232, -0.15124533292741144, -0.15584175406543116, -0.16050769251683253, -0.16523828797852094, -0.1700280613538905, -0.17487087515172978, -0.17975989289270172, -0.1846875376718702, -0.18964545005310887, -0.19462444550074698, -0.1996144715854137, -0.20460456523463744, -0.20958281033416915, -0.21453629602299634, -0.21945107606330733, -0.22431212970585282, -0.2291033245107872, -0.2338073816235713, -0.2384058440442351, -0.24287904846546207, -0.24720610128969592, -0.2513648594668244, -0.25533191682087797, -0.25908259655545657, -0.26259095064200905, -0.26582976680136566, -0.2687705837857208, -0.2713837156542617, -0.2736382857095345, -0.2755022707222038, -0.2769425560179855, -0.2779250019312789, -0.2784145220446738, -0.27837517353163604, -0.27777025980117886, -0.2765624455085223, -0.2747138838453706, -0.2721863558587383, -0.2689414213699951, -0.2649405808782801, -0.2601454476374965, -0.254517928897123, -0.24802041509791006, -0.24061597561845527, -0.23226855948228375, -0.22294319926222578, -0.21260621626452272, -0.20122542494405968, -0.1887703343990727, -0.1752123447228501, -0.1605249359550192, -0.14468384737893447, -0.1276672449565023, -0.10945587477855048, -0.09003320053750444, -0.06938552319843756, -0.047502081252106004, -0.024375130175789482, 0.0, 0.025624869824210517, 0.052497918747894, 0.08061447680156243, 0.1099667994624956, 0.14054412522144952, 0.1723327550434977, 0.20531615262106553, 0.2394750640449808, 0.27478765527714993, 0.3112296656009273, 0.34877457505594045, 0.3873937837354772, 0.42705680073777424, 0.4677314405177162, 0.5093840243815447, 0.55197958490209, 0.595482071102877, 0.6398545523625035, 0.6850594191217199, 0.7310585786300049, 0.7778136441412618, 0.8252861161546295, 0.8734375544914775, 0.922229740198821, 0.9716248264683638, 1.0215854779553262, 1.0720749980687212, 1.1230574439820142, 1.1744977292777963, 1.2263617142904655, 1.2786162843457383, 1.3312294162142793, 1.3841702331986343, 1.437409049357991, 1.4909174034445436, 1.5446680831791222, 1.5986351405331758, 1.652793898710304, 1.707120951534538, 1.7615941559557646, 1.8161926183764285, 1.870896675489213, 1.9256878702941471, 1.9805489239366927, 2.035463703977004, 2.0904171896658306, 2.1453954347653625, 2.200385528414586, 2.255375554499253, 2.3103545499468914, 2.3653124623281294, 2.4202401071072988, 2.4751291248482703, 2.5299719386461095, 2.584761712021479, 2.6394923074831675, 2.6941582459345685, 2.7487546670725886, 2.8032772909022583, 2.8577223804673, 2.9120867058759727, 2.966367509682633, 3.020562473668535, 3.0746696870503545, 3.1286876161315798, 3.1826150754003004, 3.236451200066753, 3.290195420025268, 3.3438474352178393, 3.397407192370253, 3.450874863066541, 3.5042508231232827, 3.5575356332219186, 3.610730020754624, 3.663834862837404, 3.7168511704427036, 3.7697800736030804, 3.8226228076370976, 3.8753807003486958, 3.928055160151634, 3.9806476650713027, 4.033159752577092, 4.085593010199603, 4.137949066888253, 4.190229585066207, 4.242436253341041, 4.294570779831115, 4.346634886069193, 4.398630301446546, 4.45055875816233, 4.502421986644772, 4.55422171141224, 4.60595964734395, 4.657637496331615, 4.709256944284868, 4.760819658464833, 4.8123272851216266, 4.863781447413019, 4.915183743582774, 4.966535745378576]} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_near_zero.json b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_near_zero.json new file mode 100644 index 000000000000..99329d886bb3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_near_zero.json @@ -0,0 +1 @@ +{"x": [-1.0, -0.98, -0.96, -0.94, -0.92, -0.9, -0.88, -0.86, -0.84, -0.82, -0.8, -0.78, -0.76, -0.74, -0.72, -0.7, -0.68, -0.66, -0.64, -0.62, -0.6, -0.58, -0.56, -0.54, -0.52, -0.5, -0.48, -0.46, -0.44, -0.42, -0.4, -0.38, -0.36, -0.34, -0.32, -0.3, -0.28, -0.26, -0.24, -0.22, -0.2, -0.18, -0.16, -0.14, -0.12, -0.1, -0.08, -0.06, -0.04, -0.02, 0.0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, 0.4, 0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.58, 0.6, 0.62, 0.64, 0.66, 0.68, 0.7, 0.72, 0.74, 0.76, 0.78, 0.8, 0.82, 0.84, 0.86, 0.88, 0.9, 0.92, 0.94, 0.96, 0.98, 1.0], "expected": [-0.2689414213699951, -0.2674339479856931, -0.26580306708058576, -0.2640463220285991, -0.26216126275508944, -0.2601454476374965, -0.2579964454376605, -0.2557118372635309, -0.25328921855786746, -0.25072620111141497, -0.24802041509791006, -0.24516951112816202, -0.2421711623203406, -0.23902306638349294, -0.23572294771121247, -0.23226855948228375, -0.22865768576504017, -0.22488814362208562, -0.2209577852119557, -0.21686449988422724, -0.21260621626452272, -0.20818090432580608, -0.20358657744232286, -0.1988212944225051, -0.1938831615171383, -0.1887703343990727, -0.18348102011076048, -0.1780134789759057, -0.17236602647153368, -0.16653703505681494, -0.1605249359550192, -0.1543282208850258, -0.14794544373888055, -0.14137522220196153, -0.1346162393124002, -0.1276672449565023, -0.12052705729701588, -0.11319456413121241, -0.10566872417587368, -0.09794856827641275, -0.09003320053750444, -0.08192179937275558, -0.07361361847110948, -0.06510798767784998, -0.056404313788251385, -0.047502081252106004, -0.03840085278755346, -0.02910026990283539, -0.019600053324801383, -0.009900003333200007, 0.0, 0.010099996666799995, 0.02039994667519862, 0.0308997300971646, 0.04159914721244655, 0.052497918747894, 0.0635956862117486, 0.07489201232215004, 0.08638638152889051, 0.09807820062724441, 0.1099667994624956, 0.12205143172358726, 0.1343312758241263, 0.1468054358687876, 0.15947294270298415, 0.1723327550434977, 0.18538376068759985, 0.19862477779803853, 0.21205455626111944, 0.22567177911497424, 0.2394750640449808, 0.25346296494318504, 0.26763397352846635, 0.2819865210240943, 0.2965189798892395, 0.3112296656009273, 0.3261168384828617, 0.3411787055774949, 0.3564134225576772, 0.37181909567419386, 0.3873937837354772, 0.4031355001157728, 0.4190422147880443, 0.43511185637791444, 0.4513423142349599, 0.4677314405177162, 0.4842770522887875, 0.500976933616507, 0.5178288376796595, 0.534830488871838, 0.55197958490209, 0.5692737988885851, 0.5867107814421325, 0.604288162736469, 0.6220035545623395, 0.6398545523625035, 0.6578387372449106, 0.6759536779714008, 0.6941969329194142, 0.7125660520143069, 0.7310585786300049]} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_special.json b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_special.json new file mode 100644 index 000000000000..9b0a0252f850 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/test/fixtures/python/silu_special.json @@ -0,0 +1 @@ +{"x": [-50.0, -25.0, -22.0, -2.0, -1.0, 0.0, 1.0, 2.0, 10.0, 50.0], "expected": [-9.64374923981959e-21, -3.471985966192786e-10, -6.136829802599786e-09, -0.2384058440442351, -0.2689414213699951, 0.0, 0.7310585786300049, 1.7615941559557646, 9.999546021312977, 50.0]} diff --git a/lib/node_modules/@stdlib/math/base/special/silu/test/test.js b/lib/node_modules/@stdlib/math/base/special/silu/test/test.js new file mode 100644 index 000000000000..9cb343a317fb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/test/test.js @@ -0,0 +1,171 @@ +/** +* @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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/assert/is-positive-zero' ); +var isNegativeZero = require( '@stdlib/assert/is-negative-zero' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var silu = require( './../lib' ); + + +// FIXTURES // + +var largeNegative = require( './fixtures/python/silu_large_negative.json' ); +var largePositive = require( './fixtures/python/silu_large_positive.json' ); +var nearZero = require( './fixtures/python/silu_near_zero.json' ); +var special = require( './fixtures/python/silu_special.json' ); +var medium = require( './fixtures/python/silu_medium.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof silu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` when provided `NaN`', function test( t ) { + var v = silu( NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns `+Infinity` when provided `+Infinity`', function test( t ) { + var v = silu( PINF ); + t.strictEqual( v, PINF, 'returns +Infinity' ); + t.end(); +}); + +tape( 'the function returns `-0.0` when provided `-Infinity`', function test( t ) { + var v = silu( NINF ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0.0' ); + t.end(); +}); + +tape( 'the function preserves the sign of zero', function test( t ) { + var v = silu( 0.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0.0' ); + + v = silu( -0.0 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0.0' ); + t.end(); +}); + +tape( 'the function does not return `NaN` for large inputs', function test( t ) { + var v; + + v = silu( 1e200 ); + t.strictEqual( isnan( v ), false, 'does not return NaN' ); + t.strictEqual( v, 1e200, 'returns x for very large positive x' ); + + v = silu( -1e200 ); + t.strictEqual( isnan( v ), false, 'does not return NaN' ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0.0' ); + + v = silu( 1e308 ); + t.strictEqual( isnan( v ), false, 'does not return NaN' ); + t.strictEqual( v, 1e308, 'returns x for very large positive x' ); + + v = silu( -1e308 ); + t.strictEqual( isnan( v ), false, 'does not return NaN' ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0.0' ); + t.end(); +}); + +tape( 'the function evaluates SiLU near zero', function test( t ) { + var expected; + var x; + var y; + var i; + + x = nearZero.x; + expected = nearZero.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates SiLU for moderate inputs', function test( t ) { + var expected; + var x; + var y; + var i; + + x = medium.x; + expected = medium.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates SiLU for large positive inputs', function test( t ) { + var expected; + var x; + var y; + var i; + + x = largePositive.x; + expected = largePositive.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates SiLU for large negative tail inputs', function test( t ) { + var expected; + var x; + var y; + var i; + + x = largeNegative.x; + expected = largeNegative.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates SiLU for special values', function test( t ) { + var expected; + var x; + var y; + var i; + + x = special.x; + expected = special.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/silu/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/silu/test/test.native.js new file mode 100644 index 000000000000..1df067c2896b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/silu/test/test.native.js @@ -0,0 +1,180 @@ +/** +* @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/assert/is-positive-zero' ); +var isNegativeZero = require( '@stdlib/assert/is-negative-zero' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var silu = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( silu instanceof Error ) +}; + + +// FIXTURES // + +var largeNegative = require( './fixtures/python/silu_large_negative.json' ); +var largePositive = require( './fixtures/python/silu_large_positive.json' ); +var nearZero = require( './fixtures/python/silu_near_zero.json' ); +var special = require( './fixtures/python/silu_special.json' ); +var medium = require( './fixtures/python/silu_medium.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof silu, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` when provided `NaN`', opts, function test( t ) { + var v = silu( NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function returns `+Infinity` when provided `+Infinity`', opts, function test( t ) { + var v = silu( PINF ); + t.strictEqual( v, PINF, 'returns +Infinity' ); + t.end(); +}); + +tape( 'the function returns `-0.0` when provided `-Infinity`', opts, function test( t ) { + var v = silu( NINF ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0.0' ); + t.end(); +}); + +tape( 'the function preserves the sign of zero', opts, function test( t ) { + var v = silu( 0.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0.0' ); + + v = silu( -0.0 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0.0' ); + t.end(); +}); + +tape( 'the function does not return `NaN` for large inputs', opts, function test( t ) { + var v; + + v = silu( 1e200 ); + t.strictEqual( isnan( v ), false, 'does not return NaN' ); + t.strictEqual( v, 1e200, 'returns x for very large positive x' ); + + v = silu( -1e200 ); + t.strictEqual( isnan( v ), false, 'does not return NaN' ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0.0' ); + + v = silu( 1e308 ); + t.strictEqual( isnan( v ), false, 'does not return NaN' ); + t.strictEqual( v, 1e308, 'returns x for very large positive x' ); + + v = silu( -1e308 ); + t.strictEqual( isnan( v ), false, 'does not return NaN' ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0.0' ); + t.end(); +}); + +tape( 'the function evaluates SiLU near zero', opts, function test( t ) { + var expected; + var x; + var y; + var i; + + x = nearZero.x; + expected = nearZero.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates SiLU for moderate inputs', opts, function test( t ) { + var expected; + var x; + var y; + var i; + + x = medium.x; + expected = medium.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates SiLU for large positive inputs', opts, function test( t ) { + var expected; + var x; + var y; + var i; + + x = largePositive.x; + expected = largePositive.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates SiLU for large negative tail inputs', opts, function test( t ) { + var expected; + var x; + var y; + var i; + + x = largeNegative.x; + expected = largeNegative.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates SiLU for special values', opts, function test( t ) { + var expected; + var x; + var y; + var i; + + x = special.x; + expected = special.expected; + for ( i = 0; i < x.length; i++ ) { + y = silu( x[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); From a3090f172cbe7905bffe78c2322010e6bfb6610e Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sun, 18 Oct 2026 04:50:04 +0530 Subject: [PATCH 2/2] fix: replace tab with spaces in readme Signed-off-by: Aryan Sharma --- lib/node_modules/@stdlib/math/base/special/silu/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/silu/README.md b/lib/node_modules/@stdlib/math/base/special/silu/README.md index 341e3329ef48..4b8da52653ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/silu/README.md +++ b/lib/node_modules/@stdlib/math/base/special/silu/README.md @@ -85,7 +85,7 @@ var logEachMap = require( '@stdlib/console/log-each-map' ); var silu = require( '@stdlib/math/base/special/silu' ); var opts = { - 'dtype': 'float64' + 'dtype': 'float64' }; var x = uniform( 100, -5.0, 5.0, opts );