diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/README.md b/lib/node_modules/@stdlib/math/base/special/cpolar/README.md index 6f16127ee00..fba257a77ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# polar +# cpolar -> Compute the [absolute value][@stdlib/math/base/special/cabs] and [phase][@stdlib/math/base/special/cphase] of a complex number. +> Compute the [absolute value][@stdlib/math/base/special/cabs] and [phase][@stdlib/math/base/special/cphase] of a double-precision complex floating-point number.
@@ -36,26 +36,31 @@ limitations under the License. var cpolar = require( '@stdlib/math/base/special/cpolar' ); ``` -#### cpolar( \[out,] re, im ) +#### cpolar( z ) -Computes the [absolute value][@stdlib/math/base/special/cabs] and [phase][@stdlib/math/base/special/cphase] of a complex number comprised of a **real** component `re` and an **imaginary** component `im`. +Computes the [absolute value][@stdlib/math/base/special/cabs] and [phase][@stdlib/math/base/special/cphase] of a double-precision complex floating-point number. ```javascript -var o = cpolar( 5.0, 3.0 ); +var Complex128 = require( '@stdlib/complex/float64' ); + +var o = cpolar( new Complex128( 5.0, 3.0 ) ); // returns [ ~5.83, ~0.5404 ] ``` -By default, the function returns real and imaginary components as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. +#### cpolar.assign( z, out, stride, offset ) + +Computes the [absolute value][@stdlib/math/base/special/cabs] and [phase][@stdlib/math/base/special/cphase] of a double-precision complex floating-point number and assigns results to a provided output array. ```javascript +var Complex128 = require( '@stdlib/complex/float64' ); var Float64Array = require( '@stdlib/array/float64' ); var out = new Float64Array( 2 ); -var o = cpolar( out, 5.0, 3.0 ); +var v = cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, 0 ); // returns [ ~5.83, ~0.5404 ] -var bool = ( o === out ); +var bool = ( v === out ); // returns true ``` @@ -87,7 +92,7 @@ for ( i = 0; i < 100; i++ ) { re = round( randu()*100.0 ) - 50.0; im = round( randu()*100.0 ) - 50.0; z = new Complex128( re, im ); - o = cpolar( real(z), imag(z) ); + o = cpolar( z ); z = z.toString(); console.log( 'abs(%s) = %d. arg(%s) = %d', z, o[0], z, o[1] ); } @@ -97,6 +102,110 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/cpolar.h" +``` + +#### stdlib_base_cpolar( z, cabs, cphase ) + +Computes the [absolute value][@stdlib/math/base/special/cabs] and [phase][@stdlib/math/base/special/cphase] of a double-precision complex floating-point number. + +```c +#include "stdlib/complex/float64.h" +#include "stdlib/complex/real.h" +#include "stdlib/complex/imag.h" + +stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 ); +double cabs; +double cphase; +stdlib_base_cpolar( z, &cabs, &cphase ); +``` + +The function accepts the following arguments: + +- **z**: `[in] stdlib_complex128_t` input value. +- **cabs**: `[out] double*` destination for the absolute value. +- **cphase**: `[out] double*` destination for the phase value in radians. + +```c +double stdlib_base_cpolar( const stdlib_complex128_t z, double *cabs, double *cphase ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/cpolar.h" +#include "stdlib/complex/float64.h" +#include "stdlib/complex/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 cphase; + double cabs; + double re; + double im; + int i; + for ( i = 0; i < 12; i++ ) { + stdlib_base_cpolar( x[i], &cabs, &cphase ); + stdlib_reim( x[i], &re, &im ); + printf( "cpolar(%lf + %lfi) => cabs: %lf, cphase: %lf\n", re, im, cabs, cphase ); + } +} +``` + +
+ + + +
+ + + diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/benchmark.js index 71ff152afb9..ce118f0b316 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/benchmark.js @@ -21,8 +21,9 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); var isArray = require( '@stdlib/assert/is-array' ); +var Complex128 = require( '@stdlib/complex/float64' ); var pkg = require( './../package.json' ).name; var cpolar = require( './../lib' ); @@ -30,16 +31,18 @@ var cpolar = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { - var re; - var im; + var values; var y; var i; + values = [ + new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - re = ( randu()*1000.0 ) - 500.0; - im = ( randu()*1000.0 ) - 500.0; - y = cpolar( re, im ); + y = cpolar( values[ i%values.length ] ); if ( y.length === 0 ) { b.fail( 'should not be empty' ); } @@ -52,21 +55,22 @@ bench( pkg, function benchmark( b ) { b.end(); }); -bench( pkg+'::memory_reuse', function benchmark( b ) { - var out; - var re; - var im; +bench( pkg+':assign', function benchmark( b ) { + var values; var y; var i; - out = new Array( 2 ); + values = [ + new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + y = [ 0.0, 0.0 ]; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - re = ( randu()*1000.0 ) - 500.0; - im = ( randu()*1000.0 ) - 500.0; - y = cpolar( out, re, im ); - if ( y.length === 0 ) { + cpolar.assign( values[ i%values.length ], y, 1, 0 ); + if ( y[ 0 ] !== y[ 0 ] || y[ 1 ] !== y[ 1 ] ) { b.fail( 'should not be empty' ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/benchmark.native.js new file mode 100644 index 00000000000..0c9f5d28a22 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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 Complex128 = require( '@stdlib/complex/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var cpolar = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cpolar instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var values; + var y; + var i; + + values = [ + new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), + new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cpolar( 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/cpolar/benchmark/c/native/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/c/native/Makefile new file mode 100644 index 00000000000..3cbfe3fef3b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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/cpolar/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/c/native/benchmark.c new file mode 100644 index 00000000000..994fde2a399 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/c/native/benchmark.c @@ -0,0 +1,144 @@ +/** +* @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. +*/ + +/** +* Benchmark `cpolar`. +*/ +#include "stdlib/math/base/special/cpolar.h" +#include "stdlib/complex/float64.h" +#include "stdlib/complex/reim.h" +#include +#include +#include +#include +#include + +#define NAME "cpolar" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +void print_version() { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +double tic() { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1]. +* +* @return random number +*/ +double rand_double() { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +double benchmark() { + double elapsed; + double cphase; + double cabs; + 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_cpolar( z, &cabs, &cphase); + if ( cabs != cabs ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( cphase != cphase ) { + 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/cpolar/binding.gyp b/lib/node_modules/@stdlib/math/base/special/cpolar/binding.gyp new file mode 100644 index 00000000000..f2b466aef5c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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/cpolar/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/cpolar/docs/repl.txt index 9749a395c59..174169eaa1c 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/docs/repl.txt @@ -1,17 +1,41 @@ -{{alias}}( [out,] re, im ) - Returns the absolute value and phase of a complex number. +{{alias}}( z ) + Returns the absolute value and phase of a double-precision complex + floating-point number. Parameters ---------- - out: Array|TypedArray|Object (optional) - Output array. + z: Complex128 + Complex number. - re: number - Real component. + Returns + ------- + out: Array + Absolute value and phase, respectively. + + Examples + -------- + > var out = {{alias}}( new {{alias:@stdlib/complex/float64}}( 5.0, 3.0 ) ) + [ ~5.83, ~0.5404 ] + + +{{alias}}.assign( z, out, stride, offset ) + Returns the absolute value and phase of a double-precision complex + floating-point number and assigns results to a provided output array. - im: number - Imaginary component. + Parameters + ---------- + z: Complex128 + Complex number. + + out: Array|TypedArray|Object + Destination array. + + stride: integer + Output array stride. + + offset: integer + Output array index offset. Returns ------- @@ -20,16 +44,11 @@ Examples -------- - > var out = {{alias}}( 5.0, 3.0 ) - [ ~5.83, ~0.5404 ] - - // Provide an output array: - > out = new {{alias:@stdlib/array/float64}}( 2 ); - > var v = {{alias}}( out, 5.0, 3.0 ) + > var out = new {{alias:@stdlib/array/float64}}( 2 ); + > var v = {{alias}}.assign( new {{alias:@stdlib/complex/float64}}( 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/cpolar/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cpolar/docs/types/index.d.ts index 0fad2d665aa..c22969ba018 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/docs/types/index.d.ts @@ -20,41 +20,64 @@ /// -import { ArrayLike } from '@stdlib/types/array'; +import { Complex128 } from '@stdlib/types/complex'; +import { Collection } from '@stdlib/types/array'; /** -* Computes the absolute value and the phase of a complex number. -* -* @param out - output array -* @param re - real component -* @param im - imaginary component -* @returns absolute value and phase, respectively -* -* @example -* var Float32Array = require( `@stdlib/array/float32` ); -* -* var out = new Float32Array( 2 ); -* -* var v = cpolar( out, 5.0, 3.0 ); -* // returns [ ~5.83, ~0.5404 ] -* -* var bool = ( v === out ); -* // returns true -*/ -declare function cpolar( out: ArrayLike, re: number, im: number ): ArrayLike; // tslint-disable-line max-line-length + * Interface describing `cpolar`. + */ +interface Cpolar { + /** + * Computes the absolute value and the phase of a double-precision complex floating-point number. + * + * @param z - complex number + * @returns absolute value and phase, respectively + * + * @example + * var Complex128 = require( `@stdlib/complex/float64` ); + * + * var v = cpolar( new Complex128( 5.0, 3.0 ) ); + * // returns [ ~5.83, ~0.5404 ] + */ + ( z: Complex128 ): Array; + + /** + * Computes the absolute value and the phase of a double-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 Complex128 = require( `@stdlib/complex/float64` ); + * var Float64Array = require( `@stdlib/array/float64` ); + * + * var out = new Float64Array( 2 ); + * + * var v = cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, 0 ); + * // returns [ ~5.83, ~0.5404 ] + * + * var bool = ( v === out ); + * // returns true + */ + assign( z: Complex128, out: Collection, stride: number, offset: number ): Collection; // tslint-disable-line max-line-length +} /** -* Computes the absolute value and the phase of a complex number. +* Computes the absolute value and the phase of a double-precision complex floating-point number. * -* @param re - real component -* @param im - imaginary component +* @param z - complex number * @returns absolute value and phase, respectively * * @example -* var v = cpolar( 5.0, 3.0 ); +* var Complex128 = require( `@stdlib/complex/float64` ); +* +* var v = cpolar( new Complex128( 5.0, 3.0 ) ); * // returns [ ~5.83, ~0.5404 ] */ -declare function cpolar( re: number, im: number ): ArrayLike; +declare var cpolar: Cpolar; // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cpolar/docs/types/test.ts index 5f153c36f6d..8256aa0642a 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/docs/types/test.ts @@ -16,6 +16,7 @@ * limitations under the License. */ +import Complex128 = require( '@stdlib/complex/float64' ); import cpolar = require( './index' ); @@ -23,46 +24,89 @@ import cpolar = require( './index' ); // The function returns an array of numbers... { - cpolar( -4, 3 ); // $ExpectType ArrayLike - cpolar( [], 5, 3 ); // $ExpectType ArrayLike + cpolar( new Complex128( 5.0, 3.0 ) ); // $ExpectType number[] } -// The compiler throws an error if the function is provided a real component which is not a number... +// The compiler throws an error if the function is provided a complex number... { - cpolar( true, 3 ); // $ExpectError - cpolar( false, 3 ); // $ExpectError - cpolar( null, 3 ); // $ExpectError - cpolar( undefined, 3 ); // $ExpectError - cpolar( '5', 3 ); // $ExpectError - cpolar( [], 3 ); // $ExpectError - cpolar( {}, 3 ); // $ExpectError - cpolar( ( x: number ): number => x, 3 ); // $ExpectError + cpolar( true ); // $ExpectError + cpolar( false ); // $ExpectError + cpolar( null ); // $ExpectError + cpolar( undefined ); // $ExpectError + cpolar( '5' ); // $ExpectError + cpolar( [] ); // $ExpectError + cpolar( {} ); // $ExpectError + cpolar( ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the function is provided an imaginary component which is not a number... +// The compiler throws an error if the function is provided insufficient arguments... { - cpolar( 5, true ); // $ExpectError - cpolar( 5, false ); // $ExpectError - cpolar( 5, null ); // $ExpectError - cpolar( 5, undefined ); // $ExpectError - cpolar( 5, '5' ); // $ExpectError - cpolar( 5, [] ); // $ExpectError - cpolar( 5, {} ); // $ExpectError - cpolar( 5, ( x: number ): number => x ); // $ExpectError + cpolar(); // $ExpectError } -// The compiler throws an error if the function is provided an output array which is not array-like... +// Attached to the main export is an `assign` method which returns an array-like object containing numbers... { - cpolar( true, 5, 3 ); // $ExpectError - cpolar( false, 5, 3 ); // $ExpectError - cpolar( 'abc', 5, 3 ); // $ExpectError - cpolar( {}, 5, 3 ); // $ExpectError - cpolar( ( x: number ): number => x, 5, 3 ); // $ExpectError - cpolar( 123, 5, 3 ); // $ExpectError + const out = [ 0.0, 0.0 ]; + + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, 0 ); // $ExpectType Collection + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, 0 ); // $ExpectType Collection } -// The compiler throws an error if the function is provided insufficient arguments... +// The compiler throws an error if the `assign` method is provided a first argument which is not a number... { - cpolar(); // $ExpectError - cpolar( 2 ); // $ExpectError + const out = [ 0.0, 0.0 ]; + + cpolar.assign( true, out, 1, 0 ); // $ExpectError + cpolar.assign( false, out, 1, 0 ); // $ExpectError + cpolar.assign( '5', out, 1, 0 ); // $ExpectError + cpolar.assign( null, out, 1, 0 ); // $ExpectError + cpolar.assign( [], out, 1, 0 ); // $ExpectError + cpolar.assign( {}, out, 1, 0 ); // $ExpectError + cpolar.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... +{ + cpolar.assign( new Complex128( 5.0, 3.0 ), 1, 1, 0 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), true, 1, 0 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), false, 1, 0 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), null, 1, 0 ); // $ExpectError + cpolar.assign( new Complex128( 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 ]; + + cpolar.assign( new Complex128( 5.0, 3.0 ), out, '5', 0 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, true, 0 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, false, 0 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, null, 0 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, [], 0 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, {}, 0 ); // $ExpectError + cpolar.assign( new Complex128( 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 ]; + + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, '5' ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, true ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, false ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, null ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, [] ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, {} ); // $ExpectError + cpolar.assign( new Complex128( 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 ]; + + cpolar.assign(); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ) ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1 ); // $ExpectError + cpolar.assign( new Complex128( 5.0, 3.0 ), out, 1, 0, 1 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/examples/c/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolar/examples/c/Makefile new file mode 100644 index 00000000000..f0ae66fecf0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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/cpolar/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/cpolar/examples/c/example.c new file mode 100644 index 00000000000..45ae07b804f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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/cpolar.h" +#include "stdlib/complex/float64.h" +#include "stdlib/complex/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 cphase; + double cabs; + double re; + double im; + int i; + for ( i = 0; i < 12; i++ ) { + stdlib_base_cpolar( x[i], &cabs, &cphase ); + stdlib_reim( x[i], &re, &im ); + printf( "cpolar(%lf + %lfi) => cabs: %lf, cphase: %lf\n", re, im, cabs, cphase ); + } +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cpolar/examples/index.js index 3715c605c4a..8eba399d5e0 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/examples/index.js @@ -21,8 +21,6 @@ var Complex128 = require( '@stdlib/complex/float64' ); var randu = require( '@stdlib/random/base/randu' ); var round = require( '@stdlib/math/base/special/round' ); -var real = require( '@stdlib/complex/real' ); -var imag = require( '@stdlib/complex/imag' ); var cpolar = require( './../lib' ); var re; @@ -35,7 +33,7 @@ for ( i = 0; i < 100; i++ ) { re = round( randu()*100.0 ) - 50.0; im = round( randu()*100.0 ) - 50.0; z = new Complex128( re, im ); - o = cpolar( real(z), imag(z) ); + o = cpolar( 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/cpolar/include.gypi b/lib/node_modules/@stdlib/math/base/special/cpolar/include.gypi new file mode 100644 index 00000000000..78db9faf8c7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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 = ( o === out ); +* 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/cpolar/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cpolar/lib/main.js index 80b4f726899..405c1525bea 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/lib/main.js @@ -20,37 +20,25 @@ // MODULES // -var polar = require( './cpolar.js' ); +var assign = require( './assign.js' ); // MAIN // /** -* Computes the absolute value and the phase of a complex number. +* Computes the absolute value and the phase of a double-precision complex floating-point number. * -* @param {(Array|TypedArray|Object)} [out] - output array -* @param {number} re - real component -* @param {number} im - imaginary component -* @returns {(Array|TypedArray|Object)} absolute value and phase (in radians) +* @param {Complex128} z - complex number +* @returns {Array} absolute value and phase (in radians) * * @example -* var o = cpolar( 5.0, 3.0 ); -* // returns [ ~5.83, ~0.5404 ] -* -* @example -* var out = new Array( 2 ); +* var Complex128 = require( '@stdlib/complex/float64' ); * -* var o = cpolar( out, 5.0, 3.0 ); +* var o = cpolar( new Complex128( 5.0, 3.0 ) ); * // returns [ ~5.83, ~0.5404 ] -* -* var bool = ( o === out ); -* // returns true */ -function cpolar( out, re, im ) { - if ( arguments.length === 2 ) { - return polar( [ 0.0, 0.0 ], out, re ); - } - return polar( out, re, im ); +function cpolar( z ) { + return assign( z, [ 0.0, 0.0 ], 1, 0 ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/lib/native.js b/lib/node_modules/@stdlib/math/base/special/cpolar/lib/native.js new file mode 100644 index 00000000000..7ece593c6d0 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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 Float64Array = require( '@stdlib/array/float64' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes the absolute value and the phase of a double-precision complex floating-point number. +* +* @private +* @param {Complex128} z - complex number +* @returns {Array} absolute value and phase (in radians) +* +* @example +* var Complex128 = require( '@stdlib/complex/float64' ); +* +* var o = cpolar( new Complex128( 5.0, 3.0 ) ); +* // returns [ ~5.83, ~0.5404 ] +*/ +function cpolar( z ) { + var out = new Float64Array( 2 ); + addon( out, z ); + return [ out[ 0 ], out[ 1 ] ]; +} + + +// EXPORTS // + +module.exports = cpolar; diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/manifest.json b/lib/node_modules/@stdlib/math/base/special/cpolar/manifest.json new file mode 100644 index 00000000000..1d9c396169a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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", + "@stdlib/complex/reim", + "@stdlib/math/base/special/cphase", + "@stdlib/math/base/special/cabs" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float64", + "@stdlib/complex/reim", + "@stdlib/math/base/special/cphase", + "@stdlib/math/base/special/cabs" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/complex/float64", + "@stdlib/complex/reim", + "@stdlib/math/base/special/cphase", + "@stdlib/math/base/special/cabs" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/package.json b/lib/node_modules/@stdlib/math/base/special/cpolar/package.json index b5342021e74..b76c640cfdf 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/package.json +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/math/base/special/cpolar", "version": "0.0.0", - "description": "Compute the absolute value and the phase of a complex number.", + "description": "Compute the absolute value and the phase of a double-precision complex floating-point number.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -14,6 +14,7 @@ } ], "main": "./lib", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/src/Makefile b/lib/node_modules/@stdlib/math/base/special/cpolar/src/Makefile new file mode 100644 index 00000000000..904c7dc4bd7 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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/cpolar/src/addon.c b/lib/node_modules/@stdlib/math/base/special/cpolar/src/addon.c new file mode 100644 index 00000000000..eb8e7691dd6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/src/addon.c @@ -0,0 +1,140 @@ +/** +* @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/cpolar.h" +#include "stdlib/napi/argv.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + napi_status status; + + // Get callback arguments: + size_t argc = 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 Float64Array." ); + 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 Float64Array." ); + 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 cabs; + double cphase; + stdlib_base_cpolar( stdlib_complex128( re, im ), &cabs, &cphase ); + + double *op = (double *)Out; + op[ 0 ] = cabs; + op[ 1 ] = cphase; + + return NULL; +} + +/** +* Initializes a Node-API module. +* +* @private +* @param env environment under which the function is invoked +* @param exports exports object +* @return main export +*/ +static napi_value init( napi_env env, napi_value exports ) { + napi_value fcn; + napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; +} + +NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/src/main.c b/lib/node_modules/@stdlib/math/base/special/cpolar/src/main.c new file mode 100644 index 00000000000..4a12cceb81e --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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/cpolar.h" +#include "stdlib/math/base/special/cphase.h" +#include "stdlib/math/base/special/cabs.h" +#include "stdlib/complex/float64.h" +#include "stdlib/complex/reim.h" + +/** +* Computes the absolute value and the phase of a complex double-precision complex floating-point number. +* +* @param z input value +* @param cabs destination for absolute value +* @param cphase destination for phase value +* +* @example +* #include "stdlib/complex/float64.h" +* #include "stdlib/complex/real.h" +* #include "stdlib/complex/imag.h" +* +* stdlib_complex128_t z = stdlib_complex128( 5.0, 3.0 ); +* double cabs; +* double cphase; +* stdlib_base_cpolar( z, &cabs, &cphase ); +*/ +void stdlib_base_cpolar( const stdlib_complex128_t z, double *cabs, double *cphase ) { + *cabs = stdlib_base_cabs( z ); + *cphase = stdlib_base_cphase( z ); + return; +} diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.assign.js b/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.assign.js new file mode 100644 index 00000000000..719c5f5bb10 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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 cabs = require( '@stdlib/math/base/special/cabs' ); +var Complex128 = require( '@stdlib/complex/float64' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cphase = require( '@stdlib/math/base/special/cphase' ); +var cpolar = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpolar, '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 = cpolar( new Complex128( 5.0, 3.0 ), out, 1, 0 ); + expected = [ + cabs( new Complex128( 5.0, 3.0 ) ), + cphase( new Complex128( 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 = cpolar( new Complex128( NaN, 3.0 ), out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolar( new Complex128( 5.0, NaN ), out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolar( new Complex128( 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 Float64Array( 4 ); + val = cpolar( new Complex128( 5.0, 3.0 ), out, 2, 0 ); + + t.strictEqual( val, out, 'returns output array' ); + t.strictEqual( val[ 0 ], cabs( new Complex128( 5.0, 3.0 ) ), 'returns expected value' ); + t.strictEqual( val[ 1 ], 0, 'returns expected value' ); + t.strictEqual( val[ 2 ], cphase( new Complex128( 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 Float64Array( 4 ); + val = cpolar( new Complex128( 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 ], cabs( new Complex128( 5.0, 3.0 ) ), 'returns expected value' ); + t.strictEqual( val[ 2 ], 0, 'returns expected value' ); + t.strictEqual( val[ 3 ], cphase( new Complex128( 5.0, 3.0 ) ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.js b/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.js index 16c5a3ad51d..bbbf1442b7c 100644 --- a/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. @@ -21,11 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var cabs = require( '@stdlib/math/base/special/cabs' ); -var Complex128 = require( '@stdlib/complex/float64' ); -var cphase = require( '@stdlib/math/base/special/cphase' ); -var Float64Array = require( '@stdlib/array/float64' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var cpolar = require( './../lib' ); @@ -37,85 +33,8 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function computes the absolute value and phase of a complex number', function test( t ) { - var expected; - var v; - - v = cpolar( 5.0, 3.0 ); - expected = [ cabs( new Complex128( 5.0, 3.0 ) ), cphase( new Complex128( 5.0, 3.0 ) ) ]; - - t.deepEqual( v, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function computes the absolute value and phase of a complex number (output array)', function test( t ) { - var expected; - var out; - var v; - - out = new Array( 2 ); - v = cpolar( out, 5.0, 3.0 ); - - expected = [ cabs( new Complex128( 5.0, 3.0 ) ), cphase( new Complex128( 5.0, 3.0 ) ) ]; - - t.deepEqual( v, expected, 'returns expected value' ); - t.strictEqual( v, out, 'returns output value' ); - - t.end(); -}); - -tape( 'the function computes the absolute value and phase of a complex number (output typed array)', function test( t ) { - var expected; - var out; - var abs; - var v; - - out = new Float64Array( 2 ); - v = cpolar( out, 5.0, 3.0 ); - - abs = cabs( new Complex128( 5.0, 3.0 ) ); - expected = new Float64Array( [ abs, cphase( new Complex128( 5.0, 3.0 ) ) ] ); - - t.deepEqual( v, expected, 'returns expected value' ); - t.strictEqual( v, out, 'returns output value' ); - - t.end(); -}); - -tape( 'the function computes the absolute value and phase of a complex number (output object)', function test( t ) { - var expected; - var out; - var v; - - out = {}; - v = cpolar( out, 5.0, 3.0 ); - - expected = { - '0': cabs( new Complex128( 5.0, 3.0 ) ), - '1': cphase( new Complex128( 5.0, 3.0 ) ) - }; - - t.deepEqual( v, expected, 'returns expected value' ); - t.strictEqual( v, out, 'returns output 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 = cpolar( NaN, 3.0 ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); - - v = cpolar( 5.0, NaN ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); - - v = cpolar( NaN, NaN ); - t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); - t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); - +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cpolar, 'assign' ), true, 'has property' ); + t.strictEqual( typeof cpolar.assign, 'function', 'has method' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.main.js b/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.main.js new file mode 100644 index 00000000000..59109240c75 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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 cabs = require( '@stdlib/math/base/special/cabs' ); +var Complex128 = require( '@stdlib/complex/float64' ); +var cphase = require( '@stdlib/math/base/special/cphase' ); +var cpolar = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpolar, '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 = cpolar( new Complex128( 5.0, 3.0 ) ); + expected = [ + cabs( new Complex128( 5.0, 3.0 ) ), + cphase( new Complex128( 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 = cpolar( new Complex128( NaN, 3.0 ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolar( new Complex128( 5.0, NaN ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolar( new Complex128( 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/cpolar/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cpolar/test/test.native.js new file mode 100644 index 00000000000..f2ea8942e2a --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cpolar/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 cabs = require( '@stdlib/math/base/special/cabs' ); +var Complex128 = require( '@stdlib/complex/float64' ); +var cphase = require( '@stdlib/math/base/special/cphase' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var cpolar = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cpolar instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpolar, '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 = cpolar( new Complex128( 5.0, 3.0 ) ); + expected = [ + cabs( new Complex128( 5.0, 3.0 ) ), + cphase( new Complex128( 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 = cpolar( new Complex128( NaN, 3.0 ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolar( new Complex128( 5.0, NaN ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + v = cpolar( new Complex128( NaN, NaN ) ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + t.end(); +});