From 3fc21ed39fdea15e25a09654006c534f4b17273d Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 25 May 2025 20:54:21 -0700 Subject: [PATCH 1/3] feat: temp commit --- .../gamma-lanczos-sum-expg-scaledf/LICENSE | 209 +++++++++++++++ .../gamma-lanczos-sum-expg-scaledf/README.md | 244 ++++++++++++++++++ .../benchmark/benchmark.js | 52 ++++ .../benchmark/benchmark.native.js | 61 +++++ .../benchmark/c/native/Makefile | 146 +++++++++++ .../benchmark/c/native/benchmark.c | 136 ++++++++++ .../binding.gyp | 170 ++++++++++++ .../img/equation_lanczos_approximation.svg | 75 ++++++ .../docs/img/equation_scaled_lanczos_sum.svg | 32 +++ .../docs/repl.txt | 33 +++ .../docs/types/index.d.ts | 56 ++++ .../docs/types/test.ts | 44 ++++ .../examples/c/Makefile | 146 +++++++++++ .../examples/c/example.c | 31 +++ .../examples/index.js | 30 +++ .../include.gypi | 53 ++++ .../special/gamma_lanczos_sum_expg_scaledf.h | 38 +++ .../lib/index.js | 55 ++++ .../lib/main.js | 79 ++++++ .../lib/native.js | 66 +++++ .../lib/rational_pq.js | 64 +++++ .../manifest.json | 67 +++++ .../package.json | 73 ++++++ .../scripts/evalrational.js | 129 +++++++++ .../src/Makefile | 70 +++++ .../src/addon.c | 22 ++ .../gamma-lanczos-sum-expg-scaledf/src/main.c | 87 +++++++ .../test/test.js | 74 ++++++ .../test/test.native.js | 83 ++++++ 29 files changed, 2425 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/LICENSE create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_lanczos_approximation.svg create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_scaled_lanczos_sum.svg create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/include/stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/rational_pq.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/scripts/evalrational.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.native.js 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..ce0c6eb2f769 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/README.md @@ -0,0 +1,244 @@ + + +# Gamma Scaled Lanczos Sum + +> Calculate a scaled Lanczos sum for the approximation of the [gamma function][gamma-function]. + +
+ +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/float64/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-scaled' ); +``` + +#### gammaLanczosSumExpGScaledf( x ) + +Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] (scaled by `exp(-g)`, where `g = 10.900511`). + +```javascript +var v = gammaLanczosSumExpGScaledf( 4.0 ); +// returns ~0.018 + +v = gammaLanczosSumExpGScaledf( -1.5 ); +// returns ~25.337 + +v = gammaLanczosSumExpGScaledf( -0.5 ); +// returns ~-12.911 + +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-scaled' ); + +var opts = { + 'dtype': 'float64' +}; +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_scaled.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 = 10.900511`). + +```c +double out = stdlib_base_gamma_lanczos_sum_expg_scaledf( 4.0 ); +// returns ~0.018 + +out = stdlib_base_gamma_lanczos_sum_expg_scaledf( -1.5 ); +// returns ~25.337 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. + +```c +double stdlib_base_gamma_lanczos_sum_expg_scaledf( const double x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h" +#include +#include + +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_gamma_lanczos_sum_expg_scaledf( x[ i ] ); + printf( "gamma_lanczos_sum_expg_scaled(%lf) = %lf\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..c7d2d0750bad --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.js @@ -0,0 +1,52 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +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 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gammaLanczosSumExpGScaledf( x[ i%x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/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..fc578ce09786 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/benchmark.native.js @@ -0,0 +1,61 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +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 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gammaLanczosSumExpGScaledf( x[ i%x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/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..abfa69d92cc1 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/benchmark/c/native/benchmark.c @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h" +#include +#include +#include +#include +#include + +#define NAME "gamma_lanczos_sum_expg_scaled" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double x[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 100.0 * rand_double() ) - 50.0; + } + + 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/img/equation_lanczos_approximation.svg b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_lanczos_approximation.svg new file mode 100644 index 000000000000..d17a91f6be6f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_lanczos_approximation.svg @@ -0,0 +1,75 @@ + +normal upper Gamma left-parenthesis n right-parenthesis equals StartFraction left-parenthesis n plus g minus 0.5 right-parenthesis Superscript n minus 0.5 Baseline Over e Superscript n plus g minus 0.5 Baseline EndFraction upper L Subscript g Baseline left-parenthesis n right-parenthesis + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_scaled_lanczos_sum.svg b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_scaled_lanczos_sum.svg new file mode 100644 index 000000000000..0fc4d637c9ad --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_scaled_lanczos_sum.svg @@ -0,0 +1,32 @@ + +upper L Subscript g Baseline left-parenthesis n right-parenthesis dot exp left-parenthesis negative g right-parenthesis + + + \ No newline at end of file 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..dc62d70eb95e --- /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.018 + > y = {{alias}}( -1.5 ) + ~25.337 + > y = {{alias}}( -0.5 ) + ~-12.911 + > 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..bf88af69dbe7 --- /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)` with `g = 10.900511`), as a single-precision floating-point number. +* +* @param x - input value +* @returns Lanczos sum approximation +* +* @example +* var v = gammaLanczosSumExpGScaledf( 4.0 ); +* // returns ~0.018 +* +* @example +* var v = gammaLanczosSumExpGScaledf( -1.5 ); +* // returns ~25.337 +* +* @example +* var v = gammaLanczosSumExpGScaledf( -0.5 ); +* // returns ~-12.911 +* +* @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..27b766b89b63 --- /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_scaled.h" +#include + +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_gamma_lanczos_sum_expg_scaledf( x[ i ] ); + printf( "gamma_lanczos_sum_expg_scaled(%lf) = %lf\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..0c17fb398dcf --- /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': 'float64' +}; +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..e35e80f154d7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/scripts/evalrational.js @@ -0,0 +1,129 @@ +/** +* @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 = [ + 32.81244541029783471623665933780748627823, + 32.12388941444332003446077108933558534361, + 12.58034729455216106950851080138931470954, + 2.463444478353241423633780693218408889251, + 0.2412010548258800231126240760264822486599, + 0.009446967704539249494420221613134244048319 +]; +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 ); + 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..bc6e05261ba1 --- /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 = 32.81244541029783f + (x * (32.12388941444332f + (x * (12.580347294552162f + (x * (2.4634444783532414f + (x * (0.24120105482588003f + (x * 0.009446967704539249f))))))))); + 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.009446967704539249f + (ix * (0.24120105482588003f + (ix * (2.4634444783532414f + (ix * (12.580347294552162f + (ix * (32.12388941444332f + (ix * 32.81244541029783f))))))))); + 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)` with `g = 10.900511`), 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.018f +*/ +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..6dad8c10533b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.js @@ -0,0 +1,74 @@ +/** +* @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.only( '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] ); + 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 = 10.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..190d723bf28e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/test/test.native.js @@ -0,0 +1,83 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +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 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( isnan( 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 ] ); + expected = gamma( x[ i ] ); + + // eslint-disable-next-line max-len + expected /= pow( x[ i ] + G - 0.5, x[ i ] - 0.5 ) / ( exp( x[ i ] + G - 0.5 ) ); + expected /= exp( G ); + if ( y === expected ) { + t.strictEqual( y, expected, 'x: '+x[ i ]+', y: '+y+', expected: '+expected ); + } else { + delta = absf( y - expected ); + tol = 10.0 * EPS * absf( expected ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); + } + } + t.end(); +}); From 1de91666e1bbfff3dcc05fa6fdd567bfa32496dd Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Mon, 26 May 2025 01:28:53 -0700 Subject: [PATCH 2/3] feat: add `math/base/special/gamma-lanczos-sum-expg-scaledf` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../gamma-lanczos-sum-expg-scaledf/README.md | 72 +++++++----------- .../benchmark/benchmark.js | 10 ++- .../benchmark/benchmark.native.js | 10 ++- .../benchmark/c/native/benchmark.c | 14 ++-- .../img/equation_lanczos_approximation.svg | 75 ------------------- .../docs/img/equation_scaled_lanczos_sum.svg | 32 -------- .../docs/repl.txt | 6 +- .../docs/types/index.d.ts | 8 +- .../examples/c/example.c | 8 +- .../examples/index.js | 2 +- .../special/gamma_lanczos_sum_expg_scaledf.h | 2 +- .../lib/index.js | 12 +-- .../lib/main.js | 12 +-- .../lib/native.js | 8 +- .../lib/rational_pq.js | 17 +++-- .../package.json | 2 +- .../scripts/evalrational.js | 16 ++-- .../gamma-lanczos-sum-expg-scaledf/src/main.c | 8 +- .../test/test.js | 6 +- .../test/test.native.js | 14 ++-- 20 files changed, 113 insertions(+), 221 deletions(-) delete mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_lanczos_approximation.svg delete mode 100644 lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_scaled_lanczos_sum.svg 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 index ce0c6eb2f769..5b8d4761ffb2 100644 --- 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 @@ -20,7 +20,7 @@ limitations under the License. # Gamma Scaled Lanczos Sum -> Calculate a scaled Lanczos sum for the approximation of the [gamma function][gamma-function]. +> Calculate a scaled Lanczos sum for the approximation of the [gamma function][gamma-function] as a single precision floating-point number.
@@ -32,14 +32,9 @@ The [Lanczos approximation][lanczos-approximation] for the [gamma function][gamm \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/float64/gamma-lanczos-g] and `L_g(n)` is the Lanczos sum. The scaled Lanczos sum is given by +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 @@ -47,11 +42,6 @@ where `g` is an [arbitrary constant][@stdlib/constants/float64/gamma-lanczos-g] L_g(n) \cdot \exp(-g) ``` - -
@@ -62,23 +52,27 @@ L_g(n) \cdot \exp(-g) ## Usage + + ```javascript -var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled' ); +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 = 10.900511`). +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.018 +// returns ~0.748 v = gammaLanczosSumExpGScaledf( -1.5 ); -// returns ~25.337 +// returns ~0.193 v = gammaLanczosSumExpGScaledf( -0.5 ); -// returns ~-12.911 +// returns ~-0.558 v = gammaLanczosSumExpGScaledf( 0.5 ); // returns ~1.772 @@ -100,13 +94,15 @@ v = gammaLanczosSumExpGScaledf( NaN ); + + ```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-scaled' ); +var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf' ); var opts = { - 'dtype': 'float64' + 'dtype': 'float32' }; var x = uniform( 100, -10.0, 10.0, opts ); @@ -140,27 +136,27 @@ logEachMap( 'x: %0.4f, f(x): %0.4f', x, gammaLanczosSumExpGScaledf ); ### Usage ```c -#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h" +#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 = 10.900511`). +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 -double out = stdlib_base_gamma_lanczos_sum_expg_scaledf( 4.0 ); -// returns ~0.018 +float out = stdlib_base_gamma_lanczos_sum_expg_scaledf( 4.0f ); +// returns ~0.018f -out = stdlib_base_gamma_lanczos_sum_expg_scaledf( -1.5 ); -// returns ~25.337 +out = stdlib_base_gamma_lanczos_sum_expg_scaledf( -1.5f ); +// returns ~25.337f ``` The function accepts the following arguments: -- **x**: `[in] double` input value. +- **x**: `[in] float` input value. ```c -double stdlib_base_gamma_lanczos_sum_expg_scaledf( const double x ); +float stdlib_base_gamma_lanczos_sum_expg_scaledf( const float x ); ``` @@ -182,18 +178,17 @@ double stdlib_base_gamma_lanczos_sum_expg_scaledf( const double x ); ### Examples ```c -#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h" -#include +#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h" #include int main( void ) { - const double x[] = { 4.0, -1.5, -0.5, 0.5 }; + const float x[] = { 4.0f, -1.5f, -0.5f, 0.5f }; - double y; + 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_scaled(%lf) = %lf\n", x[ i ], y ); + printf( "gamma_lanczos_sum_expg_scaledf(%f) = %f\n", x[ i ], y ); } } ``` @@ -210,13 +205,6 @@ int main( void ) { @@ -225,7 +213,7 @@ int main( void ) { 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 index c7d2d0750bad..e9739736df93 100644 --- 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 @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pkg = require( './../package.json' ).name; var gammaLanczosSumExpGScaledf = require( './../lib' ); @@ -34,17 +34,19 @@ bench( pkg, function benchmark( b ) { var y; var i; - x = uniform( 100, -50.0, 50.0 ); + 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 ( isnan( y ) ) { + if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( y ) ) { + if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); 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 index fc578ce09786..88d43b66e909 100644 --- 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 @@ -23,7 +23,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,17 +43,19 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; - x = uniform( 100, -50.0, 50.0 ); + 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 ( isnan( y ) ) { + if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( y ) ) { + if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); 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 index abfa69d92cc1..6f821d56a81a 100644 --- 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 @@ -16,14 +16,14 @@ * limitations under the License. */ -#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h" +#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h" #include #include #include #include #include -#define NAME "gamma_lanczos_sum_expg_scaled" +#define NAME "gamma_lanczos_sum_expg_scaledf" #define ITERATIONS 1000000 #define REPEATS 3 @@ -79,9 +79,9 @@ static double tic( void ) { * * @return random number */ -static double rand_double( void ) { +static float rand_float( void ) { int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); + return (float)r / ( (float)RAND_MAX + 1.0f ); } /** @@ -91,13 +91,13 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x[ 100 ]; - double y; + float x[ 100 ]; double t; + float y; int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( 100.0 * rand_double() ) - 50.0; + x[ i ] = ( 100.0f*rand_float() ) - 50.0f; } t = tic(); diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_lanczos_approximation.svg b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_lanczos_approximation.svg deleted file mode 100644 index d17a91f6be6f..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_lanczos_approximation.svg +++ /dev/null @@ -1,75 +0,0 @@ - -normal upper Gamma left-parenthesis n right-parenthesis equals StartFraction left-parenthesis n plus g minus 0.5 right-parenthesis Superscript n minus 0.5 Baseline Over e Superscript n plus g minus 0.5 Baseline EndFraction upper L Subscript g Baseline left-parenthesis n right-parenthesis - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_scaled_lanczos_sum.svg b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_scaled_lanczos_sum.svg deleted file mode 100644 index 0fc4d637c9ad..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/docs/img/equation_scaled_lanczos_sum.svg +++ /dev/null @@ -1,32 +0,0 @@ - -upper L Subscript g Baseline left-parenthesis n right-parenthesis dot exp left-parenthesis negative g right-parenthesis - - - \ No newline at end of file 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 index dc62d70eb95e..cba84914ae78 100644 --- 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 @@ -16,11 +16,11 @@ Examples -------- > var y = {{alias}}( 4.0 ) - ~0.018 + ~0.748 > y = {{alias}}( -1.5 ) - ~25.337 + ~0.193 > y = {{alias}}( -0.5 ) - ~-12.911 + ~-0.558 > y = {{alias}}( 0.5 ) ~1.772 > y = {{alias}}( 0.0 ) 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 index bf88af69dbe7..6eff2455a19b 100644 --- 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 @@ -19,22 +19,22 @@ // TypeScript Version: 4.1 /** -* Calculates the Lanczos sum for the approximation of the gamma function (scaled by `exp(-g)` with `g = 10.900511`), as a single-precision floating-point number. +* 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.018 +* // returns ~0.748 * * @example * var v = gammaLanczosSumExpGScaledf( -1.5 ); -* // returns ~25.337 +* // returns ~0.193 * * @example * var v = gammaLanczosSumExpGScaledf( -0.5 ); -* // returns ~-12.911 +* // returns ~-0.558 * * @example * var v = gammaLanczosSumExpGScaledf( 0.5 ); 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 index 27b766b89b63..c8a1d88b2e0d 100644 --- 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 @@ -16,16 +16,16 @@ * limitations under the License. */ -#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaled.h" +#include "stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h" #include int main( void ) { - const double x[] = { 4.0, -1.5, -0.5, 0.5 }; + const float x[] = { 4.0f, -1.5f, -0.5f, 0.5f }; - double y; + 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_scaled(%lf) = %lf\n", x[ i ], y ); + 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 index 0c17fb398dcf..d0c10b2a7192 100644 --- 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 @@ -23,7 +23,7 @@ var logEachMap = require( '@stdlib/console/log-each-map' ); var gammaLanczosSumExpGScaledf = require( './../lib' ); var opts = { - 'dtype': 'float64' + 'dtype': 'float32' }; var x = uniform( 100, -10.0, 10.0, opts ); diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/include/stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/include/stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h index 394cba12f281..537a3d2247e4 100644 --- a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/include/stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/include/stdlib/math/base/special/gamma_lanczos_sum_expg_scaledf.h @@ -27,7 +27,7 @@ extern "C" { #endif /** -* Calculates the Lanczos sum for the approximation of the gamma function (scaled by `exp(-g)` with `g = 10.900511`), as a single-precision floating-point number. +* 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. */ float stdlib_base_gamma_lanczos_sum_expg_scaledf( const float x ); diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/index.js index 826261539248..148326e7fe73 100644 --- a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/index.js @@ -19,21 +19,21 @@ 'use strict'; /** -* Calculate the Lanczos sum for the approximation of the gamma function (scaled by `exp(-g)` with `g = 10.900511`), as a single-precision floating-point number. +* Calculate 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. * -* @module @stdlib/math/base/special/gamma-lanczos-sum-expg-scaled +* @module @stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf * * @example -* var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled' ); +* var gammaLanczosSumExpGScaledf = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf' ); * * var v = gammaLanczosSumExpGScaledf( 4.0 ); -* // returns ~0.018 +* // returns ~0.748 * * v = gammaLanczosSumExpGScaledf( -1.5 ); -* // returns ~25.337 +* // returns ~0.193 * * v = gammaLanczosSumExpGScaledf( -0.5 ); -* // returns ~-12.911 +* // returns ~-0.558 * * v = gammaLanczosSumExpGScaledf( 0.5 ); * // returns ~1.772 diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/main.js index c36449eccbb9..74b8ea8a8a53 100644 --- a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/main.js @@ -33,29 +33,29 @@ // MODULES // -var evalrational = require( './rational_pq.js' ); var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var evalrational = require( './rational_pq.js' ); // MAIN // /** -* Calculates the Lanczos sum for the approximation of the gamma function (scaled by `exp(-g)` with `g = 10.900511`), as a single-precision floating-point number. +* 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 {number} x - input value * @returns {number} Lanczos sum approximation * * @example * var v = gammaLanczosSumExpGScaledf( 4.0 ); -* // returns ~0.018 +* // returns ~0.748 * * @example * var v = gammaLanczosSumExpGScaledf( -1.5 ); -* // returns ~25.337 +* // returns ~0.193 * * @example * var v = gammaLanczosSumExpGScaledf( -0.5 ); -* // returns ~-12.911 +* // returns ~-0.558 * * @example * var v = gammaLanczosSumExpGScaledf( 0.5 ); @@ -70,7 +70,7 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); * // returns NaN */ function gammaLanczosSumExpGScaledf( x ) { - return f32( evalrational( f32( x ) ) ); + return evalrational( f32( x ) ); } diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/native.js index b59b08e2b7a2..b9e84c20fdbf 100644 --- a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Calculates the Lanczos sum for the approximation of the gamma function (scaled by `exp(-g)` with `g = 10.900511`), as a single-precision floating-point number. +* 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. * * @private * @param {number} x - input value @@ -34,15 +34,15 @@ var addon = require( './../src/addon.node' ); * * @example * var v = gammaLanczosSumExpGScaledf( 4.0 ); -* // returns ~0.018 +* // returns ~0.748 * * @example * var v = gammaLanczosSumExpGScaledf( -1.5 ); -* // returns ~25.337 +* // returns ~0.193 * * @example * var v = gammaLanczosSumExpGScaledf( -0.5 ); -* // returns ~-12.911 +* // returns ~-0.558 * * @example * var v = gammaLanczosSumExpGScaledf( 0.5 ); diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/rational_pq.js b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/rational_pq.js index 4c374af42d63..116fd87dc00d 100644 --- a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/rational_pq.js +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/lib/rational_pq.js @@ -19,6 +19,11 @@ /* This is a generated file. Do not edit directly. */ 'use strict'; +// MODULES // + +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); + + // MAIN // /** @@ -48,14 +53,14 @@ function evalrational( x ) { ax = x; } if ( ax <= 1.0 ) { - s1 = 32.81244541029783 + (x * (32.12388941444332 + (x * (12.580347294552162 + (x * (2.4634444783532414 + (x * (0.24120105482588003 + (x * 0.009446967704539249))))))))); // eslint-disable-line max-len - s2 = 0.0 + (x * (24.0 + (x * (50.0 + (x * (35.0 + (x * (10.0 + (x * 1.0))))))))); // eslint-disable-line max-len + s1 = float64ToFloat32(14.026143074035645 + float64ToFloat32(x * float64ToFloat32(43.7473258972168 + float64ToFloat32(x * float64ToFloat32(50.59547424316406 + float64ToFloat32(x * float64ToFloat32(26.90456771850586 + float64ToFloat32(x * float64ToFloat32(6.595765590667725 + float64ToFloat32(x * 0.6007853746414185)))))))))); // eslint-disable-line max-len + s2 = float64ToFloat32(0.0 + float64ToFloat32(x * float64ToFloat32(24.0 + float64ToFloat32(x * float64ToFloat32(50.0 + float64ToFloat32(x * float64ToFloat32(35.0 + float64ToFloat32(x * float64ToFloat32(10.0 + float64ToFloat32(x * 1.0)))))))))); // eslint-disable-line max-len } else { - x = 1.0 / x; - s1 = 0.009446967704539249 + (x * (0.24120105482588003 + (x * (2.4634444783532414 + (x * (12.580347294552162 + (x * (32.12388941444332 + (x * 32.81244541029783))))))))); // eslint-disable-line max-len - s2 = 1.0 + (x * (10.0 + (x * (35.0 + (x * (50.0 + (x * (24.0 + (x * 0.0))))))))); // eslint-disable-line max-len + x = float64ToFloat32( 1.0 / x ); + s1 = float64ToFloat32(0.6007853746414185 + float64ToFloat32(x * float64ToFloat32(6.595765590667725 + float64ToFloat32(x * float64ToFloat32(26.90456771850586 + float64ToFloat32(x * float64ToFloat32(50.59547424316406 + float64ToFloat32(x * float64ToFloat32(43.7473258972168 + float64ToFloat32(x * 14.026143074035645)))))))))); // eslint-disable-line max-len + s2 = float64ToFloat32(1.0 + float64ToFloat32(x * float64ToFloat32(10.0 + float64ToFloat32(x * float64ToFloat32(35.0 + float64ToFloat32(x * float64ToFloat32(50.0 + float64ToFloat32(x * float64ToFloat32(24.0 + float64ToFloat32(x * 0.0)))))))))); // eslint-disable-line max-len } - return s1 / s2; + return float64ToFloat32( s1 / s2 ); } diff --git a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/package.json b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/package.json index 32c5e304d222..85399e2e56ab 100644 --- a/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/package.json +++ b/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/math/base/special/gamma-lanczos-sum-expg-scaledf", "version": "0.0.0", - "description": "Calculate a scaled Lanczos sum for the approximation of the gamma function.", + "description": "Calculate a scaled Lanczos sum for the approximation of the gamma function as a single precision floating-point number.", "license": "Apache-2.0 AND BSL-1.0", "author": { "name": "The Stdlib Authors", 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 index e35e80f154d7..216a5dcb4b48 100644 --- 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 @@ -39,12 +39,12 @@ var format = require( '@stdlib/string/format' ); // Polynomial coefficients ordered in ascending degree... var P = [ - 32.81244541029783471623665933780748627823, - 32.12388941444332003446077108933558534361, - 12.58034729455216106950851080138931470954, - 2.463444478353241423633780693218408889251, - 0.2412010548258800231126240760264822486599, - 0.009446967704539249494420221613134244048319 + 14.0261432874996476619570577285003839357, + 43.74732405540314316089531289293124360129, + 50.59547402616588964511581430025589038612, + 26.90456680562548195593733429204228910299, + 6.595765571169314946316366571954421695196, + 0.6007854010515290065101128585795542383721 ]; var Q = [ 0.0, @@ -109,7 +109,9 @@ function main() { }; fpath = resolve( __dirname, '..', 'lib', 'rational_pq.js' ); - str = header + compile( P, Q ); + str = header + compile( P, Q, { + 'dtype': 'float32' + }); writeFileSync( fpath, str, opts ); copts = { 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 index bc6e05261ba1..fbb42af9300d 100644 --- 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 @@ -60,11 +60,11 @@ static float rational_pq( const float x ) { ax = x; } if ( ax <= 1.0f ) { - s1 = 32.81244541029783f + (x * (32.12388941444332f + (x * (12.580347294552162f + (x * (2.4634444783532414f + (x * (0.24120105482588003f + (x * 0.009446967704539249f))))))))); + 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.009446967704539249f + (ix * (0.24120105482588003f + (ix * (2.4634444783532414f + (ix * (12.580347294552162f + (ix * (32.12388941444332f + (ix * 32.81244541029783f))))))))); + 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; @@ -73,14 +73,14 @@ static float rational_pq( const float x ) { // END: rational_pq /** -* Calculates the Lanczos sum for the approximation of the gamma function (scaled by `exp(-g)` with `g = 10.900511`), as a single-precision floating-point number. +* 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.018f +* // 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 index 6dad8c10533b..37f8ad70e1bf 100644 --- 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 @@ -47,7 +47,7 @@ tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { t.end(); }); -tape.only( 'the function evaluates the Lanczos sum (scaled by exp(-g))', function test( t ) { +tape( 'the function evaluates the Lanczos sum (scaled by exp(-g))', function test( t ) { var expected; var delta; var tol; @@ -58,6 +58,8 @@ tape.only( 'the function evaluates the Lanczos sum (scaled by exp(-g))', functio 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 ); @@ -66,7 +68,7 @@ tape.only( 'the function evaluates the Lanczos sum (scaled by exp(-g))', functio t.strictEqual( y, expected, 'returns expected value' ); } else { delta = absf( y - expected ); - tol = 10.0 * EPS * absf( expected ); + tol = 2.0 * EPS * absf( expected ); t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); } } 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 index 190d723bf28e..0eef2968d40a 100644 --- 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 @@ -23,11 +23,12 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var linspace = require( '@stdlib/array/base/linspace' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +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' ); @@ -51,7 +52,7 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) { var v = gammaLanczosSumExpGScaledf( NaN ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -66,16 +67,17 @@ tape( 'the function evaluates the Lanczos sum (scaled by exp(-g))', opts, functi x = linspace( 1.0, 100.0, 500 ); for ( i = 0; i < x.length; i++ ) { y = gammaLanczosSumExpGScaledf( x[ i ] ); - expected = gamma( x[ i ] ); - // eslint-disable-next-line max-len - expected /= pow( x[ i ] + G - 0.5, x[ i ] - 0.5 ) / ( exp( x[ i ] + G - 0.5 ) ); + // 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 = 10.0 * EPS * absf( expected ); + tol = 2.0 * EPS * absf( expected ); t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol ); } } From bf3fa26259b9f611cc64bb8550163e7efd6668a5 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 10 Jun 2025 20:17:32 -0700 Subject: [PATCH 3/3] bench: use `random_uniform` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark/c/native/benchmark.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 index 6f821d56a81a..d16061d3a9ea 100644 --- 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 @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); } /** @@ -97,7 +99,7 @@ static double benchmark( void ) { int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( 100.0f*rand_float() ) - 50.0f; + x[ i ] = random_uniform( -50.0f, 50.0f ); } t = tic();