From 0d5c983a8e1f1780a14002c230ede7a279093ae2 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 00:53:49 +0530 Subject: [PATCH 01/12] feat: add C implementation for math/base/special/boxcox --- .../math/base/special/boxcox/README.md | 97 +++++++++ .../boxcox/benchmark/benchmark.native.js | 62 ++++++ .../boxcox/benchmark/c/native/Makefile | 146 +++++++++++++ .../boxcox/benchmark/c/native/benchmark.c | 138 ++++++++++++ .../math/base/special/boxcox/binding.gyp | 170 +++++++++++++++ .../base/special/boxcox/examples/c/Makefile | 146 +++++++++++++ .../base/special/boxcox/examples/c/example.c | 36 ++++ .../math/base/special/boxcox/include.gypi | 53 +++++ .../include/stdlib/math/base/special/boxcox.h | 38 ++++ .../math/base/special/boxcox/lib/native.js | 72 +++++++ .../math/base/special/boxcox/manifest.json | 87 ++++++++ .../math/base/special/boxcox/src/Makefile | 70 ++++++ .../math/base/special/boxcox/src/addon.c | 23 ++ .../math/base/special/boxcox/src/main.c | 55 +++++ .../base/special/boxcox/test/test.native.js | 202 ++++++++++++++++++ 15 files changed, 1395 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/include/stdlib/math/base/special/boxcox.h create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/boxcox/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/README.md b/lib/node_modules/@stdlib/math/base/special/boxcox/README.md index 3032d7173169..8fdc0275d47d 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/README.md +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/README.md @@ -109,6 +109,103 @@ for ( i = 0; i < x.length; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/boxcox.h" +``` + +#### stdlib_base_boxcox( x, lambda ) + +Computes a one-parameter [Box-Cox transformation][box-cox-transformation]. + +```c +double out = stdlib_base_boxcox( 1.0, 2.5 ); +// returns 0.0 + +out = stdlib_base_boxcox( 4.0, 2.5 ); +// returns 12.4 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **lambda**: `[in] double` power parameter. + +```c +double stdlib_base_boxcox( const double x, const double lambda ); +``` + +
+ + + + + +
+ +### Notes + +- Computes a one-parameter [Box-Cox transformation][box-cox-transformation]. + +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/boxcox.h" +#include + +int main( void ) { + const double x[] = { -1.0, 10.0, 1.0 }; + const double y[] = { -0.5, 5.0, 0.5 }; + + double out; + int i; + int j; + for ( i = 0; i < 3; i++ ) { + for ( j = 0; j < 3; j++ ){ + out = stdlib_base_boxcox( x[ i ], y[ j ] ); + printf ( "x: %lf, y: %lf, out: %lf\n", x[ i ], y[ j ], out ); + } + } +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/benchmark.native.js new file mode 100644 index 000000000000..ad95b8ece8ec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/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 boxcox = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( boxcox instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var x; + var y; + var r; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = ( randu()*10.0 ) + 1.0; + y = ( randu()*10.0 ) + 1.0; + r = boxcox( x, y ); + if ( isnan( r ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( r ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/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/boxcox/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..d414e0d7b576 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/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 `boxcox`. +*/ +#include "stdlib/math/base/special/boxcox.h" +#include +#include +#include +#include +#include + +#define NAME "boxcox" +#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 y; + double r; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( ( rand_double() * 10.0 ) + 1.0 ); + y = ( ( rand_double() * 10.0 ) + 1.0 ); + r = stdlib_base_boxcox( x, y ); + if ( r != r ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( r != r ) { + 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::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/binding.gyp b/lib/node_modules/@stdlib/math/base/special/boxcox/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/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/boxcox/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/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 := 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/boxcox/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/example.c new file mode 100644 index 000000000000..ed8085d96b11 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/example.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/special/boxcox.h" +#include + +int main( void ) { + const double x[] = { -1.0, 10.0, 1.0 }; + const double y[] = { -0.5, 5.0, 0.5 }; + + double out; + int i; + int j; + for ( i = 0; i < 3; i++ ) { + for ( j = 0; j < 3; j++ ){ + out = stdlib_base_boxcox( x[ i ], y[ j ] ); + printf ( "x: %lf, y: %lf, out: %lf\n", x[ i ], y[ j ], out ); + } + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/include.gypi b/lib/node_modules/@stdlib/math/base/special/boxcox/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/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: Thu, 14 Mar 2024 01:02:53 +0530 Subject: [PATCH 02/12] feat: add C implementation for math/base/special/boxcox --- .../boxcox/benchmark/c/native/Makefile | 79 +++++-------------- 1 file changed, 20 insertions(+), 59 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile index f69e9da2b4d3..ad9fedcd4fff 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/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,77 +64,43 @@ 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 From 079b5e5b0bbbea1d110565ae50b19be6cb3f944f Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 01:04:54 +0530 Subject: [PATCH 03/12] feat: add C implementation for math/base/special/boxcox --- .../@stdlib/math/base/special/boxcox/examples/c/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/Makefile index f69e9da2b4d3..6aed70daf167 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/examples/c/Makefile @@ -82,7 +82,7 @@ LIBRARIES ?= LIBPATH ?= # List of C targets: -c_targets := benchmark.out +c_targets := example.out # RULES # @@ -124,7 +124,7 @@ $(c_targets): %.out: %.c $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) #/ -# Runs compiled benchmarks. +# Runs compiled examples. # # @example # make run From 7508ab4a09f4f2f971989828305d066f8e4e3947 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 01:12:35 +0530 Subject: [PATCH 04/12] feat: add C implementation for math/base/special/boxcox --- .../boxcox/benchmark/c/native/Makefile | 79 ++++++++++++++----- 1 file changed, 59 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile index ad9fedcd4fff..f69e9da2b4d3 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/c/native/Makefile @@ -16,14 +16,15 @@ # limitations under the License. #/ - # VARIABLES # ifndef VERBOSE QUIET := @ +else + QUIET := endif -# Determine the OS: +# Determine the OS ([1][1], [2][2]). # # [1]: https://en.wikipedia.org/wiki/Uname#Examples # [2]: http://stackoverflow.com/a/27776822/2225624 @@ -36,6 +37,10 @@ ifneq (, $(findstring MSYS,$(OS))) else ifneq (, $(findstring CYGWIN,$(OS))) OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif endif endif endif @@ -54,7 +59,7 @@ CFLAGS ?= \ -Wall \ -pedantic -# Determine whether to generate [position independent code][1]: +# 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 @@ -64,43 +69,77 @@ 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 -# TARGETS # +# RULES # -# Default target. +#/ +# Compiles source files. # -# This target is the 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 +#/ all: $(c_targets) .PHONY: all - -# Compile C source. +#/ +# Compiles C source files. # -# This target 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) -o $@ $< -lm - + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) -# Run a benchmark. +#/ +# Runs compiled benchmarks. # -# This target runs a benchmark. - +# @example +# make run +#/ run: $(c_targets) $(QUIET) ./$< .PHONY: run - -# Perform clean-up. +#/ +# Removes generated files. # -# This target removes generated files. - +# @example +# make clean +#/ clean: $(QUIET) -rm -f *.o *.out From d43451d239dbd498b3134d3f90ee692472dd6f8f Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 01:38:50 +0530 Subject: [PATCH 05/12] Update README.md Signed-off-by: GUNJ JOSHI --- lib/node_modules/@stdlib/math/base/special/boxcox/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/README.md b/lib/node_modules/@stdlib/math/base/special/boxcox/README.md index 8fdc0275d47d..05644832d6d1 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/README.md +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/README.md @@ -153,7 +153,7 @@ The function accepts the following arguments: - **lambda**: `[in] double` power parameter. ```c -double stdlib_base_boxcox( const double x, const double lambda ); +double stdlib_base_boxcox ( const double x, const double lambda ); ```
From 70d43716b8abca39c3bee6e500b458978e4b1e80 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 01:40:39 +0530 Subject: [PATCH 06/12] Update README.md Signed-off-by: GUNJ JOSHI --- lib/node_modules/@stdlib/math/base/special/boxcox/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/README.md b/lib/node_modules/@stdlib/math/base/special/boxcox/README.md index 05644832d6d1..5bbe1ecc2817 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/README.md +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/README.md @@ -164,10 +164,6 @@ double stdlib_base_boxcox ( const double x, const double lambda );
-### Notes - -- Computes a one-parameter [Box-Cox transformation][box-cox-transformation]. -
From 194ddf765f96d4d639297c0a7f82e6336731fa86 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 01:41:53 +0530 Subject: [PATCH 07/12] Update benchmark.native.js Signed-off-by: GUNJ JOSHI --- .../math/base/special/boxcox/benchmark/benchmark.native.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/benchmark.native.js index ad95b8ece8ec..76864b545343 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/benchmark/benchmark.native.js @@ -46,8 +46,8 @@ bench( pkg+'::native', opts, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*10.0 ) + 1.0; - y = ( randu()*10.0 ) + 1.0; + x = ( randu() * 10.0 ) + 1.0; + y = ( randu() * 10.0 ) + 1.0; r = boxcox( x, y ); if ( isnan( r ) ) { b.fail( 'should not return NaN' ); From 1d0f44375746db119ae14850f54c954d0741f8de Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 01:43:42 +0530 Subject: [PATCH 08/12] Update boxcox.h Signed-off-by: GUNJ JOSHI --- .../special/boxcox/include/stdlib/math/base/special/boxcox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/include/stdlib/math/base/special/boxcox.h b/lib/node_modules/@stdlib/math/base/special/boxcox/include/stdlib/math/base/special/boxcox.h index c45941239f41..599194118ef2 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/include/stdlib/math/base/special/boxcox.h +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/include/stdlib/math/base/special/boxcox.h @@ -29,7 +29,7 @@ extern "C" { /** * Computes a one-parameter Box-Cox transformation. */ -double stdlib_base_boxcox( const double x, const double y ); +double stdlib_base_boxcox( const double x, const double lambda ); #ifdef __cplusplus } From 914ab822f03ff37fd15b8de3307d3c9c08cf8cc3 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 01:45:51 +0530 Subject: [PATCH 09/12] Update test.native.js Signed-off-by: GUNJ JOSHI --- .../@stdlib/math/base/special/boxcox/test/test.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/boxcox/test/test.native.js index 6ecd41c701a5..4b074c7db737 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/test/test.native.js @@ -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. From 8627c0f6f6d0a560b43eedb27c18d4ace423a93a Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Thu, 14 Mar 2024 11:44:42 +0530 Subject: [PATCH 10/12] Update main.c Signed-off-by: GUNJ JOSHI --- lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c b/lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c index 6dfbe79ad9f5..dc6750eaf648 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c @@ -38,7 +38,7 @@ * @returns Box-Cox transformation * * @example -* var v = boxcox( 1.0, 2.5 ); +* double v = stdlib_base_boxcox( 1.0, 2.5 ); * // returns 0.0 */ double stdlib_base_boxcox( const double x, const double lambda ) { From b782bb722d7fbf9c6c95dd231d00697b1a8be2cc Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 14 Mar 2024 00:10:43 -0700 Subject: [PATCH 11/12] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/math/base/special/boxcox/lib/native.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/lib/native.js b/lib/node_modules/@stdlib/math/base/special/boxcox/lib/native.js index 701f51e2f53c..8c5f81a1a0a5 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/lib/native.js @@ -28,12 +28,7 @@ var addon = require( './../src/addon.node' ); /** * Computes a one-parameter Box-Cox transformation. * -* ## Method -* -* - If \\( \lambda << 1 \\) and \\( \ln( x ) < 1.0 \\), then the product \\( \lambda \cdot \ln(x) \\) can lose precision, and, furthermore, \\( \operatorname{expm1}(x) = x \\) for \\( x < \epsilon \\). -* - For double-precision floating-point numbers, the range of the natural log is \\( \[-744.44, 709.78\] and \\( \epsilon \\) is the smallest value produced. -* - The value range means that we will have \\( |\lambda \cdot \ln(x)| < \epsilon \\) whenever \\( |\lambda| \leq \frac{\epsilon}{-\ln(d) \\), where \\( d \\) is the minimum double-precision floating-point number, thus corresponding to the value \\( \approx 2.98 \times 10^{-19} \\). -* +* @private * @param {number} x - input value * @param {number} lambda - power parameter * @returns {number} Box-Cox transformation From d5d3603684ddad11cab0be628757ea1e14d0e933 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 14 Mar 2024 00:12:25 -0700 Subject: [PATCH 12/12] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c b/lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c index dc6750eaf648..1def199b1e2c 100644 --- a/lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/boxcox/src/main.c @@ -35,7 +35,7 @@ * * @param x input value * @param lambda power parameter -* @returns Box-Cox transformation +* @return Box-Cox transformation * * @example * double v = stdlib_base_boxcox( 1.0, 2.5 );