diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/README.md b/lib/node_modules/@stdlib/math/base/special/binomcoeff/README.md new file mode 100644 index 000000000000..75c7849c6ae8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/README.md @@ -0,0 +1,238 @@ + + +# Binomial Coefficient + +> Compute the [binomial coefficient][binomial-coefficient] as a single-precision floating-point number. + +
+ +The [binomial coefficient][binomial-coefficient] of two nonnegative integers `n` and `k` is defined as + + + +```math +\binom {n}{k} = \frac{n!}{k!\,(n-k)!} \quad \text{for }\ 0\leq k\leq n +``` + + + +The [binomial coefficient][binomial-coefficient] can be generalized to negative integers `n` as follows: + + + +```math +\binom {-n}{k} = (-1)^{k} \binom{n + k - 1}{k} = (-1)^{k} \left(\!\!{\binom {n}{k}}\!\!\right) +``` + + + +
+ + + +
+ +## Usage + +```javascript +var binomcoeff = require( '@stdlib/math/base/special/binomcoeff' ); +``` + +#### binomcoeff( n, k ) + +Evaluates the [binomial coefficient][binomial-coefficient] of two integers `n` and `k` as a single-precision floating-point number. + +```javascript +var v = binomcoeff( 8, 2 ); +// returns 28 + +v = binomcoeff( 0, 0 ); +// returns 1 + +v = binomcoeff( -4, 2 ); +// returns 10 + +v = binomcoeff( 5, 3 ); +// returns 10 + +v = binomcoeff( NaN, 3 ); +// returns NaN + +v = binomcoeff( 5, NaN ); +// returns NaN + +v = binomcoeff( NaN, NaN ); +// returns NaN +``` + +For negative `k`, the function returns `0`. + +```javascript +var v = binomcoeff( 2, -1 ); +// returns 0 + +v = binomcoeff( -3, -1 ); +// returns 0 +``` + +The function returns `NaN` for non-integer `n` or `k`. + +```javascript +var v = binomcoeff( 2, 1.5 ); +// returns NaN + +v = binomcoeff( 5.5, 2 ); +// returns NaN +``` + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var binomcoeff = require( '@stdlib/math/base/special/binomcoeff' ); + +var opts = { + 'dtype': 'int32' +}; +var n = discreteUniform( 100, -10, 30, opts ); +var k = discreteUniform( 100, 0, 20, opts ); + +logEachMap( 'binomcoeff(%d,%d) = %0.4f', n, k, binomcoeff ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/binomcoeff.h" +``` + +#### stdlib_base_binomcoeff( n, k ) + +Evaluates the [binomial coefficient][binomial-coefficient] of two integers `n` and `k` as a single-precision floating-point number. + +```c +float v = stdlib_base_binomcoeff( 8, 2 ); +// returns 28.0f +``` + +The function accepts the following arguments: + +- **n**: `[in] int32_t` input value. +- **k**: `[in] int32_t` input value. + +```c +float stdlib_base_binomcoeff( const int32_t n, const int32_t k ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/binomcoeff.h" +#include +#include + +int main( void ) { + const int32_t a[] = { 24, 32, 48, 116, 33 }; + const int32_t b[] = { 12, 6, 15, 52, 22 }; + + float out; + int i; + for ( i = 0; i < 5; i++ ) { + out = stdlib_base_binomcoeff( a[ i ], b[ i ] ); + printf( "binomcoeff(%d, %d) = %f\n", a[ i ], b[ i ], out ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/benchmark.js new file mode 100644 index 000000000000..f453e9a32e03 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/benchmark.js @@ -0,0 +1,58 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pkg = require( './../package.json' ).name; +var binomcoeff = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var opts; + var x; + var y; + var z; + var i; + + opts = { + 'dtype': 'int32' + }; + x = discreteUniform( 100, 20, 70, opts ); + y = discreteUniform( 100, 0, 20, opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = binomcoeff( x[ i%x.length ], y[ i%y.length ] ); + if ( isnanf( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/benchmark.native.js new file mode 100644 index 000000000000..9c1ed0f62f32 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/benchmark.native.js @@ -0,0 +1,67 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var binomcoeff = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( binomcoeff instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var options; + var x; + var y; + var z; + var i; + + options = { + 'dtype': 'int32' + }; + x = discreteUniform( 100, 20, 70, options ); + y = discreteUniform( 100, 0, 20, options ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = binomcoeff( x[ i%x.length ], y[ i%y.length ] ); + if ( isnanf( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..05b52c909835 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/native/benchmark.c @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/binomcoeff.h" +#include +#include +#include +#include +#include + +#define NAME "binomcoeff" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + int32_t n[ 100 ]; + int32_t k[ 100 ]; + double elapsed; + double t; + float y; + int i; + + for ( i = 0; i < 100; i++ ) { + n[ i ] = (int32_t)round( 100.0 * rand_float() ); + k[ i ] = (int32_t)round( 100.0 * rand_float() ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_binomcoeff( n[ i%100 ], k[ 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/binomcoeff/benchmark/cpp/boost/Makefile b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/cpp/boost/Makefile new file mode 100644 index 000000000000..3d019faff834 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/cpp/boost/Makefile @@ -0,0 +1,110 @@ +#/ +# @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 := @ +endif + +# Specify the path to Boost: +BOOST ?= + +# Determine the OS: +# +# [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 +endif +endif +endif + +# Define the program used for compiling C++ source files: +ifdef CXX_COMPILER + CXX := $(CXX_COMPILER) +else + CXX := g++ +endif + +# Define the command-line options when compiling C++ files: +CXXFLAGS ?= \ + -std=c++11 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate [position independent code][1]: +# +# [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 C++ targets: +cxx_targets := benchmark.out + + +# TARGETS # + +# Default target. +# +# This target is the default target. + +all: $(cxx_targets) + +.PHONY: all + + +# Compile C++ source. +# +# This target compiles C++ source files. + +$(cxx_targets): %.out: %.cpp $(BOOST) + $(QUIET) $(CXX) $(CXXFLAGS) $(fPIC) -I $(BOOST) -o $@ $< -lm + + +# Run a benchmark. +# +# This target runs a benchmark. + +run: $(cxx_targets) + $(QUIET) ./$< + +.PHONY: run + + +# Perform clean-up. +# +# This target removes generated files. + +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/cpp/boost/benchmark.cpp b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/cpp/boost/benchmark.cpp new file mode 100644 index 000000000000..ec377b6dc981 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/cpp/boost/benchmark.cpp @@ -0,0 +1,135 @@ +/** +* @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 +#include +#include +#include +#include +#include +#include +#include + +using boost::random::uniform_real_distribution; +using boost::random::mt19937; + +#define NAME "binomcoeff" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +void print_version() { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +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 +*/ +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 +*/ +double tic() { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +double benchmark() { + double elapsed; + double t; + float x; + float y; + float z; + int i; + + // Define a new pseudorandom number generator: + mt19937 rng; + + // Define a uniform distribution for generating pseudorandom numbers as "floats" between a minimum value (inclusive) and a maximum value (exclusive): + uniform_real_distribution<> randu1( 20.0f, 70.0f ); + uniform_real_distribution<> randu2( 0.0f, 20.0f ); + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = (int)randu1( rng ); + y = (int)randu2( rng ); + z = boost::math::binomial_coefficient( x, y ); + if ( z != z ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( z != z ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# cpp::boost::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); + return 0; +} diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/binding.gyp b/lib/node_modules/@stdlib/math/base/special/binomcoeff/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/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/binomcoeff/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/repl.txt new file mode 100644 index 000000000000..5b469c58f5d2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/repl.txt @@ -0,0 +1,42 @@ + +{{alias}}( n, k ) + Computes the binomial coefficient of two integers as a single-precision + floating-point number. + + If `k < 0`, the function returns `0`. + + The function returns `NaN` for non-integer `n` or `k`. + + Parameters + ---------- + n: integer + First input value. + + k: integer + Second input value. + + Returns + ------- + out: number + Function value. + + Examples + -------- + > var v = {{alias}}( 8, 2 ) + 28 + > v = {{alias}}( 0, 0 ) + 1 + > v = {{alias}}( -4, 2 ) + 10 + > v = {{alias}}( 5, 3 ) + 10 + > v = {{alias}}( NaN, 3 ) + NaN + > v = {{alias}}( 5, NaN ) + NaN + > v = {{alias}}( NaN, NaN ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/types/index.d.ts new file mode 100644 index 000000000000..acefd7cb67c5 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/types/index.d.ts @@ -0,0 +1,57 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Computes the binomial coefficient of two integers as a single-precision floating-point number. +* +* @param n - input value +* @param k - second input value +* @returns function value +* +* @example +* var v = binomcoeff( 8, 2 ); +* // returns 28 +* +* @example +* var v = binomcoeff( 0, 0 ); +* // returns 1 +* +* @example +* var v = binomcoeff( -4, 2 ); +* // returns 10 +* +* @example +* var v = binomcoeff( NaN, 3 ); +* // returns NaN +* +* @example +* var v = binomcoeff( 5, NaN ); +* // returns NaN +* +* @example +* var v = binomcoeff( NaN, NaN ); +* // returns NaN +*/ +declare function binomcoeff( n: number, k: number ): number; + + +// EXPORTS // + +export = binomcoeff; diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/types/test.ts new file mode 100644 index 000000000000..8ee694d3c4cb --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/types/test.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. +*/ + +import binomcoeff = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + binomcoeff( 8, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + binomcoeff( true, 3 ); // $ExpectError + binomcoeff( false, 2 ); // $ExpectError + binomcoeff( '5', 1 ); // $ExpectError + binomcoeff( [], 1 ); // $ExpectError + binomcoeff( {}, 2 ); // $ExpectError + binomcoeff( ( x: number ): number => x, 2 ); // $ExpectError + + binomcoeff( 9, true ); // $ExpectError + binomcoeff( 9, false ); // $ExpectError + binomcoeff( 5, '5' ); // $ExpectError + binomcoeff( 8, [] ); // $ExpectError + binomcoeff( 9, {} ); // $ExpectError + binomcoeff( 8, ( x: number ): number => x ); // $ExpectError + + binomcoeff( [], true ); // $ExpectError + binomcoeff( {}, false ); // $ExpectError + binomcoeff( false, '5' ); // $ExpectError + binomcoeff( {}, [] ); // $ExpectError + binomcoeff( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + binomcoeff(); // $ExpectError + binomcoeff( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/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/binomcoeff/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/example.c new file mode 100644 index 000000000000..9e866aa64bc7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/example.c @@ -0,0 +1,33 @@ +/** +* @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/binomcoeff.h" +#include +#include + +int main( void ) { + const int32_t a[] = { 24, 32, 48, 116, 33 }; + const int32_t b[] = { 12, 6, 15, 52, 22 }; + + float out; + int i; + for ( i = 0; i < 5; i++ ) { + out = stdlib_base_binomcoeff( a[ i ], b[ i ] ); + printf( "binomcoeff(%d, %d) = %f\n", a[ i ], b[ i ], out ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/index.js b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/index.js new file mode 100644 index 000000000000..dd23af7a7f7b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/index.js @@ -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. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var binomcoeff = require( './../lib' ); + +var opts = { + 'dtype': 'int32' +}; +var n = discreteUniform( 100, -10, 30, opts ); +var k = discreteUniform( 100, 0, 20, opts ); + +logEachMap( 'binomcoeff(%d,%d) = %0.4f', n, k, binomcoeff ); diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/include.gypi b/lib/node_modules/@stdlib/math/base/special/binomcoeff/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/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': [ + ' + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Computes the binomial coefficient of two integers as a single-precision floating-point number. +*/ +float stdlib_base_binomcoeff( const int32_t n, const int32_t k ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_BINOMCOEFF_H diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/index.js b/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/index.js new file mode 100644 index 000000000000..4eb5a0e5878a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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'; + +/** +* Compute the binomial coefficient as a single-precision floating-point number. +* +* @module @stdlib/math/base/special/binomcoeff +* +* @example +* var binomcoeff = require( '@stdlib/math/base/special/binomcoeff' ); +* +* var v = binomcoeff( 8, 2 ); +* // returns 28 +* +* v = binomcoeff( 0, 0 ); +* // returns 1 +* +* v = binomcoeff( -4, 2 ); +* // returns 10 +* +* v = binomcoeff( 5, 3 ); +* // returns 10 +* +* v = binomcoeff( NaN, 3 ); +* // returns NaN +* +* v = binomcoeff( 5, NaN ); +* // returns NaN +* +* v = binomcoeff( NaN, NaN ); +* // returns NaN +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/main.js b/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/main.js new file mode 100644 index 000000000000..dd1acf0e1ef8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/main.js @@ -0,0 +1,157 @@ +/** +* @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 MAX_SAFE_INTEGER = require( '@stdlib/constants/float32/max-safe-integer' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var isIntegerf = require( '@stdlib/math/base/assert/is-integer' ); +var isnanf = require( '@stdlib/math/base/assert/is-nan' ); +var isOddf = require( '@stdlib/math/base/assert/is-odd' ); +var floorf = require( '@stdlib/math/base/special/floorf' ); +var gcdf = require( '@stdlib/math/base/special/gcdf' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// MAIN // + +/** +* Computes the binomial coefficient of two integers as a single-precision floating-point number. +* +* @param {integer} n - input value +* @param {integer} k - second input value +* @returns {integer} function value +* +* @example +* var v = binomcoeff( 8, 2 ); +* // returns 28 +* +* @example +* var v = binomcoeff( 0, 0 ); +* // returns 1 +* +* @example +* var v = binomcoeff( -4, 2 ); +* // returns 10 +* +* @example +* var v = binomcoeff( NaN, 3 ); +* // returns NaN +* +* @example +* var v = binomcoeff( 5, NaN ); +* // returns NaN +* +* @example +* var v = binomcoeff( NaN, NaN ); +* // returns NaN +*/ +function binomcoeff( n, k ) { + var res; + var sgn; + var b; + var c; + var d; + var g; + var s; + if ( isnanf( n ) || isnanf( k ) ) { + return NaN; + } + if ( !isIntegerf( n ) || !isIntegerf( k ) ) { + return NaN; + } + if ( k < 0 ) { + return float64ToFloat32( 0.0 ); + } + sgn = float64ToFloat32( 1.0 ); + if ( n < 0 ) { + n = -n + k - 1; + if ( isOddf( k ) ) { + sgn *= float64ToFloat32( -1.0 ); + } + } + if ( k > n ) { + return float64ToFloat32( 0.0 ); + } + if ( k === 0 || k === n ) { + return float64ToFloat32( sgn ); + } + if ( k === 1 || k === n - 1 ) { + return float64ToFloat32( float64ToFloat32(sgn) * float64ToFloat32(n) ); + } + // Minimize the number of computed terms by leveraging symmetry: + if ( n - k < k ) { + k = n - k; + } + s = floorf( MAX_SAFE_INTEGER / n ); + + // Use a standard algorithm for computing the binomial coefficient (e.g., see Knuth's "The Art of Computer Programming, 3rd Edition, Volume 2: Seminumerical Algorithms")... + res = float64ToFloat32( 1.0 ); + for ( d = 1; d <= k; d++ ) { + // Check for potential overflow... + if ( res > s ) { + break; + } + res *= float64ToFloat32( n ); + res /= float64ToFloat32( d ); + n -= 1; + } + // If we did not early exit from the previous loop, the answer is exact, and we can simply return... + if ( d > k ) { + return float64ToFloat32( float64ToFloat32(sgn) * float64ToFloat32(res) ); + } + /* + * Let `N` equal the provided `n`. + * + * We want to calculate C(N,k), and, at this point, we have calculated + * + * res = C(N,n) = C(N,N-n) = C(N,d-1) + * + * where `N-n = d-1` and, hence, `n = N - d + 1`. + * + * Given the following identity, + * + * C(N,k) = C(N,d-1) * C(N-d+1,k-d+1) / C(k,k-d+1) + * = C(N,d-1) * C(n,k-d+1) / C(k,k-d+1) + * + * we can leverage recursion to perform argument reduction. + */ + b = binomcoeff( n, k-d+1 ); + if ( b === PINF ) { + return float64ToFloat32( float64ToFloat32(sgn) * float64ToFloat32(b) ); + } + c = binomcoeff( k, k-d+1 ); + + /* + * At this point, the result should be `res*b/c`. + * + * To help guard against overflow and precision loss, we calculate the greatest common divisor (gcdf). In this case, we pick `b`, as `b` should be less than `res` in most (if not all) cases. + */ + g = gcdf( b, c ); + b /= g; + c /= g; + res /= c; + return float64ToFloat32( float64ToFloat32(sgn) * float64ToFloat32(res) * float64ToFloat32(b) ); +} + + +// EXPORTS // + +module.exports = binomcoeff; diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/native.js b/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/native.js new file mode 100644 index 000000000000..486ccf14613a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/native.js @@ -0,0 +1,55 @@ +/** +* @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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes the binomial coefficient of two integers as a single-precision floating-point number. +* +* @private +* @param {integer} n - input value +* @param {integer} k - second input value +* @returns {number} function value +* +* @example +* var v = binomcoeff( 8, 2 ); +* // returns 28.0 +* +* @example +* var v = binomcoeff( 0, 0 ); +* // returns 1.0 +* +* @example +* var v = binomcoeff( -4, 2 ); +* // returns 10.0 +*/ +function binomcoeff( n, k ) { + return addon( n, k ); +} + + +// EXPORTS // + +module.exports = binomcoeff; diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/manifest.json b/lib/node_modules/@stdlib/math/base/special/binomcoeff/manifest.json new file mode 100644 index 000000000000..3bc22b3e354a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/manifest.json @@ -0,0 +1,87 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/binary", + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/gcdf", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/max-safe-integer" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/gcdf", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/max-safe-integer" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/floorf", + "@stdlib/math/base/special/gcdf", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/max-safe-integer" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/package.json b/lib/node_modules/@stdlib/math/base/special/binomcoeff/package.json new file mode 100644 index 000000000000..43bbcf77b28d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/math/base/special/binomcoeff", + "version": "0.0.0", + "description": "Compute the binomial coefficient as a single-precision floating-point number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "special functions", + "special", + "function", + "binomial", + "combinatorics", + "choose", + "factorial", + "fact", + "integer", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/Makefile b/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/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/binomcoeff/src/addon.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/addon.c new file mode 100644 index 000000000000..c00c46f7ddbc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/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/binomcoeff.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_II_F( stdlib_base_binomcoeff ) diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/main.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/main.c new file mode 100644 index 000000000000..755e115e1698 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/src/main.c @@ -0,0 +1,126 @@ +/** +* @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/binomcoeff.h" +#include "stdlib/math/base/special/floorf.h" +#include "stdlib/math/base/special/gcdf.h" +#include "stdlib/constants/float32/pinf.h" +#include "stdlib/constants/float32/max_safe_integer.h" +#include + +/** +* Computes the binomial coefficient of two integers as a single-precision floating-point number. +* +* @param n input value +* @param k second input value +* @return function value +* +* @example +* float out = stdlib_base_binomcoeff( 8, 2 ); +* // returns 28.0f +*/ +float stdlib_base_binomcoeff( const int32_t n, const int32_t k ) { + int32_t nc; + int32_t kc; + int32_t d; + float res; + float sgn; + float b; + float c; + float g; + float s; + + if ( k < 0 ) { + return 0.0f; + } + sgn = 1.0f; + nc = n; + if ( nc < 0 ) { + nc = -nc + k - 1; + if ( k & 1 ) { + sgn *= -1.0f; + } + } + if ( k > nc ) { + return 0.0f; + } + if ( k == 0 || k == nc ) { + return sgn; + } + if ( k == 1 || k == nc - 1 ) { + return sgn * (float)nc; + } + + // Minimize the number of computed terms by leveraging symmetry: + kc = k; + if ( nc - kc < kc ) { + kc = nc - kc; + } + s = stdlib_base_floorf( (float)STDLIB_CONSTANT_FLOAT32_MAX_SAFE_INTEGER / (float)nc ); + + // Use a standard algorithm for computing the binomial coefficient + res = 1.0f; + for ( d = 1; d <= kc; d++ ) { + // Check for potential overflow... + if ( res > s ) { + break; + } + res *= (float)nc; + res /= (float)d; + nc -= 1; + } + + // If we did not early exit from the previous loop, the answer is exact, and we can simply return... + if ( d > kc ) { + return sgn * res; + } + + /* + * Let `N` equal the provided `n`. + * + * We want to calculate C(N,k), and, at this point, we have calculated + * + * res = C(N,n) = C(N,N-n) = C(N,d-1) + * + * where `N-n = d-1` and, hence, `n = N - d + 1`. + * + * Given the following identity, + * + * C(N,k) = C(N,d-1) * C(N-d+1,k-d+1) / C(k,k-d+1) + * = C(N,d-1) * C(n,k-d+1) / C(k,k-d+1) + * + * we can leverage recursion to perform argument reduction. + */ + b = stdlib_base_binomcoeff( nc, kc-d+1 ); + if ( b == STDLIB_CONSTANT_FLOAT32_PINF ) { + return sgn * b; + } + c = stdlib_base_binomcoeff( kc, kc-d+1 ) ; + + /* + * At this point, the result should be `res*b/c`. + * + * To help guard against overflow and precision loss, we calculate the greatest common divisor (gcd). In this case, we pick `b`, as `b` should be less than `res` in most (if not all) cases. + */ + g = stdlib_base_gcdf( b, c ); + b /= g; + c /= g; + res /= c; + + return sgn * res * b; +} diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..308c3be89c85 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/REQUIRE @@ -0,0 +1,2 @@ +julia 1.5 +JSON 0.21 diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/integers.json b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/integers.json new file mode 100644 index 000000000000..85a086436be4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/integers.json @@ -0,0 +1 @@ +{"expected":[1652411475,3247943160,20358520,183649923622620,636983969321700,5743572120,18009460,720720,443643407165376,55,17620076360,4537567650,4845,1391975640,6250347750920,888030,1081575,231,23,98280,2349060,77413632286320,84672315,1040465790,10015005,50063860,3654,99884400,32,4292145,25827165,52,1326,1,595665,23535820,566877686933536,630,6906900,158753389900,1330,114955808528,962598,115631859759041340,40116600,17296,1326,20160075,8815083648488,14844575908435,7898654920,12341,4426165368,387221678682300,54627300,47905,253,62,1330,608359048206,4923689695575,5456,648045936942300,51895935,449972009097765,82598880,1852482996,45057474,31465,28048800,55525372,202802465047245,3188675231420,7726160,245157,123410,566877686933536,2118760,886322710,707285522580,4495151581425648,8347680,1,4686825,166871334960,565722720,630,648045936942300,43183019880,67863915,1040465790,342700125300,54,86493225,207374699821536,1370754,3796297200,23751,57963796707857040,103077446706,125994627894135,290752384208,657800,70539987842520,47,50116,25,38910617655,22512762077400,230230,9657700,4481381406320,1035,8654327655120,6236646703759395,74613,16421073515280,10295472,18009460,5047381560,739632519584070,1849081298960175,14844575908435,386206920,37442160,608359048206,16253249498640,134596,5047381560,244662670200,20448884000160,47,647520696018735,8936928,6107086800,201376,266783135710,73006209045,77558760,290752384208,891794789340,61,3108105,5166863427600,2558620845,206253075,10468434365991,4059928950,86493225,344867425584,59,2515943049305400,4187106,4537567650,140676848445,343006888770,346104,1947792,960566918220,20058300,118755,2818953098830,3679075400,265182525,16253249498640,2558620845,1420494075,707285522580,23196134763125940,116280,5996962277488,4496388,35240152720,231,5166863427600,25518731280,646646,1917334783,1275,101766230790,118030185,1275,886322710,10272278170,696190560,18424,891794789340,63,6096454,1166803110,30856,42757703560,25371763481680,20,9847379391150,145422675,5317936260,202802465047245,3679075400,135751,300540195,1761039350070,100947,21090682613,5200300,341149446,1,720720,20058300,39,28048800,10468434365991,487635,1503232609098,115631859759041340,2054455634,34597290,354860518600,501942,630,4686825,101766230790,635013559600,2080,4582116,471435600,424655979547800,1012974972473835,5047381560,253,265182525,123410,1540,3245372870670,12565671261,8145060,8996462475,3268760,6566222272575,814385,141120525,7877932561061640,2600,2925,69,601080390,268367258592576,1184040,2346,7898654920,192928249296,1676056044,435,60403728840,201376,80730,2448296039700,352716,260932815,2278,2118760,2869685,292825,8122425444,26235,818809200,903,211876,1676056044,8122425444,1771,2515943049305400,780,739632519584070,1,1,2203961430,3910797436,145422675,5200300,11058116888,94143280,20,1,50,35607051480,38320568,3124550,13983816,12565671261,4495,91390,2042975,38910617655,888030,296010,177100,49,30045015,134596,472733756,8122425444,8436285,342700125300,37711260990,23535820,13340783196,1312251244423350,7140,4922879481520,51915526432,508271323092,601080390,14950,1210269541711230,1420494075,119877472,92263734836,354860518600,33649,2042975,1344904,1,1540,1391975640,5586853480,19600,4353548972850,2349060,51,70539987842520,1275,77535155627160,1081,265182525,345780890878896,32509,7877932561061640,32308782859535,14844575908435,141120525,6724520,54627300,2203961430,991493848554,12271512,45760,42504,6096454,6358402050,42671977361650,27,20058300,14950,42504,19600,5743572120,536878650,203490,1503232609098,68923264410,1,1560780,4582116,5567902560,5586853480,99795696,280576272201225,300674088,9657648,135751,9657648,445891810,1081,100947,1560780,12271512,3910797436,42671977361650,62359143990,54627300,36576848168,54627300,472733756,720720,314457495,1307504,133784560,435,1081575,24,52360,94143280,969443904,17672631900,7307872110,7392009768,903,12271512,501942,5852925,52251400851,113380261800,154603005527328,5166863427600,113380261800,482320623240,47,98672427616,38567100,2054455634,15180,231,9762479679106,265182149218,1,17620076360,2319959400,292825,387221678682300,2760681,487635,11899700525790,30405943383200,69,197548686920970,51895935,52394,1040465790,927983760,40,113380261800,1370754,418094152866,17672631900,666,94143280,119877472,445891810,38608020,1855967520,4292145,341055,511738760544,696190560,39895566894540,13037895,35990,2211,18053528883775,2403979904200,4686825,95548245,3371363686069236,1144066,1140,1961256,17417133617,10150595910,76223753060,5985,25140840660,265182525,10142940735900,6358402050,350343565,751616304549,2741188875414,167960,13983816,46376,1469568786235308,67945521,10737573,37,18009460,1330,48,280576272201225,1,707285522580,2145,42504,10626,193536720,4280561376,215553195,20030010,1,1420494075,946,2217471399,3124550,158753389900,86493225,43,1078897248,1292706174900,20058300,62828356305,2869685,850668,17417133617,22957480,749398,4280561376,133784560,1040465790,563921995,1770,210,244662670200,472733756,145422675,23535820,5567902560,630,26334,22239974430,3838380,1476337800,12271512,4353548972850,268367258592576,63484158299081520,17383860,1770,41664,18156204,300,3262623,99795696,324632,13488561475572645,703,60992558771040,8855,19600,33,741,1533939,324632,735471,13884156,46,268367258592576,1081575,58905,536830054536825,40225345056,739632519584070,155117520,149608375854525,443643407165376,817190,1,12271512,30,133784560,443643407165376,946,155117520,9657648,421171648758,29135916264,9880,3155581562280,8436285,67863915,2217471399,5006386,192928249296,6096454,11480,43183019880,148995,1101716330,296010,7888725,11554258485616,925029565741050,1889912732400,121399651100,1352078,8597496600,254186856,677040,98672427616,15380937,60403728840,10150595910,44,561,395010,28339603908273840,1533058025824,56,225792840,4431613550,8436285,677040,18156204,52860229080,1166803110,446775310800,192928249296,21094923659355,29135916264,23535820,946,341149446,211876,2024,861,14190,1485,536878650,565722720,134596,231,84672315,3124550,247994680648,1344904,436270780,1917334783,155117520,7307872110,1391975640,418094152866,347373600,350343565,888030,30856,2480089880334220,450978066,595,197548686920970,2311801440,77558760,45057474,497420,1485,5852925,1711,124403620,1855967520,193536720,29135916264,886322710,13123110,1307504,635745396,2024,23426,80730,2211,76223753060,3478761,1891,675248872536,417225900,20160075,38,1352078,1906884,20058300,34597290,270725,260932815,144079707346575,705432,351,253,230300,10648873950,84672315,16735679449896,316251,107518933731,25827165,69668534468,2250829575120,21,475020,4496388,30260340,1225,2311801440,22,4686825,2160153123141,3796297200,148995,60992558771040,56,2707475148,497420,265182149218,245157,601080390,2944827765,347373600,38910617655,54264,270725,22957480,7694644696200,35,5166863427600,24,2324784,855420636763836,7726160,51915526432,814385,5311735,34220,118030185,450978066,159518999862720,211915132,2668424446233,14190,491796152,264385836,675248872536,4431613550,27,1,5379616,29749251314475,20058300,23535820,3169870830126,2145,8347680,720720,65033528560,445891810,1217566350,211915132,1,10015005,4047376351620,708930508,35960,90858768,1677106640,1029530696964,38910617655,3247943160,511738760544,29752626158640,4353548972850,2598960,4292145,22,82251,3247943160,45760,1560780,3155581562280,5964720367660956,184756,14950,378,2163842859360,1312251244423350,1275,6096454,63484158299081520,1128,300540195,3124550,161884603662657876,766480,2496144,1012974972473835,3188675231420,1370754,149608375854525,37387265592825,1823810410032,27,264385836,1035,3245372870670,548354040,100947,31,45379620,202112640600,903,8936928,11480,32468436,33649,8217822536,350343565,68923264410,2925,12736262814039336,446775310800,84672315,9139,3268760,4027810484880,122131734269895,79960182801345,193536720,5567902560,212327989773900,438729741450,77558760,77558760,376740,16421073515280,666,937845656300,54264,1108176102180,1107568,40225345056,4495151581425648,107518933731,1849081298960175,51,115631859759041340,70,20160075,18851684897584,2969831763694950,27405,4426165368,30421755,353697121050,36288252,1855967520,1,1081,28781143380,1711,8996462475,202802465047245,497420,818809200,94143280,1078897248,3268760,346104,1037158320,129024480,1330,66045,1469568786235308,11541847896480,20448884000160,3169870830126,593775,8654327655120,101270,31368725759168,2346,1715884494940,44,10424128,93052749919920,5804731963800,245157,68248282427325,52251400851,25,3190187286,67945521,10468434365991,475020,41648951840265,1144066,40920,28781143380,127805525001,558383307300,36,231917400,26,8347680,4154246671960,557845,178365,895068996640,35,2203961430,10660,10648873950,376992,137846528820,18424,6131164307078475,5245786,262596783764,9139,416714805914,1,249900,25371763481680,417225900,14307150,202112640600,1749695026860,4481381406320,13244,341055,265182525,1330,11554258485616,231917400,50063860,346104,149608375854525,319770,1623160,2448296039700,1913212193400684,19499099620,2349060,5006386,163185,1562275,49,367290,133784560,135751,230230,703,70607460,1917334783,4060,1225,2818953098830,7392009768,8597496600,12736262814039336,1251677700,20475,45,231917400,1562275,735471,145422675,2944827765,1217566350,23196134763125940,435897,2220075,67863915,1823810410032,41664,4187106,720720,1,40,30856,33649,127805525001,4282083008118300,1166803110,566877686933536,38,22,1849081298960175,720720,26235,376992,421171648758,254186856,68,28048800,4537567650,119032357903550,47,1166803110,100947,225792840,9139,1119487075980,657800,18851684897584,10648873950,340032449328,56672074888,52179482355,7726160,601080390,1,99795696,1715884494940,2042975,925029565741050,3872894697],"k":[8,20,6,19,19,8,6,4,15,1,13,18,16,14,15,7,8,2,1,5,5,14,11,8,20,6,3,7,1,8,6,1,2,0,4,8,15,2,9,12,18,14,5,20,14,3,2,9,12,16,12,3,8,17,11,3,2,1,18,18,16,3,16,17,18,6,12,6,4,9,6,16,15,11,16,4,15,5,8,12,17,7,0,18,14,17,2,16,10,13,8,11,1,12,15,5,14,4,20,16,20,10,19,15,1,3,1,12,14,6,14,15,2,15,20,16,13,7,6,8,17,18,16,7,15,18,15,18,8,19,13,1,18,5,14,5,12,13,15,10,12,1,8,13,8,18,13,19,12,15,1,17,5,17,13,12,17,6,20,13,5,18,9,17,15,8,8,12,18,7,12,6,14,2,13,13,10,10,2,13,8,2,8,10,7,3,12,1,6,16,3,9,13,1,17,16,9,16,9,4,16,20,6,12,13,7,0,4,14,1,9,13,4,16,20,9,11,13,5,2,18,13,13,2,5,18,19,17,8,2,14,4,2,14,9,6,9,10,13,4,12,17,3,3,1,16,15,7,2,12,13,11,2,11,5,5,13,10,8,2,5,5,4,13,3,14,2,4,11,13,20,17,2,17,0,0,16,12,14,13,12,9,19,0,1,10,7,9,6,9,3,4,16,12,7,6,6,1,20,18,10,13,17,11,16,8,11,18,3,12,13,11,16,4,20,8,6,12,13,5,16,6,0,3,14,12,3,14,5,1,15,2,20,2,17,15,3,17,17,16,19,7,11,16,16,6,3,19,6,9,18,1,13,4,5,3,8,8,13,16,20,0,7,5,15,12,6,19,7,5,4,5,9,2,6,7,6,12,18,18,19,13,19,10,4,8,9,7,2,8,1,4,9,7,19,16,8,2,6,5,8,12,18,14,13,18,14,1,15,9,9,3,2,20,16,0,13,14,4,17,6,4,15,19,1,17,17,3,8,13,1,18,5,11,18,2,9,6,9,8,19,8,4,15,7,15,16,3,2,18,14,9,8,17,10,3,14,11,11,11,17,15,17,14,9,9,15,17,11,6,4,16,6,6,1,6,3,1,19,0,12,2,19,4,11,11,8,10,0,8,2,8,9,12,12,1,7,14,14,10,5,5,11,6,5,11,7,8,9,2,19,19,10,16,8,15,2,17,16,6,13,6,14,15,19,12,2,3,8,2,6,6,5,20,2,14,19,3,1,2,5,5,16,8,1,15,17,4,17,15,17,15,16,15,9,0,6,1,7,15,2,15,5,17,11,3,13,10,16,8,5,13,6,3,10,4,9,6,8,18,18,13,12,11,19,10,4,15,7,11,11,1,2,4,20,11,1,12,9,17,4,8,14,17,19,13,16,11,8,2,7,4,3,2,3,2,8,17,18,2,11,9,10,6,7,10,15,16,20,11,19,9,7,3,16,8,2,17,11,15,6,9,2,8,2,9,19,11,11,8,10,9,10,3,3,5,2,11,5,2,14,11,9,1,12,5,13,18,4,8,18,11,2,2,4,9,11,20,4,10,6,12,15,20,6,6,8,2,11,1,9,12,14,4,14,1,12,9,16,16,16,8,19,12,6,4,6,14,1,13,1,6,16,15,13,4,10,3,8,8,15,9,12,3,7,7,14,9,1,0,7,16,13,8,20,2,7,4,9,9,8,9,0,20,13,9,4,6,9,18,12,15,15,15,14,5,8,1,4,15,3,7,13,17,10,4,2,11,18,2,6,19,2,16,17,20,4,13,17,15,5,16,14,11,1,7,2,14,12,17,1,7,18,2,5,3,6,5,10,9,19,3,18,19,11,3,10,12,15,16,11,15,18,12,14,15,6,13,2,14,6,13,6,15,17,10,18,1,20,1,9,19,19,4,8,16,18,6,19,0,2,17,2,9,16,13,14,9,7,10,7,15,11,3,4,16,19,13,20,6,15,4,13,2,18,1,5,15,14,7,17,12,1,10,6,13,6,16,13,4,17,10,12,1,7,1,7,19,4,4,11,1,18,3,9,5,20,3,19,6,13,3,16,0,4,13,11,9,18,17,15,3,4,17,3,18,7,6,17,16,14,6,13,16,10,5,5,4,18,1,4,7,4,6,2,9,10,3,2,18,8,17,18,12,4,1,7,18,16,16,8,8,18,5,8,16,11,3,5,4,0,1,3,5,10,19,16,15,1,1,18,4,3,5,17,10,1,9,17,19,1,17,17,12,3,12,19,19,9,10,9,10,15,16,0,6,18,16,18,8],"n":[57,35,52,54,57,66,51,66,68,55,41,35,20,34,53,27,25,22,23,28,51,66,31,54,29,60,29,50,32,29,54,52,52,69,63,35,69,36,28,51,21,44,43,69,28,48,52,31,69,53,41,43,64,60,30,67,23,62,21,43,50,33,65,29,58,65,37,59,31,32,61,61,51,26,23,43,69,50,53,57,68,36,35,27,45,32,36,65,57,29,54,60,54,30,65,46,36,29,67,41,52,68,26,61,47,68,25,46,61,26,26,52,46,54,61,22,65,37,51,65,62,62,53,60,28,43,56,24,65,41,66,47,59,66,37,32,53,45,29,68,58,61,28,60,60,31,63,35,30,45,59,66,57,35,47,54,24,36,43,27,29,46,52,31,56,60,56,57,70,21,67,41,41,22,60,42,22,43,51,46,42,51,53,50,65,49,58,63,43,33,58,67,67,20,50,30,54,61,52,44,31,44,23,44,25,59,67,66,27,39,32,63,60,47,69,49,29,50,38,36,27,46,52,65,58,32,56,63,65,23,31,43,56,54,59,45,57,25,61,68,31,70,26,27,69,32,66,28,69,41,48,39,30,52,32,27,57,21,46,68,50,53,53,39,55,33,43,49,39,39,23,66,40,62,52,58,34,39,30,25,42,36,20,58,50,56,44,26,49,59,31,40,25,46,27,27,25,49,30,24,38,39,27,60,39,35,46,61,36,66,44,62,32,26,57,56,69,49,50,23,25,34,56,22,34,40,50,55,51,51,61,51,51,47,31,67,59,70,53,53,31,35,30,34,46,48,66,24,43,55,52,27,27,26,24,50,66,50,21,47,39,48,29,58,36,40,67,55,58,67,44,67,42,47,23,29,48,39,52,39,30,43,30,38,66,47,24,52,30,25,24,35,36,68,37,36,68,43,48,38,30,47,40,69,60,40,48,47,42,33,49,46,22,47,43,29,41,35,53,60,38,60,55,50,69,58,29,69,54,34,40,40,46,61,37,37,36,69,42,37,34,29,55,46,65,59,27,61,67,50,53,27,41,67,23,20,24,47,45,53,21,39,31,58,55,41,47,47,20,49,34,68,63,47,37,51,21,48,55,33,57,66,24,24,33,42,45,29,47,56,44,59,26,51,30,43,69,51,27,59,53,42,47,53,41,42,52,54,43,60,21,41,38,30,35,36,36,22,38,40,35,48,55,66,70,27,60,64,34,25,39,67,35,63,38,65,23,50,33,39,47,35,24,33,46,66,25,36,61,40,62,30,60,68,23,66,48,30,52,68,44,30,67,43,49,40,58,27,29,59,59,48,43,42,57,45,46,27,31,49,60,56,50,23,36,36,65,42,39,52,45,44,34,57,65,68,56,32,53,27,65,34,42,33,42,48,54,49,35,44,59,49,24,42,45,55,50,32,24,22,31,26,67,34,61,43,30,36,34,61,32,41,27,58,70,49,35,58,40,29,59,22,55,30,59,37,34,33,49,53,28,24,39,24,53,27,67,53,55,62,49,35,31,38,23,49,27,29,52,46,55,22,27,23,50,58,31,48,54,62,54,48,50,21,29,41,36,50,40,22,27,62,36,45,65,56,38,22,43,23,32,61,32,46,21,52,53,57,35,60,24,37,66,26,44,68,26,60,42,49,64,39,63,45,62,57,49,53,27,38,34,55,27,35,45,66,36,66,70,42,55,39,30,29,59,44,32,66,48,44,46,35,46,58,55,52,29,22,39,35,66,29,58,69,20,26,28,70,61,51,43,70,48,31,26,70,67,24,63,51,46,60,63,69,27,57,46,54,34,23,31,45,41,43,66,42,56,23,49,41,39,27,68,42,31,39,25,65,63,58,33,36,56,55,29,29,28,65,37,50,21,54,33,40,68,62,62,51,69,70,31,49,61,30,64,28,42,57,34,65,47,38,59,57,61,22,33,36,69,25,24,33,32,21,37,68,48,66,45,30,54,41,68,69,45,44,68,62,56,23,55,47,25,45,63,63,29,56,23,33,38,63,56,36,56,26,36,46,62,47,65,35,34,41,58,36,40,49,63,42,49,39,44,56,51,67,35,30,41,46,52,44,55,31,21,49,56,60,24,60,22,35,57,69,53,51,59,46,26,49,56,52,44,26,38,35,43,30,50,46,68,36,68,36,28,45,56,26,24,30,61,55,70,37,27,29,69,64,57,66,70,40,58,23,63,62,33,69,38,22,62,66,55,36,43,36,68,32,35,53,47,33,23,32,39,59,26,49,58,69,69,58,26,32,40,67,45,25,60,63]} diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/negative_n.json b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/negative_n.json new file mode 100644 index 000000000000..1db2ceb892ac --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/negative_n.json @@ -0,0 +1 @@ +{"expected":[1107568,23535820,-28048800,1,1,1365,1,8008,-14307150,-4060,5852925,1144066,18156204,-4060,13884156,1,-1540,1144066,325,-817190,-116280,-1307504,7888725,10626,-26334,-293930,92561040,-455,-3124550,203490,210,38760,190,-2600,319770,5005,18564,-50388,-817190,-170544,-22,-116280,-2002,-116280,296010,-38567100,646646,-116280,18156204,-24,-6188,-1184040,-28,92378,125970,-237336,-4060,-2925,2220075,-4495,-346104,74613,593775,1365,-26334,-167960,-15504,-142506,1,5985,40920,-42504,-1771,406,43758,-364,-201376,153,406,120,1365,1,120,-53130,-20,30260340,12376,1,-1307504,-4495,-92378,-220,190,735471,120,-33649,91,-94143280,2220075,-657800,-26,-3003,-11628,465,3108105,13884156,715,-10015005,20475,-2925,-2300,-4060,75582,230230,125970,12376,20030010,2380,-10,-455,136,-5379616,296010,3060,-237336,136,475020,300,-201376,300,105,-52451256,3876,1081575,12650,-26,-169911,23535820,1001,1,1820,-4960,-98280,10626,-30,2220075,-116280,-70607460,-28048800,-4060,319770,-237336,183579396,-2042975,64512240,125970,66,2220075,325,1344904,-237336,-816,406,1,-23,1,5311735,2380,1,1,134596,92378,2220075,276,203490,-4368,-53130,-98280,-19448,1,-3654,-25,-19,27132,134596,319770,120,-2600,-680,-2042975,2380,-170544,490314,-560,-657800,38760,906192,5005,-13,14950,-8568,351,-3276,3108105,-817190,31465,2220075,-1140,184756,1,-31824,136,-657800,203490,27132,348330136,-31824,23535820,-10,-167960,-286,153,-560,43758,8008,24310,-14,-24,105,-170544,35960,92561040,18156204,120,-14,177100,-10015005,3060,-497420,-16,-52451256,-817190,-3124550,7888725,319770,-14,27405,105,5852925,4845,30045015,-15,-6188,1001,-4060,-26334,75582,-201376,-53130,-124403620,1344904,105,-18,-2035800,1820,-17,1365,3108105,13884156,-16,-201376,376740,-42504,64512240,24310,10518300,1,184756,-11440,153,-657800,-1307504,-480700,38608020,-969,-30,30045015,-11440,-27,5005,-29,-26334,1344904,3876,-92378,131128140,-31824,-680,153,13884156,-163011640,-142506,1,23751,17550,-169911,2220075,-26,18156204,-969,-170544,-2035800,-816,-2024,1,-22,-817190,183579396,100947,-14,12376,325,-245157,-560,1,378,-4272048,-27,-2035800,40920,906192,-817190,105,1,475020,-15504,1,125970,171,-6906900,-969,120,43758,-169911,-2024,-53130,3876,1562275,-26334,1,-2600,-38567100,-80730,13884156,-5379616,18564,1,120,-48620,1,-11628,593775,1,1,-28,-3365856,376740,-2042975,-70607460,-15,-245157,13123110,190,-28,-28,2220075,30045015,1,-10015005,120,7315,1623160,-293930,74613,-816,43758,1961256,3060,231,-888030,1961256,1107568,38608020,-11628,-25,-33649,153,1,-94143280,376740,490314,75582,153,-10015005,735471,-80730,406,-22,-38567100,-170544,-25,-42504,-12,74613,-48620,-455,1,-1140,23535820,1,-6188,-14307150,-13,231,-1330,1,-201376,-1184040,17550,348330136,210,-12,-70607460,30045015,203490,-3276,-20160075,-1330,1,20030010,14950,14950,-480700,-3654,-50388,3876,12376,300,3268760,-4686825,12650,-18,-27,-98280,2380,24310,105,75582,-80730,-22,43758,5852925,-18,435,1820,-2600,1107568,-286,-3003,-455,64512240,-4368,92561040,-5379616,1,376740,10518300,-3365856,-817190,-201376,230230,91,-293930,12376,-4060,-20349,-3276,18156204,-116280,1,-1184040,-94143280,-1560780,-816,-4686825,-19,-4686825,1107568,20475,-680,230230,35960,136,-23,-201376,8008,1,13884156,-15504,-346104,300,-80730,-20160075,91,-29,8008,-20,12376,66,203490,1,5852925,-6724520,-2024,319770,-4495,91,54264,490314,2380,5985,-1771,-52451256,-455,736281,-8347680,-38567100,203490,254186856,-116280,75582,100947,27132,-94143280,-201376,-293930,-6724520,91,-2002,-3365856,171,-480700,735471,-286,20030010,-560,8855,1,-38567100,435,8008,-30,4292145,-3365856,-1771,-560,-23,3060,-480700,10518300,-6188,8855,74613,-14,1,1,-21,-2300,-53130,8008,-245157,-12,-1540,1001,7315,1001,-50388,1,-15504,1,-27,406,300,131128140,376740,-3365856,-94143280,325,646646,-480700,30045015,-2925,91,1,100947,-3124550,-18,472733756,5852925,8855,7888725,171,4292145,120,-65780,-26,-19448,20475,-3003,-5379616,-497420,66,153,276,1,-4686825,-455,435,18156204,-293930,490314,-21,1820,-26334,-364,-346104,-969,1001,4845,-657800,-2042975,210,593775,-10,177100,1107568,54264,406,-2042975,100947,435,91,18156204,78,-5379616,38760,231,-11,136,66,1365,376740,-2300,23751,105,351,-3654,1344904,1,1144066,1365,-77520,378,1,-6906900,-3365856,-170544,490314,1562275,1820,-6724520,-26,4292145,23751,-286,8855,8008,-364,-4686825,183579396,-816,8436285,18156204,-1140,376740,-293930,-118755,-94143280,184756,-26,635745396,-94143280,5985,1001,406,300,-3003,-26334,1344904,-816,-118755,-17,1,-8568,-8568,-24,-142506,-6724520,1,-1184040,153,1344904,-28048800,-167960,23535820,-14307150,92378,-245157,125970,-480700,30260340,3268760,190,8855,-4272048,-42504,134596,17550,230230,-18,-1560780,27132,3108105,1,-201376,-1540,-26,120,78,92561040,-48620,5311735,-237336,-26,-1330,-42504,-13,-77520,325,-245157,-24,10518300,35960,8436285,-6188,1,-657800,-22,2380,125970,125970,-19448,-11,-3003,-1184040,735471,735471,-24,-19,-657800,-11628,1,20475,-11,-15504,38760,-2300,18564,-1771,74613,-21,-3003,-22,-124403620,1,-4368,-6906900,13123110,27405,55,-4060,465,296010,-2024,-4272048,254186856,-21,-3365856,-92378,-163011640,435,-16,30260340,14950,184756,-3003,-170544,-4060,-6906900,348330136,74613,5005,-680,-4368,4292145,-116280,300,-888030,8008,-19,1820,-21,-346104,8855,-20160075,2380,-1330,735471,-1184040,38608020,8855,-4686825,38760,-15,1820,-4495,-12,-3654,125970,-1307504,-1140,-5379616,203490,-20160075,-3124550,-94143280,-237336,348330136,-77520,78,1,-167960,475020,-2024,435,-1540,378,3060,-27,100947,10626,177100,210,-17,-11440,8855,-2024,23751,254186856,-201376,18156204,-3124550,-497420,20475,-20160075,-10015005,-2035800,-38567100,-26,490314,20475,1107568,-77520,231,-18,-1184040,-1307504,27405,-42504,325,-124403620,-657800,27132,-18,-38567100,7315,-92378,325,593775,3060,-13,-2024,-1560780,-245157,-20,38760,18564,-50388,12650,-167960,-1771,43758,-4495,-25,203490,-237336,55,-18,7315,-21,75582,253,-245157,-888030,1,1,8008,-12,23751,-278256,-6188,1,-3654,1562275,203490,190,-4272048,-11,7888725,184756,378,-118755,-4368,-48620,-364,183579396,-14,190,66,1,-42504,-2629575,435,-25,1961256,1,210,30045015,-26,-2300,-53130,3876,20475,-53130,12376,-6724520,300,1,-455,-15504,1,-480700,-1184040,-560,-10,736281,-4272048,1,66,54264,-167960,1,1,91,210,1144066,-92378,-26,7888725,8855],"k":[6,8,9,0,0,4,0,6,9,3,8,10,8,3,8,0,3,10,2,9,7,9,8,4,5,9,10,3,9,8,2,6,2,3,8,6,6,7,9,7,1,7,5,7,6,9,10,7,8,1,5,7,1,10,8,5,3,3,8,3,7,6,6,4,5,9,5,5,0,4,4,5,3,2,8,3,5,2,2,2,4,0,2,5,1,8,6,0,9,3,9,3,2,8,2,5,2,9,8,7,1,5,5,2,8,8,4,9,4,3,3,3,8,6,8,6,10,4,1,3,2,7,6,4,5,2,6,2,5,2,2,9,4,8,4,1,5,8,4,0,4,3,5,4,1,8,7,9,9,3,8,5,10,9,10,8,2,8,2,6,5,3,2,0,1,0,10,4,0,0,6,10,8,2,8,5,5,5,7,0,3,1,1,6,6,8,2,3,3,9,4,7,8,3,7,6,6,6,1,4,5,2,3,8,9,4,8,3,10,0,7,2,7,8,6,10,7,8,1,9,3,2,3,8,6,8,1,1,2,7,4,10,8,2,1,6,9,4,9,1,9,9,9,8,8,1,4,2,8,4,10,1,5,4,3,5,8,5,5,9,6,2,1,7,4,1,4,8,8,1,5,6,5,10,8,8,0,10,7,2,7,9,7,8,3,1,10,7,1,6,1,5,6,4,9,10,7,3,2,8,9,5,0,4,4,5,8,1,8,3,7,7,3,3,0,1,9,10,6,1,6,2,7,3,0,2,7,1,7,4,6,9,2,0,6,5,0,8,2,9,3,2,8,5,3,5,4,8,5,0,3,9,5,8,7,6,0,2,9,0,5,6,0,0,1,7,6,9,9,1,7,10,2,1,1,8,10,0,9,2,4,6,9,6,3,8,10,4,2,7,10,6,8,5,1,5,2,0,9,6,8,8,2,9,8,5,2,1,9,7,1,5,1,6,9,3,0,3,8,0,5,9,1,2,3,0,5,7,4,10,2,1,9,10,8,3,9,3,0,10,4,4,7,3,7,4,6,2,10,9,4,1,1,5,4,8,2,8,5,1,8,8,1,2,4,3,6,3,5,3,10,5,10,7,0,6,8,7,9,5,6,2,9,6,3,5,3,8,7,0,7,9,7,3,9,1,9,6,4,3,6,4,2,1,5,6,0,8,5,7,2,5,9,2,1,6,1,6,2,8,0,8,7,3,8,3,2,6,8,4,4,3,9,3,6,7,9,8,10,7,8,6,6,9,5,9,7,2,5,7,2,7,8,3,10,3,4,0,9,2,6,1,8,7,3,3,1,4,7,8,5,4,6,1,0,0,1,3,5,6,7,1,3,4,4,4,7,0,5,0,1,2,2,10,6,7,9,2,10,7,10,3,2,0,6,9,1,10,8,4,8,2,8,2,5,1,7,4,5,7,9,2,2,2,0,9,3,2,8,9,8,1,4,5,3,7,3,4,4,7,9,2,6,1,6,6,6,2,9,6,2,2,8,2,7,6,2,1,2,2,4,6,3,4,2,2,3,6,0,10,4,7,2,0,9,7,7,8,8,4,7,1,8,4,3,4,6,3,9,10,3,10,8,3,6,9,5,9,10,1,10,9,4,4,2,2,5,5,6,3,5,1,0,5,5,1,5,7,0,7,2,6,9,9,8,9,10,7,8,7,8,10,2,4,7,5,6,4,6,1,7,6,8,0,5,3,1,2,2,10,9,10,5,1,3,5,1,7,2,7,1,8,4,10,5,0,7,1,4,8,8,7,1,5,7,8,8,1,1,7,5,0,4,1,5,6,3,6,3,6,1,5,1,9,0,5,9,10,4,2,3,2,6,3,7,10,1,7,9,9,2,1,8,4,10,5,7,3,9,10,6,6,3,5,8,7,2,7,6,1,4,1,7,4,9,4,3,8,7,8,4,9,6,1,4,3,1,3,8,9,3,7,8,9,9,9,5,10,7,2,0,9,6,3,2,3,2,4,1,6,4,6,2,1,7,4,3,4,10,5,8,9,9,4,9,9,7,9,1,8,4,6,7,2,1,7,9,4,5,2,9,7,6,1,9,4,9,2,6,4,1,3,7,7,1,6,6,7,4,9,3,8,3,1,8,5,2,1,4,1,8,2,7,7,0,0,6,1,4,5,5,0,3,8,8,2,7,1,8,10,2,5,5,9,3,10,1,2,2,0,5,7,2,1,10,0,2,10,1,3,5,4,4,5,6,7,2,0,3,5,0,7,7,3,1,6,7,0,2,6,9,0,0,2,2,10,9,1,8,4],"n":[-28,-28,-24,-26,-18,-12,-22,-11,-22,-28,-23,-14,-27,-28,-26,-22,-20,-14,-25,-15,-15,-16,-24,-21,-18,-13,-24,-13,-18,-14,-20,-15,-19,-24,-15,-10,-13,-13,-15,-16,-22,-15,-10,-15,-22,-25,-13,-15,-27,-24,-13,-22,-28,-10,-13,-29,-28,-25,-20,-29,-18,-17,-25,-12,-18,-12,-16,-26,-20,-18,-30,-20,-21,-28,-11,-12,-28,-17,-28,-15,-12,-24,-15,-21,-20,-29,-12,-10,-16,-29,-11,-10,-19,-17,-15,-19,-13,-28,-20,-20,-26,-11,-15,-30,-21,-26,-10,-21,-25,-25,-23,-28,-12,-21,-13,-12,-20,-14,-10,-13,-16,-28,-22,-15,-29,-16,-24,-24,-28,-24,-14,-26,-16,-18,-22,-26,-27,-28,-11,-22,-13,-30,-24,-21,-30,-20,-15,-27,-24,-28,-15,-29,-26,-17,-23,-13,-11,-20,-25,-29,-29,-16,-28,-19,-23,-25,-17,-14,-30,-25,-19,-10,-20,-23,-14,-12,-21,-24,-11,-19,-27,-25,-19,-14,-19,-15,-15,-24,-15,-17,-14,-16,-16,-14,-20,-15,-27,-10,-13,-23,-14,-26,-26,-21,-15,-28,-20,-18,-11,-13,-12,-16,-20,-14,-14,-28,-12,-28,-10,-12,-11,-17,-14,-11,-11,-10,-14,-24,-14,-16,-29,-24,-27,-15,-14,-20,-21,-15,-14,-16,-26,-15,-18,-24,-15,-14,-27,-14,-23,-17,-21,-15,-13,-11,-28,-18,-12,-28,-21,-29,-29,-14,-18,-24,-13,-17,-12,-21,-26,-16,-28,-23,-20,-23,-10,-25,-17,-11,-10,-17,-20,-16,-19,-30,-17,-30,-21,-10,-27,-10,-29,-18,-29,-16,-11,-25,-12,-15,-17,-26,-30,-26,-19,-26,-24,-27,-20,-26,-27,-17,-16,-24,-16,-22,-26,-22,-15,-26,-18,-14,-12,-25,-17,-14,-19,-27,-27,-27,-24,-30,-27,-15,-14,-22,-24,-16,-20,-13,-18,-20,-17,-15,-11,-27,-22,-21,-16,-19,-18,-18,-24,-25,-23,-26,-28,-13,-18,-15,-10,-24,-15,-25,-19,-21,-28,-26,-23,-17,-27,-15,-17,-19,-19,-28,-28,-20,-21,-11,-21,-15,-19,-30,-13,-17,-16,-11,-15,-15,-21,-21,-15,-28,-30,-15,-25,-19,-17,-13,-28,-23,-16,-12,-17,-21,-17,-23,-28,-22,-25,-16,-25,-20,-12,-17,-10,-13,-27,-18,-28,-24,-13,-22,-13,-21,-19,-18,-28,-22,-24,-28,-20,-12,-27,-21,-14,-26,-23,-19,-23,-20,-23,-23,-19,-27,-13,-16,-12,-24,-16,-19,-22,-18,-27,-24,-14,-10,-14,-12,-23,-22,-11,-23,-18,-29,-13,-24,-28,-11,-11,-13,-23,-12,-24,-28,-10,-23,-25,-26,-15,-28,-21,-13,-13,-12,-28,-17,-26,-27,-15,-17,-22,-28,-23,-16,-19,-19,-19,-28,-25,-15,-21,-29,-16,-23,-28,-11,-25,-26,-16,-18,-24,-23,-23,-13,-29,-11,-20,-12,-11,-14,-17,-23,-29,-22,-15,-29,-13,-16,-16,-14,-18,-21,-26,-13,-26,-30,-25,-14,-27,-15,-12,-18,-14,-28,-28,-13,-29,-13,-10,-26,-18,-19,-17,-11,-20,-14,-20,-18,-25,-29,-11,-30,-22,-26,-21,-14,-23,-15,-19,-25,-13,-20,-17,-14,-13,-12,-21,-23,-21,-11,-17,-12,-20,-11,-19,-11,-13,-14,-16,-23,-27,-28,-24,-25,-23,-26,-28,-25,-13,-19,-21,-25,-13,-15,-18,-18,-18,-29,-23,-20,-24,-18,-22,-15,-22,-26,-11,-25,-11,-28,-14,-11,-17,-23,-10,-19,-13,-29,-27,-13,-16,-21,-13,-18,-12,-18,-17,-11,-17,-20,-17,-20,-25,-10,-20,-28,-16,-28,-17,-18,-29,-13,-27,-12,-28,-15,-21,-11,-16,-11,-12,-23,-23,-26,-14,-26,-27,-29,-23,-14,-12,-14,-27,-21,-20,-26,-16,-16,-19,-13,-29,-26,-22,-26,-11,-20,-11,-12,-19,-26,-16,-18,-27,-18,-23,-13,-25,-28,-11,-26,-30,-28,-18,-11,-28,-24,-11,-18,-29,-16,-25,-17,-28,-14,-14,-24,-26,-29,-14,-22,-17,-29,-24,-12,-28,-22,-10,-17,-13,-19,-29,-16,-19,-20,-27,-20,-19,-24,-21,-18,-23,-14,-21,-11,-28,-20,-26,-15,-12,-24,-10,-17,-29,-26,-19,-20,-13,-14,-25,-17,-24,-25,-29,-18,-13,-10,-20,-22,-14,-13,-13,-11,-11,-11,-22,-17,-17,-24,-19,-20,-15,-11,-25,-11,-16,-15,-23,-13,-21,-17,-21,-11,-22,-29,-13,-12,-20,-19,-27,-10,-28,-30,-22,-22,-27,-27,-21,-26,-11,-30,-29,-16,-29,-23,-11,-11,-16,-28,-20,-28,-17,-10,-15,-12,-22,-15,-24,-21,-11,-19,-13,-21,-18,-20,-23,-14,-19,-17,-22,-30,-20,-19,-15,-15,-13,-29,-12,-27,-13,-16,-18,-28,-14,-23,-18,-28,-29,-28,-14,-12,-23,-12,-24,-22,-29,-20,-27,-15,-27,-18,-21,-20,-20,-17,-10,-20,-22,-26,-27,-28,-27,-18,-14,-25,-23,-21,-24,-25,-26,-16,-25,-28,-14,-21,-18,-22,-16,-27,-20,-25,-29,-20,-14,-18,-25,-19,-11,-25,-25,-15,-13,-22,-23,-17,-20,-15,-13,-13,-22,-12,-21,-11,-29,-25,-14,-29,-10,-18,-19,-21,-12,-22,-17,-21,-11,-15,-11,-12,-26,-30,-13,-18,-27,-19,-14,-19,-27,-11,-24,-11,-27,-25,-12,-10,-12,-26,-14,-19,-11,-13,-20,-25,-29,-25,-15,-14,-20,-21,-26,-23,-21,-16,-25,-21,-12,-29,-24,-27,-13,-16,-23,-19,-22,-14,-10,-26,-27,-21,-11,-16,-12,-21,-27,-13,-20,-14,-11,-26,-24,-20]} diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/runner.jl new file mode 100755 index 000000000000..dc2c1cb96a4d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/runner.jl @@ -0,0 +1,77 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import JSON + +""" + gen( m, k, name ) + +Generate fixture data and write to file. + +# Arguments + +* `n`: input value +* `k`: second input value +* `name::AbstractString`: output filename + +# Examples + +``` julia +julia> n = round.( Int, rand( 1000 ) .* 170 ); +julia> k = round.( Int, rand( 1000 ) .* 170 ); +julia> gen( n, k, \"data.json\" ); +``` +""" +function gen( n, k, name ) + y = Array{Int64}( undef, length( n ) ); + for i in eachindex(n) + y[i] = binomial( n[i], k[i] ); + end + + # Store data to be written to file as a collection: + data = Dict([ + ("n", n), + ("k", k), + ("expected", y) + ]); + + # Based on the script directory, create an output filepath: + filepath = joinpath( dir, name ); + + # Write the data to the output filepath as JSON: + outfile = open( filepath, "w" ); + write( outfile, JSON.json(data) ); + write( outfile, "\n" ); + close( outfile ); +end + +# Get the filename: +file = @__FILE__; + +# Extract the directory in which this file resides: +dir = dirname( file ); + +# Integer values: +n = round.( Int, ( rand( 1000 ) .* 50 ) .+ 20 ); +k = round.( Int, rand( 1000 ) .* 20 ); +gen( n, k, "integers.json" ); + +# Negative `n` values: +n = -1 .* round.( Int, ( rand( 1000 ) .* 20 ) .+ 10 ); +k = round.( Int, rand( 1000 ) .* 10 ); +gen( n, k, "negative_n.json" ); diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/test.js b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/test.js new file mode 100644 index 000000000000..096a857bb1f6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/test.js @@ -0,0 +1,159 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var binomcoeff = require( './../lib' ); + + +// FIXTURES // + +var integers = require( './fixtures/julia/integers.json' ); +var negativeN = require( './fixtures/julia/negative_n.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof binomcoeff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided `NaN` for any parameter', function test( t ) { + var v = binomcoeff( 3, NaN ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + v = binomcoeff( NaN, 2 ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function evaluates the binomial coefficient for integers `n` and `k`', function test( t ) { + var expected; + var delta; + var tol; + var n; + var k; + var v; + var i; + + n = integers.n; + k = integers.k; + expected = integers.expected; + for ( i = 0; i < n.length; i++ ) { + v = binomcoeff( n[ i ], k[ i ] ); + expected[ i ] = float64ToFloat32( expected[ i ] ); + if ( expected[ i ] === v ) { + t.strictEqual( v, expected[ i ], 'returns expected value' ); + continue; + } + delta = absf( v - expected[ i ] ); + + // NOTE: Exact comparison fails for large values due to single-precision floating-point rounding errors when intermediate results exceed the maximum safe integer for a 32-bit float. + tol = 1.25 * EPS * absf( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. n: ' + n[ i ] + '. k: ' + k[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' ); + } + t.end(); +}); + +tape( 'the function evaluates the binomial coefficient for integers `n` and `k` (negative `n`)', function test( t ) { + var expected; + var n; + var k; + var v; + var i; + + n = negativeN.n; + k = negativeN.k; + expected = negativeN.expected; + for ( i = 0; i < n.length; i++ ) { + v = binomcoeff( n[ i ], k[ i ] ); + expected[ i ] = float64ToFloat32( expected[ i ] ); + t.strictEqual( v, expected[ i ], 'returns expected value. actual: '+v+'. expected: '+expected[i]+'. n: '+n[i]+'. k: '+k[i]+'.' ); + } + t.end(); +}); + +tape( 'the function returns `NaN` if the `n` value is not an integer', function test( t ) { + var values; + var i; + + values = [ + 2.5, + '5', + null, + true, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isnanf( binomcoeff( values[i], 2 ) ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns `NaN` if the `k` value is not an integer', function test( t ) { + var values; + var i; + + values = [ + 2.5, + '5', + null, + true, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isnanf( binomcoeff( 2, values[i] ) ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns `0` for a negative integer `k`', function test( t ) { + var v = binomcoeff( 2, -1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = binomcoeff( 2, -2 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0` when `k` is greater than `n`', function test( t ) { + var v = binomcoeff( 2, 4 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = binomcoeff( 2, 10 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/test.native.js new file mode 100644 index 000000000000..af0415643c12 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/test.native.js @@ -0,0 +1,115 @@ +/** +* @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 absf = require( '@stdlib/math/base/special/absf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var binomcoeff = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( binomcoeff instanceof Error ) +}; + + +// FIXTURES // + +var integers = require( './fixtures/julia/integers.json' ); +var negativeN = require( './fixtures/julia/negative_n.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof binomcoeff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function evaluates the binomial coefficient for integers `n` and `k`', opts, function test( t ) { + var expected; + var delta; + var tol; + var n; + var k; + var v; + var i; + + n = integers.n; + k = integers.k; + expected = integers.expected; + for ( i = 0; i < n.length; i++ ) { + v = binomcoeff( n[ i ], k[ i ] ); + expected[ i ] = float64ToFloat32( expected[ i ] ); + if ( expected[ i ] === v ) { + t.strictEqual( v, expected[ i ], 'returns expected value' ); + continue; + } + delta = absf( v - expected[ i ] ); + + // NOTE: Exact comparison fails for large values due to single-precision floating-point rounding errors when intermediate results exceed the maximum safe integer for a 32-bit float. + tol = 1.25 * EPS * absf( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. n: ' + n[ i ] + '. k: ' + k[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' ); + } + t.end(); +}); + +tape( 'the function evaluates the binomial coefficient for integers `n` and `k` (negative `n`)', opts, function test( t ) { + var expected; + var n; + var k; + var v; + var i; + + n = negativeN.n; + k = negativeN.k; + expected = negativeN.expected; + for ( i = 0; i < n.length; i++ ) { + v = binomcoeff( n[ i ], k[ i ] ); + expected[ i ] = float64ToFloat32( expected[ i ] ); + t.strictEqual( v, expected[ i ], 'returns expected value. actual: '+v+'. expected: '+expected[i]+'. n: '+n[i]+'. k: '+k[i]+'.' ); + } + t.end(); +}); + +tape( 'the function returns `0` for a negative integer `k`', opts, function test( t ) { + var v = binomcoeff( 2, -1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = binomcoeff( 2, -2 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0` when `k` is greater than `n`', opts, function test( t ) { + var v = binomcoeff( 2, 4 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + v = binomcoeff( 2, 10 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +});