From 2f2dd8f45d7e76c9ebccb3a3dbc0c8a54f689410 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 1 Jun 2025 09:41:11 -0700 Subject: [PATCH 1/6] feat: temp commit --- .../math/base/special/cpolarf/README.md | 238 ++++++++++++++++++ .../special/cpolarf/benchmark/benchmark.js | 83 ++++++ .../cpolarf/benchmark/benchmark.native.js | 65 +++++ .../cpolarf/benchmark/c/native/Makefile | 146 +++++++++++ .../cpolarf/benchmark/c/native/benchmark.c | 141 +++++++++++ .../math/base/special/cpolarf/binding.gyp | 170 +++++++++++++ .../math/base/special/cpolarf/docs/repl.txt | 54 ++++ .../special/cpolarf/docs/types/index.d.ts | 85 +++++++ .../base/special/cpolarf/docs/types/test.ts | 112 +++++++++ .../base/special/cpolarf/examples/c/Makefile | 146 +++++++++++ .../base/special/cpolarf/examples/c/example.c | 43 ++++ .../base/special/cpolarf/examples/index.js | 39 +++ .../math/base/special/cpolarf/include.gypi | 53 ++++ .../stdlib/math/base/special/cpolarf.h | 40 +++ .../math/base/special/cpolarf/lib/assign.js | 53 ++++ .../math/base/special/cpolarf/lib/index.js | 61 +++++ .../math/base/special/cpolarf/lib/main.js | 47 ++++ .../math/base/special/cpolarf/lib/native.js | 51 ++++ .../math/base/special/cpolarf/manifest.json | 81 ++++++ .../math/base/special/cpolarf/package.json | 77 ++++++ .../math/base/special/cpolarf/src/Makefile | 70 ++++++ .../math/base/special/cpolarf/src/addon.c | 138 ++++++++++ .../math/base/special/cpolarf/src/main.c | 46 ++++ .../base/special/cpolarf/test/test.assign.js | 109 ++++++++ .../math/base/special/cpolarf/test/test.js | 40 +++ .../base/special/cpolarf/test/test.main.js | 70 ++++++ .../base/special/cpolarf/test/test.native.js | 79 ++++++ 27 files changed, 2337 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/README.md create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/include/stdlib/math/base/special/cpolarf.h create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/lib/assign.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/package.json create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.main.js create mode 100644 lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md b/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md new file mode 100644 index 000000000000..bfdc18a4f5d0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md @@ -0,0 +1,238 @@ + + +# cpolarf + +> Compute the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdlib/math/base/special/cphasef] of a single-precision complex floating-point number. + +
+ +
+ + + +
+ +## Usage + +```javascript +var cpolarf = require( '@stdlib/math/base/special/cpolarf' ); +``` + +#### cpolarf( z ) + +Computes the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdlib/math/base/special/cphasef] of a single-precision complex floating-point number. + +```javascript +var Complex64 = require( '@stdlib/complex/float32/ctor' ); + +var o = cpolarf( new Complex64( 5.0, 3.0 ) ); +// returns [ ~5.83, ~0.5404 ] +``` + +#### cpolarf.assign( z, out, stride, offset ) + +Computes the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdlib/math/base/special/cphasef] of a single-precision complex floating-point number and assigns results to a provided output array. + +```javascript +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var out = new Float32Array( 2 ); + +var v = cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, 0 ); +// returns [ ~5.83, ~0.5404 ] + +var bool = ( v === out ); +// returns true +``` + +
+ + + +
+ +## Examples + + + +```javascript +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var cpolarf = require( '@stdlib/math/base/special/cpolarf' ); + +var re; +var im; +var z; +var o; +var i; + +for ( i = 0; i < 100; i++ ) { + re = round( randu()*100.0 ) - 50.0; + im = round( randu()*100.0 ) - 50.0; + z = new Complex64( re, im ); + o = cpolarf( z ); + z = z.toString(); + console.log( 'abs(%s) = %d. arg(%s) = %d', z, o[0], z, o[1] ); +} +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/cpolarf.h" +``` + +#### stdlib_base_cpolarf( z, cabsf, cphasef ) + +Computes the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdlib/math/base/special/cphasef] of a single-precision complex floating-point number. + +```c +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/real.h" +#include "stdlib/complex/float32/imag.h" + +stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 ); +double cabsf; +double cphasef; +stdlib_base_cpolarf( z, &cabsf, &cphasef ); +``` + +The function accepts the following arguments: + +- **z**: `[in] stdlib_complex128_t` input value. +- **cabsf**: `[out] double*` destination for the absolute value. +- **cphasef**: `[out] double*` destination for the phase value in radians. + +```c +double stdlib_base_cpolarf( const stdlib_complex128_t z, double *cabsf, double *cphasef ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/cpolarf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include + +int main( void ) { + const stdlib_complex128_t x[] = { + stdlib_complex128( 3.14, 1.0 ), + stdlib_complex128( -3.14, -1.0 ), + stdlib_complex128( 0.0, 0.0 ), + stdlib_complex128( 0.0/0.0, 0.0/0.0 ) + }; + + double cphasef; + double cabsf; + double re; + double im; + int i; + for ( i = 0; i < 4; i++ ) { + stdlib_base_cpolarf( x[i], &cabsf, &cphasef ); + stdlib_complex128_reim( x[i], &re, &im ); + printf( "cpolarf(%lf + %lfi) => cabsf: %lf, cphasef: %lf\n", re, im, cabsf, cphasef ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.js new file mode 100644 index 000000000000..410bd97c246b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.js @@ -0,0 +1,83 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isArray = require( '@stdlib/assert/is-array' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var pkg = require( './../package.json' ).name; +var cpolarf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var y; + var i; + + values = [ + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cpolarf( values[ i%values.length ] ); + if ( y.length === 0 ) { + b.fail( 'should not be empty' ); + } + } + b.toc(); + if ( !isArray( y ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':assign', function benchmark( b ) { + var values; + var y; + var i; + + values = [ + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + y = [ 0.0, 0.0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + cpolarf.assign( values[ i%values.length ], y, 1, 0 ); + if ( y[ 0 ] !== y[ 0 ] || y[ 1 ] !== y[ 1 ] ) { + b.fail( 'should not be empty' ); + } + } + b.toc(); + if ( !isArray( y ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f8de9f937699 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.native.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isArray = require( '@stdlib/assert/is-array' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var cpolarf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cpolarf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var values; + var y; + var i; + + values = [ + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cpolarf( values[ i%values.length ] ); + if ( y.length === 0 ) { + b.fail( 'should not be empty' ); + } + } + b.toc(); + if ( !isArray( y ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/Makefile new file mode 100644 index 000000000000..3cbfe3fef3b6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2023 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/cpolarf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c new file mode 100644 index 000000000000..751a519fba91 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c @@ -0,0 +1,141 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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/cpolarf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include +#include +#include +#include +#include + +#define NAME "cpolarf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double cphasef; + double cabsf; + double re; + double im; + double t; + int i; + + stdlib_complex128_t z; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + re = ( 1000.0*rand_double() ) - 500.0; + im = ( 1000.0*rand_double() ) - 500.0; + z = stdlib_complex128( re, im ); + stdlib_base_cpolarf( z, &cabsf, &cphasef); + if ( cabsf != cabsf ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( cphasef != cphasef ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::native::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/cpolarf/binding.gyp new file mode 100644 index 000000000000..f2b466aef5c4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2023 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/cpolarf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/repl.txt new file mode 100644 index 000000000000..d8ee16b9481f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/repl.txt @@ -0,0 +1,54 @@ + +{{alias}}( z ) + Returns the absolute value and phase of a single-precision complex + floating-point number. + + Parameters + ---------- + z: Complex64 + Complex number. + + Returns + ------- + out: Array + Absolute value and phase, respectively. + + Examples + -------- + > var out = {{alias}}( new {{alias:@stdlib/complex/float32/ctor}}( 5.0, 3.0 ) ) + [ ~5.83, ~0.5404 ] + + +{{alias}}.assign( z, out, stride, offset ) + Returns the absolute value and phase of a single-precision complex + floating-point number and assigns results to a provided output array. + + Parameters + ---------- + z: Complex64 + Complex number. + + out: Array|TypedArray|Object + Destination array. + + stride: integer + Output array stride. + + offset: integer + Output array index offset. + + Returns + ------- + out: Array|TypedArray|Object + Absolute value and phase, respectively. + + Examples + -------- + > var out = new {{alias:@stdlib/array/float32}}( 2 ); + > var v = {{alias}}.assign( new {{alias:@stdlib/complex/float32/ctor}}( 5.0, 3.0 ), out, 1, 0 ) + [ ~5.83, ~0.5404 ] + > var bool = ( v === out ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts new file mode 100644 index 000000000000..d248d8e248ac --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts @@ -0,0 +1,85 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Complex64 } from '@stdlib/types/complex'; +import { Collection } from '@stdlib/types/array'; + +/** +* Interface describing `cpolarf`. +*/ +interface Cpolar { + /** + * Computes the absolute value and the phase of a single-precision complex floating-point number. + * + * @param z - complex number + * @returns absolute value and phase, respectively + * + * @example + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * + * var v = cpolarf( new Complex64( 5.0, 3.0 ) ); + * // returns [ ~5.83, ~0.5404 ] + */ + ( z: Complex64 ): Array; + + /** + * Computes the absolute value and the phase of a single-precision complex floating-point number and assigns results to a provided output array. + * + * @param z - complex number + * @param out - output array + * @param stride - output array stride + * @param offset - output array index offset + * @returns output array + * + * @example + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var out = new Float32Array( 2 ); + * + * var v = cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, 0 ); + * // returns [ ~5.83, ~0.5404 ] + * + * var bool = ( v === out ); + * // returns true + */ + assign( z: Complex64, out: Collection, stride: number, offset: number ): Collection; +} + +/** +* Computes the absolute value and the phase of a single-precision complex floating-point number. +* +* @param z - complex number +* @returns absolute value and phase, respectively +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* var v = cpolarf( new Complex64( 5.0, 3.0 ) ); +* // returns [ ~5.83, ~0.5404 ] +*/ +declare var cpolarf: Cpolar; + + +// EXPORTS // + +export = cpolarf; diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts new file mode 100644 index 000000000000..378ac09b1315 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts @@ -0,0 +1,112 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import cpolarf = require( './index' ); + + +// TESTS // + +// The function returns an array of numbers... +{ + cpolarf( new Complex64( 5.0, 3.0 ) ); // $ExpectType number[] +} + +// The compiler throws an error if the function is provided a complex number... +{ + cpolarf( true ); // $ExpectError + cpolarf( false ); // $ExpectError + cpolarf( null ); // $ExpectError + cpolarf( undefined ); // $ExpectError + cpolarf( '5' ); // $ExpectError + cpolarf( [] ); // $ExpectError + cpolarf( {} ); // $ExpectError + cpolarf( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + cpolarf(); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns an array-like object containing numbers... +{ + const out = [ 0.0, 0.0 ]; + + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, 0 ); // $ExpectType Collection + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, 0 ); // $ExpectType Collection +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not a number... +{ + const out = [ 0.0, 0.0 ]; + + cpolarf.assign( true, out, 1, 0 ); // $ExpectError + cpolarf.assign( false, out, 1, 0 ); // $ExpectError + cpolarf.assign( '5', out, 1, 0 ); // $ExpectError + cpolarf.assign( null, out, 1, 0 ); // $ExpectError + cpolarf.assign( [], out, 1, 0 ); // $ExpectError + cpolarf.assign( {}, out, 1, 0 ); // $ExpectError + cpolarf.assign( ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object... +{ + cpolarf.assign( new Complex64( 5.0, 3.0 ), 1, 1, 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), true, 1, 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), false, 1, 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), null, 1, 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a number... +{ + const out = [ 0.0, 0 ]; + + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, '5', 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, true, 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, false, 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, null, 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, [], 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, {}, 0 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const out = [ 0.0, 0 ]; + + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, '5' ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, true ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, false ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, null ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, [] ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, {} ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const out = [ 0.0, 0 ]; + + cpolarf.assign(); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ) ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1 ); // $ExpectError + cpolarf.assign( new Complex64( 5.0, 3.0 ), out, 1, 0, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/Makefile new file mode 100644 index 000000000000..f0ae66fecf01 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2023 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/example.c new file mode 100644 index 000000000000..28e8df2aa39d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/example.c @@ -0,0 +1,43 @@ + +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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/cpolarf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" +#include + +int main( void ) { + const stdlib_complex128_t x[] = { + stdlib_complex128( 3.14, 1.0 ), + stdlib_complex128( -3.14, -1.0 ), + stdlib_complex128( 0.0, 0.0 ), + stdlib_complex128( 0.0/0.0, 0.0/0.0 ) + }; + + double cphasef; + double cabsf; + double re; + double im; + int i; + for ( i = 0; i < 4; i++ ) { + stdlib_base_cpolarf( x[i], &cabsf, &cphasef ); + stdlib_complex128_reim( x[i], &re, &im ); + printf( "cpolarf(%lf + %lfi) => cabsf: %lf, cphasef: %lf\n", re, im, cabsf, cphasef ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js new file mode 100644 index 000000000000..08cb37348e71 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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. +*/ + +'use strict'; + +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var cpolarf = require( './../lib' ); + +var re; +var im; +var z; +var o; +var i; + +for ( i = 0; i < 100; i++ ) { + re = round( randu()*100.0 ) - 50.0; + im = round( randu()*100.0 ) - 50.0; + z = new Complex64( re, im ); + o = cpolarf( z ); + z = z.toString(); + console.log( 'abs(%s) = %d. arg(%s) = %d', z, o[0], z, o[1] ); +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/include.gypi b/lib/node_modules/@stdlib/math/base/special/cpolarf/include.gypi new file mode 100644 index 000000000000..78db9faf8c74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2023 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': [ + '[ ~5.83, ~0.5404 ] +* +* var bool = ( v === out ); +* // returns true +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var assign = require( './assign.js' ); +var main = require( './main.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/main.js new file mode 100644 index 000000000000..a2c92748ca7a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/main.js @@ -0,0 +1,47 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Computes the absolute value and the phase of a single-precision complex floating-point number. +* +* @param {Complex64} z - complex number +* @returns {Array} absolute value and phase (in radians) +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* var o = cpolarf( new Complex64( 5.0, 3.0 ) ); +* // returns [ ~5.83, ~0.5404 ] +*/ +function cpolarf( z ) { + return assign( z, [ 0.0, 0.0 ], 1, 0 ); +} + + +// EXPORTS // + +module.exports = cpolarf; diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/native.js new file mode 100644 index 000000000000..c512f95e3561 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/native.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 Float32Array = require( '@stdlib/array/float32' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes the absolute value and the phase of a single-precision complex floating-point number. +* +* @private +* @param {Complex64} z - complex number +* @returns {Array} absolute value and phase (in radians) +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* var o = cpolarf( new Complex64( 5.0, 3.0 ) ); +* // returns [ ~5.83, ~0.5404 ] +*/ +function cpolarf( z ) { + var out = new Float32Array( 2 ); + addon( out, z ); + return [ out[ 0 ], out[ 1 ] ]; +} + + +// EXPORTS // + +module.exports = cpolarf; diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json b/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json new file mode 100644 index 000000000000..a855cd198c51 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json @@ -0,0 +1,81 @@ +{ + "options": { + "task": "build" + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/argv", + "@stdlib/complex/float64/ctor", + "@stdlib/complex/float64/reim", + "@stdlib/math/base/special/cphasef", + "@stdlib/math/base/special/cabsf" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float64/ctor", + "@stdlib/complex/float64/reim", + "@stdlib/math/base/special/cphasef", + "@stdlib/math/base/special/cabsf" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float64/ctor", + "@stdlib/complex/float64/reim", + "@stdlib/math/base/special/cphasef", + "@stdlib/math/base/special/cabsf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/package.json b/lib/node_modules/@stdlib/math/base/special/cpolarf/package.json new file mode 100644 index 000000000000..b3cdaafde8ec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/package.json @@ -0,0 +1,77 @@ +{ + "name": "@stdlib/math/base/special/cpolarf", + "version": "0.0.0", + "description": "Compute the absolute value and the phase of a single-precision complex floating-point number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "math.abs", + "cabsf", + "abs", + "absolute", + "magnitude", + "modulus", + "distance", + "cphasef", + "phase", + "argument", + "arg", + "carg", + "angle", + "polar", + "complex", + "cmplx", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/Makefile new file mode 100644 index 000000000000..904c7dc4bd7a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2023 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/addon.c new file mode 100644 index 000000000000..3916c4495977 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/addon.c @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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/cpolarf.h" +#include "stdlib/napi/argv.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @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 = 2; + napi_value argv[ 2 ]; + 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 < 2 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); + assert( status == napi_ok ); + return NULL; + } + if ( argc > 2 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); + assert( status == napi_ok ); + return NULL; + } + + bool res; + status = napi_is_typedarray( env, argv[ 0 ], &res ); + assert( status == napi_ok ); + if ( res == false ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float32Array." ); + assert( status == napi_ok ); + return NULL; + } + + // Get the first element out + napi_typedarray_type vtype0; + size_t len; + void *Out; + status = napi_get_typedarray_info( env, argv[ 0 ], &vtype0, &len, &Out, NULL, NULL ); + assert( status == napi_ok ); + if ( vtype0 != napi_float64_array ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float32Array." ); + assert( status == napi_ok ); + return NULL; + } + if ( len != 2 ) { + status = napi_throw_range_error( env, NULL, "invalid argument. First argument must have 2 elements." ); + assert( status == napi_ok ); + return NULL; + } + + // Get the real component + napi_value xre; + status = napi_get_named_property( env, argv[ 1 ], "re", &xre ); + assert( status == napi_ok ); + + napi_valuetype xretype; + status = napi_typeof( env, xre, &xretype ); + assert( status == napi_ok ); + if ( xretype != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." ); + assert( status == napi_ok ); + return NULL; + } + + // Get the imaginary component + napi_value xim; + status = napi_get_named_property( env, argv[ 1 ], "im", &xim ); + assert( status == napi_ok ); + + napi_valuetype ximtype; + status = napi_typeof( env, xim, &ximtype ); + assert( status == napi_ok ); + if ( ximtype != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." ); + assert( status == napi_ok ); + return NULL; + } + + double re; + status = napi_get_value_double( env, xre, &re ); + assert( status == napi_ok ); + + double im; + status = napi_get_value_double( env, xim, &im ); + assert( status == napi_ok ); + + double cabsf; + double cphasef; + stdlib_base_cpolarf( stdlib_complex128( re, im ), &cabsf, &cphasef ); + + double *op = (double *)Out; + op[ 0 ] = cabsf; + op[ 1 ] = cphasef; + + return NULL; +} + +/** +* Initializes a Node-API module. +* +* @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 ) diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c new file mode 100644 index 000000000000..5df3036b5955 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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/cpolarf.h" +#include "stdlib/math/base/special/cphasef.h" +#include "stdlib/math/base/special/cabsf.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/reim.h" + +/** +* Computes the absolute value and the phase of a complex single-precision complex floating-point number. +* +* @param z input value +* @param cabsf destination for absolute value +* @param cphasef destination for phase value +* +* @example +* #include "stdlib/complex/float32/ctor.h" +* #include "stdlib/complex/float32/real.h" +* #include "stdlib/complex/float32/imag.h" +* +* stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 ); +* double cabsf; +* double cphasef; +* stdlib_base_cpolarf( z, &cabsf, &cphasef ); +*/ +void stdlib_base_cpolarf( const stdlib_complex128_t z, double *cabsf, double *cphasef ) { + *cabsf = stdlib_base_cabs( z ); + *cphasef = stdlib_base_cphase( z ); + return; +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.assign.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.assign.js new file mode 100644 index 000000000000..e6e3737e6dbc --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.assign.js @@ -0,0 +1,109 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var cabsf = require( '@stdlib/math/base/special/cabsf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var cphasef = require( '@stdlib/math/base/special/cphasef' ); +var cpolarf = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpolarf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the absolute value and phase of a complex number', function test( t ) { + var expected; + var out; + var v; + + out = [ 0.0, 0.0 ]; + + v = cpolarf( new Complex64( 5.0, 3.0 ), out, 1, 0 ); + expected = [ + cabsf( new Complex64( 5.0, 3.0 ) ), + cphasef( new Complex64( 5.0, 3.0 ) ) + ]; + + t.deepEqual( v, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, both the absolute value and phase are `NaN`', function test( t ) { + var out; + var v; + + out = [ 0.0, 0.0 ]; + + v = cpolarf( new Complex64( NaN, 3.0 ), out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolarf( new Complex64( 5.0, NaN ), out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolarf( new Complex64( NaN, NaN ), out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var out; + var val; + + out = new Float32Array( 4 ); + val = cpolarf( new Complex64( 5.0, 3.0 ), out, 2, 0 ); + + t.strictEqual( val, out, 'returns output array' ); + t.strictEqual( val[ 0 ], cabsf( new Complex64( 5.0, 3.0 ) ), 'returns expected value' ); + t.strictEqual( val[ 1 ], 0, 'returns expected value' ); + t.strictEqual( val[ 2 ], cphasef( new Complex64( 5.0, 3.0 ) ), 'returns expected value' ); + t.strictEqual( val[ 3 ], 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset', function test( t ) { + var out; + var val; + + out = new Float32Array( 4 ); + val = cpolarf( new Complex64( 5.0, 3.0 ), out, 2, 1 ); + + t.strictEqual( val, out, 'returns output array' ); + t.strictEqual( val[ 0 ], 0, 'returns expected value' ); + t.strictEqual( val[ 1 ], cabsf( new Complex64( 5.0, 3.0 ) ), 'returns expected value' ); + t.strictEqual( val[ 2 ], 0, 'returns expected value' ); + t.strictEqual( val[ 3 ], cphasef( new Complex64( 5.0, 3.0 ) ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.js new file mode 100644 index 000000000000..449790fa0056 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var cpolarf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpolarf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cpolarf, 'assign' ), true, 'has property' ); + t.strictEqual( typeof cpolarf.assign, 'function', 'has method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.main.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.main.js new file mode 100644 index 000000000000..3690a2401786 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.main.js @@ -0,0 +1,70 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var cabsf = require( '@stdlib/math/base/special/cabsf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var cphasef = require( '@stdlib/math/base/special/cphasef' ); +var cpolarf = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpolarf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the absolute value and phase of a complex number', function test( t ) { + var expected; + var v; + + v = cpolarf( new Complex64( 5.0, 3.0 ) ); + expected = [ + cabsf( new Complex64( 5.0, 3.0 ) ), + cphasef( new Complex64( 5.0, 3.0 ) ) + ]; + + t.deepEqual( v, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, both the absolute value and phase are `NaN`', function test( t ) { + var v; + + v = cpolarf( new Complex64( NaN, 3.0 ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolarf( new Complex64( 5.0, NaN ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolarf( new Complex64( NaN, NaN ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.native.js new file mode 100644 index 000000000000..4198b3636128 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.native.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 cabsf = require( '@stdlib/math/base/special/cabsf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var cphasef = require( '@stdlib/math/base/special/cphasef' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var cpolarf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cpolarf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpolarf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the absolute value and phase of a complex number', opts, function test( t ) { + var expected; + var v; + + v = cpolarf( new Complex64( 5.0, 3.0 ) ); + expected = [ + cabsf( new Complex64( 5.0, 3.0 ) ), + cphasef( new Complex64( 5.0, 3.0 ) ) + ]; + + t.deepEqual( v, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, both the absolute value and phase are `NaN`', opts, function test( t ) { + var v; + + v = cpolarf( new Complex64( NaN, 3.0 ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolarf( new Complex64( 5.0, NaN ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolarf( new Complex64( NaN, NaN ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + t.end(); +}); From 53c811f941fe82849ba40eff028f95f8442ac57d Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 1 Jun 2025 10:04:05 -0700 Subject: [PATCH 2/6] feat: add `math/base/special/cpolarf` --- .../math/base/special/cpolarf/README.md | 55 ++++----- .../special/cpolarf/benchmark/benchmark.js | 2 +- .../cpolarf/benchmark/benchmark.native.js | 8 +- .../cpolarf/benchmark/c/native/Makefile | 2 +- .../cpolarf/benchmark/c/native/benchmark.c | 26 ++-- .../math/base/special/cpolarf/binding.gyp | 2 +- .../special/cpolarf/docs/types/index.d.ts | 2 +- .../base/special/cpolarf/docs/types/test.ts | 2 +- .../base/special/cpolarf/examples/c/Makefile | 2 +- .../base/special/cpolarf/examples/c/example.c | 24 ++-- .../base/special/cpolarf/examples/index.js | 10 +- .../math/base/special/cpolarf/include.gypi | 2 +- .../stdlib/math/base/special/cpolarf.h | 10 +- .../math/base/special/cpolarf/lib/assign.js | 2 +- .../math/base/special/cpolarf/lib/index.js | 2 +- .../math/base/special/cpolarf/lib/main.js | 2 +- .../math/base/special/cpolarf/lib/native.js | 12 +- .../math/base/special/cpolarf/manifest.json | 15 ++- .../math/base/special/cpolarf/src/Makefile | 2 +- .../math/base/special/cpolarf/src/addon.c | 115 ++---------------- .../math/base/special/cpolarf/src/main.c | 18 +-- .../base/special/cpolarf/test/test.assign.js | 16 +-- .../math/base/special/cpolarf/test/test.js | 2 +- .../base/special/cpolarf/test/test.main.js | 16 +-- .../base/special/cpolarf/test/test.native.js | 16 +-- 25 files changed, 132 insertions(+), 233 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md b/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md index bfdc18a4f5d0..6fabaca6f4fb 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2025 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -77,9 +77,7 @@ var bool = ( v === out ); ```javascript var Complex64 = require( '@stdlib/complex/float32/ctor' ); var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var real = require( '@stdlib/complex/float32/real' ); -var imag = require( '@stdlib/complex/float32/imag' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); var cpolarf = require( '@stdlib/math/base/special/cpolarf' ); var re; @@ -89,12 +87,12 @@ var o; var i; for ( i = 0; i < 100; i++ ) { - re = round( randu()*100.0 ) - 50.0; - im = round( randu()*100.0 ) - 50.0; + re = roundf( randu()*100.0 ) - 50.0; + im = roundf( randu()*100.0 ) - 50.0; z = new Complex64( re, im ); o = cpolarf( z ); z = z.toString(); - console.log( 'abs(%s) = %d. arg(%s) = %d', z, o[0], z, o[1] ); + console.log( 'absf(%s) = %d. argf(%s) = %d', z, o[0], z, o[1] ); } ``` @@ -137,20 +135,20 @@ Computes the [absolute value][@stdlib/math/base/special/cabsf] and [phase][@stdl #include "stdlib/complex/float32/real.h" #include "stdlib/complex/float32/imag.h" -stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 ); -double cabsf; -double cphasef; +stdlib_complex64_t z = stdlib_complex64( 5.0f, 3.0f ); +float cabsf; +float cphasef; stdlib_base_cpolarf( z, &cabsf, &cphasef ); ``` The function accepts the following arguments: -- **z**: `[in] stdlib_complex128_t` input value. -- **cabsf**: `[out] double*` destination for the absolute value. -- **cphasef**: `[out] double*` destination for the phase value in radians. +- **z**: `[in] stdlib_complex64_t` input value. +- **cabsf**: `[out] float*` destination for the absolute value. +- **cphasef**: `[out] float*` destination for the phase value in radians. ```c -double stdlib_base_cpolarf( const stdlib_complex128_t z, double *cabsf, double *cphasef ); +float stdlib_base_cpolarf( const stdlib_complex64_t z, float *cabsf, float *cphasef ); ``` @@ -178,22 +176,22 @@ double stdlib_base_cpolarf( const stdlib_complex128_t z, double *cabsf, double * #include int main( void ) { - const stdlib_complex128_t x[] = { - stdlib_complex128( 3.14, 1.0 ), - stdlib_complex128( -3.14, -1.0 ), - stdlib_complex128( 0.0, 0.0 ), - stdlib_complex128( 0.0/0.0, 0.0/0.0 ) + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.0f ), + stdlib_complex64( -3.14f, -1.0f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) }; - double cphasef; - double cabsf; - double re; - double im; + float cphasef; + float cabsf; + float re; + float im; int i; for ( i = 0; i < 4; i++ ) { stdlib_base_cpolarf( x[i], &cabsf, &cphasef ); - stdlib_complex128_reim( x[i], &re, &im ); - printf( "cpolarf(%lf + %lfi) => cabsf: %lf, cphasef: %lf\n", re, im, cabsf, cphasef ); + stdlib_complex64_reim( x[i], &re, &im ); + printf( "cpolarf(%f + %fi) => cabsf: %f, cphasef: %f\n", re, im, cabsf, cphasef ); } } ``` @@ -210,13 +208,6 @@ int main( void ) { diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.js index 410bd97c246b..f86a04fa2595 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.native.js index f8de9f937699..7c50394b9678 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/base/uniform' ); -var isArray = require( '@stdlib/assert/is-array' ); +var isFloat32Array = require( '@stdlib/assert/is-float32array' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -57,8 +57,8 @@ bench( pkg+'::native', opts, function benchmark( b ) { } } b.toc(); - if ( !isArray( y ) ) { - b.fail( 'should return an array' ); + if ( !isFloat32Array( y ) ) { + b.fail( 'should return a Float32Array' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/Makefile index 3cbfe3fef3b6..a4bd7b38fd74 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2023 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c index 751a519fba91..86eacc73f7f8 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,9 +81,9 @@ static double tic( void ) { * * @return random number */ -static double rand_double( void ) { +static float rand_float( void ) { int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); + return (float)r / ( (float)RAND_MAX + 1.0f ); } /** @@ -93,21 +93,23 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double cphasef; - double cabsf; - double re; - double im; + float cphasef; + float cabsf; + float re; + float im; double t; int i; - stdlib_complex128_t z; + stdlib_complex64_t z[ 100 ]; + for ( i = 0; i < 100; i++ ) { + re = ( 1000.0f*rand_float() ) - 500.0f; + im = ( 1000.0f*rand_float() ) - 500.0f; + z[ i ] = stdlib_complex64( re, im ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0*rand_double() ) - 500.0; - im = ( 1000.0*rand_double() ) - 500.0; - z = stdlib_complex128( re, im ); - stdlib_base_cpolarf( z, &cabsf, &cphasef); + stdlib_base_cpolarf( z[ i%100 ], &cabsf, &cphasef); if ( cabsf != cabsf ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/binding.gyp b/lib/node_modules/@stdlib/math/base/special/cpolarf/binding.gyp index f2b466aef5c4..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/binding.gyp +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/binding.gyp @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2023 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts index d248d8e248ac..a5674e0271bf 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts index 378ac09b1315..1152560286fb 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/Makefile index f0ae66fecf01..25ced822f96a 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2023 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/example.c index 28e8df2aa39d..e7ecad43ef97 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/c/example.c @@ -2,7 +2,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,21 +23,21 @@ #include int main( void ) { - const stdlib_complex128_t x[] = { - stdlib_complex128( 3.14, 1.0 ), - stdlib_complex128( -3.14, -1.0 ), - stdlib_complex128( 0.0, 0.0 ), - stdlib_complex128( 0.0/0.0, 0.0/0.0 ) + const stdlib_complex64_t x[] = { + stdlib_complex64( 3.14f, 1.0f ), + stdlib_complex64( -3.14f, -1.0f ), + stdlib_complex64( 0.0f, 0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) }; - double cphasef; - double cabsf; - double re; - double im; + float cphasef; + float cabsf; + float re; + float im; int i; for ( i = 0; i < 4; i++ ) { stdlib_base_cpolarf( x[i], &cabsf, &cphasef ); - stdlib_complex128_reim( x[i], &re, &im ); - printf( "cpolarf(%lf + %lfi) => cabsf: %lf, cphasef: %lf\n", re, im, cabsf, cphasef ); + stdlib_complex64_reim( x[i], &re, &im ); + printf( "cpolarf(%f + %fi) => cabsf: %f, cphasef: %f\n", re, im, cabsf, cphasef ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js index 08cb37348e71..7036ba4b4c11 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ var Complex64 = require( '@stdlib/complex/float32/ctor' ); var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var roundf = require( '@stdlib/math/base/special/roundf' ); var cpolarf = require( './../lib' ); var re; @@ -30,10 +30,10 @@ var o; var i; for ( i = 0; i < 100; i++ ) { - re = round( randu()*100.0 ) - 50.0; - im = round( randu()*100.0 ) - 50.0; + re = roundf( randu()*100.0 ) - 50.0; + im = roundf( randu()*100.0 ) - 50.0; z = new Complex64( re, im ); o = cpolarf( z ); z = z.toString(); - console.log( 'abs(%s) = %d. arg(%s) = %d', z, o[0], z, o[1] ); + console.log( 'absf(%s) = %d. argf(%s) = %d', z, o[0], z, o[1] ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/include.gypi b/lib/node_modules/@stdlib/math/base/special/cpolarf/include.gypi index 78db9faf8c74..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/include.gypi +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/include.gypi @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2023 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/include/stdlib/math/base/special/cpolarf.h b/lib/node_modules/@stdlib/math/base/special/cpolarf/include/stdlib/math/base/special/cpolarf.h index 0538ffd7fd8f..dae499c7a9af 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/include/stdlib/math/base/special/cpolarf.h +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/include/stdlib/math/base/special/cpolarf.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ * limitations under the License. */ -#ifndef STDLIB_MATH_BASE_SPECIAL_CPOLAR_H -#define STDLIB_MATH_BASE_SPECIAL_CPOLAR_H +#ifndef STDLIB_MATH_BASE_SPECIAL_CPOLARF_H +#define STDLIB_MATH_BASE_SPECIAL_CPOLARF_H #include "stdlib/complex/float32/ctor.h" @@ -31,10 +31,10 @@ extern "C" { /** * Computes the absolute value and the phase of a single-precision complex floating-point number. */ -void stdlib_base_cpolarf( const stdlib_complex128_t z, double *cabsf, double *cphasef ); +void stdlib_base_cpolarf( const stdlib_complex64_t z, float *cabsf, float *cphasef ); #ifdef __cplusplus } #endif -#endif // !STDLIB_MATH_BASE_SPECIAL_CPOLAR_H +#endif // !STDLIB_MATH_BASE_SPECIAL_CPOLARF_H diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/assign.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/assign.js index de4c37490ace..80c4e9fd05d5 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/assign.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/assign.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/index.js index c348ec8510a0..30e43cb5e704 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/main.js index a2c92748ca7a..2735408cb1ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/native.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/native.js index c512f95e3561..c510dea431d0 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/lib/native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,18 +31,18 @@ var addon = require( './../src/addon.node' ); * * @private * @param {Complex64} z - complex number -* @returns {Array} absolute value and phase (in radians) +* @returns {Float32Array} absolute value and phase (in radians) * * @example * var Complex64 = require( '@stdlib/complex/float32/ctor' ); * * var o = cpolarf( new Complex64( 5.0, 3.0 ) ); -* // returns [ ~5.83, ~0.5404 ] +* // returns [ ~5.83, ~0.5404 ] */ function cpolarf( z ) { - var out = new Float32Array( 2 ); - addon( out, z ); - return [ out[ 0 ], out[ 1 ] ]; + var o = new Float32Array( 2 ); + addon( z, o ); + return o; } diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json b/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json index a855cd198c51..f6d26aeb5f79 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json @@ -37,8 +37,11 @@ "libpath": [], "dependencies": [ "@stdlib/napi/argv", - "@stdlib/complex/float64/ctor", - "@stdlib/complex/float64/reim", + "@stdlib/napi/argv-complex64", + "@stdlib/napi/argv-float32array", + "@stdlib/napi/export", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", "@stdlib/math/base/special/cphasef", "@stdlib/math/base/special/cabsf" ] @@ -54,8 +57,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/complex/float64/ctor", - "@stdlib/complex/float64/reim", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", "@stdlib/math/base/special/cphasef", "@stdlib/math/base/special/cabsf" ] @@ -71,8 +74,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/complex/float64/ctor", - "@stdlib/complex/float64/reim", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/reim", "@stdlib/math/base/special/cphasef", "@stdlib/math/base/special/cabsf" ] diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/Makefile index 904c7dc4bd7a..7733b6180cb4 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/Makefile +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2023 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/addon.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/addon.c index 3916c4495977..b8a8c60a9dca 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,9 @@ #include "stdlib/math/base/special/cpolarf.h" #include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_complex64.h" +#include "stdlib/napi/argv_float32array.h" +#include "stdlib/napi/export.h" #include /** @@ -28,111 +31,11 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; - - // Get callback arguments: - size_t argc = 2; - napi_value argv[ 2 ]; - 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 < 2 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); - assert( status == napi_ok ); - return NULL; - } - if ( argc > 2 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); - assert( status == napi_ok ); - return NULL; - } - - bool res; - status = napi_is_typedarray( env, argv[ 0 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float32Array." ); - assert( status == napi_ok ); - return NULL; - } - - // Get the first element out - napi_typedarray_type vtype0; - size_t len; - void *Out; - status = napi_get_typedarray_info( env, argv[ 0 ], &vtype0, &len, &Out, NULL, NULL ); - assert( status == napi_ok ); - if ( vtype0 != napi_float64_array ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float32Array." ); - assert( status == napi_ok ); - return NULL; - } - if ( len != 2 ) { - status = napi_throw_range_error( env, NULL, "invalid argument. First argument must have 2 elements." ); - assert( status == napi_ok ); - return NULL; - } - - // Get the real component - napi_value xre; - status = napi_get_named_property( env, argv[ 1 ], "re", &xre ); - assert( status == napi_ok ); - - napi_valuetype xretype; - status = napi_typeof( env, xre, &xretype ); - assert( status == napi_ok ); - if ( xretype != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." ); - assert( status == napi_ok ); - return NULL; - } - - // Get the imaginary component - napi_value xim; - status = napi_get_named_property( env, argv[ 1 ], "im", &xim ); - assert( status == napi_ok ); - - napi_valuetype ximtype; - status = napi_typeof( env, xim, &ximtype ); - assert( status == napi_ok ); - if ( ximtype != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." ); - assert( status == napi_ok ); - return NULL; - } - - double re; - status = napi_get_value_double( env, xre, &re ); - assert( status == napi_ok ); - - double im; - status = napi_get_value_double( env, xim, &im ); - assert( status == napi_ok ); - - double cabsf; - double cphasef; - stdlib_base_cpolarf( stdlib_complex128( re, im ), &cabsf, &cphasef ); - - double *op = (double *)Out; - op[ 0 ] = cabsf; - op[ 1 ] = cphasef; - + STDLIB_NAPI_ARGV( env, info, argv, argc, 2 ); + STDLIB_NAPI_ARGV_COMPLEX64( env, z, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT32ARRAY( env, o, olen, argv, 1 ); + stdlib_base_cpolarf( z, &o[ 0 ], &o[ 1 ] ); return NULL; } -/** -* Initializes a Node-API module. -* -* @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 ) +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c index 5df3036b5955..d758dac4756f 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,21 +26,21 @@ * Computes the absolute value and the phase of a complex single-precision complex floating-point number. * * @param z input value -* @param cabsf destination for absolute value -* @param cphasef destination for phase value +* @param cabsf destination for the absolute value +* @param cphasef destination for the phase value * * @example * #include "stdlib/complex/float32/ctor.h" * #include "stdlib/complex/float32/real.h" * #include "stdlib/complex/float32/imag.h" * -* stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 ); -* double cabsf; -* double cphasef; +* stdlib_complex64_t z = stdlib_complex64( 5.0f, 3.0f ); +* float cabsf; +* float cphasef; * stdlib_base_cpolarf( z, &cabsf, &cphasef ); */ -void stdlib_base_cpolarf( const stdlib_complex128_t z, double *cabsf, double *cphasef ) { - *cabsf = stdlib_base_cabs( z ); - *cphasef = stdlib_base_cphase( z ); +void stdlib_base_cpolarf( const stdlib_complex64_t z, float *cabsf, float *cphasef ) { + *cabsf = stdlib_base_cabsf( z ); + *cphasef = stdlib_base_cphasef( z ); return; } diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.assign.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.assign.js index e6e3737e6dbc..25096c6b5304 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.assign.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.assign.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var cabsf = require( '@stdlib/math/base/special/cabsf' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -62,16 +62,16 @@ tape( 'if a real or imaginary component is `NaN`, both the absolute value and ph out = [ 0.0, 0.0 ]; v = cpolarf( new Complex64( NaN, 3.0 ), out, 1, 0 ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); v = cpolarf( new Complex64( 5.0, NaN ), out, 1, 0 ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); v = cpolarf( new Complex64( NaN, NaN ), out, 1, 0 ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.js index 449790fa0056..0e85802020a6 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.main.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.main.js index 3690a2401786..d36146d96cc4 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.main.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var cabsf = require( '@stdlib/math/base/special/cabsf' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var cphasef = require( '@stdlib/math/base/special/cphasef' ); @@ -55,16 +55,16 @@ tape( 'if a real or imaginary component is `NaN`, both the absolute value and ph var v; v = cpolarf( new Complex64( NaN, 3.0 ) ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); v = cpolarf( new Complex64( 5.0, NaN ) ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); v = cpolarf( new Complex64( NaN, NaN ) ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.native.js index 4198b3636128..353dda31aa2a 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var cabsf = require( '@stdlib/math/base/special/cabsf' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var cphasef = require( '@stdlib/math/base/special/cphasef' ); @@ -64,16 +64,16 @@ tape( 'if a real or imaginary component is `NaN`, both the absolute value and ph var v; v = cpolarf( new Complex64( NaN, 3.0 ) ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); v = cpolarf( new Complex64( 5.0, NaN ) ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); v = cpolarf( new Complex64( NaN, NaN ) ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + t.strictEqual( isnanf( v[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( v[ 1 ] ), true, 'returns expected value' ); t.end(); }); From 3e135f3a5bcf1825a52d87f8355df66a3e38d63a Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 10 Jun 2025 21:01:12 -0700 Subject: [PATCH 3/6] bench: use `random_uniform` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../cpolarf/benchmark/c/native/benchmark.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c index 86eacc73f7f8..0e9010ce09d5 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/benchmark/c/native/benchmark.c @@ -77,13 +77,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); } /** @@ -102,8 +104,8 @@ static double benchmark( void ) { stdlib_complex64_t z[ 100 ]; for ( i = 0; i < 100; i++ ) { - re = ( 1000.0f*rand_float() ) - 500.0f; - im = ( 1000.0f*rand_float() ) - 500.0f; + re = random_uniform( -500.0f, 500.0f ); + im = random_uniform( -500.0f, 500.0f ); z[ i ] = stdlib_complex64( re, im ); } From bff28a267f924d1f14c9ddd3ccc0ba9410d3407c Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Wed, 11 Jun 2025 13:28:36 -0700 Subject: [PATCH 4/6] docs: fix examples --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/cpolarf/README.md | 9 ++++----- .../@stdlib/math/base/special/cpolarf/examples/index.js | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md b/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md index 6fabaca6f4fb..76ccb1f62a29 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md @@ -76,8 +76,7 @@ var bool = ( v === out ); ```javascript var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var randu = require( '@stdlib/random/base/randu' ); -var roundf = require( '@stdlib/math/base/special/roundf' ); +var uniform = require( '@stdlib/random/base/uniform' ); var cpolarf = require( '@stdlib/math/base/special/cpolarf' ); var re; @@ -87,12 +86,12 @@ var o; var i; for ( i = 0; i < 100; i++ ) { - re = roundf( randu()*100.0 ) - 50.0; - im = roundf( randu()*100.0 ) - 50.0; + re = uniform( -50.0, 50.0 ); + im = uniform( -50.0, 50.0 ); z = new Complex64( re, im ); o = cpolarf( z ); z = z.toString(); - console.log( 'absf(%s) = %d. argf(%s) = %d', z, o[0], z, o[1] ); + console.log( 'absf(%s) = %d. argf(%s) = %d', z, o[ 0 ], z, o[ 1 ] ); } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js index 7036ba4b4c11..e036be600f06 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js @@ -19,8 +19,7 @@ 'use strict'; var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var randu = require( '@stdlib/random/base/randu' ); -var roundf = require( '@stdlib/math/base/special/roundf' ); +var uniform = require( '@stdlib/random/base/uniform' ); var cpolarf = require( './../lib' ); var re; @@ -30,10 +29,10 @@ var o; var i; for ( i = 0; i < 100; i++ ) { - re = roundf( randu()*100.0 ) - 50.0; - im = roundf( randu()*100.0 ) - 50.0; + re = uniform( -50.0, 50.0 ); + im = uniform( -50.0, 50.0 ); z = new Complex64( re, im ); o = cpolarf( z ); z = z.toString(); - console.log( 'absf(%s) = %d. argf(%s) = %d', z, o[0], z, o[1] ); + console.log( 'absf(%s) = %d. argf(%s) = %d', z, o[ 0 ], z, o[ 1 ] ); } From 74130301d9a4c2d93c75d6febc4b9c114071d5b8 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Thu, 12 Jun 2025 20:57:34 -0700 Subject: [PATCH 5/6] chore: minor clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/base/special/cpolarf/manifest.json | 3 --- lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json b/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json index f6d26aeb5f79..fe0fb13c7805 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/manifest.json @@ -41,7 +41,6 @@ "@stdlib/napi/argv-float32array", "@stdlib/napi/export", "@stdlib/complex/float32/ctor", - "@stdlib/complex/float32/reim", "@stdlib/math/base/special/cphasef", "@stdlib/math/base/special/cabsf" ] @@ -58,7 +57,6 @@ "libpath": [], "dependencies": [ "@stdlib/complex/float32/ctor", - "@stdlib/complex/float32/reim", "@stdlib/math/base/special/cphasef", "@stdlib/math/base/special/cabsf" ] @@ -75,7 +73,6 @@ "libpath": [], "dependencies": [ "@stdlib/complex/float32/ctor", - "@stdlib/complex/float32/reim", "@stdlib/math/base/special/cphasef", "@stdlib/math/base/special/cabsf" ] diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c index d758dac4756f..a5d16fc4cc41 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/src/main.c @@ -20,12 +20,11 @@ #include "stdlib/math/base/special/cphasef.h" #include "stdlib/math/base/special/cabsf.h" #include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float32/reim.h" /** * Computes the absolute value and the phase of a complex single-precision complex floating-point number. * -* @param z input value +* @param z input value * @param cabsf destination for the absolute value * @param cphasef destination for the phase value * From 64f1566a8517385d53a2e954220b34f8a7ffa7b9 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 13 Jun 2025 23:55:39 -0700 Subject: [PATCH 6/6] chore: apply suggestions from review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../math/base/special/cpolarf/README.md | 26 +++++++------------ .../special/cpolarf/docs/types/index.d.ts | 2 +- .../base/special/cpolarf/docs/types/test.ts | 2 +- .../base/special/cpolarf/examples/index.js | 22 +++++----------- 4 files changed, 18 insertions(+), 34 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md b/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md index 76ccb1f62a29..8e836a1bc6b3 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/README.md @@ -75,24 +75,16 @@ var bool = ( v === out ); ```javascript -var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var uniform = require( '@stdlib/random/base/uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var cpolarf = require( '@stdlib/math/base/special/cpolarf' ); -var re; -var im; -var z; -var o; -var i; - -for ( i = 0; i < 100; i++ ) { - re = uniform( -50.0, 50.0 ); - im = uniform( -50.0, 50.0 ); - z = new Complex64( re, im ); - o = cpolarf( z ); - z = z.toString(); - console.log( 'absf(%s) = %d. argf(%s) = %d', z, o[ 0 ], z, o[ 1 ] ); -} +// Create an array of random numbers: +var arr = new Complex64Array( uniform( 200, -100.0, 100.0 ) ); + +// Compute the polar form of each number in the array: +logEachMap( 'cpolarf(%s) = [%s]', arr, cpolarf ); ``` @@ -147,7 +139,7 @@ The function accepts the following arguments: - **cphasef**: `[out] float*` destination for the phase value in radians. ```c -float stdlib_base_cpolarf( const stdlib_complex64_t z, float *cabsf, float *cphasef ); +void stdlib_base_cpolarf( const stdlib_complex64_t z, float *cabsf, float *cphasef ); ``` diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts index a5674e0271bf..591fbb87d157 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/index.d.ts @@ -39,7 +39,7 @@ interface Cpolar { * var v = cpolarf( new Complex64( 5.0, 3.0 ) ); * // returns [ ~5.83, ~0.5404 ] */ - ( z: Complex64 ): Array; + ( z: Complex64 ): [ number, number ]; /** * Computes the absolute value and the phase of a single-precision complex floating-point number and assigns results to a provided output array. diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts index 1152560286fb..5a3ce0075256 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/docs/types/test.ts @@ -24,7 +24,7 @@ import cpolarf = require( './index' ); // The function returns an array of numbers... { - cpolarf( new Complex64( 5.0, 3.0 ) ); // $ExpectType number[] + cpolarf( new Complex64( 5.0, 3.0 ) ); // $ExpectType [number, number] } // The compiler throws an error if the function is provided a complex number... diff --git a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js index e036be600f06..f7d6aa92320e 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolarf/examples/index.js @@ -18,21 +18,13 @@ 'use strict'; -var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var uniform = require( '@stdlib/random/base/uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var cpolarf = require( './../lib' ); -var re; -var im; -var z; -var o; -var i; +// Create an array of random numbers: +var arr = new Complex64Array( uniform( 200, -100.0, 100.0 ) ); -for ( i = 0; i < 100; i++ ) { - re = uniform( -50.0, 50.0 ); - im = uniform( -50.0, 50.0 ); - z = new Complex64( re, im ); - o = cpolarf( z ); - z = z.toString(); - console.log( 'absf(%s) = %d. argf(%s) = %d', z, o[ 0 ], z, o[ 1 ] ); -} +// Compute the polar form of each number in the array: +logEachMap( 'cpolarf(%s) = [%s]', arr, cpolarf );