From 127546c901e729da7cde4ef728e028b458480af7 Mon Sep 17 00:00:00 2001 From: ishwarthecodddr Date: Mon, 2 Mar 2026 19:47:52 +0530 Subject: [PATCH 1/2] feat: add math/base/special/sechf This commit adds @stdlib/math/base/special/sechf, which computes the hyperbolic secant of a single-precision floating-point number. --- .../@stdlib/math/base/special/sechf/README.md | 182 ++++++++++++++++++ .../base/special/sechf/benchmark/benchmark.js | 54 ++++++ .../sechf/benchmark/benchmark.native.js | 63 ++++++ .../special/sechf/benchmark/c/native/Makefile | 146 ++++++++++++++ .../sechf/benchmark/c/native/benchmark.c | 136 +++++++++++++ .../math/base/special/sechf/binding.gyp | 170 ++++++++++++++++ .../math/base/special/sechf/docs/repl.txt | 27 +++ .../base/special/sechf/docs/types/index.d.ts | 48 +++++ .../base/special/sechf/docs/types/test.ts | 44 +++++ .../math/base/special/sechf/examples/index.js | 30 +++ .../math/base/special/sechf/include.gypi | 53 +++++ .../include/stdlib/math/base/special/sechf.h | 38 ++++ .../math/base/special/sechf/lib/index.js | 49 +++++ .../math/base/special/sechf/lib/main.js | 58 ++++++ .../math/base/special/sechf/lib/native.js | 58 ++++++ .../math/base/special/sechf/manifest.json | 72 +++++++ .../math/base/special/sechf/package.json | 136 +++++++++++++ .../math/base/special/sechf/src/Makefile | 70 +++++++ .../math/base/special/sechf/src/addon.c | 22 +++ .../math/base/special/sechf/src/main.c | 38 ++++ .../special/sechf/test/fixtures/julia/REQUIRE | 1 + .../sechf/test/fixtures/julia/data.json | 1 + .../sechf/test/fixtures/julia/large.json | 1 + .../sechf/test/fixtures/julia/runner.jl | 74 +++++++ .../sechf/test/fixtures/julia/tiny.json | 1 + .../math/base/special/sechf/test/test.js | 154 +++++++++++++++ .../base/special/sechf/test/test.native.js | 163 ++++++++++++++++ 27 files changed, 1889 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/include/stdlib/math/base/special/sechf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/REQUIRE create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/data.json create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/large.json create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/runner.jl create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/tiny.json create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/README.md b/lib/node_modules/@stdlib/math/base/special/sechf/README.md new file mode 100644 index 000000000000..07b187030b5d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/README.md @@ -0,0 +1,182 @@ + + +# sechf + +> Compute the [hyperbolic secant][hyperbolic-functions] of a single-precision floating-point number. + +
+ +## Usage + +```javascript +var sechf = require( '@stdlib/math/base/special/sechf' ); +``` + +#### sechf( x ) + +Computes the [hyperbolic secant][hyperbolic-functions] of a single-precision floating-point number. + +```javascript +var v = sechf( 0.0 ); +// returns 1.0 + +v = sechf( 2.0 ); +// returns ~0.2658 + +v = sechf( -2.0 ); +// returns ~0.2658 + +v = sechf( NaN ); +// returns NaN +``` + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var sechf = require( '@stdlib/math/base/special/sechf' ); + +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 100, -5.0, 5.0, opts ); + +logEachMap( 'sechf(%0.4f) = %0.4f', x, sechf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/sechf.h" +``` + +#### stdlib_base_sechf( x ) + +Computes the [hyperbolic secant][hyperbolic-functions] of a single-precision floating-point number. + +```c +float out = stdlib_base_sechf( 2.0f ); +// returns ~0.2658f + +out = stdlib_base_sechf( -2.0f ); +// returns ~0.2658f +``` + +The function accepts the following arguments: + +- **x**: `[in] float` input value. + +```c +float stdlib_base_sechf( const float x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/sechf.h" +#include + +int main( void ) { + const float x[] = { -5.0f, -3.89f, -2.78f, -1.67f, -0.56f, 0.56f, 1.67f, 2.78f, 3.89f, 5.0f }; + + float v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_sechf( x[ i ] ); + printf( "sechf(%f) = %f\n", x[ i ], v ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/benchmark.js new file mode 100644 index 000000000000..841bb8278e2d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var sechf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -5.0, 5.0, { + 'dtype': 'float32' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = sechf( x[ i%x.length ] ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f5066812f4de --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var sechf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( sechf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -5.0, 5.0, { + 'dtype': 'float32' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = sechf( x[ i%x.length ] ); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/c/native/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 := 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/sechf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..e45237e090fa --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/benchmark/c/native/benchmark.c @@ -0,0 +1,136 @@ +/** +* @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/sechf.h" +#include +#include +#include +#include +#include + +#define NAME "sechf" +#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 float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + float x[ 100 ]; + double elapsed; + float y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 10.0f * rand_float() ) - 5.0f; + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_sechf( 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/sechf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/sechf/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/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/sechf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/sechf/docs/repl.txt new file mode 100644 index 000000000000..6771e9fe4191 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/docs/repl.txt @@ -0,0 +1,27 @@ + +{{alias}}( x ) + Computes the hyperbolic secant of a single-precision floating-point number. + + Parameters + ---------- + x: number + Input value. + + Returns + ------- + y: number + Hyperbolic secant. + + Examples + -------- + > var y = {{alias}}( 0.0 ) + 1.0 + > y = {{alias}}( 2.0 ) + ~0.2658 + > y = {{alias}}( -2.0 ) + ~0.2658 + > y = {{alias}}( NaN ) + NaN + + See Also + -------- diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/sechf/docs/types/index.d.ts new file mode 100644 index 000000000000..910aeefc84dd --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/docs/types/index.d.ts @@ -0,0 +1,48 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/** +* Computes the hyperbolic secant of a single-precision floating-point number. +* +* @param x - input value +* @returns hyperbolic secant +* +* @example +* var v = sechf( 0.0 ); +* // returns 1.0 +* +* @example +* var v = sechf( 2.0 ); +* // returns ~0.2658 +* +* @example +* var v = sechf( -2.0 ); +* // returns ~0.2658 +* +* @example +* var v = sechf( NaN ); +* // returns NaN +*/ +declare function sechf( x: number ): number; + + +// EXPORTS // + +export = sechf; diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/sechf/docs/types/test.ts new file mode 100644 index 000000000000..d9751febe8ed --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @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. +*/ + +import sechf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + sechf( 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a number... +{ + sechf( true ); // $ExpectError + sechf( false ); // $ExpectError + sechf( null ); // $ExpectError + sechf( undefined ); // $ExpectError + sechf( '5' ); // $ExpectError + sechf( [] ); // $ExpectError + sechf( {} ); // $ExpectError + sechf( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + sechf(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/sechf/examples/index.js new file mode 100644 index 000000000000..5afe94f05574 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var sechf = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 100, -5.0, 5.0, opts ); + +logEachMap( 'sechf(%0.4f) = %0.4f', x, sechf ); diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/include.gypi b/lib/node_modules/@stdlib/math/base/special/sechf/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/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': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "sec", + "sech", + "sechf", + "secant", + "math.sech", + "cos", + "cosine", + "hyperbolic", + "trig", + "trigonometry", + "radians", + "angle", + "float32", + "single", + "float" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "sech", + "alias": "sechf", + "pkg_desc": "compute the hyperbolic secant of a single-precision floating-point number", + "desc": "computes the hyperbolic secant of a single-precision floating-point number", + "short_desc": "hyperbolic secant (single-precision)", + "parameters": [ + { + "name": "x", + "desc": "input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "float", + "dtype": "float32" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/uniform", + "parameters": [ + -5, + 5 + ] + }, + "example_values": [ + 0.0, + 2.0, + -2.0, + 1.0, + -1.0, + 0.5, + -0.5 + ] + } + ], + "returns": { + "desc": "hyperbolic secant", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "float", + "dtype": "float32" + } + }, + "keywords": [ + "sech", + "secant", + "hyperbolic", + "float32", + "single-precision" + ], + "extra_keywords": [] + } + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/sechf/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/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/sechf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/sechf/src/addon.c new file mode 100644 index 000000000000..35df53fe0ca3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/src/addon.c @@ -0,0 +1,22 @@ +/** +* @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/sechf.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_sechf ) diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/src/main.c b/lib/node_modules/@stdlib/math/base/special/sechf/src/main.c new file mode 100644 index 000000000000..02f51d4fae87 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/src/main.c @@ -0,0 +1,38 @@ +/** +* @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/sechf.h" +#include "stdlib/math/base/special/coshf.h" + +/** +* Computes the hyperbolic secant of a single-precision floating-point number. +* +* @param x input value +* @return hyperbolic secant +* +* @example +* float y = stdlib_base_sechf( 2.0f ); +* // returns ~0.2658f +* +* @example +* float y = stdlib_base_sechf( -2.0f ); +* // returns ~0.2658f +*/ +float stdlib_base_sechf( const float x ) { + return 1.0f / stdlib_base_coshf( x ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..732835a50676 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/REQUIRE @@ -0,0 +1 @@ +JSON diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/data.json new file mode 100644 index 000000000000..fb7ff2a2ccb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"x":[-100.0,-99.9001,-99.80019960079841,-99.70029920159681,-99.60039880239521,-99.50049850299401,-99.40059820359281,-99.30069780439122,-99.20079740518962,-99.10089700598803,-99.00099660678643,-98.90109620758483,-98.80119580838323,-98.70129540918163,-98.60139500998004,-98.50149461077844,-98.40159421157684,-98.30169381237524,-98.20179341317364,-98.10189301397205,-98.00199261477045,-97.90209221556885,-97.80219181636725,-97.70229141716566,-97.60239101796406,-97.50249061876246,-97.40259021956087,-97.30268982035927,-97.20278942115767,-97.10288902195607,-97.00298862275448,-96.90308822355288,-96.80318782435128,-96.70328742514968,-96.60338702594809,-96.50348662674649,-96.40358622754489,-96.3036858283433,-96.2037854291417,-96.1038850299401,-96.0039846307385,-95.9040842315369,-95.80418383233531,-95.70428343313371,-95.60438303393211,-95.50448263473051,-95.40458223552892,-95.30468183632732,-95.20478143712572,-95.10488103792413],"expected":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]} diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/large.json b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/large.json new file mode 100644 index 000000000000..7491b80deb5a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/large.json @@ -0,0 +1 @@ +{"x":[50.0,50.018972054891234,50.03794410978247,50.056916164673704,50.07588821956494,50.09486027445617,50.11383232934741,50.132804384238646,50.151776439129875,50.17074849402111,50.18972054891235,50.20869260380358,50.22766465869482,50.24663671358606,50.26560876847729,50.28458082336853,50.30355287825976,50.322524933151,50.34149698804224,50.36046904293347,50.379441097824705,50.39841315271594,50.41738520760718,50.43635726249841,50.45532931738965,50.47430137228089,50.49327342717212,50.51224548206336,50.53121753695459,50.55018959184583,50.56916164673707,50.5881337016283,50.60710575651954,50.62607781141077,50.64504986630201,50.66402192119325,50.68299397608448,50.70196603097572,50.72093808586695,50.73991014075819,50.75888219564943,50.77785425054066,50.7968263054319,50.81579836032313,50.83477041521437,50.85374247010561,50.87271452499684,50.89168657988808,50.910658634779314,50.92963068967055],"expected":[3.8539246274877774e-22,3.7806752700014684e-22,3.709386704787645e-22,3.6400146916398744e-22,3.572513605377628e-22,3.506836442609299e-22,3.4429348285316917e-22,3.3807590229890044e-22,3.320258028200653e-22,3.261379605665785e-22,3.2040703894951877e-22,3.148275910010481e-22,3.0939406165932285e-22,3.041008908456823e-22,2.989424264236376e-22,2.9391303623313643e-22,2.890070199073169e-22,2.8421871996063313e-22,2.7954243332802946e-22,2.749725120399474e-22,2.705033747632927e-22,2.661295082044051e-22,2.6184547839499267e-22,2.576459319113091e-22,2.5352559692026015e-22,2.4947928414795135e-22,2.455018876548704e-22,2.4158838551180474e-22,2.377338403012635e-22,2.3393340954451697e-22,2.301823461552972e-22,2.2647600771936934e-22,2.228098556740831e-22,2.191794558853046e-22,2.1558047803965984e-22,2.1200869499556054e-22,2.0845998110276726e-22,2.0493031038850987e-22,2.0141575344015403e-22,1.9791247532430298e-22,1.9441673347889098e-22,1.909248756081148e-22,1.8743333768665673e-22,1.8393864191113903e-22,1.8043739457853306e-22,1.7692628404085006e-22,1.7340207838298704e-22,1.6986162293405588e-22,1.6630183768340816e-22,1.6271971474166952e-22]} diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..3262393e2321 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/runner.jl @@ -0,0 +1,74 @@ +#!/usr/bin/env julia +# +# @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. + +import JSON + +""" + gen( domain, name ) + +Generate fixture data and write to file. + +# Arguments + +* `domain`: domain +* `name::AbstractString`: output filename + +# Examples + +``` julia +julia> x = range( -1000, stop = 1000, length = 2001 ); +julia> gen( x, "data.json" ); +``` +""" +function gen( domain, name ) + x = collect( domain ); + y = sech.( Float32.( x ) ); + + # Store data to be written to file as a collection: + data = Dict([ + ("x", x), + ("expected", y) + ]); + + # Based on the script directory, create an output filepath: + filepath = joinpath( dir, name ); + + # Write the data to the output filepath as JSON: + outfile = open( filepath, "w" ); + write( outfile, JSON.json(data) ); + write( outfile, "\n" ); + close( outfile ); +end + +# Get the filename: +file = @__FILE__; + +# Extract the directory in which this file resides: +dir = dirname( file ); + +# Generate fixture data for decimal values: +x = range( -100, stop = 100, length = 2003 ); +gen( x, "data.json" ); + +# Generate fixture data for large values: +x = range( 50, stop = 88, length = 2003 ); +gen( x, "large.json" ); + +# Generate fixture data for tiny values: +x = range( -1e-30, stop = -1e-38, length = 2003 ); +gen( x, "tiny.json" ); diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/tiny.json b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/tiny.json new file mode 100644 index 000000000000..95995b0fd126 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/test/fixtures/julia/tiny.json @@ -0,0 +1 @@ +{"x":[-1.0e-30,-9.500249875062469e-31,-9.000499750124937e-31,-8.500749625187407e-31,-8.000999500249875e-31,-7.501249375312344e-31,-7.001499250374813e-31,-6.501749125437281e-31,-6.00199900049975e-31,-5.502248875562219e-31,-5.002498750624688e-31,-4.502748625687157e-31,-4.002998500749625e-31,-3.5032483758120947e-31,-3.003498250874563e-31,-2.5037481259370317e-31,-2.0039980009995e-31,-1.504247876061969e-31,-1.0044977511244375e-31,-5.04747626186906e-32,-4.9975012493753123e-34,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38,-1.0e-38],"expected":[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]} diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/test/test.js b/lib/node_modules/@stdlib/math/base/special/sechf/test/test.js new file mode 100644 index 000000000000..00b906861507 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/test/test.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var sechf = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var tiny = require( './fixtures/julia/tiny.json' ); +var large = require( './fixtures/julia/large.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sechf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the hyperbolic secant', function test( t ) { + var expected; + var delta; + var tol; + var x; + var y; + var i; + + x = data.x; + expected = data.expected; + + for ( i = 0; i < x.length; i++ ) { + x[ i ] = f32( x[ i ] ); + expected[ i ] = f32( expected[ i ] ); + y = sechf( x[ i ] ); + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); + } else { + delta = abs( y - expected[i] ); + tol = 1.4 * EPS * abs( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the hyperbolic secant (tiny values)', function test( t ) { + var expected; + var delta; + var tol; + var x; + var y; + var i; + + x = tiny.x; + expected = tiny.expected; + + for ( i = 0; i < x.length; i++ ) { + x[ i ] = f32( x[ i ] ); + expected[ i ] = f32( expected[ i ] ); + y = sechf( x[ i ] ); + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); + } else { + delta = abs( y - expected[i] ); + tol = EPS * abs( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the hyperbolic secant (large values)', function test( t ) { + var expected; + var delta; + var tol; + var x; + var y; + var i; + + x = large.x; + expected = large.expected; + + for ( i = 0; i < x.length; i++ ) { + x[ i ] = f32( x[ i ] ); + expected[ i ] = f32( expected[ i ] ); + y = sechf( x[ i ] ); + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); + } else { + delta = abs( y - expected[i] ); + tol = 1.4 * EPS * abs( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns `1` if provided `+-0`', function test( t ) { + var v; + + v = sechf( -0.0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + v = sechf( +0.0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { + var v = sechf( NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0.0` if provided `+-infinity`', function test( t ) { + var v; + + v = sechf( PINF ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = sechf( NINF ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/sechf/test/test.native.js new file mode 100644 index 000000000000..a43ac49da482 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/test/test.native.js @@ -0,0 +1,163 @@ +/** +* @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 tryRequire = require( '@stdlib/utils/try-require' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var tiny = require( './fixtures/julia/tiny.json' ); +var large = require( './fixtures/julia/large.json' ); + + +// VARIABLES // + +var sechf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( sechf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sechf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the hyperbolic secant', opts, function test( t ) { + var expected; + var delta; + var tol; + var x; + var y; + var i; + + x = data.x; + expected = data.expected; + + for ( i = 0; i < x.length; i++ ) { + x[ i ] = f32( x[ i ] ); + expected[ i ] = f32( expected[ i ] ); + y = sechf( x[ i ] ); + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); + } else { + delta = abs( y - expected[i] ); + tol = 1.4 * EPS * abs( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the hyperbolic secant (tiny values)', opts, function test( t ) { + var expected; + var delta; + var tol; + var x; + var y; + var i; + + x = tiny.x; + expected = tiny.expected; + + for ( i = 0; i < x.length; i++ ) { + x[ i ] = f32( x[ i ] ); + expected[ i ] = f32( expected[ i ] ); + y = sechf( x[ i ] ); + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); + } else { + delta = abs( y - expected[i] ); + tol = EPS * abs( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes the hyperbolic secant (large values)', opts, function test( t ) { + var expected; + var delta; + var tol; + var x; + var y; + var i; + + x = large.x; + expected = large.expected; + + for ( i = 0; i < x.length; i++ ) { + x[ i ] = f32( x[ i ] ); + expected[ i ] = f32( expected[ i ] ); + y = sechf( x[ i ] ); + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); + } else { + delta = abs( y - expected[i] ); + tol = 1.4 * EPS * abs( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns `1` if provided `+-0`', opts, function test( t ) { + var v; + + v = sechf( -0.0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + v = sechf( +0.0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { + var v = sechf( NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0.0` if provided `+-infinity`', opts, function test( t ) { + var v; + + v = sechf( PINF ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = sechf( NINF ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); From 1ac04bbd9db84e296547d72ac2d9aa56a647e7e8 Mon Sep 17 00:00:00 2001 From: ishwarthecodddr Date: Wed, 4 Mar 2026 20:22:15 +0530 Subject: [PATCH 2/2] added c examples for sechf function --- .../base/special/sechf/examples/c/Makefile | 146 ++++++++++++++++++ .../base/special/sechf/examples/c/example.c | 31 ++++ 2 files changed, 177 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/sechf/examples/c/example.c diff --git a/lib/node_modules/@stdlib/math/base/special/sechf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/sechf/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/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/sechf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/sechf/examples/c/example.c new file mode 100644 index 000000000000..6afaa3302261 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sechf/examples/c/example.c @@ -0,0 +1,31 @@ +/** +* @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/sechf.h" +#include + +int main( void ) { + const float x[] = { -5.0f, -3.89f, -2.78f, -1.67f, -0.56f, 0.56f, 1.67f, 2.78f, 3.89f, 5.0f }; + + float v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_sechf( x[ i ] ); + printf( "sechf(%f) = %f\n", x[ i ], v ); + } +}