diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/LICENSE b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/LICENSE new file mode 100644 index 000000000000..05757b1b8026 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/LICENSE @@ -0,0 +1,209 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + +DEPENDENCIES & ATTRIBUTION + +The library links against the following external libraries or contains +implementations from the following external libraries, which have their own +licenses: + +* Boost + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/README.md b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/README.md new file mode 100644 index 000000000000..5b8d4761ffb2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/README.md @@ -0,0 +1,228 @@ + + +# Gamma Scaled Lanczos Sum + +> Calculate a scaled Lanczos sum for the approximation of the [gamma function][gamma-function] as a single precision floating-point number. + +
+ +The [Lanczos approximation][lanczos-approximation] for the [gamma function][gamma-function] can be written in partial fraction form as follows: + + + +```math +\Gamma ( n ) = \frac{(n+g-0.5)^{n-0.5}}{e^{n+g-0.5}} L_g(n) +``` + + + +where `g` is an [arbitrary constant][@stdlib/constants/float32/gamma-lanczos-g] and `L_g(n)` is the Lanczos sum. The scaled Lanczos sum is given by + + + +```math +L_g(n) \cdot \exp(-g) +``` + + + +
+ + + +
+ +## Usage + + + +```javascript +var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf' ); +``` + +#### gammaLanczosSumExpGScaledf( x ) + +Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] (scaled by `exp(-g)`, where `g = 1.42845618724823`) as a single precision floating-point number. + + + +```javascript +var v = gammaLanczosSumExpGScaledf( 4.0 ); +// returns ~0.748 + +v = gammaLanczosSumExpGScaledf( -1.5 ); +// returns ~0.193 + +v = gammaLanczosSumExpGScaledf( -0.5 ); +// returns ~-0.558 + +v = gammaLanczosSumExpGScaledf( 0.5 ); +// returns ~1.772 + +v = gammaLanczosSumExpGScaledf( 0.0 ); +// returns Infinity + +v = gammaLanczosSumExpGScaledf( NaN ); +// returns NaN +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf' ); + +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 100, -10.0, 10.0, opts ); + +logEachMap( 'x: %0.4f, f(x): %0.4f', x, gammaLanczosSumExpGScaledf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h" +``` + +#### stdlib_base_gamma_lanczos_sum_expg_scaledf( x ) + +Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] (scaled by `exp(-g)`, where `g = 1.42845618724823`) as a single precision floating-point number. + +```c +float out = stdlib_base_gamma_lanczos_sum_expg_scaledf( 4.0f ); +// returns ~0.018f + +out = stdlib_base_gamma_lanczos_sum_expg_scaledf( -1.5f ); +// returns ~25.337f +``` + +The function accepts the following arguments: + +- **x**: `[in] float` input value. + +```c +float stdlib_base_gamma_lanczos_sum_expg_scaledf( const float x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h" +#include + +int main( void ) { + const float x[] = { 4.0f, -1.5f, -0.5f, 0.5f }; + + float y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_gamma_lanczos_sum_expg_scaledf( x[ i ] ); + printf( "gamma_lanczos_sum_expg_scaledf(%f) = %f\n", x[ i ], y ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.js new file mode 100644 index 000000000000..e9739736df93 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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 gammaLanczosSumExpGScaledf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -50.0, 50.0, { + 'dtype': 'float32' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gammaLanczosSumExpGScaledf( 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/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..88d43b66e909 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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 gammaLanczosSumExpGScaledf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( gammaLanczosSumExpGScaledf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -50.0, 50.0, { + 'dtype': 'float32' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gammaLanczosSumExpGScaledf( 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/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..5d7e79f50788 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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 C source files. +# +# @param {string} SOURCE_FILES - list of C source files +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [C_COMPILER] - C compiler +# @param {string} [CFLAGS] - C compiler flags +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} SOURCE_FILES - list of C source files +# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) +# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} CC - C compiler +# @param {string} CFLAGS - C compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(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/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..d16061d3a9ea --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/benchmark.c @@ -0,0 +1,138 @@ +/** +* @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/gamma_lanczos_sum_expg_scaledf.h" +#include +#include +#include +#include +#include + +#define NAME "gamma_lanczos_sum_expg_scaledf" +#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 [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + float x[ 100 ]; + double t; + float y; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -50.0f, 50.0f ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_gamma_lanczos_sum_expg_scaledf( 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/gamma-lanczos-sum-expg-scaledf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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/gamma-lanczos-sum-expg-scaledf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/repl.txt new file mode 100644 index 000000000000..cba84914ae78 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( x ) + Calculates the scaled Lanczos sum for the approximation of the gamma + function as a single precision floating-point number. + + Parameters + ---------- + x: number + Input value. + + Returns + ------- + y: number + Scaled Lanczos sum. + + Examples + -------- + > var y = {{alias}}( 4.0 ) + ~0.748 + > y = {{alias}}( -1.5 ) + ~0.193 + > y = {{alias}}( -0.5 ) + ~-0.558 + > y = {{alias}}( 0.5 ) + ~1.772 + > y = {{alias}}( 0.0 ) + Infinity + > y = {{alias}}( NaN ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/types/index.d.ts new file mode 100644 index 000000000000..6eff2455a19b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/types/index.d.ts @@ -0,0 +1,56 @@ +/* +* @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 + +/** +* Calculates the Lanczos sum for the approximation of the gamma function (scaled by `exp(-g)`, where `g = 1.42845618724823`) as a single precision floating-point number. +* +* @param x - input value +* @returns Lanczos sum approximation +* +* @example +* var v = gammaLanczosSumExpGScaledf( 4.0 ); +* // returns ~0.748 +* +* @example +* var v = gammaLanczosSumExpGScaledf( -1.5 ); +* // returns ~0.193 +* +* @example +* var v = gammaLanczosSumExpGScaledf( -0.5 ); +* // returns ~-0.558 +* +* @example +* var v = gammaLanczosSumExpGScaledf( 0.5 ); +* // returns ~1.772 +* +* @example +* var v = gammaLanczosSumExpGScaledf( 0.0 ); +* // returns Infinity +* +* @example +* var v = gammaLanczosSumExpGScaledf( NaN ); +* // returns NaN +*/ +declare function gammaLanczosSumExpGScaledf( x: number ): number; + + +// EXPORTS // + +export = gammaLanczosSumExpGScaledf; diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/types/test.ts new file mode 100644 index 000000000000..f688b53c948e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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 gammaLanczosSumExpGScaledf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + gammaLanczosSumExpGScaledf( 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a number... +{ + gammaLanczosSumExpGScaledf( true ); // $ExpectError + gammaLanczosSumExpGScaledf( false ); // $ExpectError + gammaLanczosSumExpGScaledf( null ); // $ExpectError + gammaLanczosSumExpGScaledf( undefined ); // $ExpectError + gammaLanczosSumExpGScaledf( '5' ); // $ExpectError + gammaLanczosSumExpGScaledf( [] ); // $ExpectError + gammaLanczosSumExpGScaledf( {} ); // $ExpectError + gammaLanczosSumExpGScaledf( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + gammaLanczosSumExpGScaledf(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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/gamma-lanczos-sum-expg-scaledf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/examples/c/example.c new file mode 100644 index 000000000000..c8a1d88b2e0d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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/gamma_lanczos_sum_expg_scaledf.h" +#include + +int main( void ) { + const float x[] = { 4.0f, -1.5f, -0.5f, 0.5f }; + + float y; + int i; + for ( i = 0; i < 4; i++ ) { + y = stdlib_base_gamma_lanczos_sum_expg_scaledf( x[ i ] ); + printf( "gamma_lanczos_sum_expg_scaledf(%f) = %f\n", x[ i ], y ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/examples/index.js new file mode 100644 index 000000000000..d0c10b2a7192 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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 gammaLanczosSumExpGScaledf = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; +var x = uniform( 100, -10.0, 10.0, opts ); + +logEachMap( 'x: %0.4f, f(x): %0.4f', x, gammaLanczosSumExpGScaledf ); diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/include.gypi b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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", + "special function", + "special", + "function", + "gamma", + "lanczos", + "scaled", + "approx", + "approximation", + "polynomial", + "rational", + "factorial", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/scripts/evalrational.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/scripts/evalrational.js new file mode 100644 index 000000000000..216a5dcb4b48 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/scripts/evalrational.js @@ -0,0 +1,131 @@ +/** +* @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. +*/ + +/* +* This script compiles modules for evaluating polynomial functions. If any polynomial coefficients change, this script should be rerun to update the compiled files. +*/ +'use strict'; + +// 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 // + +// Polynomial coefficients ordered in ascending degree... +var P = [ + 14.0261432874996476619570577285003839357, + 43.74732405540314316089531289293124360129, + 50.59547402616588964511581430025589038612, + 26.90456680562548195593733429204228910299, + 6.595765571169314946316366571954421695196, + 0.6007854010515290065101128585795542383721 +]; +var Q = [ + 0.0, + 24.0, + 50.0, + 35.0, + 10.0, + 1.0 +]; + +// Header to add to output files: +var header = licenseHeader( 'Apache-2.0', 'js', { + 'year': currentYear(), + 'copyright': 'The Stdlib Authors' +}); +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 // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var fpath; + var copts; + var opts; + var file; + var str; + + opts = { + 'encoding': 'utf8' + }; + + fpath = resolve( __dirname, '..', 'lib', 'rational_pq.js' ); + str = header + compile( P, Q, { + 'dtype': 'float32' + }); + writeFileSync( fpath, str, opts ); + + copts = { + 'dtype': 'float', + 'name': 'rational_pq' + }; + + fpath = resolve( __dirname, '..', 'src', 'main.c' ); + file = readFileSync( fpath, opts ); + + str = compileC( P, Q, copts ); + file = insert( file, copts.name, str ); + + writeFileSync( fpath, file, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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/gamma-lanczos-sum-expg-scaledf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/addon.c new file mode 100644 index 000000000000..d853615d6261 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/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/gamma_lanczos_sum_expg_scaledf.h" +#include "stdlib/math/base/napi/unary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_gamma_lanczos_sum_expg_scaledf ) diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/main.c b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/main.c new file mode 100644 index 000000000000..fbb42af9300d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/main.c @@ -0,0 +1,87 @@ +/** +* @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. +* +* +* ## Notice +* +* The original C++ code and copyright notice are from the [Boost library]{@link https://www.boost.org/doc/libs/1_88_0/boost/math/special_functions/lanczos.hpp}. The implementation has been modified according to stdlib conventions. +* +* ```text +* 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/gamma_lanczos_sum_expg_scaledf.h" + +// BEGIN: rational_pq + +/** +* 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 float rational_pq( const float x ) { + float ax; + float ix; + float s1; + float s2; + if ( x == 0.0f ) { + return 1.0f / 0.0f; + } + if ( x < 0.0f ) { + ax = -x; + } else { + ax = x; + } + if ( ax <= 1.0f ) { + s1 = 14.026143287499648f + (x * (43.74732405540314f + (x * (50.59547402616589f + (x * (26.904566805625482f + (x * (6.595765571169315f + (x * 0.600785401051529f))))))))); + s2 = 0.0f + (x * (24.0f + (x * (50.0f + (x * (35.0f + (x * (10.0f + (x * 1.0f))))))))); + } else { + ix = 1.0f / x; + s1 = 0.600785401051529f + (ix * (6.595765571169315f + (ix * (26.904566805625482f + (ix * (50.59547402616589f + (ix * (43.74732405540314f + (ix * 14.026143287499648f))))))))); + s2 = 1.0f + (ix * (10.0f + (ix * (35.0f + (ix * (50.0f + (ix * (24.0f + (ix * 0.0f))))))))); + } + return s1 / s2; +} + +// END: rational_pq + +/** +* Calculates the Lanczos sum for the approximation of the gamma function (scaled by `exp(-g)`, where `g = 1.42845618724823`) as a single precision floating-point number. +* +* @param x input value +* @return Lanczos sum approximation +* +* @example +* float v = stdlib_base_gamma_lanczos_sum_expg_scaledf( 4.0f ); +* // returns ~0.748f +*/ +float stdlib_base_gamma_lanczos_sum_expg_scaledf( const float x ) { + return rational_pq( x ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.js new file mode 100644 index 000000000000..37f8ad70e1bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.js @@ -0,0 +1,76 @@ +/** +* @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 linspace = require( '@stdlib/array/base/linspace' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var gamma = require( '@stdlib/math/base/special/gamma' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var exp = require( '@stdlib/math/base/special/exp' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var G = require( '@stdlib/constants/float32/gamma-lanczos-g' ); +var gammaLanczosSumExpGScaledf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gammaLanczosSumExpGScaledf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { + var v = gammaLanczosSumExpGScaledf( NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function evaluates the Lanczos sum (scaled by exp(-g))', function test( t ) { + var expected; + var delta; + var tol; + var i; + var x; + var y; + + x = linspace( 1.0, 100.0, 500 ); + for ( i = 0; i < x.length; i++ ) { + y = gammaLanczosSumExpGScaledf( x[i] ); + + // TODO: replace with `gammaf`, `powf`, and `expf` when available + expected = gamma( x[i] ); + expected /= pow( x[i]+G-0.5, x[i]-0.5 ) / ( exp( x[i]+G-0.5 ) ); + expected /= exp( G ); + expected = f32( expected ); + if ( y === expected ) { + t.strictEqual( y, expected, 'returns expected value' ); + } else { + delta = absf( y - expected ); + tol = 2.0 * EPS * absf( expected ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.native.js new file mode 100644 index 000000000000..0eef2968d40a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.native.js @@ -0,0 +1,85 @@ +/** +* @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 linspace = require( '@stdlib/array/base/linspace' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var gamma = require( '@stdlib/math/base/special/gamma' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var exp = require( '@stdlib/math/base/special/exp' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var G = require( '@stdlib/constants/float32/gamma-lanczos-g' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var gammaLanczosSumExpGScaledf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( gammaLanczosSumExpGScaledf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gammaLanczosSumExpGScaledf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) { + var v = gammaLanczosSumExpGScaledf( NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function evaluates the Lanczos sum (scaled by exp(-g))', opts, function test( t ) { + var expected; + var delta; + var tol; + var i; + var x; + var y; + + x = linspace( 1.0, 100.0, 500 ); + for ( i = 0; i < x.length; i++ ) { + y = gammaLanczosSumExpGScaledf( x[ i ] ); + + // TODO: replace with `gammaf`, `powf`, and `expf` when available + expected = gamma( x[i] ); + expected /= pow( x[i]+G-0.5, x[i]-0.5 ) / ( exp( x[i]+G-0.5 ) ); + expected /= exp( G ); + expected = f32( expected ); + if ( y === expected ) { + t.strictEqual( y, expected, 'x: '+x[ i ]+', y: '+y+', expected: '+expected ); + } else { + delta = absf( y - expected ); + tol = 2.0 * EPS * absf( expected ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + } + } + t.end(); +});