Usage
var Complex128Array = require( '@stdlib/array-complex128' );
Complex128Array()
Creates a 128-bit complex number array.
var arr = new Complex128Array();
Complex128Array( length )
Creates a 128-bit complex number array having a specified length
.
var arr = new Complex128Array( 10 );
var len = arr.length;
Complex128Array( complexarray )
Creates a 128-bit complex number array from another complex number array.
var arr1 = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] );
var arr2 = new Complex128Array( arr1 );
var len = arr2.length;
Complex128Array( typedarray )
Creates a 128-bit complex number array from a typed array containing interleaved real and imaginary components.
var Float64Array = require( '@stdlib/array-float64' );
var buf = new Float64Array( [ 1.0, -1.0, 2.0, -2.0 ] );
var arr = new Complex128Array( buf );
var len = arr.length;
Complex128Array( obj )
Creates a 128-bit complex number array from an array-like object or iterable.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var arr1 = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] );
var len = arr1.length;
var buf = [ new Complex128( 1.0, -1.0 ), new Complex128( 2.0, -2.0 ) ];
var arr2 = new Complex128Array( buf );
len = arr2.length;
Complex128Array( buffer[, byteOffset[, length]] )
Returns a 128-bit complex number array view of an ArrayBuffer
.
var ArrayBuffer = require( '@stdlib/array-buffer' );
var buf = new ArrayBuffer( 480 );
var arr1 = new Complex128Array( buf );
var len = arr1.length;
var arr2 = new Complex128Array( buf, 16 );
len = arr2.length;
var arr3 = new Complex128Array( buf, 16, 20 );
len = arr3.length;
Properties
Complex128Array.BYTES_PER_ELEMENT
Static property returning the size (in bytes) of each array element.
var nbytes = Complex128Array.BYTES_PER_ELEMENT;
Complex128Array.name
Static property returning the constructor name.
var str = Complex128Array.name;
Complex128Array.prototype.buffer
Pointer to the underlying data buffer.
var arr = new Complex128Array( 2 );
var buf = arr.buffer;
Complex128Array.prototype.byteLength
Size (in bytes) of the array.
var arr = new Complex128Array( 10 );
var nbytes = arr.byteLength;
Complex128Array.prototype.byteOffset
Offset (in bytes) of the array from the start of its underlying ArrayBuffer
.
var ArrayBuffer = require( '@stdlib/array-buffer' );
var arr = new Complex128Array( 10 );
var offset = arr.byteOffset;
var buf = new ArrayBuffer( 480 );
arr = new Complex128Array( buf, 128 );
offset = arr.byteOffset;
Complex128Array.prototype.BYTES_PER_ELEMENT
Size (in bytes) of each array element.
var arr = new Complex128Array( 10 );
var nbytes = arr.BYTES_PER_ELEMENT;
Complex128Array.prototype.length
Number of array elements.
var arr = new Complex128Array( 10 );
var len = arr.length;
Methods
Complex128Array.from( src[, clbk[, thisArg]] )
Creates a new 128-bit complex number array from an array-like object or an iterable.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var arr = Complex128Array.from( [ 1.0, -1.0 ] );
var len = arr.length;
arr = Complex128Array.from( [ new Complex128( 1.0, -1.0 ) ] );
len = arr.length;
The iterator returned by an iterable must return either a complex number or an array-like object containing a real and imaginary component.
var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' );
var Float64Array = require( '@stdlib/array-float64' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var iter;
var arr;
var len;
var re;
var im;
var z;
function iterable() {
var buf = new Float64Array( 2 );
var i = 0;
return {
'next': next
};
function next() {
i += 1;
if ( i < 3 ) {
buf[ 0 ] = i;
buf[ 1 ] = -i;
return {
'value': buf
};
}
return {
'done': true
};
}
}
if ( ITERATOR_SYMBOL === null ) {
console.error( 'Environment does not support iterables.' );
} else {
iter = {};
iter[ ITERATOR_SYMBOL ] = iterable;
arr = Complex128Array.from( iter );
len = arr.length;
z = arr.get( 0 );
re = real( z );
im = imag( z );
}
To invoke a function for each src
value, provide a callback function. If src
is an iterable or an array-like object containing complex numbers, the callback must return either a complex number
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function map( z ) {
return new Complex128( real(z)*2.0, imag(z)*2.0 );
}
var src = [ new Complex128( 1.0, -1.0 ) ];
var arr = Complex128Array.from( src, map );
var len = arr.length;
var z = arr.get( 0 );
var re = real( z );
var im = imag( z );
or an array-like object containing real and imaginary components
var Float64Array = require( '@stdlib/array-float64' );
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function mapFcn() {
var buf = new Float64Array( 2 );
return map;
function map( z ) {
buf[ 0 ] = real( z ) * 2.0;
buf[ 1 ] = imag( z ) * 2.0;
return buf;
}
}
var src = [ new Complex128( 1.0, -1.0 ), new Complex128( 2.0, -2.0 ) ];
var arr = Complex128Array.from( src, mapFcn() );
var len = arr.length;
var z = arr.get( 0 );
var re = real( z );
var im = imag( z );
z = arr.get( 1 );
re = real( z );
im = imag( z );
If src
is an array-like object containing interleaved real and imaginary components, the callback is invoked for each component and should return the transformed component value.
var Float64Array = require( '@stdlib/array-float64' );
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function map( v ) {
return v * 2.0;
}
var src = new Float64Array( [ 1.0, -1.0 ] );
var arr = Complex128Array.from( src, map );
var len = arr.length;
var z = arr.get( 0 );
var re = real( z );
var im = imag( z );
A callback function is provided two arguments:
- value: source value.
- index: source index.
To set the callback execution context, provide a thisArg
.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function map( z ) {
this.count += 1;
return new Complex128( real(z)*2.0, imag(z)*2.0 );
}
var src = [ new Complex128( 1.0, -1.0 ), new Complex128( 1.0, -1.0 ) ];
var ctx = {
'count': 0
};
var arr = Complex128Array.from( src, map, ctx );
var len = arr.length;
var n = ctx.count;
Complex128Array.of( element0[, element1[, ...elementN]] )
Creates a new 128-bit complex number array from a variable number of arguments.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var arr = Complex128Array.of( 1.0, -1.0, 2.0, -2.0 );
var len = arr.length;
var z1 = new Complex128( 1.0, -1.0 );
var z2 = new Complex128( 2.0, -2.0 );
arr = Complex128Array.of( z1, z2 );
len = arr.length;
Complex128Array.prototype.at( i )
Returns an array element located at integer position (index) i
, with support for both nonnegative and negative integer positions.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 10 );
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 9.0, -9.0 ], 9 );
var z = arr.at( 0 );
var re = real( z );
var im = imag( z );
z = arr.at( -1 );
re = real( z );
im = imag( z );
If provided an out-of-bounds index, the method returns undefined
.
var arr = new Complex128Array( 10 );
var z = arr.at( 100 );
z = arr.at( -100 );
Complex128Array.prototype.copyWithin( target, start[, end] )
Copies a sequence of elements within the array starting at start
and ending at end
(non-inclusive) to the position starting at target
.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 4 );
arr.set( new Complex128( 1.0, -1.0 ), 0 );
arr.set( new Complex128( 2.0, -2.0 ), 1 );
arr.set( new Complex128( 3.0, -3.0 ), 2 );
arr.set( new Complex128( 4.0, -4.0 ), 3 );
var z = arr.get( 0 );
var re = real( z );
var im = imag( z );
z = arr.get( 1 );
re = real( z );
im = imag( z );
arr.copyWithin( 0, 2 );
z = arr.get( 0 );
re = real( z );
im = imag( z );
z = arr.get( 1 );
re = real( z );
im = imag( z );
By default, end
equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an end
argument.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 4 );
arr.set( new Complex128( 1.0, -1.0 ), 0 );
arr.set( new Complex128( 2.0, -2.0 ), 1 );
arr.set( new Complex128( 3.0, -3.0 ), 2 );
arr.set( new Complex128( 4.0, -4.0 ), 3 );
var z = arr.get( 2 );
var re = real( z );
var im = imag( z );
z = arr.get( 3 );
re = real( z );
im = imag( z );
arr.copyWithin( 2, 0, 2 );
z = arr.get( 2 );
re = real( z );
im = imag( z );
z = arr.get( 3 );
re = real( z );
im = imag( z );
When a target
, start
, and/or end
index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example:
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 4 );
arr.set( new Complex128( 1.0, -1.0 ), 0 );
arr.set( new Complex128( 2.0, -2.0 ), 1 );
arr.set( new Complex128( 3.0, -3.0 ), 2 );
arr.set( new Complex128( 4.0, -4.0 ), 3 );
var z = arr.get( 2 );
var re = real( z );
var im = imag( z );
z = arr.get( 3 );
re = real( z );
im = imag( z );
arr.copyWithin( -2, -4, -2 );
z = arr.get( 2 );
re = real( z );
im = imag( z );
z = arr.get( 3 );
re = real( z );
im = imag( z );
Complex128Array.prototype.entries()
Returns an iterator for iterating over array key-value pairs.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = [
new Complex128( 1.0, -1.0 ),
new Complex128( 2.0, -2.0 ),
new Complex128( 3.0, -3.0 )
];
arr = new Complex128Array( arr );
var it = arr.entries();
var v = it.next().value;
var re = real( v[ 1 ] );
var im = imag( v[ 1 ] );
v = it.next().value;
re = real( v[ 1 ] );
im = imag( v[ 1 ] );
v = it.next().value;
re = real( v[ 1 ] );
im = imag( v[ 1 ] );
var bool = it.next().done;
Complex128Array.prototype.every( predicate[, thisArg] )
Returns a boolean indicating whether all elements pass a test.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v ) {
return ( real( v ) === 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 bool = arr.every( predicate );
The predicate
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
.
function predicate( v, i ) {
this.count += 1;
return ( i >= 0 );
}
var arr = new Complex128Array( 3 );
var context = {
'count': 0
};
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );
var bool = arr.every( predicate, context );
var count = context.count;
Complex128Array.prototype.fill( value[, start[, end]] )
Returns a modified typed array filled with a fill value.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 3 );
arr.fill( new Complex128( 1.0, 1.0 ) );
var z = arr.get( 0 );
var re = real( z );
var im = imag( z );
z = arr.get( 2 );
re = real( z );
im = imag( z );
arr.fill( new Complex128( 2.0, 2.0 ), 1 );
z = arr.get( 1 );
re = real( z );
im = imag( z );
z = arr.get( 2 );
re = real( z );
im = imag( z );
arr.fill( new Complex128( 3.0, 3.0 ), 0, 2 );
z = arr.get( 0 );
re = real( z );
im = imag( z );
z = arr.get( 1 );
re = real( z );
im = imag( z );
When a start
and/or end
index is negative, the respective index is determined relative to the last array element.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 3 );
arr.fill( new Complex128( 1.0, 1.0 ), 0, -1 );
var z = arr.get( 0 );
var re = real( z );
var im = imag( z );
z = arr.get( arr.length - 1 );
re = real( z );
im = imag( z );
Complex128Array.prototype.filter( predicate[, thisArg] )
Returns a new array containing the elements of an array which pass a test implemented by a predicate function.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v ) {
return ( real( v ) === 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.filter( predicate );
var len = out.length;
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
The predicate
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
.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v, i ) {
this.count += 1;
return ( i >= 0 && real( v ) === imag( v ) );
}
var arr = new Complex128Array( 3 );
var context = {
'count': 0
};
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );
var out = arr.filter( predicate, context );
var len = out.length;
var count = context.count;
Complex128Array.prototype.find( predicate[, thisArg] )
Returns the first element in an array for which a predicate function returns a truthy value.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v ) {
return ( real( v ) === 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 z = arr.find( predicate );
var re = real( z );
var im = imag( z );
The predicate
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
.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v, i ) {
this.count += 1;
return ( i >= 0 && real( v ) === imag( v ) );
}
var arr = new Complex128Array( 3 );
var context = {
'count': 0
};
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, 3.0 ], 2 );
var z = arr.find( predicate, context );
var re = real( z );
var im = imag( z );
var count = context.count;
Complex128Array.prototype.findIndex( predicate[, thisArg] )
Returns the index of the first element in an array for which a predicate function returns a truthy value.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v ) {
return ( real( v ) === 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 idx = arr.findIndex( predicate );
The predicate
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
.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v, i ) {
this.count += 1;
return ( i >= 0 && real( v ) === imag( v ) );
}
var arr = new Complex128Array( 3 );
var context = {
'count': 0
};
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );
var idx = arr.findIndex( predicate, context );
var count = context.count;
Complex128Array.prototype.findLast( predicate[, thisArg] )
Returns the last element in an array for which a predicate function returns a truthy value.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v ) {
return ( real( v ) === 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 z = arr.findLast( predicate );
var re = real( z );
var im = imag( z );
The predicate
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
.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v, i ) {
this.count += 1;
return ( i >= 0 && real( v ) === imag( v ) );
}
var arr = new Complex128Array( 3 );
var context = {
'count': 0
};
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );
var z = arr.findLast( predicate, context );
var re = real( z );
var im = imag( z );
var count = context.count;
Complex128Array.prototype.findLastIndex( predicate[, thisArg] )
Returns the index of the last element in an array for which a predicate function returns a truthy value.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v ) {
return ( real( v ) === 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 idx = arr.findLastIndex( predicate );
The predicate
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
.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v, i ) {
this.count += 1;
return ( i >= 0 && real( v ) === imag( v ) );
}
var arr = new Complex128Array( 3 );
var context = {
'count': 0
};
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );
var idx = arr.findLastIndex( predicate, context );
var count = context.count;
Complex128Array.prototype.forEach( callbackFn[, thisArg] )
Invokes a function once for each array element.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
function log( v, i ) {
console.log( '%s: %s', i, v.toString() );
}
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 );
arr.forEach( log );
The invoked 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
.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
function fcn( v, i ) {
this.count += 1;
console.log( '%s: %s', i, v.toString() );
}
var arr = new Complex128Array( 3 );
var context = {
'count': 0
};
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );
arr.forEach( fcn, context );
var count = context.count;
Complex128Array.prototype.get( i )
Returns an array element located at position (index) i
.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 10 );
arr.set( [ 1.0, -1.0 ], 0 );
var z = arr.get( 0 );
var re = real( z );
var im = imag( z );
If provided an out-of-bounds index, the method returns undefined
.
var arr = new Complex128Array( 10 );
var z = arr.get( 100 );
Complex128Array.prototype.includes( searchElement[, fromIndex] )
Returns a boolean indicating whether an array includes a provided value.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var arr = new Complex128Array( 5 );
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );
arr.set( [ 4.0, -4.0 ], 3 );
arr.set( [ 5.0, -5.0 ], 4 );
var bool = arr.includes( new Complex128( 3.0, -3.0 ) );
bool = arr.includes( new Complex128( 3.0, -3.0 ), 3 );
bool = arr.includes( new Complex128( 4.0, -4.0 ), -3 );
Complex128Array.prototype.indexOf( searchElement[, fromIndex] )
Returns the first index at which a given element can be found.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var arr = new Complex128Array( 5 );
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );
arr.set( [ 4.0, -4.0 ], 3 );
arr.set( [ 2.0, -2.0 ], 4 );
var idx = arr.indexOf( new Complex128( 3.0, -3.0 ) );
idx = arr.indexOf( new Complex128( 2.0, -2.0 ), 2 );
idx = arr.indexOf( new Complex128( 4.0, -4.0 ), -3 );
If searchElement
is not present in the array, the method returns -1
.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var arr = new Complex128Array( 5 );
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
var idx = arr.indexOf( new Complex128( 3.0, -3.0 ) );
idx = arr.indexOf( new Complex128( 1.0, -1.0 ), 1 );
Complex128Array.prototype.join( [separator] )
Returns a new string by concatenating all array elements.
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 str = arr.join();
By default, the method separates serialized array elements with a comma. To use an alternative separator, provide a separator
string.
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 str = arr.join( '/' );
Complex128Array.prototype.keys()
Returns an iterator for iterating over each index key in a typed array.
var arr = new Complex128Array( 2 );
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
var iter = arr.keys();
var v = iter.next().value;
v = iter.next().value;
var bool = iter.next().done;
The returned iterator protocol-compliant object has the following properties:
- next: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a
value
property and a done
property having a boolean
value indicating whether the iterator is finished. - return: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.
Complex128Array.prototype.lastIndexOf( searchElement[, fromIndex] )
Returns the last index at which a given element can be found.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var arr = new Complex128Array( 5 );
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );
arr.set( [ 4.0, -4.0 ], 3 );
arr.set( [ 2.0, -2.0 ], 4 );
var idx = arr.lastIndexOf( new Complex128( 3.0, -3.0 ) );
idx = arr.lastIndexOf( new Complex128( 2.0, -2.0 ), 2 );
idx = arr.lastIndexOf( new Complex128( 4.0, -4.0 ), -1 );
If searchElement
is not present in the array, the method returns -1
.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var arr = new Complex128Array( 5 );
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
var idx = arr.lastIndexOf( new Complex128( 3.0, -3.0 ) );
idx = arr.lastIndexOf( new Complex128( 2.0, -2.0 ), 0 );
Complex128Array.prototype.map( callbackFn[, thisArg] )
Returns a new array with each element being the result of a provided callback function.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function scale( v ) {
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 );
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
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
.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-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
};
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 );
var count = context.count;
Complex128Array.prototype.reduce( reducerFn[, initialValue] )
Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var cadd = require( '@stdlib/complex-float64-base-add' );
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 z = arr.reduce( cadd );
var re = real( z );
var im = imag( z );
The reducer function is provided four arguments:
- acc: accumulated result.
- value: current array element.
- index: current array element index.
- arr: the array on which this method was called.
By default, the function initializes the accumulated result to the first element in the array and passes the second array element as value
during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as value
during the first invocation of the provided callback, provide an initialValue
argument.
var real = require( '@stdlib/complex-float64-real' );
function reducer( acc, v ) {
acc += real( v );
return acc;
}
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 z = arr.reduce( reducer, 0.0 );
Complex128Array.prototype.reduceRight( reducerFn[, initialValue] )
Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var cadd = require( '@stdlib/complex-float64-base-add' );
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 z = arr.reduceRight( cadd );
var re = real( z );
var im = imag( z );
The reducer function is provided four arguments:
- acc: accumulated result.
- value: current array element.
- index: current array element index.
- arr: the array on which this method was called.
By default, the function initializes the accumulated result to the last element in the array and passes the second-last array element as value
during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the last array element as value
during the first invocation of the provided callback, provide an initialValue
argument.
var real = require( '@stdlib/complex-float64-real' );
function reducer( acc, v ) {
acc += real( v );
return acc;
}
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 z = arr.reduceRight( reducer, 0.0 );
Complex128Array.prototype.reverse()
Reverses an array in-place.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
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.reverse();
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
z = out.get( 1 );
re = real( z );
im = imag( z );
z = out.get( 2 );
re = real( z );
im = imag( z );
Complex128Array.prototype.set( z[, i] )
Sets one or more array elements.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 10 );
var z = arr.get( 0 );
var re = real( z );
var im = imag( z );
arr.set( new Complex128( 1.0, -1.0 ) );
z = arr.get( 0 );
re = real( z );
im = imag( z );
By default, the method sets array elements starting at position (index) i = 0
. To set elements starting elsewhere in the array, provide an index argument i
.
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 10 );
var z = arr.get( 4 );
var re = real( z );
var im = imag( z );
arr.set( new Complex128( 1.0, -1.0 ), 4 );
z = arr.get( 4 );
re = real( z );
im = imag( z );
In addition to providing a complex number, to set one or more array elements, provide an array-like object containing either complex numbers
var Complex128 = require( '@stdlib/complex-float64-ctor' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 10 );
var buf = [
new Complex128( 1.0, -1.0 ),
new Complex128( 2.0, -2.0 ),
new Complex128( 3.0, -3.0 )
];
arr.set( buf, 4 );
var z = arr.get( 5 );
var re = real( z );
var im = imag( z );
or interleaved real and imaginary components
var Float64Array = require( '@stdlib/array-float64' );
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 10 );
var buf = new Float64Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] );
arr.set( buf, 4 );
var z = arr.get( 5 );
var re = real( z );
var im = imag( z );
A few notes:
- If
i
is out-of-bounds, the method throws an error. - If a target array cannot accommodate all values (i.e., the length of source array plus
i
exceeds the target array length), the method throws an error. - If provided a typed array which shares an
ArrayBuffer
with the target array, the method will intelligently copy the source range to the destination range.
Complex128Array.prototype.slice( [start[, end]] )
Copies a portion of a typed array to a new typed array.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var out = arr.slice();
var len = out.length;
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
z = out.get( len-1 );
re = real( z );
im = imag( z );
By default, the method returns a typed array beginning with the first array element. To specify an alternative array index at which to begin, provide a start
index (inclusive).
var imag = require( '@stdlib/complex-float64-imag' );
var real = require( '@stdlib/complex-float64-real' );
var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var out = arr.slice( 1 );
var len = out.length;
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
By default, the method returns a typed array which includes all array elements after start
. To limit the number of array elements after start
, provide an end
index (exclusive).
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var out = arr.slice( 1, -1 );
var len = out.length;
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
z = out.get( len-1 );
re = real( z );
im = imag( z );
Complex128Array.prototype.some( predicate[, thisArg] )
Returns a boolean indicating whether at least one element passes a test.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v ) {
return ( real( v ) === 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 bool = arr.some( predicate );
The predicate
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
.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function predicate( v, i ) {
this.count += 1;
return ( imag( v ) === real( v ) );
}
var arr = new Complex128Array( 3 );
var context = {
'count': 0
};
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
arr.set( [ 3.0, -3.0 ], 2 );
var bool = arr.some( predicate, context );
var count = context.count;
Complex128Array.prototype.sort( compareFcn )
Sorts an array in-place.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function compare( a, b ) {
var re1;
var re2;
var im1;
var im2;
re1 = real( a );
re2 = real( b );
if ( re1 < re2 ) {
return -1;
}
if ( re1 > re2 ) {
return 1;
}
im1 = imag( a );
im2 = imag( b );
if ( im1 < im2 ) {
return -1;
}
if ( im1 > im2 ) {
return 1;
}
return 0;
}
var arr = new Complex128Array( 3 );
arr.set( [ 3.0, -3.0 ], 0 );
arr.set( [ 1.0, -1.0 ], 1 );
arr.set( [ 2.0, -2.0 ], 2 );
var out = arr.sort( compare );
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
z = out.get( 1 );
re = real( z );
im = imag( z );
z = out.get( 2 );
re = real( z );
im = imag( z );
The compareFcn
determines the order of the elements. The function is called with the following arguments:
- a: the first element for comparison.
- b: the second element for comparison.
The function should return a number where:
- a negative value indicates that
a
should come before b
. - a positive value indicates that
a
should come after b
. - zero or
NaN
indicates that a
and b
are considered equal.
In contrast to real numbers, one cannot define a default order relation which is compatible with multiplication. Accordingly, users must explicitly provide a compareFcn
argument and are thus responsible for specifying a complex number ordering.
Complex128Array.prototype.subarray( [begin[, end]] )
Creates a new typed array view over the same underlying ArrayBuffer
and with the same underlying data type as the host array.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var subarr = arr.subarray();
var len = subarr.length;
var z = subarr.get( 0 );
var re = real( z );
var im = imag( z );
z = subarr.get( len-1 );
re = real( z );
im = imag( z );
By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a begin
index (inclusive).
var imag = require( '@stdlib/complex-float64-imag' );
var real = require( '@stdlib/complex-float64-real' );
var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var subarr = arr.subarray( 1 );
var len = subarr.length;
var z = subarr.get( 0 );
var re = real( z );
var im = imag( z );
By default, the method creates a typed array view which includes all array elements after begin
. To limit the number of array elements after begin
, provide an end
index (exclusive).
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var subarr = arr.subarray( 1, -1 );
var len = subarr.length;
var z = subarr.get( 0 );
var re = real( z );
var im = imag( z );
z = subarr.get( len-1 );
re = real( z );
im = imag( z );
Complex128Array.prototype.toLocaleString( [locales[, options]] )
Serializes an array as a locale-specific string.
var arr = new Complex128Array( 2 );
arr.set( [ 1.0, 1.0 ], 0 );
arr.set( [ 2.0, 2.0 ], 1 );
var str = arr.toLocaleString();
The method supports the following arguments:
- locales: a string with a BCP 47 language tag or an array of such strings.
- options: configuration properties.
Complex128Array.prototype.toReversed()
Returns a new typed array containing the elements in reversed order.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
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.toReversed();
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
z = out.get( 1 );
re = real( z );
im = imag( z );
z = out.get( 2 );
re = real( z );
im = imag( z );
Complex128Array.prototype.toSorted( compareFcn )
Returns a new typed array containing the elements in sorted order.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
function compare( a, b ) {
var re1;
var re2;
var im1;
var im2;
re1 = real( a );
re2 = real( b );
if ( re1 < re2 ) {
return -1;
}
if ( re1 > re2 ) {
return 1;
}
im1 = imag( a );
im2 = imag( b );
if ( im1 < im2 ) {
return -1;
}
if ( im1 > im2 ) {
return 1;
}
return 0;
}
var arr = new Complex128Array( 3 );
arr.set( [ 3.0, -3.0 ], 0 );
arr.set( [ 1.0, -1.0 ], 1 );
arr.set( [ 2.0, -2.0 ], 2 );
var out = arr.toSorted( compare );
var z = out.get( 0 );
var re = real( z );
var im = imag( z );
z = out.get( 1 );
re = real( z );
im = imag( z );
z = out.get( 2 );
re = real( z );
im = imag( z );
The compareFcn
determines the order of the elements. The function is called with the following arguments:
- a: the first element for comparison.
- b: the second element for comparison.
The function should return a number where:
- a negative value indicates that
a
should come before b
. - a positive value indicates that
a
should come after b
. - zero or
NaN
indicates that a
and b
are considered equal.
In contrast to real numbers, one cannot define a default order relation which is compatible with multiplication. Accordingly, users must explicitly provide a compareFcn
argument and are thus responsible for specifying a complex number ordering.
Complex128Array.prototype.toString()
Serializes an array as a string.
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 str = arr.toString();
Complex128Array.prototype.values()
Returns an iterator for iterating over each value in a typed array.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var arr = new Complex128Array( 2 );
arr.set( [ 1.0, -1.0 ], 0 );
arr.set( [ 2.0, -2.0 ], 1 );
var iter = arr.values();
var v = iter.next().value;
var re = real( v );
var im = imag( v );
v = iter.next().value;
re = real( v );
im = imag( v );
var bool = iter.next().done;
The returned iterator protocol-compliant object has the following properties:
- next: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a
value
property and a done
property having a boolean
value indicating whether the iterator is finished. - return: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.
Complex128Array.prototype.with( index, value )
Returns a new typed array with the element at a provided index replaced with a provided value.
var real = require( '@stdlib/complex-float64-real' );
var imag = require( '@stdlib/complex-float64-imag' );
var Complex128 = require( '@stdlib/complex-float64-ctor' );
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 ], 1 );
var out = arr.with( 0, new Complex128( 4.0, 4.0 ) );
var z = out.get( 0 );
var re = real( z );
var im = imag( z );