From 2e71bf1347bffdd9f68b6428ebfbfa0513bb8867 Mon Sep 17 00:00:00 2001 From: kgryte Date: Sun, 22 Jul 2018 14:06:47 -0700 Subject: [PATCH 1/3] Add pkg scaffold --- .../math/base/complex/negate/README.md | 134 ++++++++++++++++ .../complex/negate/benchmark/benchmark.js | 128 ++++++++++++++++ .../base/complex/negate/benchmark/c/Makefile | 107 +++++++++++++ .../complex/negate/benchmark/c/benchmark.c | 140 +++++++++++++++++ .../complex/negate/benchmark/julia/REQUIRE | 2 + .../negate/benchmark/julia/benchmark.jl | 143 ++++++++++++++++++ .../math/base/complex/negate/docs/repl.txt | 35 +++++ .../base/complex/negate/examples/index.js | 41 +++++ .../math/base/complex/negate/lib/cnegate.js | 58 +++++++ .../math/base/complex/negate/lib/index.js | 57 +++++++ .../math/base/complex/negate/lib/main.js | 67 ++++++++ .../math/base/complex/negate/package.json | 63 ++++++++ .../math/base/complex/negate/test/test.js | 124 +++++++++++++++ 13 files changed, 1099 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/README.md create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/benchmark/julia/REQUIRE create mode 100755 lib/node_modules/@stdlib/math/base/complex/negate/benchmark/julia/benchmark.jl create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/examples/index.js create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/lib/cnegate.js create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/lib/main.js create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/package.json create mode 100644 lib/node_modules/@stdlib/math/base/complex/negate/test/test.js diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/README.md b/lib/node_modules/@stdlib/math/base/complex/negate/README.md new file mode 100644 index 000000000000..f7aabb8c8894 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/README.md @@ -0,0 +1,134 @@ + + +# Negate + +> Negate a complex number. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var cnegate = require( '@stdlib/math/base/complex/negate' ); +``` + +#### cnegate( \[out,] re, im ) + +Negates a `complex` number comprised of a **real** component `re` and an **imaginary** component `im`. + +```javascript +var v = cnegate( -4.2, 5.5 ); +// returns [ TODO, TODO ] + +v = cnegate( 0.0, 0.0 ); +// returns [ TODO, TODO ] + +v = cnegate( NaN, NaN ); +// returns [ TODO, TODO ] +``` + +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. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var out = new Float64Array( 2 ); + +var v = cnegate( out, -4.2, 5.5 ); +// returns [ TODO, TODO ] + +var bool = ( v === out ); +// returns true +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var Complex128 = require( '@stdlib/complex/float64' ); +var randu = require( '@stdlib/random/base/randu' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); +var cnegate = require( '@stdlib/math/base/complex/negate' ); + +var re; +var im; +var z; +var o; +var w; +var i; + +for ( i = 0; i < 100; i++ ) { + re = ( randu()*100.0 ) - 50.0; + im = ( randu()*100.0 ) - 50.0; + z = new Complex128( re, im ); + o = cnegate( real(z), imag(z) ); + w = new Complex128( o[ 0 ], o[ 1 ] ); + console.log( 'negate(%s) = %s', z.toString(), w.toString() ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/benchmark.js new file mode 100644 index 000000000000..71f6d0a3ec56 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/benchmark.js @@ -0,0 +1,128 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var cnegate = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var re; + var im; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + re = ( randu()*1000.0 ) - 500.0; + im = ( randu()*1000.0 ) - 500.0; + y = cnegate( re, im ); + if ( y.length === 0 ) { + b.fail( 'should not be empty' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::memory_reuse', function benchmark( b ) { + var out; + var re; + var im; + var y; + var i; + + out = new Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + re = ( randu()*1000.0 ) - 500.0; + im = ( randu()*1000.0 ) - 500.0; + y = cnegate( out, re, im ); + if ( y.length === 0 ) { + b.fail( 'should not be empty' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::manual', function benchmark( b ) { + var re; + var im; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + re = ( randu()*1000.0 ) - 500.0; + im = ( randu()*1000.0 ) - 500.0; + y = [ -re, -im ]; + if ( y.length === 0 ) { + b.fail( 'should not be empty' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::manual,memory_reuse', function benchmark( b ) { + var re; + var im; + var y; + var i; + + y = new Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + re = ( randu()*1000.0 ) - 500.0; + im = ( randu()*1000.0 ) - 500.0; + y[ 0 ] = -re; + y[ 1 ] = -im; + if ( y.length === 0 ) { + b.fail( 'should not be empty' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/c/Makefile b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/c/Makefile new file mode 100644 index 000000000000..e4542b1e66e9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/c/Makefile @@ -0,0 +1,107 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2018 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +endif + +# Determine the OS: +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate [position independent code][1]: +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of C targets: +c_targets := benchmark.out + + +# TARGETS # + +# Default target. +# +# This target is the default target. + +all: $(c_targets) + +.PHONY: all + + +# Compile C source. +# +# This target compiles C source files. + +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm + + +# Run a benchmark. +# +# This target runs a benchmark. + +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + + +# Perform clean-up. +# +# This target removes generated files. + +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/c/benchmark.c new file mode 100644 index 000000000000..54880692961f --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/c/benchmark.c @@ -0,0 +1,140 @@ +/** +* @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. +*/ + +/** +* Benchmark complex number negation. +*/ +#include +#include +#include +#include +#include + +#define NAME "negate" +#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 double on the interval [0,1]. +* +* @return random double +*/ +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 re; + double im; + double t; + int i; + + double complex z; + double complex y; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + re = ( 1000.0*rand_double() ) - 500.0; + im = ( 1000.0*rand_double() ) - 500.0; + z = re + im*I; + y = -creal(z) - ( cimag(z) )*I; + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%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/complex/negate/benchmark/julia/REQUIRE b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/julia/REQUIRE new file mode 100644 index 000000000000..11b2b096cae4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/julia/REQUIRE @@ -0,0 +1,2 @@ +julia 0.5 +BenchmarkTools 0.0.8 diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/julia/benchmark.jl b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/julia/benchmark.jl new file mode 100755 index 000000000000..6b65286ab0ed --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/benchmark/julia/benchmark.jl @@ -0,0 +1,143 @@ +#!/usr/bin/env julia +# +# @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. + +import BenchmarkTools + +# Benchmark variables: +name = "negate"; +repeats = 3; + +""" + print_version() + +Prints the TAP version. + +# Examples + +``` julia +julia> print_version() +``` +""" +function print_version() + @printf( "TAP version 13\n" ); +end + +""" + print_summary( total, passing ) + +Print the benchmark summary. + +# Arguments + +* `total`: total number of tests +* `passing`: number of passing tests + +# Examples + +``` julia +julia> print_summary( 3, 3 ) +``` +""" +function print_summary( total, 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" ); +end + +""" + print_results( iterations, elapsed ) + +Print benchmark results. + +# Arguments + +* `iterations`: number of iterations +* `elapsed`: elapsed time (in seconds) + +# Examples + +``` julia +julia> print_results( 1000000, 0.131009101868 ) +``` +""" +function print_results( iterations, elapsed ) + rate = iterations / elapsed + + @printf( " ---\n" ); + @printf( " iterations: %d\n", iterations ); + @printf( " elapsed: %0.9f\n", elapsed ); + @printf( " rate: %0.9f\n", rate ); + @printf( " ...\n" ); +end + +""" + benchmark() + +Run a benchmark. + +# Notes + +* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. +* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. +* The elapsed time is in seconds. + +# Examples + +``` julia +julia> out = benchmark(); +``` +""" +function benchmark() + t = BenchmarkTools.@benchmark -( Complex128( (rand()*1000.0) - 500.0, (rand()*1000.0) - 500.0 ) ) samples=1e6 + + # Compute the total "elapsed" time and convert from nanoseconds to seconds: + s = sum( t.times ) / 1.0e9; + + # Determine the number of "iterations": + iter = length( t.times ); + + # Return the results: + [ iter, s ]; +end + +""" + main() + +Run benchmarks. + +# Examples + +``` julia +julia> main(); +``` +""" +function main() + print_version(); + for i in 1:repeats + @printf( "# julia::%s\n", name ); + results = benchmark(); + print_results( results[ 1 ], results[ 2 ] ); + @printf( "ok %d benchmark finished\n", i ); + end + print_summary( repeats, repeats ); +end + +main(); diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/docs/repl.txt b/lib/node_modules/@stdlib/math/base/complex/negate/docs/repl.txt new file mode 100644 index 000000000000..36d244f0fe1b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/docs/repl.txt @@ -0,0 +1,35 @@ + +{{alias}}( [out,] re, im ) + Negates a complex number. + + Parameters + ---------- + out: Array|TypedArray|Object (optional) + Output array. + + re: number + Real component. + + im: number + Imaginary component. + + Returns + ------- + out: Array|TypedArray|Object + Negated components. + + Examples + -------- + > var out = {{alias}}( TODO, TODO ) + TODO + + // Provide an output array: + > out = new {{alias:@stdlib/array/float64}}( 2 ); + > var v = {{alias}}( out, TODO, TODO ) + [ TODO, TODO ] + > var bool = ( v === out ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/examples/index.js b/lib/node_modules/@stdlib/math/base/complex/negate/examples/index.js new file mode 100644 index 000000000000..bc5c17cae799 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/examples/index.js @@ -0,0 +1,41 @@ +/** +* @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 Complex128 = require( '@stdlib/complex/float64' ); +var randu = require( '@stdlib/random/base/randu' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); +var cnegate = require( './../lib' ); + +var re; +var im; +var z; +var o; +var w; +var i; + +for ( i = 0; i < 100; i++ ) { + re = ( randu()*100.0 ) - 50.0; + im = ( randu()*100.0 ) - 50.0; + z = new Complex128( re, im ); + o = cnegate( real(z), imag(z) ); + w = new Complex128( o[ 0 ], o[ 1 ] ); + console.log( 'negate(%s) = %s', z.toString(), w.toString() ); +} diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/lib/cnegate.js b/lib/node_modules/@stdlib/math/base/complex/negate/lib/cnegate.js new file mode 100644 index 000000000000..ecfd4aa83d3b --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/lib/cnegate.js @@ -0,0 +1,58 @@ +/** +* @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'; + +// MAIN // + +/** +* Negates a complex number. +* +* @private +* @param {(Array|TypedArray|Object)} out - output array +* @param {number} re - real component +* @param {number} im - imaginary component +* @returns {(Array|TypedArray|Object)} negated components +* +* @example +* var out = new Array( 2 ); +* +* var v = cnegate( out, TODO, TODO ); +* // returns [ TODO, TODO ] +* +* var bool = ( v === out ); +* // returns true +* +* @example +* var out = new Array( 2 ); +* var v = cnegate( out, 0.0, 0.0 ); +* // returns [ TODO, TODO ] +* +* @example +* var out = new Array( 2 ); +* var v = cnegate( out, NaN, NaN ); +* // returns [ TODO, TODO ] +*/ +function cnegate( out, re, im ) { + // TODO: implementation +} + + +// EXPORTS // + +module.exports = cnegate; diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js b/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js new file mode 100644 index 000000000000..1b9e9c9d1f74 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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'; + +/** +* Negate a complex number. +* +* @module @stdlib/math/base/complex/negate +* +* @example +* var cnegate = require( '@stdlib/math/base/complex/negate' ); +* +* var v = cnegate( -4.2, 5.5 ); +* // returns [ TODO, TODO ] +* +* v = cnegate( 0.0, 0.0 ); +* // returns [ TODO, TODO ] +* +* v = cnegate( NaN, NaN ); +* // returns [ TODO, TODO ] +* +* @example +* var cnegate = require( '@stdlib/math/base/complex/round' ); +* +* var out = new Array( 2 ); +* +* var v = cnegate( out, -4.2, 5.5 ); +* // returns [ TODO, TODO ] +* +* var bool = ( v === out ); +* // returns true +*/ + +// MODULES // + +var cnegate = require( './main.js' ); + + +// EXPORTS // + +module.exports = cnegate; diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/lib/main.js b/lib/node_modules/@stdlib/math/base/complex/negate/lib/main.js new file mode 100644 index 000000000000..cdf3067d487d --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/lib/main.js @@ -0,0 +1,67 @@ +/** +* @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 negate = require( './cnegate.js' ); + + +// MAIN // + +/** +* Negates a complex number. +* +* @param {(Array|TypedArray|Object)} [out] - output array +* @param {number} re - real component +* @param {number} im - imaginary component +* @returns {(Array|TypedArray|Object)} negated components +* +* @example +* var v = cnegate( -4.2, 5.5 ); +* // returns [ TODO, TODO ] +* +* @example +* var out = new Array( 2 ); +* +* var v = cnegate( out, -4.2, 5.5 ); +* // returns [ TODO, TODO ] +* +* var bool = ( v === out ); +* // returns true +* +* @example +* var v = cnegate( 0.0, 0.0 ); +* // returns [ TODO, TODO ] +* +* @example +* var v = cnegate( NaN, NaN ); +* // returns [ TODO, TODO ] +*/ +function cnegate( out, re, im ) { + if ( arguments.length === 2 ) { + return negate( [ 0.0, 0.0 ], out, re ); + } + return negate( out, re, im ); +} + + +// EXPORTS // + +module.exports = cnegate; diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/package.json b/lib/node_modules/@stdlib/math/base/complex/negate/package.json new file mode 100644 index 000000000000..68100e4817f6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/math/base/complex/negate", + "version": "0.0.0", + "description": "Negate a complex 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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "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", + "neg", + "negate", + "negation", + "negative", + "complex", + "cmplx", + "number" + ] +} diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/test/test.js b/lib/node_modules/@stdlib/math/base/complex/negate/test/test.js new file mode 100644 index 000000000000..2fd279d6ff9c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/complex/negate/test/test.js @@ -0,0 +1,124 @@ +/** +* @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 PINF = require( '@stdlib/constants/math/float64-pinf' ); +var NINF = require( '@stdlib/constants/math/float64-ninf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cnegate = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cnegate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function negates real and imaginary components', function test( t ) { + var expected; + var actual; + + // TODO: tests + + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function negates real and imaginary components (output array)', function test( t ) { + var expected; + var actual; + var out; + + // TODO: tests + + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns output value' ); + + t.end(); +}); + +tape( 'the function negates real and imaginary components (output typed array)', function test( t ) { + var expected; + var actual; + var out; + + // TODO: tests + + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns output value' ); + + t.end(); +}); + +tape( 'the function negates real and imaginary components (output object)', function test( t ) { + var expected; + var actual; + var out; + + // TODO: tests + + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, out, 'returns output value' ); + + t.end(); +}); + +tape( 'the function returns a `NaN` if provided a `NaN`', function test( t ) { + var val = cnegate( NaN, NaN ); + t.strictEqual( isnan( val[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnan( val[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `+0` if provided `-0`', function test( t ) { + var val = cnegate( -0.0, -0.0 ); + t.strictEqual( isPositiveZero( val[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( val[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-0` if provided `+0`', function test( t ) { + var val = cnegate( +0.0, +0.0 ); + t.strictEqual( isNegativeZero( val[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( val[ 1 ] ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `-infinity` if provided `+infinity`', function test( t ) { + var val = cnegate( PINF, PINF ); + t.strictEqual( val[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( val[ 1 ], NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `+infinity` if provided `-infinity`', function test( t ) { + var val = cnegate( NINF, NINF ); + t.strictEqual( val[ 0 ], PINF, 'returns expected value' ); + t.strictEqual( val[ 1 ], PINF, 'returns expected value' ); + t.end(); +}); From bf32566ee970ee94bdff120a9ba065e324d4f2db Mon Sep 17 00:00:00 2001 From: kgryte Date: Sun, 22 Jul 2018 14:07:44 -0700 Subject: [PATCH 2/3] Fix pkg path --- lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js b/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js index 1b9e9c9d1f74..f694f0db9de6 100644 --- a/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js @@ -36,7 +36,7 @@ * // returns [ TODO, TODO ] * * @example -* var cnegate = require( '@stdlib/math/base/complex/round' ); +* var cnegate = require( '@stdlib/math/base/complex/negate' ); * * var out = new Array( 2 ); * From 53d50f1230fd534317dc88b21fbfc9b2477e5061 Mon Sep 17 00:00:00 2001 From: Shraddheya Shendre Date: Mon, 23 Jul 2018 21:32:19 +0530 Subject: [PATCH 3/3] Add support for negating a complex number (#193) * Completed all the TODO's * Fixed the minus zero results * Edited the redundant tests which are being checked later --- .../math/base/complex/negate/README.md | 8 ++--- .../math/base/complex/negate/docs/repl.txt | 8 ++--- .../math/base/complex/negate/lib/cnegate.js | 12 ++++--- .../math/base/complex/negate/lib/index.js | 8 ++--- .../math/base/complex/negate/lib/main.js | 8 ++--- .../math/base/complex/negate/test/test.js | 32 ++++++++++++++++--- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/README.md b/lib/node_modules/@stdlib/math/base/complex/negate/README.md index f7aabb8c8894..4864b14ac45f 100644 --- a/lib/node_modules/@stdlib/math/base/complex/negate/README.md +++ b/lib/node_modules/@stdlib/math/base/complex/negate/README.md @@ -46,13 +46,13 @@ Negates a `complex` number comprised of a **real** component `re` and an **imagi ```javascript var v = cnegate( -4.2, 5.5 ); -// returns [ TODO, TODO ] +// returns [ 4.2, -5.5 ] v = cnegate( 0.0, 0.0 ); -// returns [ TODO, TODO ] +// returns [ -0.0, -0.0 ] v = cnegate( NaN, NaN ); -// returns [ TODO, TODO ] +// returns [ NaN, NaN ] ``` 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. @@ -63,7 +63,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var out = new Float64Array( 2 ); var v = cnegate( out, -4.2, 5.5 ); -// returns [ TODO, TODO ] +// returns [ 4.2, -5.5 ] var bool = ( v === out ); // returns true diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/docs/repl.txt b/lib/node_modules/@stdlib/math/base/complex/negate/docs/repl.txt index 36d244f0fe1b..17da52ec96ac 100644 --- a/lib/node_modules/@stdlib/math/base/complex/negate/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/complex/negate/docs/repl.txt @@ -20,13 +20,13 @@ Examples -------- - > var out = {{alias}}( TODO, TODO ) - TODO + > var out = {{alias}}( -4.2, 5.5 ) + [ 4.2, -5.5 ] // Provide an output array: > out = new {{alias:@stdlib/array/float64}}( 2 ); - > var v = {{alias}}( out, TODO, TODO ) - [ TODO, TODO ] + > var v = {{alias}}( out, -4.2, 5.5 ) + [ 4.2, -5.5 ] > var bool = ( v === out ) true diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/lib/cnegate.js b/lib/node_modules/@stdlib/math/base/complex/negate/lib/cnegate.js index ecfd4aa83d3b..c2ef6250787e 100644 --- a/lib/node_modules/@stdlib/math/base/complex/negate/lib/cnegate.js +++ b/lib/node_modules/@stdlib/math/base/complex/negate/lib/cnegate.js @@ -32,8 +32,8 @@ * @example * var out = new Array( 2 ); * -* var v = cnegate( out, TODO, TODO ); -* // returns [ TODO, TODO ] +* var v = cnegate( out, -4.2, 5.5 ); +* // returns [ 4.2, -5.5 ] * * var bool = ( v === out ); * // returns true @@ -41,15 +41,17 @@ * @example * var out = new Array( 2 ); * var v = cnegate( out, 0.0, 0.0 ); -* // returns [ TODO, TODO ] +* // returns [ -0.0, -0.0 ] * * @example * var out = new Array( 2 ); * var v = cnegate( out, NaN, NaN ); -* // returns [ TODO, TODO ] +* // returns [ NaN, NaN ] */ function cnegate( out, re, im ) { - // TODO: implementation + out[ 0 ] = -re; + out[ 1 ] = -im; + return out; } diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js b/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js index f694f0db9de6..c452649c537c 100644 --- a/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/complex/negate/lib/index.js @@ -27,13 +27,13 @@ * var cnegate = require( '@stdlib/math/base/complex/negate' ); * * var v = cnegate( -4.2, 5.5 ); -* // returns [ TODO, TODO ] +* // returns [ 4.2, -5.5 ] * * v = cnegate( 0.0, 0.0 ); -* // returns [ TODO, TODO ] +* // returns [ -0.0, -0.0 ] * * v = cnegate( NaN, NaN ); -* // returns [ TODO, TODO ] +* // returns [ NaN, NaN ] * * @example * var cnegate = require( '@stdlib/math/base/complex/negate' ); @@ -41,7 +41,7 @@ * var out = new Array( 2 ); * * var v = cnegate( out, -4.2, 5.5 ); -* // returns [ TODO, TODO ] +* // returns [ 4.2, -5.5 ] * * var bool = ( v === out ); * // returns true diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/lib/main.js b/lib/node_modules/@stdlib/math/base/complex/negate/lib/main.js index cdf3067d487d..f300dd85cb3d 100644 --- a/lib/node_modules/@stdlib/math/base/complex/negate/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/complex/negate/lib/main.js @@ -35,24 +35,24 @@ var negate = require( './cnegate.js' ); * * @example * var v = cnegate( -4.2, 5.5 ); -* // returns [ TODO, TODO ] +* // returns [ 4.2, -5.5 ] * * @example * var out = new Array( 2 ); * * var v = cnegate( out, -4.2, 5.5 ); -* // returns [ TODO, TODO ] +* // returns [ 4.2, -5.5 ] * * var bool = ( v === out ); * // returns true * * @example * var v = cnegate( 0.0, 0.0 ); -* // returns [ TODO, TODO ] +* // returns [ -0.0, -0.0 ] * * @example * var v = cnegate( NaN, NaN ); -* // returns [ TODO, TODO ] +* // returns [ NaN, NaN ] */ function cnegate( out, re, im ) { if ( arguments.length === 2 ) { diff --git a/lib/node_modules/@stdlib/math/base/complex/negate/test/test.js b/lib/node_modules/@stdlib/math/base/complex/negate/test/test.js index 2fd279d6ff9c..ccec6c0bfbf4 100644 --- a/lib/node_modules/@stdlib/math/base/complex/negate/test/test.js +++ b/lib/node_modules/@stdlib/math/base/complex/negate/test/test.js @@ -42,8 +42,20 @@ tape( 'the function negates real and imaginary components', function test( t ) { var expected; var actual; - // TODO: tests + actual = cnegate( -4.2, 5.5 ); + expected = [ 4.2, -5.5 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = cnegate( 9.99999, 0.1 ); + expected = [ -9.99999, -0.1 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = cnegate( 4.0, 7.0 ); + expected = [ -4.0, -7.0 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + actual = cnegate( -4.0, -7.0 ); + expected = [ 4.0, 7.0 ]; t.deepEqual( actual, expected, 'returns expected value' ); t.end(); @@ -54,7 +66,10 @@ tape( 'the function negates real and imaginary components (output array)', funct var actual; var out; - // TODO: tests + out = new Array( 2 ); + actual = cnegate( out, -4.2, 5.5 ); + + expected = [ 4.2, -5.5 ]; t.deepEqual( actual, expected, 'returns expected value' ); t.strictEqual( actual, out, 'returns output value' ); @@ -67,7 +82,10 @@ tape( 'the function negates real and imaginary components (output typed array)', var actual; var out; - // TODO: tests + out = new Float64Array( 2 ); + actual = cnegate( out, 9.99999, 0.1 ); + + expected = new Float64Array( [ -9.99999, -0.1 ] ); t.deepEqual( actual, expected, 'returns expected value' ); t.strictEqual( actual, out, 'returns output value' ); @@ -80,7 +98,13 @@ tape( 'the function negates real and imaginary components (output object)', func var actual; var out; - // TODO: tests + out = {}; + actual = cnegate( out, 4.2, -5.5 ); + + expected = { + '0': -4.2, + '1': 5.5 + }; t.deepEqual( actual, expected, 'returns expected value' ); t.strictEqual( actual, out, 'returns output value' );