diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/README.md b/lib/node_modules/@stdlib/math/base/special/trigamma/README.md index 548e0d53df6f..1573ce61a128 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/README.md +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/README.md @@ -115,6 +115,95 @@ for ( i = 0; i < 10; i++ ) { <!-- /.examples --> +<!-- C interface documentation. --> + +* * * + +<section class="c"> + +## C APIs + +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> + +<section class="intro"> + +</section> + +<!-- /.intro --> + +<!-- C usage documentation. --> + +<section class="usage"> + +### Usage + +```c +#include "stdlib/math/base/special/trigamma.h" +``` + +#### stdlib_base_trigamma( x ) + +Evaluates the [trigamma function][trigamma-function]. + +```c +double out = stdlib_base_trigamma( -2.5 ); +// returns ~9.539 + +out = stdlib_base_trigamma( 1.0 ); +// returns ~1.645 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. + +```c +double stdlib_base_trigamma( const double x ); +``` + +</section> + +<!-- /.usage --> + +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> + +<section class="notes"> + +</section> + +<!-- /.notes --> + +<!-- C API usage examples. --> + +<section class="examples"> + +### Examples + +```c +#include "stdlib/math/base/special/trigamma.h" +#include <stdlib.h> +#include <stdio.h> + +int main( void ) { + const double x[] = { 4.0, -1.5, -0.5, 0.5 }; + + double y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_trigamma( x[ i ] ); + printf( "trigamma(%lf) = %lf\n", x[ i ], y ); + } +} +``` + +</section> + +<!-- /.examples --> + +</section> + +<!-- /.c --> + <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> <section class="related"> diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/trigamma/benchmark/benchmark.native.js new file mode 100644 index 000000000000..53f098b6e7f0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/benchmark/benchmark.native.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var trigamma = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( trigamma instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu() * 100.0 ) + EPS; + y = trigamma( x ); + 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/trigamma/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/trigamma/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/trigamma/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/trigamma/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..02c46808c0c8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/benchmark/c/native/benchmark.c @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/trigamma.h" +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <time.h> +#include <sys/time.h> + +#define NAME "trigamma" +#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; + double y; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 100.0 * rand_double() ); + y = stdlib_base_trigamma( x ); + 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/trigamma/binding.gyp b/lib/node_modules/@stdlib/math/base/special/trigamma/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/trigamma/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/trigamma/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/trigamma/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/trigamma/examples/c/example.c new file mode 100644 index 000000000000..460ba7dde271 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/examples/c/example.c @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/trigamma.h" +#include <stdio.h> + +int main( void ) { + const double x[] = { 4.0, -1.5, -0.5, 0.5 }; + + double y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_trigamma( x[ i ] ); + printf( "trigamma(%lf) = %lf\n", x[ i ], y ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/include.gypi b/lib/node_modules/@stdlib/math/base/special/trigamma/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 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': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Add-on destination directory: + 'addon_output_dir': './src', + + # Source files: + 'src_files': [ + '<(src_dir)/addon.c', + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Library dependencies: + 'libraries': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + + # Library directories: + 'library_dirs': [ + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', + ], + }, # end variables +} diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/include/stdlib/math/base/special/trigamma.h b/lib/node_modules/@stdlib/math/base/special/trigamma/include/stdlib/math/base/special/trigamma.h new file mode 100644 index 000000000000..ca5100fb4ded --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/include/stdlib/math/base/special/trigamma.h @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +#ifndef STDLIB_MATH_BASE_SPECIAL_TRIGAMMA_H +#define STDLIB_MATH_BASE_SPECIAL_TRIGAMMA_H + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Evaluates the trigamma function. +*/ +double stdlib_base_trigamma( const double x ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_TRIGAMMA_H diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/main.js b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/main.js index 3ef55bf4fb79..9d8e0eea2e55 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/main.js @@ -18,7 +18,7 @@ * * ## Notice * -* The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_65_0/boost/math/special_functions/trigamma.hpp}. The implementation follows the original but has been reformatted and modified for JavaScript. +* The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_85_0/boost/math/special_functions/trigamma.hpp}. The implementation follows the original but has been reformatted and modified for JavaScript. * * ```text * (C) Copyright John Maddock 2006. diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/native.js b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/native.js new file mode 100644 index 000000000000..0d8e16069c1c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/native.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates the trigamma function. +* +* @private +* @param {number} x - input value +* @returns {number} function value +* +* @example +* var v = trigamma( -2.5 ); +* // returns ~9.539 +* +* @example +* var v = trigamma( 1.0 ); +* // returns ~1.645 +* +* @example +* var v = trigamma( 10.0 ); +* // returns ~0.105 +* +* @example +* var v = trigamma( NaN ); +* // returns NaN +* +* @example +* var v = trigamma( -1.0 ); +* // returns NaN +*/ +function trigamma( x ) { + return addon( x ); +} + + +// EXPORTS // + +module.exports = trigamma; diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p12q12.js b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p12q12.js index 0b4a03907a9b..2111dee370b2 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p12q12.js +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p12q12.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,7 @@ // MAIN // /** -* Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p16infq16inf.js b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p16infq16inf.js index 7d730840ccb6..e4310e712754 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p16infq16inf.js +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p16infq16inf.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,7 @@ // MAIN // /** -* Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p24q24.js b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p24q24.js index a4cdee8d4702..5cd7acaac2b6 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p24q24.js +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p24q24.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,7 @@ // MAIN // /** -* Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p48q48.js b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p48q48.js index 0f35c9c75ed2..5fb9941f24cd 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p48q48.js +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p48q48.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,7 @@ // MAIN // /** -* Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p816q816.js b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p816q816.js index a53ccd4ec463..abc598aef5c2 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p816q816.js +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/lib/rational_p816q816.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -22,7 +22,7 @@ // MAIN // /** -* Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). * * ## Notes * diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/manifest.json b/lib/node_modules/@stdlib/math/base/special/trigamma/manifest.json new file mode 100644 index 000000000000..e0983f2170a0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/manifest.json @@ -0,0 +1,79 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/unary", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/sinpi", + "@stdlib/constants/float64/pi-squared" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/sinpi", + "@stdlib/constants/float64/pi-squared" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/sinpi", + "@stdlib/constants/float64/pi-squared" + ] + } + ] +} + diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/scripts/evalrational.js b/lib/node_modules/@stdlib/math/base/special/trigamma/scripts/evalrational.js index 37db6aac6a0f..99ff6d250a06 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/scripts/evalrational.js +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/scripts/evalrational.js @@ -24,10 +24,15 @@ // MODULES // var resolve = require( 'path' ).resolve; +var readFileSync = require( '@stdlib/fs/read-file' ).sync; var writeFileSync = require( '@stdlib/fs/write-file' ).sync; var currentYear = require( '@stdlib/time/current-year' ); var licenseHeader = require( '@stdlib/_tools/licenses/header' ); var compile = require( '@stdlib/math/base/tools/evalrational-compile' ); +var compileC = require( '@stdlib/math/base/tools/evalrational-compile-c' ); +var substringBefore = require( '@stdlib/string/substring-before' ); +var substringAfter = require( '@stdlib/string/substring-after' ); +var format = require( '@stdlib/string/format' ); // VARIABLES // @@ -172,6 +177,33 @@ var header = licenseHeader( 'Apache-2.0', 'js', { header += '\n/* This is a generated file. Do not edit directly. */\n'; +// FUNCTIONS // + +/** +* Inserts a compiled function into file content. +* +* @private +* @param {string} text - source content +* @param {string} id - function identifier +* @param {string} str - function string +* @returns {string} updated content +*/ +function insert( text, id, str ) { + var before; + var after; + var begin; + var end; + + begin = '// BEGIN: '+id; + end = '// END: '+id; + + before = substringBefore( text, begin ); + after = substringAfter( text, end ); + + return format( '%s// BEGIN: %s\n\n%s\n%s%s', before, id, str, end, after ); +} + + // MAIN // /** @@ -181,7 +213,9 @@ header += '\n/* This is a generated file. Do not edit directly. */\n'; */ function main() { var fpath; + var copts; var opts; + var file; var str; opts = { @@ -207,6 +241,36 @@ function main() { fpath = resolve( __dirname, '..', 'lib', 'rational_p16infq16inf.js' ); str = header + compile( P16INF, Q16INF ); writeFileSync( fpath, str, opts ); + + copts = { + 'dtype': 'double', + 'name': '' + }; + + fpath = resolve( __dirname, '..', 'src', 'main.c' ); + file = readFileSync( fpath, opts ); + + copts.name = 'rational_p12q12'; + str = compileC( P12, Q12, copts ); + file = insert( file, copts.name, str ); + + copts.name = 'rational_p24q24'; + str = compileC( P24, Q24, copts ); + file = insert( file, copts.name, str ); + + copts.name = 'rational_p48q48'; + str = compileC( P48, Q48, copts ); + file = insert( file, copts.name, str ); + + copts.name = 'rational_p816q816'; + str = compileC( P816, Q816, copts ); + file = insert( file, copts.name, str ); + + copts.name = 'rational_p16infq16inf'; + str = compileC( P16INF, Q16INF, copts ); + file = insert( file, copts.name, str ); + + writeFileSync( fpath, file, opts ); } main(); diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/src/Makefile b/lib/node_modules/@stdlib/math/base/special/trigamma/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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/trigamma/src/addon.c b/lib/node_modules/@stdlib/math/base/special/trigamma/src/addon.c new file mode 100644 index 000000000000..21c5a19ac001 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/src/addon.c @@ -0,0 +1,23 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/trigamma.h" +#include "stdlib/math/base/napi/unary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_trigamma ) diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/src/main.c b/lib/node_modules/@stdlib/math/base/special/trigamma/src/main.c new file mode 100644 index 000000000000..f8504bd7afda --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/src/main.c @@ -0,0 +1,300 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* +* +* ## Notice +* +* The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_85_0/boost/math/special_functions/trigamma.hpp}. The implementation follows the original but has been reformatted and modified for JavaScript. +* +* ```text +* (C) Copyright John Maddock 2006. +* +* Use, modification and distribution are subject to the +* Boost Software License, Version 1.0. (See accompanying file +* LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) +* ``` +*/ + +#include "stdlib/math/base/special/trigamma.h" +#include "stdlib/math/base/special/floor.h" +#include "stdlib/math/base/special/sinpi.h" +#include "stdlib/constants/float64/pi_squared.h" + +static const double YOFFSET24 = 3.558437347412109375; + +/* Begin auto-generated functions. The following functions are auto-generated. Do not edit directly. */ + +// BEGIN: rational_p12q12 + +/** +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). +* +* ## Notes +* +* - Coefficients should be sorted in ascending degree. +* - The implementation uses [Horner's rule][horners-method] for efficient computation. +* +* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method +* +* @param x value at which to evaluate the rational function +* @return evaluated rational function +*/ +static double rational_p12q12( const double x ) { + double ax; + double ix; + double s1; + double s2; + if ( x == 0.0 ) { + return -0.9999999999999991; + } + if ( x < 0.0 ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0 ) { + s1 = -0.9999999999999991 + (x * (-4.712373111208652 + (x * (-7.94125711970499 + (x * (-5.746577466976647 + (x * (-0.4042133494563989 + (x * (2.4787778117864288 + (x * (2.0771415170245513 + (x * (0.8588778991623601 + (x * (0.20499222604410033 + (x * (0.027210314034819473 + (x * 0.001576484902087695))))))))))))))))))); + s2 = 1.0 + (x * (4.712373111208634 + (x * (9.586191186553398 + (x * (11.094006726982938 + (x * (8.090754247493278 + (x * (3.877058901598914 + (x * (1.2275867870191448 + (x * (0.249092040606385 + (x * (0.02957504139006556 + (x * (0.0015764849020049815 + (x * 1.6126405034405948e-15))))))))))))))))))); + } else { + ix = 1.0 / x; + s1 = 0.001576484902087695 + (ix * (0.027210314034819473 + (ix * (0.20499222604410033 + (ix * (0.8588778991623601 + (ix * (2.0771415170245513 + (ix * (2.4787778117864288 + (ix * (-0.4042133494563989 + (ix * (-5.746577466976647 + (ix * (-7.94125711970499 + (ix * (-4.712373111208652 + (ix * -0.9999999999999991))))))))))))))))))); + s2 = 1.6126405034405948e-15 + (ix * (0.0015764849020049815 + (ix * (0.02957504139006556 + (ix * (0.249092040606385 + (ix * (1.2275867870191448 + (ix * (3.877058901598914 + (ix * (8.090754247493278 + (ix * (11.094006726982938 + (ix * (9.586191186553398 + (ix * (4.712373111208634 + (ix * 1.0))))))))))))))))))); + } + return s1 / s2; +} + +// END: rational_p12q12 + +// BEGIN: rational_p24q24 + +/** +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). +* +* ## Notes +* +* - Coefficients should be sorted in ascending degree. +* - The implementation uses [Horner's rule][horners-method] for efficient computation. +* +* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method +* +* @param x value at which to evaluate the rational function +* @return evaluated rational function +*/ +static double rational_p24q24( const double x ) { + double ax; + double ix; + double s1; + double s2; + if ( x == 0.0 ) { + return -2.5584373473990794; + } + if ( x < 0.0 ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0 ) { + s1 = -2.5584373473990794 + (x * (-12.283020824054201 + (x * (-23.9195022162768 + (x * (-24.925643150482347 + (x * (-14.797912276547878 + (x * (-4.466544539286106 + (x * (-0.01914390334056497 + (x * (0.5154120525543513 + (x * (0.1953783487860643 + (x * (0.03347612826241743 + (x * (0.0023736652059422065 + (x * 0.0))))))))))))))))))))); + s2 = 1.0 + (x * (4.800985584544199 + (x * (9.992207278431701 + (x * (11.889614616763133 + (x * (8.966132566838091 + (x * (4.4725413614962415 + (x * (1.4860098202819654 + (x * (0.31957073576676426 + (x * (0.040735834578768094 + (x * (0.0023736652059327163 + (x * (2.3955488790352614e-16 + (x * -2.9474924474061867e-18))))))))))))))))))))); + } else { + ix = 1.0 / x; + s1 = 0.0 + (ix * (0.0023736652059422065 + (ix * (0.03347612826241743 + (ix * (0.1953783487860643 + (ix * (0.5154120525543513 + (ix * (-0.01914390334056497 + (ix * (-4.466544539286106 + (ix * (-14.797912276547878 + (ix * (-24.925643150482347 + (ix * (-23.9195022162768 + (ix * (-12.283020824054201 + (ix * -2.5584373473990794))))))))))))))))))))); + s2 = -2.9474924474061867e-18 + (ix * (2.3955488790352614e-16 + (ix * (0.0023736652059327163 + (ix * (0.040735834578768094 + (ix * (0.31957073576676426 + (ix * (1.4860098202819654 + (ix * (4.4725413614962415 + (ix * (8.966132566838091 + (ix * (11.889614616763133 + (ix * (9.992207278431701 + (ix * (4.800985584544199 + (ix * 1.0))))))))))))))))))))); + } + return s1 / s2; +} + +// END: rational_p24q24 + +// BEGIN: rational_p48q48 + +/** +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). +* +* ## Notes +* +* - Coefficients should be sorted in ascending degree. +* - The implementation uses [Horner's rule][horners-method] for efficient computation. +* +* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method +* +* @param x value at which to evaluate the rational function +* @return evaluated rational function +*/ +static double rational_p48q48( const double x ) { + double ax; + double ix; + double s1; + double s2; + if ( x == 0.0 ) { + return 1.6662611269702147e-17; + } + if ( x < 0.0 ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0 ) { + s1 = 1.6662611269702147e-17 + (x * (0.4999999999999977 + (x * (6.402709450190538 + (x * (41.38333741550006 + (x * (166.8033418545628 + (x * (453.39964786925367 + (x * (851.153712317697 + (x * (1097.7065756728507 + (x * (938.4312324784553 + (x * (487.26800160465194 + (x * 119.95344524233573))))))))))))))))))); + s2 = 1.0 + (x * (12.472085567047449 + (x * (78.60931297532986 + (x * (307.47024605031834 + (x * (805.1406861011516 + (x * (1439.1201976029215 + (x * (1735.6105285756048 + (x * (1348.3250071285634 + (x * (607.2259858605709 + (x * (119.95231785727705 + (x * 0.00014016591835503607))))))))))))))))))); + } else { + ix = 1.0 / x; + s1 = 119.95344524233573 + (ix * (487.26800160465194 + (ix * (938.4312324784553 + (ix * (1097.7065756728507 + (ix * (851.153712317697 + (ix * (453.39964786925367 + (ix * (166.8033418545628 + (ix * (41.38333741550006 + (ix * (6.402709450190538 + (ix * (0.4999999999999977 + (ix * 1.6662611269702147e-17))))))))))))))))))); + s2 = 0.00014016591835503607 + (ix * (119.95231785727705 + (ix * (607.2259858605709 + (ix * (1348.3250071285634 + (ix * (1735.6105285756048 + (ix * (1439.1201976029215 + (ix * (805.1406861011516 + (ix * (307.47024605031834 + (ix * (78.60931297532986 + (ix * (12.472085567047449 + (ix * 1.0))))))))))))))))))); + } + return s1 / s2; +} + +// END: rational_p48q48 + +// BEGIN: rational_p816q816 + +/** +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). +* +* ## Notes +* +* - Coefficients should be sorted in ascending degree. +* - The implementation uses [Horner's rule][horners-method] for efficient computation. +* +* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method +* +* @param x value at which to evaluate the rational function +* @return evaluated rational function +*/ +static double rational_p816q816( const double x ) { + double ax; + double ix; + double s1; + double s2; + if ( x == 0.0 ) { + return -1.848283152741466e-20; + } + if ( x < 0.0 ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0 ) { + s1 = -1.848283152741466e-20 + (x * (0.5 + (x * (3.0253386524731334 + (x * (13.599592751745737 + (x * (35.31322242830879 + (x * (67.16394245507142 + (x * (83.5767733658514 + (x * (71.07349121223571 + (x * (35.86215156147256 + (x * 8.721522316399835))))))))))))))))); + s2 = 1.0 + (x * (5.717343971612935 + (x * (25.29340417962044 + (x * (62.26197679674682 + (x * (113.955048909239 + (x * (130.80713832893898 + (x * (102.42314690233765 + (x * (44.04247728052452 + (x * (8.89898032477904 + (x * -0.029662733687204))))))))))))))))); + } else { + ix = 1.0 / x; + s1 = 8.721522316399835 + (ix * (35.86215156147256 + (ix * (71.07349121223571 + (ix * (83.5767733658514 + (ix * (67.16394245507142 + (ix * (35.31322242830879 + (ix * (13.599592751745737 + (ix * (3.0253386524731334 + (ix * (0.5 + (ix * -1.848283152741466e-20))))))))))))))))); + s2 = -0.029662733687204 + (ix * (8.89898032477904 + (ix * (44.04247728052452 + (ix * (102.42314690233765 + (ix * (130.80713832893898 + (ix * (113.955048909239 + (ix * (62.26197679674682 + (ix * (25.29340417962044 + (ix * (5.717343971612935 + (ix * 1.0))))))))))))))))); + } + return s1 / s2; +} + +// END: rational_p816q816 + +// BEGIN: rational_p16infq16inf + +/** +* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). +* +* ## Notes +* +* - Coefficients should be sorted in ascending degree. +* - The implementation uses [Horner's rule][horners-method] for efficient computation. +* +* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method +* +* @param x value at which to evaluate the rational function +* @return evaluated rational function +*/ +static double rational_p16infq16inf( const double x ) { + double ax; + double ix; + double s1; + double s2; + if ( x == 0.0 ) { + return 0.0; + } + if ( x < 0.0 ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0 ) { + s1 = 0.0 + (x * (0.5 + (x * (0.34562566988545623 + (x * (9.628954993608422 + (x * (3.5936085382439025 + (x * (49.45959911843888 + (x * (7.775192373218939 + (x * (74.4536074488178 + (x * (2.7520934039706906 + (x * (23.92923597114717 + (x * 0.0))))))))))))))))))); + s2 = 1.0 + (x * (0.3579180064375791 + (x * (19.138603985070986 + (x * (0.8743490814641436 + (x * (98.65160974348555 + (x * (-16.10519728333829 + (x * (154.31686021625373 + (x * (-40.2026880424379 + (x * (60.167913667426475 + (x * (-13.341484462225642 + (x * 2.537956362006499))))))))))))))))))); + } else { + ix = 1.0 / x; + s1 = 0.0 + (ix * (23.92923597114717 + (ix * (2.7520934039706906 + (ix * (74.4536074488178 + (ix * (7.775192373218939 + (ix * (49.45959911843888 + (ix * (3.5936085382439025 + (ix * (9.628954993608422 + (ix * (0.34562566988545623 + (ix * (0.5 + (ix * 0.0))))))))))))))))))); + s2 = 2.537956362006499 + (ix * (-13.341484462225642 + (ix * (60.167913667426475 + (ix * (-40.2026880424379 + (ix * (154.31686021625373 + (ix * (-16.10519728333829 + (ix * (98.65160974348555 + (ix * (0.8743490814641436 + (ix * (19.138603985070986 + (ix * (0.3579180064375791 + (ix * 1.0))))))))))))))))))); + } + return s1 / s2; +} + +// END: rational_p16infq16inf + +/* End auto-generated functions. */ + +/** +* Evaluates the trigamma function. +* +* @param x input value +* @return function value +* +* @example +* double v = stdlib_base_trigamma( -2.5 ); +* // returns ~9.539 +*/ +double stdlib_base_trigamma( const double x ) { + double result; + double xc; + double s; + double y; + double z; + + result = 0.0; + + // Check for negative arguments and use reflection: + if ( x <= 0.0 ) { + if ( stdlib_base_floor( x ) == x ) { + return 0.0 / 0.0; // NaN + } + s = stdlib_base_sinpi( x ); + z = 1.0 - x; + return -stdlib_base_trigamma( z ) + ( STDLIB_CONSTANT_FLOAT64_PI_SQUARED / ( s * s ) ); + } + xc = x; + if ( xc < 1.0 ) { + result = 1.0 / ( xc * xc ); + xc += 1.0; + } + if ( xc <= 2.0 ) { + result += ( 2.0 + rational_p12q12( xc ) ) / ( xc * xc ); + } + else if ( xc <= 4.0 ) { + result += ( YOFFSET24 + rational_p24q24( xc ) ) / ( xc * xc ); + } + else if ( xc <= 8.0 ) { + y = 1.0 / xc; + result += ( 1.0 + rational_p48q48( y ) ) / xc; + } + else if ( xc <= 16.0 ) { + y = 1.0 / xc; + result += ( 1.0 + rational_p816q816( y ) ) / xc; + } + else { + y = 1.0 / xc; + result += ( 1.0 + rational_p16infq16inf( y ) ) / xc; + } + return result; +} diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/test/test.js b/lib/node_modules/@stdlib/math/base/special/trigamma/test/test.js index 02ebe6d6bc08..fca26be0bb67 100644 --- a/lib/node_modules/@stdlib/math/base/special/trigamma/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/test/test.js @@ -44,25 +44,25 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'if provided a `NaN`, the function returns `NaN` ', function test( t ) { +tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) { var val = trigamma( NaN ); t.strictEqual( isnan( val ), true, 'returns NaN' ); t.end(); }); -tape( 'if provided `0`, the function returns `NaN` ', function test( t ) { +tape( 'if provided `0`, the function returns `NaN`', function test( t ) { var val = trigamma( 0.0 ); t.strictEqual( isnan( val ), true, 'returns NaN' ); t.end(); }); -tape( 'if provided positive infinity, the function returns `0` ', function test( t ) { +tape( 'if provided positive infinity, the function returns `0`', function test( t ) { var val = trigamma( PINF ); t.strictEqual( val, 0.0, 'returns 0' ); t.end(); }); -tape( 'if provided negative infinity, the function returns `NaN` ', function test( t ) { +tape( 'if provided negative infinity, the function returns `NaN`', function test( t ) { var val = trigamma( NINF ); t.strictEqual( isnan( val ), true, 'returns NaN' ); t.end(); diff --git a/lib/node_modules/@stdlib/math/base/special/trigamma/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/trigamma/test/test.native.js new file mode 100644 index 000000000000..18fdc0e201a0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/trigamma/test/test.native.js @@ -0,0 +1,137 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 incrspace = require( '@stdlib/array/base/incrspace' ); +var isnan = require( '@stdlib/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var trigamma = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( trigamma instanceof Error ) +}; + + +// FIXTURES // + +var positive = require( './fixtures/cpp/positive.json' ); +var negative = require( './fixtures/cpp/negative.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof trigamma, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided a `NaN`, the function returns `NaN`', opts, function test( t ) { + var val = trigamma( NaN ); + t.strictEqual( isnan( val ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `0`, the function returns `NaN`', opts, function test( t ) { + var val = trigamma( 0.0 ); + t.strictEqual( isnan( val ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided positive infinity, the function returns `0`', opts, function test( t ) { + var val = trigamma( PINF ); + t.strictEqual( val, 0.0, 'returns 0' ); + t.end(); +}); + +tape( 'if provided negative infinity, the function returns `NaN`', opts, function test( t ) { + var val = trigamma( NINF ); + t.strictEqual( isnan( val ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a negative integer, the function returns `NaN`', opts, function test( t ) { + var values; + var val; + var i; + + values = incrspace( -1.0, -100.0, -1.0 ); + for ( i = 0; i < values.length; i++ ) { + val = trigamma( values[ i ] ); + t.strictEqual( isnan( val ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function evaluates the trigamma function for positive numbers', opts, function test( t ) { + var expected; + var delta; + var tol; + var x; + var y; + var i; + + x = positive.x; + expected = positive.y; + for ( i = 0; i < x.length; i++ ) { + y = trigamma( x[i] ); + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); + } else { + delta = abs( y - expected[i] ); + tol = 10.0 * EPS * abs( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); + } + } + t.end(); +}); + +tape( 'the function evaluates the trigamma function for negative numbers', opts, function test( t ) { + var expected; + var delta; + var tol; + var x; + var y; + var i; + + x = negative.x; + expected = negative.y; + for ( i = 0; i < x.length; i++ ) { + y = trigamma( x[i] ); + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] ); + } else { + delta = abs( y - expected[i] ); + tol = 10.0 * EPS * abs( expected[i] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); + } + } + t.end(); +});