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..e69de29bb2d1 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..c6d62b338a68 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var 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 x; + var y; + var z; + var i; + + x = discreteUniform( 100, 20, 70 ); + y = discreteUniform( 100, 0, 20 ); + + 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..193441aaa00e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/benchmark.native.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var 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 x; + var y; + var z; + var i; + + x = discreteUniform( 100, 20, 70 ); + y = discreteUniform( 100, 0, 20 ); + + 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/Makefile b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/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 := 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/benchmark.c b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/benchmark.c new file mode 100644 index 000000000000..805a898ea61c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/benchmark/c/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 "binomcoef" +#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 float benchmark( void ) { + int32_t n[ 100 ]; + int32_t k[ 100 ]; + float elapsed; + float y; + float t; + int i; + + for ( i = 0; i < 100; i++ ) { + n[ i ] = (int32_t)round( 500.0f * rand_float() ); + k[ i ] = (int32_t)round( 500.0f * 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/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..91d82256c890 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/docs/repl.txt @@ -0,0 +1,41 @@ + +{{alias}}( n, k ) + Computes the binomial coefficient of two integers. + + 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..916fa348fdd0 --- /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. +* +* @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..9d7da3f5d911 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/c/example.c @@ -0,0 +1,34 @@ +/** +* @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 + +int main( void ) { + const int32_t a[] = { 24.0f, 32.0f, 48.0f, 116.0f, 33.0f }; + const int32_t b[] = { 12.0f, 6.0f, 15.0f, 52.0f, 22.0f }; + + float out; + int i; + for ( i = 0; i < 5; i++ ) { + out = stdlib_base_binomcoeff( a[ i ], b[ i ] ); + printf( "binomcoef(%" PRId64 ", %" PRId64 ") = %lf\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..59c159f10c44 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/binomcoeff/examples/index.js @@ -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. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); +var binomcoeff = require( './../lib' ); + +var n; +var k; +var i; + +for ( i = 0; i < 100; i++ ) { + n = roundf( (randu()*40.0) - 10.0 ); + k = roundf( randu()*20.0 ); + console.log( '%d choose %d = %d', n, k, binomcoeff( n, k ) ); +} 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. +*/ +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..d56716b288e2 --- /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. +* +* @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..cd9b1bd35670 --- /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-integerf' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Float64toFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var isOddf = require( '@stdlib/math/base/assert/is-oddf' ); +var floorf = require( '@stdlib/math/base/special/floorf' ); +var gcdf = require( '@stdlib/math/base/special/gcdf' ); + + +// MAIN // + +/** +* Computes the binomial coefficient of two integers. +* +* @param {integer} n - input value +* @param {integer} k - second input value +* @returns {integer} function value +* +* @example +* var v = binomcoeff( 8.0, 2.0 ); +* // returns 28.0 +* +* @example +* var v = binomcoeff( 0.0, 0.0 ); +* // returns 1.0 +* +* @example +* var v = binomcoeff( -4.0, 2.0 ); +* // returns 10.0 +* +* @example +* var v = binomcoeff( NaN, 3.0 ); +* // returns NaN +* +* @example +* var v = binomcoeff( 5.0, 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 0; + } + sgn = 1; + if ( n < 0 ) { + n = -n + k - 1; + if ( isOddf( k ) ) { + sgn *= -1; + } + } + if ( k > n ) { + return 0; + } + if ( k === 0 || k === n ) { + return sgn; + } + if ( k === 1 || k === n - 1 ) { + return Float64toFloat32( sgn * 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 = 1; + for ( d = 1; d <= k; d++ ) { + // Check for potential overflow... + if ( res > s ) { + break; + } + res *= n; + res /= 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( 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 = binomcoeff( n, k-d+1 ); + if ( b === PINF ) { + return Float64toFloat32( sgn * 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 (gcd). 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( sgn * res * 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..05f883122c4d --- /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. +* +* @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..e69de29bb2d1 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..2cb578033c2b --- /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. +* +* @param n input value +* @param k second input value +* @return function value +* +* @example +* float out = stdlib_base_binomcoeff( 8, 2 ); +* // returns 28.0 +*/ +float stdlib_base_binomcoeff( const int32_t n, const int32_t k ) { + float res; + float sgn; + int32_t nc; + int32_t kc; + int32_t d; + float b; + float c; + float g; + float s; + + if ( k < 0.0f ) { + return 0.0f; + } + sgn = 1.0f; + nc = n; + if ( nc < 0.0f ) { + nc = -nc + k - 1.0f; + if ( k & 1 ) { + sgn *= -1.0f; + } + } + if ( k > nc ) { + return 0.0f; + } + if ( k == 0.0f || k == nc ) { + return sgn; + } + if ( k == 1.0f || k == nc - 1.0f ) { + 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.0f; d <= kc; d++ ) { + // Check for potential overflow... + if ( res > s ) { + break; + } + res *= nc; + res /= d; + nc -= 1.0f; + } + + // 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.0f ); + if ( b == STDLIB_CONSTANT_FLOAT32_PINF ) { + return sgn * b; + } + c = stdlib_base_binomcoeff( kc, kc - d + 1.0f ) ; + + /* + * 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/runner.jl b/lib/node_modules/@stdlib/math/base/special/binomcoeff/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..80e21e59bbd8 --- /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{Int32}( 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..e69de29bb2d1 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..e69de29bb2d1