Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions lib/node_modules/@stdlib/array/complex128/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,77 @@ idx = arr.lastIndexOf( new Complex128( 2.0, -2.0 ), 0 );
// returns -1
```

<a name="method-map"></a>

#### Complex128Array.prototype.map( callbackFn\[, thisArg] )

Returns a new array with each element being the result of a provided callback function.

```javascript
var Complex128 = require( '@stdlib/complex/float64' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );

function scale( v ) {
return new Complex128( 2.0*real( v ), 2.0*imag( v ) );
}

var arr = new Complex128Array( 3 );

// Set the first three elements:
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );

var out = arr.map( scale );
// returns <Complex128Array>

var z = out.get( 0 );
// returns <Complex128>

var re = real( z );
// returns 2.0

var im = imag( z );
// returns -2.0
```

The callback function is provided three arguments:

- **value**: current array element.
- **index**: current array element index.
- **arr**: the array on which this method was called.

To set the function execution context, provide a `thisArg`.

```javascript
var Complex128 = require( '@stdlib/complex/float64' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );

function scale( v ) {
this.count += 1;
return new Complex128( 2.0*real( v ), 2.0*imag( v ) );
}

var arr = new Complex128Array( 3 );

var context = {
'count': 0
};

// Set the first three elements:
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );

var out = arr.map( scale, context );
// returns <Complex128Array>

var count = context.count;
// returns 3
```

<a name="method-set"></a>

#### Complex128Array.prototype.set( z\[, i] )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @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 bench = require( '@stdlib/bench' );
var isComplex128Array = require( '@stdlib/assert/is-complex128array' );
var realf = require( '@stdlib/complex/realf' );
var imagf = require( '@stdlib/complex/imagf' );
var Complex128 = require('@stdlib/complex/float64');
var pkg = require( './../package.json' ).name;
var Complex128Array = require( './../lib' );


// MAIN //

bench( pkg+':map', function benchmark( b ) {
var out;
var arr;
var i;

arr = new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.map( scale );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isComplex128Array( out ) ) {
b.fail( 'should return a Complex128Array' );
}
b.pass( 'benchmark finished' );
b.end();

function scale( v ) {
return new Complex128( realf(v)*2.0, imagf(v)*2.0 );
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @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 bench = require( '@stdlib/bench' );
var isComplex128Array = require( '@stdlib/assert/is-complex128array' );
var pow = require( '@stdlib/math/base/special/pow' );
var identity = require( '@stdlib/utils/identity-function' );
var Complex128 = require( '@stdlib/complex/float64' );
var pkg = require( './../package.json' ).name;
var Complex128Array = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr;
var i;

arr = [];
for ( i = 0; i < len; i++ ) {
arr.push( new Complex128( i, i ) );
}
arr = new Complex128Array( arr );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = arr.map( identity );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isComplex128Array( out ) ) {
b.fail( 'should return a Complex128Array' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':map:len='+len, f );
}
}

main();
82 changes: 82 additions & 0 deletions lib/node_modules/@stdlib/array/complex128/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable max-lines */

/*
* @license Apache-2.0
*
Expand Down Expand Up @@ -105,6 +107,50 @@ type TernaryPredicate<U> = ( this: U, value: Complex128, index: number, arr: Com
*/
type Predicate<U> = NullaryPredicate<U> | UnaryPredicate<U> | BinaryPredicate<U> | TernaryPredicate<U>;

/**
* Callback invoked for each element in an array.
*
* @returns transformed value
*/
type NullaryMapFcn<U> = ( this: U ) => ComplexLike | ArrayLike<number>;

/**
* Callback invoked for each element in an array.
*
* @param value - current array element
* @returns transformed value
*/
type UnaryMapFcn<U> = ( this: U, value: Complex128 ) => ComplexLike | ArrayLike<number>;

/**
* Callback invoked for each element in an array.
*
* @param value - current array element
* @param index - current array element index
* @returns transformed value
*/
type BinaryMapFcn<U> = ( this: U, value: Complex128, index: number ) => ComplexLike | ArrayLike<number>;

/**
* Callback invoked for each element in an array.
*
* @param value - current array element
* @param index - current array element index
* @param arr - array on which the method was called
* @returns transformed value
*/
type TernaryMapFcn<U> = ( this: U, value: Complex128, index: number, arr: Complex128Array ) => ComplexLike | ArrayLike<number>;

/**
* Callback invoked for each element in an array.
*
* @param value - current array element
* @param index - current array element index
* @param arr - array on which the method was called
* @returns transformed value
*/
type MapFcn<U> = NullaryMapFcn<U> | UnaryMapFcn<U> | BinaryMapFcn<U> | TernaryMapFcn<U>;

/**
* Class for creating a 128-bit complex number array.
*/
Expand Down Expand Up @@ -602,6 +648,42 @@ declare class Complex128Array implements Complex128ArrayInterface {
*/
lastIndexOf( searchElement: ComplexLike, fromIndex?: number ): number;

/**
* Returns a new array with each element being the result of a provided callback function.
*
* @param fcn - callback function
* @param thisArg - execution context
* @returns new array containing transformed elements
*
* @example
* var Complex128 = require( '@stdlib/complex/float64' );
* var real = require( '@stdlib/complex/real' );
* var imag = require( '@stdlib/complex/imag' );
*
* function scale( v, i ) {
* return new Complex128( 2.0*real( v ), 2.0*imag( v ) );
* }
*
* var arr = new Complex128Array( 3 );
*
* arr.set( [ 1.0, -1.0 ], 0 );
* arr.set( [ 2.0, -2.0 ], 1 );
* arr.set( [ 3.0, -3.0 ], 2 );
*
* var out = arr.map( scale );
* // returns <Complex128Array>
*
* var z = out.get( 0 );
* // returns <Complex128>
*
* var re = real( z );
* // returns 2.0
*
* var im = imag( z );
* // returns -2.0
*/
map<U = unknown>( fcn: MapFcn<U>, thisArg?: ThisParameterType<MapFcn<U>> ): Complex128Array;

/**
* Sets an array element.
*
Expand Down
Loading