@stdlib/array-complex64 0.0.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -304
- package/NOTICE +1 -1
- package/README.md +1391 -146
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +920 -29
- package/lib/from_iterator.js +2 -1
- package/lib/from_iterator_map.js +2 -1
- package/lib/main.js +1606 -222
- package/package.json +51 -37
- package/docs/types/test.ts +0 -153
package/lib/main.js
CHANGED
|
@@ -28,21 +28,27 @@ var isCollection = require( '@stdlib/assert-is-collection' );
|
|
|
28
28
|
var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' );
|
|
29
29
|
var isObject = require( '@stdlib/assert-is-object' );
|
|
30
30
|
var isArray = require( '@stdlib/assert-is-array' );
|
|
31
|
+
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
|
|
31
32
|
var isFunction = require( '@stdlib/assert-is-function' );
|
|
32
33
|
var isComplexLike = require( '@stdlib/assert-is-complex-like' );
|
|
33
34
|
var isEven = require( '@stdlib/math-base-assert-is-even' );
|
|
34
35
|
var isInteger = require( '@stdlib/math-base-assert-is-integer' );
|
|
36
|
+
var isComplex64Array = require( '@stdlib/array-base-assert-is-complex64array' );
|
|
37
|
+
var isComplex128Array = require( '@stdlib/array-base-assert-is-complex128array' );
|
|
35
38
|
var hasIteratorSymbolSupport = require( '@stdlib/assert-has-iterator-symbol-support' );
|
|
36
39
|
var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' );
|
|
37
40
|
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
38
41
|
var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );
|
|
39
42
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
40
43
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
44
|
+
var format = require( '@stdlib/string-format' );
|
|
41
45
|
var realf = require( '@stdlib/complex-realf' );
|
|
42
46
|
var imagf = require( '@stdlib/complex-imagf' );
|
|
47
|
+
var floor = require( '@stdlib/math-base-special-floor' );
|
|
43
48
|
var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' );
|
|
44
49
|
var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' );
|
|
45
|
-
var
|
|
50
|
+
var getter = require( '@stdlib/array-base-getter' );
|
|
51
|
+
var accessorGetter = require( '@stdlib/array-base-accessor-getter' );
|
|
46
52
|
var fromIterator = require( './from_iterator.js' );
|
|
47
53
|
var fromIteratorMap = require( './from_iterator_map.js' );
|
|
48
54
|
var fromArray = require( './from_array.js' );
|
|
@@ -98,35 +104,16 @@ function isComplexArrayConstructor( value ) {
|
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
101
|
-
*
|
|
107
|
+
* Retrieves a complex number from a complex number array buffer.
|
|
102
108
|
*
|
|
103
109
|
* @private
|
|
104
|
-
* @param {
|
|
105
|
-
* @
|
|
106
|
-
|
|
107
|
-
function isComplex64Array( value ) {
|
|
108
|
-
return (
|
|
109
|
-
typeof value === 'object' &&
|
|
110
|
-
value !== null &&
|
|
111
|
-
value.constructor.name === 'Complex64Array' &&
|
|
112
|
-
value.BYTES_PER_ELEMENT === BYTES_PER_ELEMENT
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Returns a boolean indicating if a value is a `Complex128Array`.
|
|
118
|
-
*
|
|
119
|
-
* @private
|
|
120
|
-
* @param {*} value - value to test
|
|
121
|
-
* @returns {boolean} boolean indicating if a value is a `Complex128Array`
|
|
110
|
+
* @param {Float32Array} buf - array buffer
|
|
111
|
+
* @param {NonNegativeInteger} idx - element index
|
|
112
|
+
* @returns {Complex64} complex number
|
|
122
113
|
*/
|
|
123
|
-
function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
value !== null &&
|
|
127
|
-
value.constructor.name === 'Complex128Array' &&
|
|
128
|
-
value.BYTES_PER_ELEMENT === BYTES_PER_ELEMENT*2
|
|
129
|
-
);
|
|
114
|
+
function getComplex64( buf, idx ) {
|
|
115
|
+
idx *= 2;
|
|
116
|
+
return new Complex64( buf[ idx ], buf[ idx+1 ] );
|
|
130
117
|
}
|
|
131
118
|
|
|
132
119
|
|
|
@@ -235,7 +222,7 @@ function Complex64Array() {
|
|
|
235
222
|
if ( buf === null ) {
|
|
236
223
|
// We failed and we are now forced to allocate a new array :-(
|
|
237
224
|
if ( !isEven( len ) ) {
|
|
238
|
-
throw new RangeError( 'invalid argument. Array-like object
|
|
225
|
+
throw new RangeError( format( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `%u`.', len ) );
|
|
239
226
|
}
|
|
240
227
|
// We failed, so fall back to directly setting values...
|
|
241
228
|
buf = new Float32Array( arguments[0] );
|
|
@@ -246,27 +233,27 @@ function Complex64Array() {
|
|
|
246
233
|
} else if ( isComplex128Array( buf ) ) {
|
|
247
234
|
buf = reinterpret128( buf, 0 );
|
|
248
235
|
} else if ( !isEven( len ) ) {
|
|
249
|
-
throw new RangeError( 'invalid argument. Array-like object and typed array
|
|
236
|
+
throw new RangeError( format( 'invalid argument. Array-like object and typed array arguments must have a length which is a multiple of two. Length: `%u`.', len ) );
|
|
250
237
|
}
|
|
251
238
|
buf = new Float32Array( buf );
|
|
252
239
|
}
|
|
253
240
|
} else if ( isArrayBuffer( arguments[0] ) ) {
|
|
254
241
|
buf = arguments[ 0 ];
|
|
255
242
|
if ( !isInteger( buf.byteLength/BYTES_PER_ELEMENT ) ) {
|
|
256
|
-
throw new RangeError( 'invalid argument. ArrayBuffer byte length must be a multiple of
|
|
243
|
+
throw new RangeError( format( 'invalid argument. ArrayBuffer byte length must be a multiple of %u. Byte length: `%u`.', BYTES_PER_ELEMENT, buf.byteLength ) );
|
|
257
244
|
}
|
|
258
245
|
buf = new Float32Array( buf );
|
|
259
246
|
} else if ( isObject( arguments[0] ) ) {
|
|
260
247
|
buf = arguments[ 0 ];
|
|
261
248
|
if ( HAS_ITERATOR_SYMBOL === false ) {
|
|
262
|
-
throw new TypeError( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value:
|
|
249
|
+
throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.', buf ) );
|
|
263
250
|
}
|
|
264
251
|
if ( !isFunction( buf[ ITERATOR_SYMBOL ] ) ) {
|
|
265
|
-
throw new TypeError( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value:
|
|
252
|
+
throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) );
|
|
266
253
|
}
|
|
267
254
|
buf = buf[ ITERATOR_SYMBOL ]();
|
|
268
255
|
if ( !isFunction( buf.next ) ) {
|
|
269
|
-
throw new TypeError( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable.' );
|
|
256
|
+
throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); // FIXME: `buf` is what is returned from above, NOT the original value
|
|
270
257
|
}
|
|
271
258
|
buf = fromIterator( buf );
|
|
272
259
|
if ( buf instanceof Error ) {
|
|
@@ -274,33 +261,33 @@ function Complex64Array() {
|
|
|
274
261
|
}
|
|
275
262
|
buf = new Float32Array( buf );
|
|
276
263
|
} else {
|
|
277
|
-
throw new TypeError( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value:
|
|
264
|
+
throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arguments[0] ) );
|
|
278
265
|
}
|
|
279
266
|
} else {
|
|
280
267
|
buf = arguments[ 0 ];
|
|
281
268
|
if ( !isArrayBuffer( buf ) ) {
|
|
282
|
-
throw new TypeError( 'invalid argument. First argument must be an
|
|
269
|
+
throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', buf ) );
|
|
283
270
|
}
|
|
284
271
|
byteOffset = arguments[ 1 ];
|
|
285
272
|
if ( !isNonNegativeInteger( byteOffset ) ) {
|
|
286
|
-
throw new TypeError( 'invalid argument. Byte offset must be a nonnegative integer. Value:
|
|
273
|
+
throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', byteOffset ) );
|
|
287
274
|
}
|
|
288
275
|
if ( !isInteger( byteOffset/BYTES_PER_ELEMENT ) ) {
|
|
289
|
-
throw new RangeError( 'invalid argument. Byte offset must be a multiple of
|
|
276
|
+
throw new RangeError( format( 'invalid argument. Byte offset must be a multiple of %u. Value: `%u`.', BYTES_PER_ELEMENT, byteOffset ) );
|
|
290
277
|
}
|
|
291
278
|
if ( nargs === 2 ) {
|
|
292
279
|
len = buf.byteLength - byteOffset;
|
|
293
280
|
if ( !isInteger( len/BYTES_PER_ELEMENT ) ) {
|
|
294
|
-
throw new RangeError( 'invalid arguments. ArrayBuffer view byte length must be a multiple of
|
|
281
|
+
throw new RangeError( format( 'invalid arguments. ArrayBuffer view byte length must be a multiple of %u. View byte length: `%u`.', BYTES_PER_ELEMENT, len ) );
|
|
295
282
|
}
|
|
296
283
|
buf = new Float32Array( buf, byteOffset );
|
|
297
284
|
} else {
|
|
298
285
|
len = arguments[ 2 ];
|
|
299
286
|
if ( !isNonNegativeInteger( len ) ) {
|
|
300
|
-
throw new TypeError( 'invalid argument. Length must be a nonnegative integer. Value:
|
|
287
|
+
throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', len ) );
|
|
301
288
|
}
|
|
302
289
|
if ( (len*BYTES_PER_ELEMENT) > (buf.byteLength-byteOffset) ) {
|
|
303
|
-
throw new RangeError( 'invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity:
|
|
290
|
+
throw new RangeError( format( 'invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `%u`.', len*BYTES_PER_ELEMENT ) );
|
|
304
291
|
}
|
|
305
292
|
buf = new Float32Array( buf, byteOffset, len*2 );
|
|
306
293
|
}
|
|
@@ -397,6 +384,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
397
384
|
var out;
|
|
398
385
|
var buf;
|
|
399
386
|
var tmp;
|
|
387
|
+
var get;
|
|
400
388
|
var len;
|
|
401
389
|
var flg;
|
|
402
390
|
var v;
|
|
@@ -412,7 +400,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
412
400
|
if ( nargs > 1 ) {
|
|
413
401
|
clbk = arguments[ 1 ];
|
|
414
402
|
if ( !isFunction( clbk ) ) {
|
|
415
|
-
throw new TypeError( 'invalid argument. Second argument must be a function. Value:
|
|
403
|
+
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) );
|
|
416
404
|
}
|
|
417
405
|
if ( nargs > 2 ) {
|
|
418
406
|
thisArg = arguments[ 2 ];
|
|
@@ -433,7 +421,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
433
421
|
buf[ j ] = v[ 0 ];
|
|
434
422
|
buf[ j+1 ] = v[ 1 ];
|
|
435
423
|
} else {
|
|
436
|
-
throw new TypeError( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value:
|
|
424
|
+
throw new TypeError( format( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', v ) );
|
|
437
425
|
}
|
|
438
426
|
j += 2; // stride
|
|
439
427
|
}
|
|
@@ -446,11 +434,14 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
446
434
|
// Note: array contents affect how we iterate over a provided data source. If only complex number objects, we can extract real and imaginary components. Otherwise, for non-complex number arrays (e.g., `Float64Array`, etc), we assume a strided array where real and imaginary components are interleaved. In the former case, we expect a callback to return real and imaginary components (possibly as a complex number). In the latter case, we expect a callback to return *either* a real or imaginary component.
|
|
447
435
|
|
|
448
436
|
len = src.length;
|
|
449
|
-
|
|
450
|
-
|
|
437
|
+
if ( src.get && src.set ) {
|
|
438
|
+
get = accessorGetter( 'default' );
|
|
439
|
+
} else {
|
|
440
|
+
get = getter( 'default' );
|
|
441
|
+
}
|
|
451
442
|
// Detect whether we've been provided an array which returns complex number objects...
|
|
452
443
|
for ( i = 0; i < len; i++ ) {
|
|
453
|
-
if ( !isComplexLike(
|
|
444
|
+
if ( !isComplexLike( get( src, i ) ) ) {
|
|
454
445
|
flg = true;
|
|
455
446
|
break;
|
|
456
447
|
}
|
|
@@ -458,12 +449,12 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
458
449
|
// If an array does not contain only complex number objects, then we assume interleaved real and imaginary components...
|
|
459
450
|
if ( flg ) {
|
|
460
451
|
if ( !isEven( len ) ) {
|
|
461
|
-
throw new RangeError( 'invalid argument. First argument must have a length which is a multiple of
|
|
452
|
+
throw new RangeError( format( 'invalid argument. First argument must have a length which is a multiple of %u. Length: `%u`.', 2, len ) );
|
|
462
453
|
}
|
|
463
454
|
out = new this( len/2 );
|
|
464
455
|
buf = out._buffer; // eslint-disable-line no-underscore-dangle
|
|
465
456
|
for ( i = 0; i < len; i++ ) {
|
|
466
|
-
buf[ i ] = clbk.call( thisArg,
|
|
457
|
+
buf[ i ] = clbk.call( thisArg, get( src, i ), i );
|
|
467
458
|
}
|
|
468
459
|
return out;
|
|
469
460
|
}
|
|
@@ -472,7 +463,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
472
463
|
buf = out._buffer; // eslint-disable-line no-underscore-dangle
|
|
473
464
|
j = 0;
|
|
474
465
|
for ( i = 0; i < len; i++ ) {
|
|
475
|
-
v = clbk.call( thisArg,
|
|
466
|
+
v = clbk.call( thisArg, get( src, i ), i );
|
|
476
467
|
if ( isComplexLike( v ) ) {
|
|
477
468
|
buf[ j ] = realf( v );
|
|
478
469
|
buf[ j+1 ] = imagf( v );
|
|
@@ -480,7 +471,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
480
471
|
buf[ j ] = v[ 0 ];
|
|
481
472
|
buf[ j+1 ] = v[ 1 ];
|
|
482
473
|
} else {
|
|
483
|
-
throw new TypeError( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value:
|
|
474
|
+
throw new TypeError( format( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', v ) );
|
|
484
475
|
}
|
|
485
476
|
j += 2; // stride
|
|
486
477
|
}
|
|
@@ -491,7 +482,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
491
482
|
if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len
|
|
492
483
|
buf = src[ ITERATOR_SYMBOL ]();
|
|
493
484
|
if ( !isFunction( buf.next ) ) {
|
|
494
|
-
throw new TypeError( 'invalid argument. First argument must be an array-like object or an iterable.' );
|
|
485
|
+
throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) );
|
|
495
486
|
}
|
|
496
487
|
if ( clbk ) {
|
|
497
488
|
tmp = fromIteratorMap( buf, clbk, thisArg );
|
|
@@ -509,7 +500,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) {
|
|
|
509
500
|
}
|
|
510
501
|
return out;
|
|
511
502
|
}
|
|
512
|
-
throw new TypeError( 'invalid argument. First argument must be an array-like object or an iterable. Value:
|
|
503
|
+
throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) );
|
|
513
504
|
});
|
|
514
505
|
|
|
515
506
|
/**
|
|
@@ -546,6 +537,75 @@ setReadOnly( Complex64Array, 'of', function of() {
|
|
|
546
537
|
return new this( args );
|
|
547
538
|
});
|
|
548
539
|
|
|
540
|
+
/**
|
|
541
|
+
* Returns an array element with support for both nonnegative and negative integer indices.
|
|
542
|
+
*
|
|
543
|
+
* @name at
|
|
544
|
+
* @memberof Complex64Array.prototype
|
|
545
|
+
* @type {Function}
|
|
546
|
+
* @param {integer} idx - element index
|
|
547
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
548
|
+
* @throws {TypeError} must provide an integer
|
|
549
|
+
* @returns {(Complex64|void)} array element
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* var arr = new Complex64Array( 10 );
|
|
553
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
554
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
555
|
+
*
|
|
556
|
+
* var z = arr.at( 0 );
|
|
557
|
+
* // returns <Complex64>
|
|
558
|
+
*
|
|
559
|
+
* var re = realf( z );
|
|
560
|
+
* // returns 0.0
|
|
561
|
+
*
|
|
562
|
+
* var im = imagf( z );
|
|
563
|
+
* // returns 0.0
|
|
564
|
+
*
|
|
565
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
566
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
567
|
+
* arr.set( [ 9.0, -9.0 ], 9 );
|
|
568
|
+
*
|
|
569
|
+
* z = arr.at( 0 );
|
|
570
|
+
* // returns <Complex64>
|
|
571
|
+
*
|
|
572
|
+
* re = realf( z );
|
|
573
|
+
* // returns 1.0
|
|
574
|
+
*
|
|
575
|
+
* im = imagf( z );
|
|
576
|
+
* // returns -1.0
|
|
577
|
+
*
|
|
578
|
+
* z = arr.at( -1 );
|
|
579
|
+
* // returns <Complex64>
|
|
580
|
+
*
|
|
581
|
+
* re = realf( z );
|
|
582
|
+
* // returns 9.0
|
|
583
|
+
*
|
|
584
|
+
* im = imagf( z );
|
|
585
|
+
* // returns -9.0
|
|
586
|
+
*
|
|
587
|
+
* z = arr.at( 100 );
|
|
588
|
+
* // returns undefined
|
|
589
|
+
*
|
|
590
|
+
* z = arr.at( -100 );
|
|
591
|
+
* // returns undefined
|
|
592
|
+
*/
|
|
593
|
+
setReadOnly( Complex64Array.prototype, 'at', function at( idx ) {
|
|
594
|
+
if ( !isComplexArray( this ) ) {
|
|
595
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
596
|
+
}
|
|
597
|
+
if ( !isInteger( idx ) ) {
|
|
598
|
+
throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) );
|
|
599
|
+
}
|
|
600
|
+
if ( idx < 0 ) {
|
|
601
|
+
idx += this._length;
|
|
602
|
+
}
|
|
603
|
+
if ( idx < 0 || idx >= this._length ) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
return getComplex64( this._buffer, idx );
|
|
607
|
+
});
|
|
608
|
+
|
|
549
609
|
/**
|
|
550
610
|
* Pointer to the underlying data buffer.
|
|
551
611
|
*
|
|
@@ -785,183 +845,1038 @@ setReadOnly( Complex64Array.prototype, 'entries', function entries() {
|
|
|
785
845
|
});
|
|
786
846
|
|
|
787
847
|
/**
|
|
788
|
-
*
|
|
848
|
+
* Tests whether all elements in an array pass a test implemented by a predicate function.
|
|
789
849
|
*
|
|
790
|
-
* @name
|
|
850
|
+
* @name every
|
|
791
851
|
* @memberof Complex64Array.prototype
|
|
792
852
|
* @type {Function}
|
|
793
|
-
* @param {
|
|
853
|
+
* @param {Function} predicate - test function
|
|
854
|
+
* @param {*} [thisArg] - predicate function execution context
|
|
794
855
|
* @throws {TypeError} `this` must be a complex number array
|
|
795
|
-
* @throws {TypeError} must
|
|
796
|
-
* @returns {
|
|
856
|
+
* @throws {TypeError} first argument must be a function
|
|
857
|
+
* @returns {boolean} boolean indicating whether all elements pass a test
|
|
797
858
|
*
|
|
798
859
|
* @example
|
|
799
|
-
* var arr = new Complex64Array( 10 );
|
|
800
860
|
* var realf = require( '@stdlib/complex-realf' );
|
|
801
861
|
* var imagf = require( '@stdlib/complex-imagf' );
|
|
802
862
|
*
|
|
803
|
-
*
|
|
863
|
+
* function predicate( v ) {
|
|
864
|
+
* return ( realf( v ) === imagf( v ) );
|
|
865
|
+
* }
|
|
866
|
+
*
|
|
867
|
+
* var arr = new Complex64Array( 3 );
|
|
868
|
+
*
|
|
869
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
870
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
871
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
872
|
+
*
|
|
873
|
+
* var bool = arr.every( predicate );
|
|
874
|
+
* // returns true
|
|
875
|
+
*/
|
|
876
|
+
setReadOnly( Complex64Array.prototype, 'every', function every( predicate, thisArg ) {
|
|
877
|
+
var buf;
|
|
878
|
+
var i;
|
|
879
|
+
if ( !isComplexArray( this ) ) {
|
|
880
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
881
|
+
}
|
|
882
|
+
if ( !isFunction( predicate ) ) {
|
|
883
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
|
|
884
|
+
}
|
|
885
|
+
buf = this._buffer;
|
|
886
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
887
|
+
if ( !predicate.call( thisArg, getComplex64( buf, i ), i, this ) ) {
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
return true;
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Returns a modified typed array filled with a fill value.
|
|
896
|
+
*
|
|
897
|
+
* @name fill
|
|
898
|
+
* @memberof Complex64Array.prototype
|
|
899
|
+
* @type {Function}
|
|
900
|
+
* @param {ComplexLike} value - fill value
|
|
901
|
+
* @param {integer} [start=0] - starting index (inclusive)
|
|
902
|
+
* @param {integer} [end] - ending index (exclusive)
|
|
903
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
904
|
+
* @throws {TypeError} first argument must be a complex number
|
|
905
|
+
* @throws {TypeError} second argument must be an integer
|
|
906
|
+
* @throws {TypeError} third argument must be an integer
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
910
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
911
|
+
*
|
|
912
|
+
* var arr = new Complex64Array( 3 );
|
|
913
|
+
*
|
|
914
|
+
* arr.fill( new Complex64( 1.0, 1.0 ), 1 );
|
|
915
|
+
*
|
|
916
|
+
* var z = arr.get( 1 );
|
|
804
917
|
* // returns <Complex64>
|
|
805
918
|
*
|
|
806
919
|
* var re = realf( z );
|
|
807
|
-
* // returns
|
|
920
|
+
* // returns 1.0
|
|
808
921
|
*
|
|
809
922
|
* var im = imagf( z );
|
|
810
|
-
* // returns
|
|
811
|
-
*
|
|
812
|
-
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
923
|
+
* // returns 1.0
|
|
813
924
|
*
|
|
814
|
-
* z = arr.get(
|
|
925
|
+
* z = arr.get( 1 );
|
|
815
926
|
* // returns <Complex64>
|
|
816
927
|
*
|
|
817
928
|
* re = realf( z );
|
|
818
929
|
* // returns 1.0
|
|
819
930
|
*
|
|
820
931
|
* im = imagf( z );
|
|
821
|
-
* // returns
|
|
822
|
-
*
|
|
823
|
-
* z = arr.get( 100 );
|
|
824
|
-
* // returns undefined
|
|
932
|
+
* // returns 1.0
|
|
825
933
|
*/
|
|
826
|
-
setReadOnly( Complex64Array.prototype, '
|
|
934
|
+
setReadOnly( Complex64Array.prototype, 'fill', function fill( value, start, end ) {
|
|
827
935
|
var buf;
|
|
936
|
+
var len;
|
|
937
|
+
var idx;
|
|
938
|
+
var re;
|
|
939
|
+
var im;
|
|
940
|
+
var i;
|
|
828
941
|
if ( !isComplexArray( this ) ) {
|
|
829
942
|
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
830
943
|
}
|
|
831
|
-
if ( !
|
|
832
|
-
throw new TypeError( 'invalid argument.
|
|
833
|
-
}
|
|
834
|
-
if ( idx >= this._length ) {
|
|
835
|
-
return;
|
|
944
|
+
if ( !isComplexLike( value ) ) {
|
|
945
|
+
throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', value ) );
|
|
836
946
|
}
|
|
837
947
|
buf = this._buffer;
|
|
838
|
-
|
|
839
|
-
|
|
948
|
+
len = this._length;
|
|
949
|
+
if ( arguments.length > 1 ) {
|
|
950
|
+
if ( !isInteger( start ) ) {
|
|
951
|
+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', start ) );
|
|
952
|
+
}
|
|
953
|
+
if ( start < 0 ) {
|
|
954
|
+
start += len;
|
|
955
|
+
if ( start < 0 ) {
|
|
956
|
+
start = 0;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
if ( arguments.length > 2 ) {
|
|
960
|
+
if ( !isInteger( end ) ) {
|
|
961
|
+
throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', end ) );
|
|
962
|
+
}
|
|
963
|
+
if ( end < 0 ) {
|
|
964
|
+
end += len;
|
|
965
|
+
if ( end < 0 ) {
|
|
966
|
+
end = 0;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if ( end > len ) {
|
|
970
|
+
end = len;
|
|
971
|
+
}
|
|
972
|
+
} else {
|
|
973
|
+
end = len;
|
|
974
|
+
}
|
|
975
|
+
} else {
|
|
976
|
+
start = 0;
|
|
977
|
+
end = len;
|
|
978
|
+
}
|
|
979
|
+
re = realf( value );
|
|
980
|
+
im = imagf( value );
|
|
981
|
+
for ( i = start; i < end; i++ ) {
|
|
982
|
+
idx = 2*i;
|
|
983
|
+
buf[ idx ] = re;
|
|
984
|
+
buf[ idx+1 ] = im;
|
|
985
|
+
}
|
|
986
|
+
return this;
|
|
840
987
|
});
|
|
841
988
|
|
|
842
989
|
/**
|
|
843
|
-
*
|
|
990
|
+
* Returns a new array containing the elements of an array which pass a test implemented by a predicate function.
|
|
844
991
|
*
|
|
845
|
-
* @name
|
|
992
|
+
* @name filter
|
|
846
993
|
* @memberof Complex64Array.prototype
|
|
847
|
-
* @
|
|
848
|
-
* @
|
|
994
|
+
* @type {Function}
|
|
995
|
+
* @param {Function} predicate - test function
|
|
996
|
+
* @param {*} [thisArg] - predicate function execution context
|
|
997
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
998
|
+
* @throws {TypeError} first argument must be a function
|
|
999
|
+
* @returns {Complex64Array} complex number array
|
|
849
1000
|
*
|
|
850
1001
|
* @example
|
|
851
|
-
* var
|
|
852
|
-
*
|
|
853
|
-
* var len = arr.length;
|
|
854
|
-
* // returns 10
|
|
855
|
-
*/
|
|
856
|
-
setReadOnlyAccessor( Complex64Array.prototype, 'length', function get() {
|
|
857
|
-
return this._length;
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* Sets an array element.
|
|
1002
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1003
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
862
1004
|
*
|
|
863
|
-
*
|
|
1005
|
+
* function predicate( v ) {
|
|
1006
|
+
* return ( realf( v ) === imagf( v ) );
|
|
1007
|
+
* }
|
|
864
1008
|
*
|
|
865
|
-
*
|
|
1009
|
+
* var arr = new Complex64Array( 3 );
|
|
866
1010
|
*
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
* ```
|
|
1011
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1012
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1013
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
871
1014
|
*
|
|
872
|
-
*
|
|
1015
|
+
* var out = arr.filter( predicate );
|
|
1016
|
+
* // returns <Complex64Array>
|
|
873
1017
|
*
|
|
874
|
-
*
|
|
1018
|
+
* var len = out.length;
|
|
1019
|
+
* // returns 1
|
|
875
1020
|
*
|
|
876
|
-
*
|
|
877
|
-
*
|
|
878
|
-
* src: ---------------------
|
|
879
|
-
* ```
|
|
1021
|
+
* var z = out.get( 0 );
|
|
1022
|
+
* // returns <Complex64>
|
|
880
1023
|
*
|
|
881
|
-
*
|
|
1024
|
+
* var re = realf( z );
|
|
1025
|
+
* // returns 2.0
|
|
882
1026
|
*
|
|
1027
|
+
* var im = imagf( z );
|
|
1028
|
+
* // returns 2.0
|
|
1029
|
+
*/
|
|
1030
|
+
setReadOnly( Complex64Array.prototype, 'filter', function filter( predicate, thisArg ) {
|
|
1031
|
+
var buf;
|
|
1032
|
+
var out;
|
|
1033
|
+
var i;
|
|
1034
|
+
var z;
|
|
1035
|
+
if ( !isComplexArray( this ) ) {
|
|
1036
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1037
|
+
}
|
|
1038
|
+
if ( !isFunction( predicate ) ) {
|
|
1039
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
|
|
1040
|
+
}
|
|
1041
|
+
buf = this._buffer;
|
|
1042
|
+
out = [];
|
|
1043
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
1044
|
+
z = getComplex64( buf, i );
|
|
1045
|
+
if ( predicate.call( thisArg, z, i, this ) ) {
|
|
1046
|
+
out.push( z );
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return new this.constructor( out );
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Returns the first element in an array for which a predicate function returns a truthy value.
|
|
883
1054
|
*
|
|
884
|
-
* @name
|
|
1055
|
+
* @name find
|
|
885
1056
|
* @memberof Complex64Array.prototype
|
|
886
1057
|
* @type {Function}
|
|
887
|
-
* @param {
|
|
888
|
-
* @param {
|
|
1058
|
+
* @param {Function} predicate - test function
|
|
1059
|
+
* @param {*} [thisArg] - predicate function execution context
|
|
889
1060
|
* @throws {TypeError} `this` must be a complex number array
|
|
890
|
-
* @throws {TypeError} first argument must be
|
|
891
|
-
* @
|
|
892
|
-
* @throws {RangeError} array-like objects must have a length which is a multiple of two
|
|
893
|
-
* @throws {RangeError} index argument is out-of-bounds
|
|
894
|
-
* @throws {RangeError} target array lacks sufficient storage to accommodate source values
|
|
895
|
-
* @returns {void}
|
|
1061
|
+
* @throws {TypeError} first argument must be a function
|
|
1062
|
+
* @returns {(Complex64|void)} array element or undefined
|
|
896
1063
|
*
|
|
897
1064
|
* @example
|
|
898
1065
|
* var realf = require( '@stdlib/complex-realf' );
|
|
899
1066
|
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1067
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
900
1068
|
*
|
|
901
|
-
*
|
|
902
|
-
*
|
|
903
|
-
*
|
|
904
|
-
* // returns <Complex64>
|
|
905
|
-
*
|
|
906
|
-
* var re = realf( z );
|
|
907
|
-
* // returns 0.0
|
|
1069
|
+
* function predicate( v ) {
|
|
1070
|
+
* return ( realf( v ) === imagf( v ) );
|
|
1071
|
+
* }
|
|
908
1072
|
*
|
|
909
|
-
* var
|
|
910
|
-
* // returns 0.0
|
|
1073
|
+
* var arr = new Complex64Array( 3 );
|
|
911
1074
|
*
|
|
912
|
-
* arr.set( [ 1.0,
|
|
1075
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
1076
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1077
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
913
1078
|
*
|
|
914
|
-
* z = arr.
|
|
1079
|
+
* var z = arr.find( predicate );
|
|
915
1080
|
* // returns <Complex64>
|
|
916
1081
|
*
|
|
917
|
-
* re = realf( z );
|
|
1082
|
+
* var re = realf( z );
|
|
918
1083
|
* // returns 1.0
|
|
919
1084
|
*
|
|
920
|
-
* im = imagf( z );
|
|
921
|
-
* // returns
|
|
1085
|
+
* var im = imagf( z );
|
|
1086
|
+
* // returns 1.0
|
|
922
1087
|
*/
|
|
923
|
-
setReadOnly( Complex64Array.prototype, '
|
|
924
|
-
/* eslint-disable no-underscore-dangle */
|
|
925
|
-
var sbuf;
|
|
926
|
-
var idx;
|
|
1088
|
+
setReadOnly( Complex64Array.prototype, 'find', function find( predicate, thisArg ) {
|
|
927
1089
|
var buf;
|
|
928
|
-
var tmp;
|
|
929
|
-
var flg;
|
|
930
|
-
var N;
|
|
931
|
-
var v;
|
|
932
1090
|
var i;
|
|
933
|
-
var
|
|
1091
|
+
var z;
|
|
934
1092
|
if ( !isComplexArray( this ) ) {
|
|
935
1093
|
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
936
1094
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
idx = arguments[ 1 ];
|
|
940
|
-
if ( !isNonNegativeInteger( idx ) ) {
|
|
941
|
-
throw new TypeError( 'invalid argument. Index argument must be a nonnegative integer. Value: `'+idx+'`.' );
|
|
942
|
-
}
|
|
943
|
-
} else {
|
|
944
|
-
idx = 0;
|
|
1095
|
+
if ( !isFunction( predicate ) ) {
|
|
1096
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
|
|
945
1097
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1098
|
+
buf = this._buffer;
|
|
1099
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
1100
|
+
z = getComplex64( buf, i );
|
|
1101
|
+
if ( predicate.call( thisArg, z, i, this ) ) {
|
|
1102
|
+
return z;
|
|
949
1103
|
}
|
|
950
|
-
idx *= 2;
|
|
951
|
-
buf[ idx ] = realf( value );
|
|
952
|
-
buf[ idx+1 ] = imagf( value );
|
|
953
|
-
return;
|
|
954
1104
|
}
|
|
955
|
-
|
|
956
|
-
N = value._length;
|
|
957
|
-
if ( idx+N > this._length ) {
|
|
958
|
-
throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
|
|
959
|
-
}
|
|
960
|
-
sbuf = value._buffer;
|
|
1105
|
+
});
|
|
961
1106
|
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1107
|
+
/**
|
|
1108
|
+
* Returns the index of the first element in an array for which a predicate function returns a truthy value.
|
|
1109
|
+
*
|
|
1110
|
+
* @name findIndex
|
|
1111
|
+
* @memberof Complex64Array.prototype
|
|
1112
|
+
* @type {Function}
|
|
1113
|
+
* @param {Function} predicate - test function
|
|
1114
|
+
* @param {*} [thisArg] - predicate function execution context
|
|
1115
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1116
|
+
* @throws {TypeError} first argument must be a function
|
|
1117
|
+
* @returns {integer} index or -1
|
|
1118
|
+
*
|
|
1119
|
+
* @example
|
|
1120
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1121
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1122
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1123
|
+
*
|
|
1124
|
+
* function predicate( v ) {
|
|
1125
|
+
* return ( realf( v ) === imagf( v ) );
|
|
1126
|
+
* }
|
|
1127
|
+
*
|
|
1128
|
+
* var arr = new Complex64Array( 3 );
|
|
1129
|
+
*
|
|
1130
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1131
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
1132
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
1133
|
+
*
|
|
1134
|
+
* var idx = arr.findIndex( predicate );
|
|
1135
|
+
* // returns 2
|
|
1136
|
+
*/
|
|
1137
|
+
setReadOnly( Complex64Array.prototype, 'findIndex', function findIndex( predicate, thisArg ) {
|
|
1138
|
+
var buf;
|
|
1139
|
+
var i;
|
|
1140
|
+
var z;
|
|
1141
|
+
if ( !isComplexArray( this ) ) {
|
|
1142
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1143
|
+
}
|
|
1144
|
+
if ( !isFunction( predicate ) ) {
|
|
1145
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
|
|
1146
|
+
}
|
|
1147
|
+
buf = this._buffer;
|
|
1148
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
1149
|
+
z = getComplex64( buf, i );
|
|
1150
|
+
if ( predicate.call( thisArg, z, i, this ) ) {
|
|
1151
|
+
return i;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return -1;
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Returns the last element in an array for which a predicate function returns a truthy value.
|
|
1159
|
+
*
|
|
1160
|
+
* @name findLast
|
|
1161
|
+
* @memberof Complex64Array.prototype
|
|
1162
|
+
* @type {Function}
|
|
1163
|
+
* @param {Function} predicate - test function
|
|
1164
|
+
* @param {*} [thisArg] - predicate function execution context
|
|
1165
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1166
|
+
* @throws {TypeError} first argument must be a function
|
|
1167
|
+
* @returns {(Complex64|void)} array element or undefined
|
|
1168
|
+
*
|
|
1169
|
+
* @example
|
|
1170
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1171
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1172
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1173
|
+
*
|
|
1174
|
+
* function predicate( v ) {
|
|
1175
|
+
* return ( realf( v ) === imagf( v ) );
|
|
1176
|
+
* }
|
|
1177
|
+
*
|
|
1178
|
+
* var arr = new Complex64Array( 3 );
|
|
1179
|
+
*
|
|
1180
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
1181
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1182
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
1183
|
+
*
|
|
1184
|
+
* var z = arr.findLast( predicate );
|
|
1185
|
+
* // returns <Complex64>
|
|
1186
|
+
*
|
|
1187
|
+
* var re = realf( z );
|
|
1188
|
+
* // returns 3.0
|
|
1189
|
+
*
|
|
1190
|
+
* var im = imagf( z );
|
|
1191
|
+
* // returns 3.0
|
|
1192
|
+
*/
|
|
1193
|
+
setReadOnly( Complex64Array.prototype, 'findLast', function findLast( predicate, thisArg ) {
|
|
1194
|
+
var buf;
|
|
1195
|
+
var i;
|
|
1196
|
+
var z;
|
|
1197
|
+
if ( !isComplexArray( this ) ) {
|
|
1198
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1199
|
+
}
|
|
1200
|
+
if ( !isFunction( predicate ) ) {
|
|
1201
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
|
|
1202
|
+
}
|
|
1203
|
+
buf = this._buffer;
|
|
1204
|
+
for ( i = this._length-1; i >= 0; i-- ) {
|
|
1205
|
+
z = getComplex64( buf, i );
|
|
1206
|
+
if ( predicate.call( thisArg, z, i, this ) ) {
|
|
1207
|
+
return z;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Returns the index of the last element in an array for which a predicate function returns a truthy value.
|
|
1214
|
+
*
|
|
1215
|
+
* @name findLastIndex
|
|
1216
|
+
* @memberof Complex64Array.prototype
|
|
1217
|
+
* @type {Function}
|
|
1218
|
+
* @param {Function} predicate - test function
|
|
1219
|
+
* @param {*} [thisArg] - predicate function execution context
|
|
1220
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1221
|
+
* @throws {TypeError} first argument must be a function
|
|
1222
|
+
* @returns {integer} index or -1
|
|
1223
|
+
*
|
|
1224
|
+
* @example
|
|
1225
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1226
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1227
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1228
|
+
*
|
|
1229
|
+
* function predicate( v ) {
|
|
1230
|
+
* return ( realf( v ) === imagf( v ) );
|
|
1231
|
+
* }
|
|
1232
|
+
*
|
|
1233
|
+
* var arr = new Complex64Array( 3 );
|
|
1234
|
+
*
|
|
1235
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
1236
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1237
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
1238
|
+
*
|
|
1239
|
+
* var idx = arr.findLastIndex( predicate );
|
|
1240
|
+
* // returns 1
|
|
1241
|
+
*/
|
|
1242
|
+
setReadOnly( Complex64Array.prototype, 'findLastIndex', function findLastIndex( predicate, thisArg ) {
|
|
1243
|
+
var buf;
|
|
1244
|
+
var i;
|
|
1245
|
+
var z;
|
|
1246
|
+
if ( !isComplexArray( this ) ) {
|
|
1247
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1248
|
+
}
|
|
1249
|
+
if ( !isFunction( predicate ) ) {
|
|
1250
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
|
|
1251
|
+
}
|
|
1252
|
+
buf = this._buffer;
|
|
1253
|
+
for ( i = this._length-1; i >= 0; i-- ) {
|
|
1254
|
+
z = getComplex64( buf, i );
|
|
1255
|
+
if ( predicate.call( thisArg, z, i, this ) ) {
|
|
1256
|
+
return i;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
return -1;
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* Invokes a function once for each array element.
|
|
1264
|
+
*
|
|
1265
|
+
* @name forEach
|
|
1266
|
+
* @memberof Complex64Array.prototype
|
|
1267
|
+
* @type {Function}
|
|
1268
|
+
* @param {Function} fcn - function to invoke
|
|
1269
|
+
* @param {*} [thisArg] - function invocation context
|
|
1270
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1271
|
+
* @throws {TypeError} first argument must be a function
|
|
1272
|
+
*
|
|
1273
|
+
* @example
|
|
1274
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1275
|
+
*
|
|
1276
|
+
* function log( v, i ) {
|
|
1277
|
+
* console.log( '%s: %s', i, v.toString() );
|
|
1278
|
+
* }
|
|
1279
|
+
*
|
|
1280
|
+
* var arr = new Complex64Array( 3 );
|
|
1281
|
+
*
|
|
1282
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
1283
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1284
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
1285
|
+
*
|
|
1286
|
+
* arr.forEach( log );
|
|
1287
|
+
*/
|
|
1288
|
+
setReadOnly( Complex64Array.prototype, 'forEach', function forEach( fcn, thisArg ) {
|
|
1289
|
+
var buf;
|
|
1290
|
+
var i;
|
|
1291
|
+
var z;
|
|
1292
|
+
if ( !isComplexArray( this ) ) {
|
|
1293
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1294
|
+
}
|
|
1295
|
+
if ( !isFunction( fcn ) ) {
|
|
1296
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );
|
|
1297
|
+
}
|
|
1298
|
+
buf = this._buffer;
|
|
1299
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
1300
|
+
z = getComplex64( buf, i );
|
|
1301
|
+
fcn.call( thisArg, z, i, this );
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1305
|
+
/**
|
|
1306
|
+
* Returns an array element.
|
|
1307
|
+
*
|
|
1308
|
+
* @name get
|
|
1309
|
+
* @memberof Complex64Array.prototype
|
|
1310
|
+
* @type {Function}
|
|
1311
|
+
* @param {NonNegativeInteger} idx - element index
|
|
1312
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1313
|
+
* @throws {TypeError} must provide a nonnegative integer
|
|
1314
|
+
* @returns {(Complex64|void)} array element
|
|
1315
|
+
*
|
|
1316
|
+
* @example
|
|
1317
|
+
* var arr = new Complex64Array( 10 );
|
|
1318
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1319
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1320
|
+
*
|
|
1321
|
+
* var z = arr.get( 0 );
|
|
1322
|
+
* // returns <Complex64>
|
|
1323
|
+
*
|
|
1324
|
+
* var re = realf( z );
|
|
1325
|
+
* // returns 0.0
|
|
1326
|
+
*
|
|
1327
|
+
* var im = imagf( z );
|
|
1328
|
+
* // returns 0.0
|
|
1329
|
+
*
|
|
1330
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1331
|
+
*
|
|
1332
|
+
* z = arr.get( 0 );
|
|
1333
|
+
* // returns <Complex64>
|
|
1334
|
+
*
|
|
1335
|
+
* re = realf( z );
|
|
1336
|
+
* // returns 1.0
|
|
1337
|
+
*
|
|
1338
|
+
* im = imagf( z );
|
|
1339
|
+
* // returns -1.0
|
|
1340
|
+
*
|
|
1341
|
+
* z = arr.get( 100 );
|
|
1342
|
+
* // returns undefined
|
|
1343
|
+
*/
|
|
1344
|
+
setReadOnly( Complex64Array.prototype, 'get', function get( idx ) {
|
|
1345
|
+
if ( !isComplexArray( this ) ) {
|
|
1346
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1347
|
+
}
|
|
1348
|
+
if ( !isNonNegativeInteger( idx ) ) {
|
|
1349
|
+
throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) );
|
|
1350
|
+
}
|
|
1351
|
+
if ( idx >= this._length ) {
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
return getComplex64( this._buffer, idx );
|
|
1355
|
+
});
|
|
1356
|
+
|
|
1357
|
+
/**
|
|
1358
|
+
* Returns a boolean indicating whether an array includes a provided value.
|
|
1359
|
+
*
|
|
1360
|
+
* @name includes
|
|
1361
|
+
* @memberof Complex64Array.prototype
|
|
1362
|
+
* @type {Function}
|
|
1363
|
+
* @param {ComplexLike} searchElement - search element
|
|
1364
|
+
* @param {integer} [fromIndex=0] - starting index (inclusive)
|
|
1365
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1366
|
+
* @throws {TypeError} first argument must be a complex number
|
|
1367
|
+
* @throws {TypeError} second argument must be an integer
|
|
1368
|
+
* @returns {boolean} boolean indicating whether an array includes a provided value
|
|
1369
|
+
*
|
|
1370
|
+
* @example
|
|
1371
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1372
|
+
*
|
|
1373
|
+
* var arr = new Complex64Array( 5 );
|
|
1374
|
+
*
|
|
1375
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1376
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
1377
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
1378
|
+
* arr.set( [ 4.0, -4.0 ], 3 );
|
|
1379
|
+
* arr.set( [ 5.0, -5.0 ], 4 );
|
|
1380
|
+
*
|
|
1381
|
+
* var bool = arr.includes( new Complex64( 3.0, -3.0 ) );
|
|
1382
|
+
* // returns true
|
|
1383
|
+
*
|
|
1384
|
+
* bool = arr.includes( new Complex64( 3.0, -3.0 ), 3 );
|
|
1385
|
+
* // returns false
|
|
1386
|
+
*
|
|
1387
|
+
* bool = arr.includes( new Complex64( 4.0, -4.0 ), -3 );
|
|
1388
|
+
* // returns true
|
|
1389
|
+
*/
|
|
1390
|
+
setReadOnly( Complex64Array.prototype, 'includes', function includes( searchElement, fromIndex ) {
|
|
1391
|
+
var buf;
|
|
1392
|
+
var idx;
|
|
1393
|
+
var re;
|
|
1394
|
+
var im;
|
|
1395
|
+
var i;
|
|
1396
|
+
if ( !isComplexArray( this ) ) {
|
|
1397
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1398
|
+
}
|
|
1399
|
+
if ( !isComplexLike( searchElement ) ) {
|
|
1400
|
+
throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) );
|
|
1401
|
+
}
|
|
1402
|
+
if ( arguments.length > 1 ) {
|
|
1403
|
+
if ( !isInteger( fromIndex ) ) {
|
|
1404
|
+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
|
|
1405
|
+
}
|
|
1406
|
+
if ( fromIndex < 0 ) {
|
|
1407
|
+
fromIndex += this._length;
|
|
1408
|
+
if ( fromIndex < 0 ) {
|
|
1409
|
+
fromIndex = 0;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
} else {
|
|
1413
|
+
fromIndex = 0;
|
|
1414
|
+
}
|
|
1415
|
+
re = realf( searchElement );
|
|
1416
|
+
im = imagf( searchElement );
|
|
1417
|
+
buf = this._buffer;
|
|
1418
|
+
for ( i = fromIndex; i < this._length; i++ ) {
|
|
1419
|
+
idx = 2 * i;
|
|
1420
|
+
if ( re === buf[ idx ] && im === buf[ idx+1 ] ) {
|
|
1421
|
+
return true;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
return false;
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Returns the first index at which a given element can be found.
|
|
1429
|
+
*
|
|
1430
|
+
* @name indexOf
|
|
1431
|
+
* @memberof Complex64Array.prototype
|
|
1432
|
+
* @type {Function}
|
|
1433
|
+
* @param {ComplexLike} searchElement - element to find
|
|
1434
|
+
* @param {integer} [fromIndex=0] - starting index (inclusive)
|
|
1435
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1436
|
+
* @throws {TypeError} first argument must be a complex number
|
|
1437
|
+
* @throws {TypeError} second argument must be an integer
|
|
1438
|
+
* @returns {integer} index or -1
|
|
1439
|
+
*
|
|
1440
|
+
* @example
|
|
1441
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1442
|
+
*
|
|
1443
|
+
* var arr = new Complex64Array( 10 );
|
|
1444
|
+
*
|
|
1445
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1446
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
1447
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
1448
|
+
* arr.set( [ 4.0, -4.0 ], 3 );
|
|
1449
|
+
* arr.set( [ 5.0, -5.0 ], 4 );
|
|
1450
|
+
*
|
|
1451
|
+
* var idx = arr.indexOf( new Complex64( 3.0, -3.0 ) );
|
|
1452
|
+
* // returns 2
|
|
1453
|
+
*
|
|
1454
|
+
* idx = arr.indexOf( new Complex64( 3.0, -3.0 ), 3 );
|
|
1455
|
+
* // returns -1
|
|
1456
|
+
*
|
|
1457
|
+
* idx = arr.indexOf( new Complex64( 4.0, -4.0 ), -3 );
|
|
1458
|
+
* // returns -1
|
|
1459
|
+
*/
|
|
1460
|
+
setReadOnly( Complex64Array.prototype, 'indexOf', function indexOf( searchElement, fromIndex ) {
|
|
1461
|
+
var buf;
|
|
1462
|
+
var idx;
|
|
1463
|
+
var re;
|
|
1464
|
+
var im;
|
|
1465
|
+
var i;
|
|
1466
|
+
if ( !isComplexArray( this ) ) {
|
|
1467
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1468
|
+
}
|
|
1469
|
+
if ( !isComplexLike( searchElement ) ) {
|
|
1470
|
+
throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) );
|
|
1471
|
+
}
|
|
1472
|
+
if ( arguments.length > 1 ) {
|
|
1473
|
+
if ( !isInteger( fromIndex ) ) {
|
|
1474
|
+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
|
|
1475
|
+
}
|
|
1476
|
+
if ( fromIndex < 0 ) {
|
|
1477
|
+
fromIndex += this._length;
|
|
1478
|
+
if ( fromIndex < 0 ) {
|
|
1479
|
+
fromIndex = 0;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
} else {
|
|
1483
|
+
fromIndex = 0;
|
|
1484
|
+
}
|
|
1485
|
+
re = realf( searchElement );
|
|
1486
|
+
im = imagf( searchElement );
|
|
1487
|
+
buf = this._buffer;
|
|
1488
|
+
for ( i = fromIndex; i < this._length; i++ ) {
|
|
1489
|
+
idx = 2 * i;
|
|
1490
|
+
if ( re === buf[ idx ] && im === buf[ idx+1 ] ) {
|
|
1491
|
+
return i;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
return -1;
|
|
1495
|
+
});
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
* Returns a new string by concatenating all array elements.
|
|
1499
|
+
*
|
|
1500
|
+
* @name join
|
|
1501
|
+
* @memberof Complex64Array.prototype
|
|
1502
|
+
* @type {Function}
|
|
1503
|
+
* @param {string} [separator=','] - element separator
|
|
1504
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1505
|
+
* @throws {TypeError} first argument must be a string
|
|
1506
|
+
* @returns {string} string representation
|
|
1507
|
+
*
|
|
1508
|
+
* @example
|
|
1509
|
+
* var arr = new Complex64Array( 2 );
|
|
1510
|
+
*
|
|
1511
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
1512
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1513
|
+
*
|
|
1514
|
+
* var str = arr.join();
|
|
1515
|
+
* // returns '1 + 1i,2 + 2i'
|
|
1516
|
+
*
|
|
1517
|
+
* str = arr.join( '/' );
|
|
1518
|
+
* // returns '1 + 1i/2 + 2i'
|
|
1519
|
+
*/
|
|
1520
|
+
setReadOnly( Complex64Array.prototype, 'join', function join( separator ) {
|
|
1521
|
+
var out;
|
|
1522
|
+
var buf;
|
|
1523
|
+
var sep;
|
|
1524
|
+
var i;
|
|
1525
|
+
if ( !isComplexArray( this ) ) {
|
|
1526
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1527
|
+
}
|
|
1528
|
+
if ( arguments.length === 0 ) {
|
|
1529
|
+
sep = ',';
|
|
1530
|
+
} else if ( isString( separator ) ) {
|
|
1531
|
+
sep = separator;
|
|
1532
|
+
} else {
|
|
1533
|
+
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', separator ) );
|
|
1534
|
+
}
|
|
1535
|
+
out = [];
|
|
1536
|
+
buf = this._buffer;
|
|
1537
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
1538
|
+
out.push( getComplex64( buf, i ).toString() );
|
|
1539
|
+
}
|
|
1540
|
+
return out.join( sep );
|
|
1541
|
+
});
|
|
1542
|
+
|
|
1543
|
+
/**
|
|
1544
|
+
* Returns the last index at which a given element can be found.
|
|
1545
|
+
*
|
|
1546
|
+
* @name lastIndexOf
|
|
1547
|
+
* @memberof Complex64Array.prototype
|
|
1548
|
+
* @type {Function}
|
|
1549
|
+
* @param {ComplexLike} searchElement - element to find
|
|
1550
|
+
* @param {integer} [fromIndex] - index at which to start searching backward (inclusive)
|
|
1551
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1552
|
+
* @throws {TypeError} first argument must be a complex number
|
|
1553
|
+
* @throws {TypeError} second argument must be an integer
|
|
1554
|
+
* @returns {integer} index or -1
|
|
1555
|
+
*
|
|
1556
|
+
* @example
|
|
1557
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1558
|
+
*
|
|
1559
|
+
* var arr = new Complex64Array( 5 );
|
|
1560
|
+
*
|
|
1561
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1562
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
1563
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
1564
|
+
* arr.set( [ 4.0, -4.0 ], 3 );
|
|
1565
|
+
* arr.set( [ 3.0, -3.0 ], 4 );
|
|
1566
|
+
*
|
|
1567
|
+
* var idx = arr.lastIndexOf( new Complex64( 3.0, -3.0 ) );
|
|
1568
|
+
* // returns 4
|
|
1569
|
+
*
|
|
1570
|
+
* idx = arr.lastIndexOf( new Complex64( 3.0, -3.0 ), 3 );
|
|
1571
|
+
* // returns 2
|
|
1572
|
+
*
|
|
1573
|
+
* idx = arr.lastIndexOf( new Complex64( 5.0, -5.0 ), 3 );
|
|
1574
|
+
* // returns -1
|
|
1575
|
+
*
|
|
1576
|
+
* idx = arr.lastIndexOf( new Complex64( 2.0, -2.0 ), -3 );
|
|
1577
|
+
* // returns 1
|
|
1578
|
+
*/
|
|
1579
|
+
setReadOnly( Complex64Array.prototype, 'lastIndexOf', function lastIndexOf( searchElement, fromIndex ) {
|
|
1580
|
+
var buf;
|
|
1581
|
+
var idx;
|
|
1582
|
+
var re;
|
|
1583
|
+
var im;
|
|
1584
|
+
var i;
|
|
1585
|
+
if ( !isComplexArray( this ) ) {
|
|
1586
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1587
|
+
}
|
|
1588
|
+
if ( !isComplexLike( searchElement ) ) {
|
|
1589
|
+
throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) );
|
|
1590
|
+
}
|
|
1591
|
+
if ( arguments.length > 1 ) {
|
|
1592
|
+
if ( !isInteger( fromIndex ) ) {
|
|
1593
|
+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
|
|
1594
|
+
}
|
|
1595
|
+
if ( fromIndex >= this._length ) {
|
|
1596
|
+
fromIndex = this._length - 1;
|
|
1597
|
+
} else if ( fromIndex < 0 ) {
|
|
1598
|
+
fromIndex += this._length;
|
|
1599
|
+
}
|
|
1600
|
+
} else {
|
|
1601
|
+
fromIndex = this._length - 1;
|
|
1602
|
+
}
|
|
1603
|
+
re = realf( searchElement );
|
|
1604
|
+
im = imagf( searchElement );
|
|
1605
|
+
buf = this._buffer;
|
|
1606
|
+
for ( i = fromIndex; i >= 0; i-- ) {
|
|
1607
|
+
idx = 2 * i;
|
|
1608
|
+
if ( re === buf[ idx ] && im === buf[ idx+1 ] ) {
|
|
1609
|
+
return i;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return -1;
|
|
1613
|
+
});
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* Number of array elements.
|
|
1617
|
+
*
|
|
1618
|
+
* @name length
|
|
1619
|
+
* @memberof Complex64Array.prototype
|
|
1620
|
+
* @readonly
|
|
1621
|
+
* @type {NonNegativeInteger}
|
|
1622
|
+
*
|
|
1623
|
+
* @example
|
|
1624
|
+
* var arr = new Complex64Array( 10 );
|
|
1625
|
+
*
|
|
1626
|
+
* var len = arr.length;
|
|
1627
|
+
* // returns 10
|
|
1628
|
+
*/
|
|
1629
|
+
setReadOnlyAccessor( Complex64Array.prototype, 'length', function get() {
|
|
1630
|
+
return this._length;
|
|
1631
|
+
});
|
|
1632
|
+
|
|
1633
|
+
/**
|
|
1634
|
+
* Returns a new array with each element being the result of a provided callback function.
|
|
1635
|
+
*
|
|
1636
|
+
* @name map
|
|
1637
|
+
* @memberof Complex64Array.prototype
|
|
1638
|
+
* @type {Function}
|
|
1639
|
+
* @param {Function} fcn - callback function
|
|
1640
|
+
* @param {*} [thisArg] - callback function execution context
|
|
1641
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1642
|
+
* @throws {TypeError} first argument must be a function
|
|
1643
|
+
* @returns {Complex64Array} complex number array
|
|
1644
|
+
*
|
|
1645
|
+
* @example
|
|
1646
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1647
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1648
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1649
|
+
*
|
|
1650
|
+
* function scale( v, i ) {
|
|
1651
|
+
* return new Complex64( 2.0*realf( v ), 2.0*imagf( v ) );
|
|
1652
|
+
* }
|
|
1653
|
+
*
|
|
1654
|
+
* var arr = new Complex64Array( 3 );
|
|
1655
|
+
*
|
|
1656
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1657
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
1658
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
1659
|
+
*
|
|
1660
|
+
* var out = arr.map( scale );
|
|
1661
|
+
* // returns <Complex64Array>
|
|
1662
|
+
*
|
|
1663
|
+
* var z = out.get( 0 );
|
|
1664
|
+
* // returns <Complex64>
|
|
1665
|
+
*
|
|
1666
|
+
* var re = realf( z );
|
|
1667
|
+
* // returns 2
|
|
1668
|
+
*
|
|
1669
|
+
* var im = imagf( z );
|
|
1670
|
+
* // returns -2
|
|
1671
|
+
*/
|
|
1672
|
+
setReadOnly( Complex64Array.prototype, 'map', function map( fcn, thisArg ) {
|
|
1673
|
+
var outbuf;
|
|
1674
|
+
var buf;
|
|
1675
|
+
var out;
|
|
1676
|
+
var i;
|
|
1677
|
+
var v;
|
|
1678
|
+
if ( !isComplexArray( this ) ) {
|
|
1679
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1680
|
+
}
|
|
1681
|
+
if ( !isFunction( fcn ) ) {
|
|
1682
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );
|
|
1683
|
+
}
|
|
1684
|
+
buf = this._buffer;
|
|
1685
|
+
out = new this.constructor( this._length );
|
|
1686
|
+
outbuf = out._buffer; // eslint-disable-line no-underscore-dangle
|
|
1687
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
1688
|
+
v = fcn.call( thisArg, getComplex64( buf, i ), i, this );
|
|
1689
|
+
if ( isComplexLike( v ) ) {
|
|
1690
|
+
outbuf[ 2*i ] = realf( v );
|
|
1691
|
+
outbuf[ (2*i)+1 ] = imagf( v );
|
|
1692
|
+
} else if ( isArrayLikeObject( v ) && v.length === 2 ) {
|
|
1693
|
+
outbuf[ 2*i ] = v[ 0 ];
|
|
1694
|
+
outbuf[ (2*i)+1 ] = v[ 1 ];
|
|
1695
|
+
} else {
|
|
1696
|
+
throw new TypeError( format( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', v ) );
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
return out;
|
|
1700
|
+
});
|
|
1701
|
+
|
|
1702
|
+
/**
|
|
1703
|
+
* Reverses an array in-place.
|
|
1704
|
+
*
|
|
1705
|
+
* @name reverse
|
|
1706
|
+
* @memberof Complex64Array.prototype
|
|
1707
|
+
* @type {Function}
|
|
1708
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1709
|
+
* @returns {Complex64Array} reversed array
|
|
1710
|
+
*
|
|
1711
|
+
* @example
|
|
1712
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1713
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1714
|
+
*
|
|
1715
|
+
* var arr = new Complex64Array( 3 );
|
|
1716
|
+
*
|
|
1717
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
1718
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1719
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
1720
|
+
*
|
|
1721
|
+
* var out = arr.reverse();
|
|
1722
|
+
* // returns <Complex64Array>
|
|
1723
|
+
*
|
|
1724
|
+
* var z = out.get( 0 );
|
|
1725
|
+
* // returns <Complex64>
|
|
1726
|
+
*
|
|
1727
|
+
* var re = realf( z );
|
|
1728
|
+
* // returns 3.0
|
|
1729
|
+
*
|
|
1730
|
+
* var im = imagf( z );
|
|
1731
|
+
* // returns 3.0
|
|
1732
|
+
*
|
|
1733
|
+
* z = out.get( 1 );
|
|
1734
|
+
* // returns <Complex64>
|
|
1735
|
+
*
|
|
1736
|
+
* re = realf( z );
|
|
1737
|
+
* // returns 2.0
|
|
1738
|
+
*
|
|
1739
|
+
* im = imagf( z );
|
|
1740
|
+
* // returns 2.0
|
|
1741
|
+
*
|
|
1742
|
+
* z = out.get( 2 );
|
|
1743
|
+
* // returns <Complex64>
|
|
1744
|
+
*
|
|
1745
|
+
* re = realf( z );
|
|
1746
|
+
* // returns 1.0
|
|
1747
|
+
*
|
|
1748
|
+
* im = imagf( z );
|
|
1749
|
+
* // returns 1.0
|
|
1750
|
+
*/
|
|
1751
|
+
setReadOnly( Complex64Array.prototype, 'reverse', function reverse() {
|
|
1752
|
+
var buf;
|
|
1753
|
+
var tmp;
|
|
1754
|
+
var len;
|
|
1755
|
+
var N;
|
|
1756
|
+
var i;
|
|
1757
|
+
var j;
|
|
1758
|
+
if ( !isComplexArray( this ) ) {
|
|
1759
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1760
|
+
}
|
|
1761
|
+
len = this._length;
|
|
1762
|
+
buf = this._buffer;
|
|
1763
|
+
N = floor( len / 2 );
|
|
1764
|
+
for ( i = 0; i < N; i++ ) {
|
|
1765
|
+
j = len - i - 1;
|
|
1766
|
+
tmp = buf[ (2*i) ];
|
|
1767
|
+
buf[ (2*i) ] = buf[ (2*j) ];
|
|
1768
|
+
buf[ (2*j) ] = tmp;
|
|
1769
|
+
tmp = buf[ (2*i)+1 ];
|
|
1770
|
+
buf[ (2*i)+1 ] = buf[ (2*j)+1 ];
|
|
1771
|
+
buf[ (2*j)+1 ] = tmp;
|
|
1772
|
+
}
|
|
1773
|
+
return this;
|
|
1774
|
+
});
|
|
1775
|
+
|
|
1776
|
+
/**
|
|
1777
|
+
* Sets an array element.
|
|
1778
|
+
*
|
|
1779
|
+
* ## Notes
|
|
1780
|
+
*
|
|
1781
|
+
* - When provided a typed array, real or complex, we must check whether the source array shares the same buffer as the target array and whether the underlying memory overlaps. In particular, we are concerned with the following scenario:
|
|
1782
|
+
*
|
|
1783
|
+
* ```text
|
|
1784
|
+
* buf: ---------------------
|
|
1785
|
+
* src: ---------------------
|
|
1786
|
+
* ```
|
|
1787
|
+
*
|
|
1788
|
+
* In the above, as we copy values from `src`, we will overwrite values in the `src` view, resulting in duplicated values copied into the end of `buf`, which is not intended. Hence, to avoid overwriting source values, we must **copy** source values to a temporary array.
|
|
1789
|
+
*
|
|
1790
|
+
* In the other overlapping scenario,
|
|
1791
|
+
*
|
|
1792
|
+
* ```text
|
|
1793
|
+
* buf: ---------------------
|
|
1794
|
+
* src: ---------------------
|
|
1795
|
+
* ```
|
|
1796
|
+
*
|
|
1797
|
+
* by the time we begin copying into the overlapping region, we are copying from the end of `src`, a non-overlapping region, which means we don't run the risk of copying copied values, rather than the original `src` values, as intended.
|
|
1798
|
+
*
|
|
1799
|
+
* @name set
|
|
1800
|
+
* @memberof Complex64Array.prototype
|
|
1801
|
+
* @type {Function}
|
|
1802
|
+
* @param {(Collection|Complex|ComplexArray)} value - value(s)
|
|
1803
|
+
* @param {NonNegativeInteger} [i=0] - element index at which to start writing values
|
|
1804
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1805
|
+
* @throws {TypeError} first argument must be either a complex number, an array-like object, or a complex number array
|
|
1806
|
+
* @throws {TypeError} index argument must be a nonnegative integer
|
|
1807
|
+
* @throws {RangeError} array-like objects must have a length which is a multiple of two
|
|
1808
|
+
* @throws {RangeError} index argument is out-of-bounds
|
|
1809
|
+
* @throws {RangeError} target array lacks sufficient storage to accommodate source values
|
|
1810
|
+
* @returns {void}
|
|
1811
|
+
*
|
|
1812
|
+
* @example
|
|
1813
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1814
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1815
|
+
*
|
|
1816
|
+
* var arr = new Complex64Array( 10 );
|
|
1817
|
+
*
|
|
1818
|
+
* var z = arr.get( 0 );
|
|
1819
|
+
* // returns <Complex64>
|
|
1820
|
+
*
|
|
1821
|
+
* var re = realf( z );
|
|
1822
|
+
* // returns 0.0
|
|
1823
|
+
*
|
|
1824
|
+
* var im = imagf( z );
|
|
1825
|
+
* // returns 0.0
|
|
1826
|
+
*
|
|
1827
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1828
|
+
*
|
|
1829
|
+
* z = arr.get( 0 );
|
|
1830
|
+
* // returns <Complex64>
|
|
1831
|
+
*
|
|
1832
|
+
* re = realf( z );
|
|
1833
|
+
* // returns 1.0
|
|
1834
|
+
*
|
|
1835
|
+
* im = imagf( z );
|
|
1836
|
+
* // returns -1.0
|
|
1837
|
+
*/
|
|
1838
|
+
setReadOnly( Complex64Array.prototype, 'set', function set( value ) {
|
|
1839
|
+
/* eslint-disable no-underscore-dangle */
|
|
1840
|
+
var sbuf;
|
|
1841
|
+
var idx;
|
|
1842
|
+
var buf;
|
|
1843
|
+
var tmp;
|
|
1844
|
+
var flg;
|
|
1845
|
+
var N;
|
|
1846
|
+
var v;
|
|
1847
|
+
var i;
|
|
1848
|
+
var j;
|
|
1849
|
+
if ( !isComplexArray( this ) ) {
|
|
1850
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1851
|
+
}
|
|
1852
|
+
buf = this._buffer;
|
|
1853
|
+
if ( arguments.length > 1 ) {
|
|
1854
|
+
idx = arguments[ 1 ];
|
|
1855
|
+
if ( !isNonNegativeInteger( idx ) ) {
|
|
1856
|
+
throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) );
|
|
1857
|
+
}
|
|
1858
|
+
} else {
|
|
1859
|
+
idx = 0;
|
|
1860
|
+
}
|
|
1861
|
+
if ( isComplexLike( value ) ) {
|
|
1862
|
+
if ( idx >= this._length ) {
|
|
1863
|
+
throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) );
|
|
1864
|
+
}
|
|
1865
|
+
idx *= 2;
|
|
1866
|
+
buf[ idx ] = realf( value );
|
|
1867
|
+
buf[ idx+1 ] = imagf( value );
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
if ( isComplexArray( value ) ) {
|
|
1871
|
+
N = value._length;
|
|
1872
|
+
if ( idx+N > this._length ) {
|
|
1873
|
+
throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
|
|
1874
|
+
}
|
|
1875
|
+
sbuf = value._buffer;
|
|
1876
|
+
|
|
1877
|
+
// Check for overlapping memory...
|
|
1878
|
+
j = buf.byteOffset + (idx*BYTES_PER_ELEMENT);
|
|
1879
|
+
if (
|
|
965
1880
|
sbuf.buffer === buf.buffer &&
|
|
966
1881
|
(
|
|
967
1882
|
sbuf.byteOffset < j &&
|
|
@@ -973,80 +1888,549 @@ setReadOnly( Complex64Array.prototype, 'set', function set( value ) {
|
|
|
973
1888
|
for ( i = 0; i < sbuf.length; i++ ) {
|
|
974
1889
|
tmp[ i ] = sbuf[ i ];
|
|
975
1890
|
}
|
|
976
|
-
sbuf = tmp;
|
|
1891
|
+
sbuf = tmp;
|
|
1892
|
+
}
|
|
1893
|
+
idx *= 2;
|
|
1894
|
+
j = 0;
|
|
1895
|
+
for ( i = 0; i < N; i++ ) {
|
|
1896
|
+
buf[ idx ] = sbuf[ j ];
|
|
1897
|
+
buf[ idx+1 ] = sbuf[ j+1 ];
|
|
1898
|
+
idx += 2; // stride
|
|
1899
|
+
j += 2; // stride
|
|
1900
|
+
}
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1903
|
+
if ( isCollection( value ) ) {
|
|
1904
|
+
// Detect whether we've been provided an array of complex numbers...
|
|
1905
|
+
N = value.length;
|
|
1906
|
+
for ( i = 0; i < N; i++ ) {
|
|
1907
|
+
if ( !isComplexLike( value[ i ] ) ) {
|
|
1908
|
+
flg = true;
|
|
1909
|
+
break;
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
// If an array does not contain only complex numbers, then we assume interleaved real and imaginary components...
|
|
1913
|
+
if ( flg ) {
|
|
1914
|
+
if ( !isEven( N ) ) {
|
|
1915
|
+
throw new RangeError( format( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `%u`.', N ) );
|
|
1916
|
+
}
|
|
1917
|
+
if ( idx+(N/2) > this._length ) {
|
|
1918
|
+
throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
|
|
1919
|
+
}
|
|
1920
|
+
sbuf = value;
|
|
1921
|
+
|
|
1922
|
+
// Check for overlapping memory...
|
|
1923
|
+
j = buf.byteOffset + (idx*BYTES_PER_ELEMENT);
|
|
1924
|
+
if (
|
|
1925
|
+
sbuf.buffer === buf.buffer &&
|
|
1926
|
+
(
|
|
1927
|
+
sbuf.byteOffset < j &&
|
|
1928
|
+
sbuf.byteOffset+sbuf.byteLength > j
|
|
1929
|
+
)
|
|
1930
|
+
) {
|
|
1931
|
+
// We need to copy source values...
|
|
1932
|
+
tmp = new Float32Array( N );
|
|
1933
|
+
for ( i = 0; i < N; i++ ) {
|
|
1934
|
+
tmp[ i ] = sbuf[ i ]; // TODO: handle accessor arrays
|
|
1935
|
+
}
|
|
1936
|
+
sbuf = tmp;
|
|
1937
|
+
}
|
|
1938
|
+
idx *= 2;
|
|
1939
|
+
N /= 2;
|
|
1940
|
+
j = 0;
|
|
1941
|
+
for ( i = 0; i < N; i++ ) {
|
|
1942
|
+
buf[ idx ] = sbuf[ j ];
|
|
1943
|
+
buf[ idx+1 ] = sbuf[ j+1 ];
|
|
1944
|
+
idx += 2; // stride
|
|
1945
|
+
j += 2; // stride
|
|
1946
|
+
}
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1949
|
+
// If an array contains only complex numbers, then we need to extract real and imaginary components...
|
|
1950
|
+
if ( idx+N > this._length ) {
|
|
1951
|
+
throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
|
|
1952
|
+
}
|
|
1953
|
+
idx *= 2;
|
|
1954
|
+
for ( i = 0; i < N; i++ ) {
|
|
1955
|
+
v = value[ i ];
|
|
1956
|
+
buf[ idx ] = realf( v );
|
|
1957
|
+
buf[ idx+1 ] = imagf( v );
|
|
1958
|
+
idx += 2; // stride
|
|
1959
|
+
}
|
|
1960
|
+
return;
|
|
1961
|
+
}
|
|
1962
|
+
throw new TypeError( format( 'invalid argument. First argument must be either a complex number, an array-like object, or a complex number array. Value: `%s`.', value ) );
|
|
1963
|
+
|
|
1964
|
+
/* eslint-enable no-underscore-dangle */
|
|
1965
|
+
});
|
|
1966
|
+
|
|
1967
|
+
/**
|
|
1968
|
+
* Copies a portion of a typed array to a new typed array.
|
|
1969
|
+
*
|
|
1970
|
+
* @name slice
|
|
1971
|
+
* @memberof Complex64Array.prototype
|
|
1972
|
+
* @type {Function}
|
|
1973
|
+
* @param {integer} [start=0] - starting index (inclusive)
|
|
1974
|
+
* @param {integer} [end] - ending index (exclusive)
|
|
1975
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1976
|
+
* @throws {TypeError} first argument must be an integer
|
|
1977
|
+
* @throws {TypeError} second argument must be an integer
|
|
1978
|
+
* @returns {Complex64Array} complex number array
|
|
1979
|
+
*
|
|
1980
|
+
* @example
|
|
1981
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
1982
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
1983
|
+
*
|
|
1984
|
+
* var arr = new Complex64Array( 5 );
|
|
1985
|
+
*
|
|
1986
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
1987
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
1988
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
1989
|
+
* arr.set( [ 4.0, -4.0 ], 3 );
|
|
1990
|
+
* arr.set( [ 5.0, -5.0 ], 4 );
|
|
1991
|
+
*
|
|
1992
|
+
* var out = arr.slice();
|
|
1993
|
+
* // returns <Complex64Array>
|
|
1994
|
+
*
|
|
1995
|
+
* var len = out.length;
|
|
1996
|
+
* // returns 5
|
|
1997
|
+
*
|
|
1998
|
+
* var z = out.get( 0 );
|
|
1999
|
+
* // returns <Complex64>
|
|
2000
|
+
*
|
|
2001
|
+
* var re = realf( z );
|
|
2002
|
+
* // returns 1.0
|
|
2003
|
+
*
|
|
2004
|
+
* var im = imagf( z );
|
|
2005
|
+
* // returns -1.0
|
|
2006
|
+
*
|
|
2007
|
+
* z = out.get( len-1 );
|
|
2008
|
+
* // returns <Complex64>
|
|
2009
|
+
*
|
|
2010
|
+
* re = realf( z );
|
|
2011
|
+
* // returns 5.0
|
|
2012
|
+
*
|
|
2013
|
+
* im = imagf( z );
|
|
2014
|
+
* // returns -5.0
|
|
2015
|
+
*
|
|
2016
|
+
* out = arr.slice( 1, -2 );
|
|
2017
|
+
* // returns <Complex64Array>
|
|
2018
|
+
*
|
|
2019
|
+
* len = out.length;
|
|
2020
|
+
* // returns 2
|
|
2021
|
+
*
|
|
2022
|
+
* z = out.get( 0 );
|
|
2023
|
+
* // returns <Complex64>
|
|
2024
|
+
*
|
|
2025
|
+
* re = realf( z );
|
|
2026
|
+
* // returns 2.0
|
|
2027
|
+
*
|
|
2028
|
+
* im = imagf( z );
|
|
2029
|
+
* // returns -2.0
|
|
2030
|
+
*
|
|
2031
|
+
* z = out.get( len-1 );
|
|
2032
|
+
* // returns <Complex64>
|
|
2033
|
+
*
|
|
2034
|
+
* re = realf( z );
|
|
2035
|
+
* // returns 3.0
|
|
2036
|
+
*
|
|
2037
|
+
* im = imagf( z );
|
|
2038
|
+
* // returns -3.0
|
|
2039
|
+
*/
|
|
2040
|
+
setReadOnly( Complex64Array.prototype, 'slice', function slice( start, end ) {
|
|
2041
|
+
var outlen;
|
|
2042
|
+
var outbuf;
|
|
2043
|
+
var out;
|
|
2044
|
+
var idx;
|
|
2045
|
+
var buf;
|
|
2046
|
+
var len;
|
|
2047
|
+
var i;
|
|
2048
|
+
if ( !isComplexArray( this ) ) {
|
|
2049
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2050
|
+
}
|
|
2051
|
+
buf = this._buffer;
|
|
2052
|
+
len = this._length;
|
|
2053
|
+
if ( arguments.length === 0 ) {
|
|
2054
|
+
start = 0;
|
|
2055
|
+
end = len;
|
|
2056
|
+
} else {
|
|
2057
|
+
if ( !isInteger( start ) ) {
|
|
2058
|
+
throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', start ) );
|
|
2059
|
+
}
|
|
2060
|
+
if ( start < 0 ) {
|
|
2061
|
+
start += len;
|
|
2062
|
+
if ( start < 0 ) {
|
|
2063
|
+
start = 0;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
if ( arguments.length === 1 ) {
|
|
2067
|
+
end = len;
|
|
2068
|
+
} else {
|
|
2069
|
+
if ( !isInteger( end ) ) {
|
|
2070
|
+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) );
|
|
2071
|
+
}
|
|
2072
|
+
if ( end < 0 ) {
|
|
2073
|
+
end += len;
|
|
2074
|
+
if ( end < 0 ) {
|
|
2075
|
+
end = 0;
|
|
2076
|
+
}
|
|
2077
|
+
} else if ( end > len ) {
|
|
2078
|
+
end = len;
|
|
2079
|
+
}
|
|
977
2080
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
2081
|
+
}
|
|
2082
|
+
if ( start < end ) {
|
|
2083
|
+
outlen = end - start;
|
|
2084
|
+
} else {
|
|
2085
|
+
outlen = 0;
|
|
2086
|
+
}
|
|
2087
|
+
out = new this.constructor( outlen );
|
|
2088
|
+
outbuf = out._buffer; // eslint-disable-line no-underscore-dangle
|
|
2089
|
+
for ( i = 0; i < outlen; i++ ) {
|
|
2090
|
+
idx = 2*(i+start);
|
|
2091
|
+
outbuf[ 2*i ] = buf[ idx ];
|
|
2092
|
+
outbuf[ (2*i)+1 ] = buf[ idx+1 ];
|
|
2093
|
+
}
|
|
2094
|
+
return out;
|
|
2095
|
+
});
|
|
2096
|
+
|
|
2097
|
+
/**
|
|
2098
|
+
* Tests whether at least one element in an array passes a test implemented by a predicate function.
|
|
2099
|
+
*
|
|
2100
|
+
* @name some
|
|
2101
|
+
* @memberof Complex64Array.prototype
|
|
2102
|
+
* @type {Function}
|
|
2103
|
+
* @param {Function} predicate - test function
|
|
2104
|
+
* @param {*} [thisArg] - predicate function execution context
|
|
2105
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2106
|
+
* @throws {TypeError} first argument must be a function
|
|
2107
|
+
* @returns {boolean} boolean indicating whether at least one element passes a test
|
|
2108
|
+
*
|
|
2109
|
+
* @example
|
|
2110
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
2111
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
2112
|
+
*
|
|
2113
|
+
* function predicate( v ) {
|
|
2114
|
+
* return ( realf( v ) === imagf( v ) );
|
|
2115
|
+
* }
|
|
2116
|
+
*
|
|
2117
|
+
* var arr = new Complex64Array( 3 );
|
|
2118
|
+
*
|
|
2119
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
2120
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
2121
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
2122
|
+
*
|
|
2123
|
+
* var bool = arr.some( predicate );
|
|
2124
|
+
* // returns true
|
|
2125
|
+
*/
|
|
2126
|
+
setReadOnly( Complex64Array.prototype, 'some', function some( predicate, thisArg ) {
|
|
2127
|
+
var buf;
|
|
2128
|
+
var i;
|
|
2129
|
+
if ( !isComplexArray( this ) ) {
|
|
2130
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2131
|
+
}
|
|
2132
|
+
if ( !isFunction( predicate ) ) {
|
|
2133
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
|
|
2134
|
+
}
|
|
2135
|
+
buf = this._buffer;
|
|
2136
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
2137
|
+
if ( predicate.call( thisArg, getComplex64( buf, i ), i, this ) ) {
|
|
2138
|
+
return true;
|
|
985
2139
|
}
|
|
986
|
-
return;
|
|
987
2140
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
2141
|
+
return false;
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
/**
|
|
2145
|
+
* Creates a new typed array view over the same underlying `ArrayBuffer` and with the same underlying data type as the host array.
|
|
2146
|
+
*
|
|
2147
|
+
* @name subarray
|
|
2148
|
+
* @memberof Complex64Array.prototype
|
|
2149
|
+
* @type {Function}
|
|
2150
|
+
* @param {integer} [begin=0] - starting index (inclusive)
|
|
2151
|
+
* @param {integer} [end] - ending index (exclusive)
|
|
2152
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2153
|
+
* @throws {TypeError} first argument must be an integer
|
|
2154
|
+
* @throws {TypeError} second argument must be an integer
|
|
2155
|
+
* @returns {Complex64Array} subarray
|
|
2156
|
+
*
|
|
2157
|
+
* @example
|
|
2158
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
2159
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
2160
|
+
*
|
|
2161
|
+
* var arr = new Complex64Array( 5 );
|
|
2162
|
+
*
|
|
2163
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
2164
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
2165
|
+
* arr.set( [ 3.0, -3.0 ], 2 );
|
|
2166
|
+
* arr.set( [ 4.0, -4.0 ], 3 );
|
|
2167
|
+
* arr.set( [ 5.0, -5.0 ], 4 );
|
|
2168
|
+
*
|
|
2169
|
+
* var subarr = arr.subarray();
|
|
2170
|
+
* // returns <Complex64Array>
|
|
2171
|
+
*
|
|
2172
|
+
* var len = subarr.length;
|
|
2173
|
+
* // returns 5
|
|
2174
|
+
*
|
|
2175
|
+
* var z = subarr.get( 0 );
|
|
2176
|
+
* // returns <Complex64>
|
|
2177
|
+
*
|
|
2178
|
+
* var re = realf( z );
|
|
2179
|
+
* // returns 1.0
|
|
2180
|
+
*
|
|
2181
|
+
* var im = imagf( z );
|
|
2182
|
+
* // returns -1.0
|
|
2183
|
+
*
|
|
2184
|
+
* z = subarr.get( len-1 );
|
|
2185
|
+
* // returns <Complex64>
|
|
2186
|
+
*
|
|
2187
|
+
* re = realf( z );
|
|
2188
|
+
* // returns 5.0
|
|
2189
|
+
*
|
|
2190
|
+
* im = imagf( z );
|
|
2191
|
+
* // returns -5.0
|
|
2192
|
+
*
|
|
2193
|
+
* subarr = arr.subarray( 1, -2 );
|
|
2194
|
+
* // returns <Complex64Array>
|
|
2195
|
+
*
|
|
2196
|
+
* len = subarr.length;
|
|
2197
|
+
* // returns 2
|
|
2198
|
+
*
|
|
2199
|
+
* z = subarr.get( 0 );
|
|
2200
|
+
* // returns <Complex64>
|
|
2201
|
+
*
|
|
2202
|
+
* re = realf( z );
|
|
2203
|
+
* // returns 2.0
|
|
2204
|
+
*
|
|
2205
|
+
* im = imagf( z );
|
|
2206
|
+
* // returns -2.0
|
|
2207
|
+
*
|
|
2208
|
+
* z = subarr.get( len-1 );
|
|
2209
|
+
* // returns <Complex64>
|
|
2210
|
+
*
|
|
2211
|
+
* re = realf( z );
|
|
2212
|
+
* // returns 3.0
|
|
2213
|
+
*
|
|
2214
|
+
* im = imagf( z );
|
|
2215
|
+
* // returns -3.0
|
|
2216
|
+
*/
|
|
2217
|
+
setReadOnly( Complex64Array.prototype, 'subarray', function subarray( begin, end ) {
|
|
2218
|
+
var offset;
|
|
2219
|
+
var buf;
|
|
2220
|
+
var len;
|
|
2221
|
+
if ( !isComplexArray( this ) ) {
|
|
2222
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2223
|
+
}
|
|
2224
|
+
buf = this._buffer;
|
|
2225
|
+
len = this._length;
|
|
2226
|
+
if ( arguments.length === 0 ) {
|
|
2227
|
+
begin = 0;
|
|
2228
|
+
end = len;
|
|
2229
|
+
} else {
|
|
2230
|
+
if ( !isInteger( begin ) ) {
|
|
2231
|
+
throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', begin ) );
|
|
996
2232
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
if (
|
|
1000
|
-
|
|
2233
|
+
if ( begin < 0 ) {
|
|
2234
|
+
begin += len;
|
|
2235
|
+
if ( begin < 0 ) {
|
|
2236
|
+
begin = 0;
|
|
1001
2237
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
2238
|
+
}
|
|
2239
|
+
if ( arguments.length === 1 ) {
|
|
2240
|
+
end = len;
|
|
2241
|
+
} else {
|
|
2242
|
+
if ( !isInteger( end ) ) {
|
|
2243
|
+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) );
|
|
1004
2244
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
if (
|
|
1010
|
-
sbuf.buffer === buf.buffer &&
|
|
1011
|
-
(
|
|
1012
|
-
sbuf.byteOffset < j &&
|
|
1013
|
-
sbuf.byteOffset+sbuf.byteLength > j
|
|
1014
|
-
)
|
|
1015
|
-
) {
|
|
1016
|
-
// We need to copy source values...
|
|
1017
|
-
tmp = new Float32Array( N );
|
|
1018
|
-
for ( i = 0; i < N; i++ ) {
|
|
1019
|
-
tmp[ i ] = sbuf[ i ];
|
|
2245
|
+
if ( end < 0 ) {
|
|
2246
|
+
end += len;
|
|
2247
|
+
if ( end < 0 ) {
|
|
2248
|
+
end = 0;
|
|
1020
2249
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
idx *= 2;
|
|
1024
|
-
N /= 2;
|
|
1025
|
-
j = 0;
|
|
1026
|
-
for ( i = 0; i < N; i++ ) {
|
|
1027
|
-
buf[ idx ] = sbuf[ j ];
|
|
1028
|
-
buf[ idx+1 ] = sbuf[ j+1 ];
|
|
1029
|
-
idx += 2; // stride
|
|
1030
|
-
j += 2; // stride
|
|
2250
|
+
} else if ( end > len ) {
|
|
2251
|
+
end = len;
|
|
1031
2252
|
}
|
|
1032
|
-
return;
|
|
1033
|
-
}
|
|
1034
|
-
// If an array contains only complex numbers, then we need to extract real and imaginary components...
|
|
1035
|
-
if ( idx+N > this._length ) {
|
|
1036
|
-
throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
|
|
1037
|
-
}
|
|
1038
|
-
idx *= 2;
|
|
1039
|
-
for ( i = 0; i < N; i++ ) {
|
|
1040
|
-
v = value[ i ];
|
|
1041
|
-
buf[ idx ] = realf( v );
|
|
1042
|
-
buf[ idx+1 ] = imagf( v );
|
|
1043
|
-
idx += 2; // stride
|
|
1044
2253
|
}
|
|
1045
|
-
return;
|
|
1046
2254
|
}
|
|
1047
|
-
|
|
2255
|
+
if ( begin >= len ) {
|
|
2256
|
+
len = 0;
|
|
2257
|
+
offset = buf.byteLength;
|
|
2258
|
+
} else if ( begin >= end ) {
|
|
2259
|
+
len = 0;
|
|
2260
|
+
offset = buf.byteOffset + (begin*BYTES_PER_ELEMENT);
|
|
2261
|
+
} else {
|
|
2262
|
+
len = end - begin;
|
|
2263
|
+
offset = buf.byteOffset + ( begin*BYTES_PER_ELEMENT );
|
|
2264
|
+
}
|
|
2265
|
+
return new this.constructor( buf.buffer, offset, ( len < 0 ) ? 0 : len );
|
|
2266
|
+
});
|
|
1048
2267
|
|
|
1049
|
-
|
|
2268
|
+
/**
|
|
2269
|
+
* Returns a new typed array containing the elements in reversed order.
|
|
2270
|
+
*
|
|
2271
|
+
* @name toReversed
|
|
2272
|
+
* @memberof Complex64Array.prototype
|
|
2273
|
+
* @type {Function}
|
|
2274
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2275
|
+
* @returns {Complex64Array} reversed array
|
|
2276
|
+
*
|
|
2277
|
+
* @example
|
|
2278
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
2279
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
2280
|
+
*
|
|
2281
|
+
* var arr = new Complex64Array( 3 );
|
|
2282
|
+
*
|
|
2283
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
2284
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
2285
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
2286
|
+
*
|
|
2287
|
+
* var out = arr.toReversed();
|
|
2288
|
+
* // returns <Complex64Array>
|
|
2289
|
+
*
|
|
2290
|
+
* var z = out.get( 0 );
|
|
2291
|
+
* // returns <Complex64>
|
|
2292
|
+
*
|
|
2293
|
+
* var re = realf( z );
|
|
2294
|
+
* // returns 3.0
|
|
2295
|
+
*
|
|
2296
|
+
* var im = imagf( z );
|
|
2297
|
+
* // returns 3.0
|
|
2298
|
+
*
|
|
2299
|
+
* z = out.get( 1 );
|
|
2300
|
+
* // returns <Complex64>
|
|
2301
|
+
*
|
|
2302
|
+
* re = realf( z );
|
|
2303
|
+
* // returns 2.0
|
|
2304
|
+
*
|
|
2305
|
+
* im = imagf( z );
|
|
2306
|
+
* // returns 2.0
|
|
2307
|
+
*
|
|
2308
|
+
* z = out.get( 2 );
|
|
2309
|
+
* // returns <Complex64>
|
|
2310
|
+
*
|
|
2311
|
+
* re = realf( z );
|
|
2312
|
+
* // returns 1.0
|
|
2313
|
+
*
|
|
2314
|
+
* im = imagf( z );
|
|
2315
|
+
* // returns 1.0
|
|
2316
|
+
*/
|
|
2317
|
+
setReadOnly( Complex64Array.prototype, 'toReversed', function toReversed() {
|
|
2318
|
+
var outbuf;
|
|
2319
|
+
var out;
|
|
2320
|
+
var len;
|
|
2321
|
+
var buf;
|
|
2322
|
+
var i;
|
|
2323
|
+
var j;
|
|
2324
|
+
if ( !isComplexArray( this ) ) {
|
|
2325
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2326
|
+
}
|
|
2327
|
+
len = this._length;
|
|
2328
|
+
out = new this.constructor( len );
|
|
2329
|
+
buf = this._buffer;
|
|
2330
|
+
outbuf = out._buffer; // eslint-disable-line no-underscore-dangle
|
|
2331
|
+
for ( i = 0; i < len; i++ ) {
|
|
2332
|
+
j = len - i - 1;
|
|
2333
|
+
outbuf[ (2*i) ] = buf[ (2*j) ];
|
|
2334
|
+
outbuf[ (2*i)+1 ] = buf[ (2*j)+1 ];
|
|
2335
|
+
}
|
|
2336
|
+
return out;
|
|
2337
|
+
});
|
|
2338
|
+
|
|
2339
|
+
/**
|
|
2340
|
+
* Serializes an array as a string.
|
|
2341
|
+
*
|
|
2342
|
+
* @name toString
|
|
2343
|
+
* @memberof Complex64Array.prototype
|
|
2344
|
+
* @type {Function}
|
|
2345
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2346
|
+
* @returns {string} string representation
|
|
2347
|
+
*
|
|
2348
|
+
* @example
|
|
2349
|
+
* var arr = new Complex64Array( 2 );
|
|
2350
|
+
*
|
|
2351
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
2352
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
2353
|
+
*
|
|
2354
|
+
* var str = arr.toString();
|
|
2355
|
+
* // returns '1 + 1i,2 + 2i'
|
|
2356
|
+
*/
|
|
2357
|
+
setReadOnly( Complex64Array.prototype, 'toString', function toString() {
|
|
2358
|
+
var out;
|
|
2359
|
+
var buf;
|
|
2360
|
+
var i;
|
|
2361
|
+
if ( !isComplexArray( this ) ) {
|
|
2362
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2363
|
+
}
|
|
2364
|
+
out = [];
|
|
2365
|
+
buf = this._buffer;
|
|
2366
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
2367
|
+
out.push( getComplex64( buf, i ).toString() );
|
|
2368
|
+
}
|
|
2369
|
+
return out.join( ',' );
|
|
2370
|
+
});
|
|
2371
|
+
|
|
2372
|
+
/**
|
|
2373
|
+
* Returns a new typed array with the element at a provided index replaced with a provided value.
|
|
2374
|
+
*
|
|
2375
|
+
* @name with
|
|
2376
|
+
* @memberof Complex64Array.prototype
|
|
2377
|
+
* @type {Function}
|
|
2378
|
+
* @param {integer} index - element index
|
|
2379
|
+
* @param {ComplexLike} value - new value
|
|
2380
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2381
|
+
* @throws {TypeError} first argument must be an integer
|
|
2382
|
+
* @throws {RangeError} index argument is out-of-bounds
|
|
2383
|
+
* @throws {TypeError} second argument must be a complex number
|
|
2384
|
+
* @returns {Complex64Array} new typed array
|
|
2385
|
+
*
|
|
2386
|
+
* @example
|
|
2387
|
+
* var realf = require( '@stdlib/complex-realf' );
|
|
2388
|
+
* var imagf = require( '@stdlib/complex-imagf' );
|
|
2389
|
+
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
2390
|
+
*
|
|
2391
|
+
* var arr = new Complex64Array( 3 );
|
|
2392
|
+
*
|
|
2393
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
2394
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
2395
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
2396
|
+
*
|
|
2397
|
+
* var out = arr.with( 0, new Complex64( 4.0, 4.0 ) );
|
|
2398
|
+
* // returns <Complex64Array>
|
|
2399
|
+
*
|
|
2400
|
+
* var z = out.get( 0 );
|
|
2401
|
+
* // returns <Complex64>
|
|
2402
|
+
*
|
|
2403
|
+
* var re = realf( z );
|
|
2404
|
+
* // returns 4.0
|
|
2405
|
+
*
|
|
2406
|
+
* var im = imagf( z );
|
|
2407
|
+
* // returns 4.0
|
|
2408
|
+
*/
|
|
2409
|
+
setReadOnly( Complex64Array.prototype, 'with', function copyWith( index, value ) {
|
|
2410
|
+
var buf;
|
|
2411
|
+
var out;
|
|
2412
|
+
var len;
|
|
2413
|
+
if ( !isComplexArray( this ) ) {
|
|
2414
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2415
|
+
}
|
|
2416
|
+
if ( !isInteger( index ) ) {
|
|
2417
|
+
throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', index ) );
|
|
2418
|
+
}
|
|
2419
|
+
len = this._length;
|
|
2420
|
+
if ( index < 0 ) {
|
|
2421
|
+
index += len;
|
|
2422
|
+
}
|
|
2423
|
+
if ( index < 0 || index >= len ) {
|
|
2424
|
+
throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%s`.', index ) );
|
|
2425
|
+
}
|
|
2426
|
+
if ( !isComplexLike( value ) ) {
|
|
2427
|
+
throw new TypeError( format( 'invalid argument. Second argument must be a complex number. Value: `%s`.', value ) );
|
|
2428
|
+
}
|
|
2429
|
+
out = new this.constructor( this._buffer );
|
|
2430
|
+
buf = out._buffer; // eslint-disable-line no-underscore-dangle
|
|
2431
|
+
buf[ 2*index ] = realf( value );
|
|
2432
|
+
buf[ (2*index)+1 ] = imagf( value );
|
|
2433
|
+
return out;
|
|
1050
2434
|
});
|
|
1051
2435
|
|
|
1052
2436
|
|