From 10b24bff34388de5e879c9a3b3e51a7d5b9e611d Mon Sep 17 00:00:00 2001 From: Shashankss1205 Date: Sun, 3 Mar 2024 04:16:36 +0530 Subject: [PATCH 1/8] feat: Add C implementation for @stdlib/math/base/special/max --- .../@stdlib/math/base/special/max/README.md | 84 ++++++++- .../special/max/benchmark/benchmark.native.js | 62 +++++++ .../base/special/max/benchmark/c/Makefile | 107 ----------- .../special/max/benchmark/c/native/Makefile | 146 +++++++++++++++ .../max/benchmark/c/{ => native}/benchmark.c | 17 +- .../@stdlib/math/base/special/max/binding.gyp | 170 ++++++++++++++++++ .../math/base/special/max/examples/c/Makefile | 146 +++++++++++++++ .../base/special/max/examples/c/example.c | 34 ++++ .../math/base/special/max/include.gypi | 53 ++++++ .../include/stdlib/math/base/special/max.h | 38 ++++ .../math/base/special/max/lib/native.js | 59 ++++++ .../math/base/special/max/manifest.json | 78 ++++++++ .../math/base/special/max/src/Makefile | 70 ++++++++ .../math/base/special/max/src/addone.c | 22 +++ .../@stdlib/math/base/special/max/src/main.c | 56 ++++++ .../math/base/special/max/test/test.native.js | 100 +++++++++++ 16 files changed, 1126 insertions(+), 116 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.native.js delete mode 100644 lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/Makefile rename lib/node_modules/@stdlib/math/base/special/max/benchmark/c/{ => native}/benchmark.c (91%) create mode 100644 lib/node_modules/@stdlib/math/base/special/max/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/max/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/max/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/max/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/max/include/stdlib/math/base/special/max.h create mode 100644 lib/node_modules/@stdlib/math/base/special/max/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/max/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/max/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/max/src/addone.c create mode 100644 lib/node_modules/@stdlib/math/base/special/max/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/max/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/max/README.md b/lib/node_modules/@stdlib/math/base/special/max/README.md index 0224dc2e2fd8..e6d6d8bd7aa1 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/README.md +++ b/lib/node_modules/@stdlib/math/base/special/max/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2024 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -103,6 +103,88 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/max.h" +``` + +#### stdlib_base_max( x, y ) + +Returns the maximum value. + +```c +double out = stdlib_base_max( 4.2, 3.14 ); +// returns 4.2 + +out = stdlib_base_max( 0.0, -0.0 ); +// returns 0.0 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **y**: `[in] double` input value. + +```c +double stdlib_base_max( const double x, const double y ); +``` +
+ + +
+
+ + +
+### Examples +```c +#include "stdlib/math/base/special/max.h" +#include +#include +int main( void ) { + double x; + double y; + double v; + int i; + + for ( i = 0; i < 100; i++ ) { + x = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0; + y = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0; + v = stdlib_base_max( x, y ); + printf( "x: %lf, y: %lf, max(x, y): %lf\n", x, y, v ); + } +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.native.js new file mode 100644 index 000000000000..46372275289f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.native.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var max = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( max instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*200.0 ) - 100.0; + y = ( randu()*200.0 ) - 100.0; + z = max( x, y ); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile deleted file mode 100644 index e4542b1e66e9..000000000000 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile +++ /dev/null @@ -1,107 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2018 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 - -# 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 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]: 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: -c_targets := benchmark.out - - -# TARGETS # - -# Default target. -# -# This target is the default target. - -all: $(c_targets) - -.PHONY: all - - -# Compile C source. -# -# This target compiles C source files. - -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm - - -# Run a benchmark. -# -# This target runs a benchmark. - -run: $(c_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/max/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c similarity index 91% rename from lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c rename to lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c index f59bfa084053..e348de1da371 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,9 @@ */ /** -* Benchmark `fmax`. +* Benchmark `max`. */ +#include "stdlib/math/base/special/max.h" #include #include #include @@ -93,17 +94,17 @@ double rand_double() { */ double benchmark() { double elapsed; + double t; double x; double y; double z; - double t; int i; t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = ( 1000.0*rand_double() ) - 500.0; - z = fmax( x, y ); + x = ( 200.0*rand_double() ) - 100.0; + y = ( 200.0*rand_double() ) - 100.0; + z = stdlib_base_max( x, y ); if ( z != z ) { printf( "should not return NaN\n" ); break; @@ -128,10 +129,10 @@ int main( void ) { print_version(); for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::%s\n", NAME ); + printf( "# c::native::%s\n", NAME ); elapsed = benchmark(); print_results( elapsed ); printf( "ok %d benchmark finished\n", i+1 ); } print_summary( REPEATS, REPEATS ); -} +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/max/binding.gyp b/lib/node_modules/@stdlib/math/base/special/max/binding.gyp new file mode 100644 index 000000000000..507cb00291e7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/max/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/max/examples/c/Makefile new file mode 100644 index 000000000000..d53ef397c77d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/max/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/max/examples/c/example.c new file mode 100644 index 000000000000..2b75580e3c99 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/examples/c/example.c @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/max.h" +#include + +int main( void ) { + double x; + double y; + double v; + int i; + + for ( i = 0; i < 100; i++ ) { + x = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0; + y = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0; + v = stdlib_base_max( x, y ); + printf( "x: %lf, y: %lf, max(x, y): %lf\n", x, y, v ); + } +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/max/include.gypi b/lib/node_modules/@stdlib/math/base/special/max/include.gypi new file mode 100644 index 000000000000..c6495fc1da3f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' y ) { + return x; + } + return y; +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/max/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/max/test/test.native.js new file mode 100644 index 000000000000..646b9e92539b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/test/test.native.js @@ -0,0 +1,100 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var max = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( max instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof max, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) { + var v; + + v = max( NaN, 3.14 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + v = max( 3.14, NaN ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns `Infinity` if provided `Infinity`', opts, function test( t ) { + var v; + + v = max( PINF, 3.14 ); + t.strictEqual( v, PINF, 'returns infinity' ); + + v = max( 3.14, PINF ); + t.strictEqual( v, PINF, 'returns infinity' ); + + t.end(); +}); + +tape( 'the function returns a correctly signed zero', opts, function test( t ) { + var v; + + v = max( +0.0, -0.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + + v = max( -0.0, +0.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + + v = max( -0.0, -0.0 ); + t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + + v = max( +0.0, +0.0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + + t.end(); +}); + +tape( 'the function returns the maximum value', opts, function test( t ) { + var v; + + v = max( 4.2, 3.14 ); + t.strictEqual( v, 4.2, 'returns max value' ); + + v = max( -4.2, 3.14 ); + t.strictEqual( v, 3.14, 'returns max value' ); + + t.end(); +}); From 3b136249bfd48a486f0519863e7e903ffed72468 Mon Sep 17 00:00:00 2001 From: Shashank Shekhar Singh <123410790+Shashankss1205@users.noreply.github.com> Date: Sun, 3 Mar 2024 14:08:14 +0530 Subject: [PATCH 2/8] Update README.md Signed-off-by: Shashank Shekhar Singh <123410790+Shashankss1205@users.noreply.github.com> --- .../@stdlib/math/base/special/max/README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/max/README.md b/lib/node_modules/@stdlib/math/base/special/max/README.md index e6d6d8bd7aa1..30dc1806b69e 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/README.md +++ b/lib/node_modules/@stdlib/math/base/special/max/README.md @@ -149,17 +149,27 @@ The function accepts the following arguments: ```c double stdlib_base_max( const double x, const double y ); ``` +
+ + +
+
+ + +
+ ### Examples + ```c -#include "stdlib/math/base/special/max.h" +#include "stdlib/math/base/special/min.h" #include #include int main( void ) { From 558a5e8db5afb85cdb84079789a17c9ce332705c Mon Sep 17 00:00:00 2001 From: Shashank Shekhar Singh <123410790+Shashankss1205@users.noreply.github.com> Date: Sun, 3 Mar 2024 14:13:17 +0530 Subject: [PATCH 3/8] Update README.md Signed-off-by: Shashank Shekhar Singh <123410790+Shashankss1205@users.noreply.github.com> --- lib/node_modules/@stdlib/math/base/special/max/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/max/README.md b/lib/node_modules/@stdlib/math/base/special/max/README.md index 30dc1806b69e..df28ac5fa8c0 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/README.md +++ b/lib/node_modules/@stdlib/math/base/special/max/README.md @@ -169,7 +169,7 @@ double stdlib_base_max( const double x, const double y ); ### Examples ```c -#include "stdlib/math/base/special/min.h" +#include "stdlib/math/base/special/max.h" #include #include int main( void ) { From ad7247776e1d3602d70bd7b956747505246936d4 Mon Sep 17 00:00:00 2001 From: Shashankss1205 Date: Sun, 3 Mar 2024 14:47:00 +0530 Subject: [PATCH 4/8] fix: requested changes made for #1459 --- .../@stdlib/math/base/special/max/README.md | 10 ++ .../base/special/max/benchmark/c/Makefile | 146 +++++++++++++++++ .../base/special/max/benchmark/c/benchmark.c | 138 ++++++++++++++++ .../math/base/special/max/manifest.json | 152 +++++++++--------- 4 files changed, 370 insertions(+), 76 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c diff --git a/lib/node_modules/@stdlib/math/base/special/max/README.md b/lib/node_modules/@stdlib/math/base/special/max/README.md index e6d6d8bd7aa1..ecb6b17dad86 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/README.md +++ b/lib/node_modules/@stdlib/math/base/special/max/README.md @@ -149,15 +149,25 @@ The function accepts the following arguments: ```c double stdlib_base_max( const double x, const double y ); ``` +
+ + +
+
+ + +
+ ### Examples + ```c #include "stdlib/math/base/special/max.h" #include diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := 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/max/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c new file mode 100644 index 000000000000..e348de1da371 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/** +* Benchmark `max`. +*/ +#include "stdlib/math/base/special/max.h" +#include +#include +#include +#include +#include + +#define NAME "max" +#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; +} + +/** +* Generates a random number on the interval [0,1]. +* +* @return random number +*/ +double rand_double() { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +double benchmark() { + double elapsed; + double t; + double x; + double y; + double z; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 200.0*rand_double() ) - 100.0; + y = ( 200.0*rand_double() ) - 100.0; + z = stdlib_base_max( 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; + + // 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 ); +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/max/manifest.json b/lib/node_modules/@stdlib/math/base/special/max/manifest.json index 389cf8a63b7c..374b5de554a7 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/max/manifest.json @@ -1,78 +1,78 @@ { - "options": { - "task": "build" + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true }, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "task": "build", - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/math/base/napi/binary", - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/assert/is-negative-zero", - "@stdlib/constants/float64/ninf" - ] - }, - { - "task": "benchmark", - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/assert/is-negative-zero", - "@stdlib/constants/float64/ninf" - ] - }, - { - "task": "examples", - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/assert/is-negative-zero", - "@stdlib/constants/float64/ninf" - ] - } - ] - } \ No newline at end of file + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/binary", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-negative-zero", + "@stdlib/constants/float64/ninf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-negative-zero", + "@stdlib/constants/float64/ninf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-negative-zero", + "@stdlib/constants/float64/ninf" + ] + } + ] +} \ No newline at end of file From 7ca99078b936095f473679ea89c5c54ba6eb06d2 Mon Sep 17 00:00:00 2001 From: Shashankss1205 Date: Sun, 3 Mar 2024 14:57:58 +0530 Subject: [PATCH 5/8] fix: requested changes made for #1459 --- .../math/base/special/max/benchmark/c/benchmark.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c index e348de1da371..98ed4941769f 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c @@ -17,9 +17,9 @@ */ /** -* Benchmark `max`. +* Benchmark `fmax`. */ -#include "stdlib/math/base/special/max.h" + #include #include #include @@ -94,6 +94,7 @@ double rand_double() { */ double benchmark() { double elapsed; + double t; double x; double y; @@ -104,7 +105,7 @@ double benchmark() { for ( i = 0; i < ITERATIONS; i++ ) { x = ( 200.0*rand_double() ) - 100.0; y = ( 200.0*rand_double() ) - 100.0; - z = stdlib_base_max( x, y ); + z = fmax( x, y ); if ( z != z ) { printf( "should not return NaN\n" ); break; @@ -129,7 +130,7 @@ int main( void ) { print_version(); for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s\n", NAME ); + printf( "# c::%s\n", NAME ); elapsed = benchmark(); print_results( elapsed ); printf( "ok %d benchmark finished\n", i+1 ); From 215caf6b37f7cd817bec03125549c4a5f766333c Mon Sep 17 00:00:00 2001 From: Shashankss1205 Date: Sun, 3 Mar 2024 15:06:24 +0530 Subject: [PATCH 6/8] fix: requested changes made for #1459 --- .../base/special/max/benchmark/c/Makefile | 81 +++++-------------- 1 file changed, 21 insertions(+), 60 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile index f69e9da2b4d3..6bb27312ba8c 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/Makefile @@ -16,15 +16,14 @@ # limitations under the License. #/ + # VARIABLES # ifndef VERBOSE QUIET := @ -else - QUIET := endif -# Determine the OS ([1][1], [2][2]). +# Determine the OS: # # [1]: https://en.wikipedia.org/wiki/Uname#Examples # [2]: http://stackoverflow.com/a/27776822/2225624 @@ -37,10 +36,6 @@ ifneq (, $(findstring MSYS,$(OS))) else ifneq (, $(findstring CYGWIN,$(OS))) OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif endif endif endif @@ -59,7 +54,7 @@ CFLAGS ?= \ -Wall \ -pedantic -# Determine whether to generate position independent code ([1][1], [2][2]). +# 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 @@ -69,78 +64,44 @@ 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 # +# TARGETS # -#/ -# Compiles source files. +# Default target. # -# @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 -#/ +# This target is the default target. + all: $(c_targets) .PHONY: all -#/ -# Compiles C source files. + +# Compile C source. # -# @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`) -#/ +# This target compiles C source files. + $(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm -#/ -# Runs compiled benchmarks. + +# Run a benchmark. # -# @example -# make run -#/ +# This target runs a benchmark. + run: $(c_targets) $(QUIET) ./$< .PHONY: run -#/ -# Removes generated files. + +# Perform clean-up. # -# @example -# make clean -#/ +# This target removes generated files. + clean: $(QUIET) -rm -f *.o *.out -.PHONY: clean +.PHONY: clean \ No newline at end of file From 5698fad7c123228ac01d186b0c65e01738bc0194 Mon Sep 17 00:00:00 2001 From: Shashankss1205 Date: Sun, 3 Mar 2024 18:43:52 +0530 Subject: [PATCH 7/8] feat: add C implementation for @stdlib/math/base/special/maxabs --- .../math/base/special/maxabs/README.md | 94 +++++++++- .../maxabs/benchmark/benchmark.native.js | 62 +++++++ .../maxabs/benchmark/c/native/Makefile | 146 +++++++++++++++ .../maxabs/benchmark/c/native/benchmark.c | 138 ++++++++++++++ .../math/base/special/maxabs/binding.gyp | 170 ++++++++++++++++++ .../base/special/maxabs/examples/c/Makefile | 146 +++++++++++++++ .../base/special/maxabs/examples/c/example.c | 34 ++++ .../math/base/special/maxabs/include.gypi | 53 ++++++ .../include/stdlib/math/base/special/maxabs.h | 38 ++++ .../math/base/special/maxabs/lib/native.js | 59 ++++++ .../math/base/special/maxabs/manifest.json | 75 ++++++++ .../math/base/special/maxabs/src/Makefile | 70 ++++++++ .../math/base/special/maxabs/src/addon.c | 22 +++ .../math/base/special/maxabs/src/main.c | 40 +++++ .../base/special/maxabs/test/test.native.js | 93 ++++++++++ 15 files changed, 1239 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/include/stdlib/math/base/special/maxabs.h create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/maxabs/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/maxabs/README.md b/lib/node_modules/@stdlib/math/base/special/maxabs/README.md index f0fa3f32096b..e4eba9fd7ffe 100644 --- a/lib/node_modules/@stdlib/math/base/special/maxabs/README.md +++ b/lib/node_modules/@stdlib/math/base/special/maxabs/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2024 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -103,6 +103,98 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/maxabs.h" +``` + +#### stdlib_base_maxabs( x, y ) + +Returns the maximum absolute value. + +```c +double out = stdlib_base_maxabs( -4.2, 3.14 ); +// returns 4.2 + +out = stdlib_base_maxabs( 0.0, -0.0 ); +// returns +0.0 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **y**: `[in] double` input value. + +```c +double stdlib_base_maxabs( const double x, const double y ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/maxabs.h" +#include +#include +int main( void ) { + double x; + double y; + double v; + int i; + + for ( i = 0; i < 100; i++ ) { + x = ( ( (double)rand() / (double)RAND_MAX ) * 1000.0 ) - 500.0; + y = ( ( (double)rand() / (double)RAND_MAX ) * 1000.0 ) - 500.0; + v = stdlib_base_maxabs( x, y ); + printf( "x: %lf, y: %lf, maxabs(x, y): %lf\n", x, y, v ); + } +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f720d94e02ac --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/benchmark.native.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var maxabs = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( maxabs instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*1000.0 ) - 500.0; + y = ( randu()*1000.0 ) - 500.0; + z = maxabs( x, y ); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/c/native/Makefile new file mode 100644 index 000000000000..0ebf4545e1a9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..43dcdc9dd41e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/maxabs/benchmark/c/native/benchmark.c @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/** +* Benchmark `maxabs`. +*/ +#include "stdlib/math/base/special/maxabs.h" +#include +#include +#include +#include +#include + +#define NAME "maxabs" +#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; +} + +/** +* Generates a random number on the interval [0,1]. +* +* @return random number +*/ +double rand_double() { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +double benchmark() { + double elapsed; + double t; + double x; + double y; + double z; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( 1000.0*rand_double() ) - 500.0; + y = ( 1000.0*rand_double() ) - 500.0; + z = stdlib_base_maxabs( 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; + + // 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 ); +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/maxabs/binding.gyp b/lib/node_modules/@stdlib/math/base/special/maxabs/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/maxabs/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/math/base/special/maxabs/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/maxabs/examples/c/Makefile new file mode 100644 index 000000000000..d53ef397c77d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/maxabs/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/maxabs/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/maxabs/examples/c/example.c new file mode 100644 index 000000000000..aaa192c3dc7a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/maxabs/examples/c/example.c @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/special/maxabs.h" +#include + +int main( void ) { + double x; + double y; + double v; + int i; + + for ( i = 0; i < 100; i++ ) { + x = ( ( (double)rand() / (double)RAND_MAX ) * 1000.0 ) - 500.0; + y = ( ( (double)rand() / (double)RAND_MAX ) * 1000.0 ) - 500.0; + v = stdlib_base_maxabs( x, y ); + printf( "x: %lf, y: %lf, maxabs(x, y): %lf\n", x, y, v ); + } +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/special/maxabs/include.gypi b/lib/node_modules/@stdlib/math/base/special/maxabs/include.gypi new file mode 100644 index 000000000000..c6495fc1da3f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/maxabs/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' Date: Sun, 3 Mar 2024 19:38:05 +0530 Subject: [PATCH 8/8] feat: add C implementation for @stdlib/math/base/assert/is-odd --- .../@stdlib/math/base/assert/is-odd/README.md | 97 +++++++++- .../is-odd/benchmark/benchmark.native.js | 61 +++++++ .../assert/is-odd/benchmark/c/native/Makefile | 146 +++++++++++++++ .../is-odd/benchmark/c/native/benchmark.c | 137 ++++++++++++++ .../math/base/assert/is-odd/binding.gyp | 170 ++++++++++++++++++ .../base/assert/is-odd/examples/c/Makefile | 146 +++++++++++++++ .../base/assert/is-odd/examples/c/example.c | 34 ++++ .../math/base/assert/is-odd/include.gypi | 53 ++++++ .../include/stdlib/math/base/assert/is_odd.h | 40 +++++ .../math/base/assert/is-odd/lib/native.js | 51 ++++++ .../math/base/assert/is-odd/manifest.json | 40 +++++ .../math/base/assert/is-odd/src/Makefile | 70 ++++++++ .../math/base/assert/is-odd/src/addon.c | 90 ++++++++++ .../math/base/assert/is-odd/src/main.c | 36 ++++ .../base/assert/is-odd/test/test.native.js | 96 ++++++++++ 15 files changed, 1264 insertions(+), 3 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/include/stdlib/math/base/assert/is_odd.h create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/README.md b/lib/node_modules/@stdlib/math/base/assert/is-odd/README.md index 46fb3e6bc803..3db4d938602a 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-odd/README.md +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2024 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -104,6 +104,97 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/assert/is_odd.h" +``` + +#### stdlib_base_is_odd( x ) + +Tests if a finite numeric value is an odd number. + +```c +bool out = stdlib_base_is_odd( 1.0 ); +// returns false + +out = stdlib_base_is_odd( 4.0 ); +// returns true +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. + +```c +bool stdlib_base_is_odd( const double x ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/assert/is_odd.h" +#include +#include +#include + +int main( void ) { + double x; + bool v; + int i; + + for ( i = 0; i < 100; i++ ) { + x = ( ( (double)rand() / (double)RAND_MAX ) * 100.0 ); + v = stdlib_base_is_odd( x ); + printf( "x = %lf, is_odd(x) = %s\n", x, ( v ) ? "odd" : "not odd" ); + } +} +``` + +
+ + + +
+ + + @@ -124,7 +215,7 @@ for ( i = 0; i < 100; i++ ) { -[@stdlib/math/base/assert/is-even]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/assert/is-even +[@stdlib/math/base/assert/is-odd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/assert/is-odd diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/benchmark.native.js new file mode 100644 index 000000000000..36a0ea8579d0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/benchmark.native.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var isOdd = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( isOdd instanceof Error ) +}; + + +// MAIN // + +bench( pkg, opts, function benchmark( b ) { + var x; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = round( (randu()*1.0e7) - 5.0e6 ); + y = isOdd( x ); + if ( typeof y !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( y ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..5fd44612794c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/benchmark/c/native/benchmark.c @@ -0,0 +1,137 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/** +* Benchmark `is-odd`. +*/ +#include "stdlib/math/base/assert/is_odd.h" +#include +#include +#include +#include +#include +#include + +#define NAME "is-odd" +#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; +} + +/** +* Generates a random number on the interval [0,1]. +* +* @return random number +*/ +double rand_double() { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +double benchmark() { + double elapsed; + double x; + double t; + bool b; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( rand_double() * 200.0 ) - 100.0; + b = stdlib_base_is_odd( x ); + if ( b != true && b != false ) { + printf( "should return either true or false\n" ); + break; + } + } + elapsed = tic() - t; + if ( b != true && b != false ) { + printf( "should return either true or false\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 ); +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/binding.gyp b/lib/node_modules/@stdlib/math/base/assert/is-odd/binding.gyp new file mode 100644 index 000000000000..507cb00291e7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/assert/is-odd/examples/c/Makefile new file mode 100644 index 000000000000..d53ef397c77d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/examples/c/example.c b/lib/node_modules/@stdlib/math/base/assert/is-odd/examples/c/example.c new file mode 100644 index 000000000000..c638844bd43f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/examples/c/example.c @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/assert/is_odd.h" +#include +#include +#include + +int main( void ) { + double x; + bool v; + int i; + + for ( i = 0; i < 100; i++ ) { + x = ( ( (double)rand() / (double)RAND_MAX ) * 100.0 ); + v = stdlib_base_is_odd( x ); + printf( "x = %lf, is_odd(x) = %s\n", x, ( v ) ? "odd" : "not odd" ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/include.gypi b/lib/node_modules/@stdlib/math/base/assert/is-odd/include.gypi new file mode 100644 index 000000000000..c6495fc1da3f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + +/* +* 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 + +/** +* Tests if a finite numeric value is an odd number. +*/ +bool stdlib_base_is_odd( const double x ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_ASSERT_IS_ODD_H \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/lib/native.js b/lib/node_modules/@stdlib/math/base/assert/is-odd/lib/native.js new file mode 100644 index 000000000000..3c8a963c8350 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/lib/native.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var Boolean = require( '@stdlib/boolean/ctor' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Tests if a finite numeric value is an odd number. +* +* @private +* @param {number} x - value to test +* @returns {boolean} boolean indicating whether the number is odd +* +* @example +* var bool = isOdd( 2.0 ); +* // returns false +* +* @example +* var bool = isOdd( 5.0 ); +* // returns true +*/ +function isOdd( x ) { + return Boolean( addon( x ) ); +} + + +// EXPORTS // + +module.exports = isOdd; diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/manifest.json b/lib/node_modules/@stdlib/math/base/assert/is-odd/manifest.json new file mode 100644 index 000000000000..5ed819710e15 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/manifest.json @@ -0,0 +1,40 @@ +{ + "options": {}, + "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": [ + { + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-integer" + ] + } + ] +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/src/Makefile b/lib/node_modules/@stdlib/math/base/assert/is-odd/src/Makefile new file mode 100644 index 000000000000..81bb164286c3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/src/addon.c b/lib/node_modules/@stdlib/math/base/assert/is-odd/src/addon.c new file mode 100644 index 000000000000..86c545fce598 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/src/addon.c @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/assert/is_odd.h" +#include +#include +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + napi_status status; + + // Get callback arguments: + size_t argc = 1; + napi_value argv[ 1 ]; + status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); + assert( status == napi_ok ); + + // Check whether we were provided the correct number of arguments: + if ( argc < 1 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); + assert( status == napi_ok ); + return NULL; + } + if ( argc > 1 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + double x; + status = napi_get_value_double( env, argv[ 0 ], &x ); + assert( status == napi_ok ); + + bool result = stdlib_base_is_odd( x ); + + napi_value v; + status = napi_create_int32( env, (int32_t)result, &v ); + assert( status == napi_ok ); + + return v; +} + +/** +* Initializes a Node-API module. +* +* @private +* @param env environment under which the function is invoked +* @param exports exports object +* @return main export +*/ +static napi_value init( napi_env env, napi_value exports ) { + napi_value fcn; + napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; +} + +NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) \ No newline at end of file diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/src/main.c b/lib/node_modules/@stdlib/math/base/assert/is-odd/src/main.c new file mode 100644 index 000000000000..5c3f8cf03bd2 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/src/main.c @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/assert/is_odd.h" +#include "stdlib/math/base/assert/is_integer.h" + +/** +* Test if a finite numeric value is an odd number. +* +* @param x input value +* @return output value +* +* @example +* #include +* +* bool out = stdlib_base_is_odd( 3.0 ); +* // returns true +*/ +bool stdlib_base_is_odd( const double x ) { + return !( stdlib_base_is_integer( x/2.0 ) ); +} diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.native.js b/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.native.js new file mode 100644 index 000000000000..eb85371aea8a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.native.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var isOdd = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( isOdd instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isOdd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided an odd number', opts, function test( t ) { + var bool; + var x; + var i; + for ( i = 0; i < 1000; i++ ) { + x = round( randu()*1.0e6 ) - 5.0e5; + x *= 2; // always odd + bool = isOdd( x ); + t.equal( bool, true, 'returns true when provided '+x ); + } + t.end(); +}); + +tape( 'the function returns `false` if provided an odd number', opts, function test( t ) { + var bool; + var x; + var i; + for ( i = 0; i < 1000; i++ ) { + x = round( randu()*1.0e6 ) - 5.0e5; + if ( x%2 === 0 ) { + x += 1; + } + bool = isOdd( x ); + t.equal( bool, false, 'returns false when provided '+x ); + } + t.end(); +}); + +tape( 'the function returns `false` if provided `+-0`', opts, function test( t ) { + t.equal( isOdd( +0.0 ), false, 'returns false' ); + t.equal( isOdd( -0.0 ), false, 'returns false' ); + t.end(); +}); + +tape( 'WARNING: the function returns `true` if provided `+infinity`', opts, function test( t ) { + t.equal( isOdd( PINF ), true, 'returns true' ); + t.end(); +}); + +tape( 'WARNING: the function returns `true` if provided `-infinity`', opts, function test( t ) { + t.equal( isOdd( NINF ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if provided `NaN`', opts, function test( t ) { + t.equal( isOdd( NaN ), false, 'returns false' ); + t.equal( isOdd( 0.0/0.0 ), false, 'returns false' ); + t.end(); +});