@stdlib/array-complex64 0.0.5 → 0.1.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/lib/main.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable no-restricted-syntax, max-lines */
1
+ /* eslint-disable no-restricted-syntax, max-lines, no-invalid-this */
2
2
 
3
3
  /**
4
4
  * @license Apache-2.0
@@ -34,11 +34,17 @@ var isEven = require( '@stdlib/math-base-assert-is-even' );
34
34
  var isInteger = require( '@stdlib/math-base-assert-is-integer' );
35
35
  var hasIteratorSymbolSupport = require( '@stdlib/assert-has-iterator-symbol-support' );
36
36
  var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' );
37
- var defineProperty = require( '@stdlib/utils-define-property' );
37
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
38
+ var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );
38
39
  var Float32Array = require( '@stdlib/array-float32' );
39
40
  var Complex64 = require( '@stdlib/complex-float32' );
40
- var real = require( '@stdlib/complex-real' );
41
- var imag = require( '@stdlib/complex-imag' );
41
+ var format = require( '@stdlib/string-format' );
42
+ var realf = require( '@stdlib/complex-realf' );
43
+ var imagf = require( '@stdlib/complex-imagf' );
44
+ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' );
45
+ var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' );
46
+ var getter = require( '@stdlib/array-base-getter' );
47
+ var accessorGetter = require( '@stdlib/array-base-accessor-getter' );
42
48
  var fromIterator = require( './from_iterator.js' );
43
49
  var fromIteratorMap = require( './from_iterator_map.js' );
44
50
  var fromArray = require( './from_array.js' );
@@ -93,6 +99,38 @@ function isComplexArrayConstructor( value ) {
93
99
  );
94
100
  }
95
101
 
102
+ /**
103
+ * Returns a boolean indicating if a value is a `Complex64Array`.
104
+ *
105
+ * @private
106
+ * @param {*} value - value to test
107
+ * @returns {boolean} boolean indicating if a value is a `Complex64Array`
108
+ */
109
+ function isComplex64Array( value ) {
110
+ return (
111
+ typeof value === 'object' &&
112
+ value !== null &&
113
+ value.constructor.name === 'Complex64Array' &&
114
+ value.BYTES_PER_ELEMENT === BYTES_PER_ELEMENT
115
+ );
116
+ }
117
+
118
+ /**
119
+ * Returns a boolean indicating if a value is a `Complex128Array`.
120
+ *
121
+ * @private
122
+ * @param {*} value - value to test
123
+ * @returns {boolean} boolean indicating if a value is a `Complex128Array`
124
+ */
125
+ function isComplex128Array( value ) {
126
+ return (
127
+ typeof value === 'object' &&
128
+ value !== null &&
129
+ value.constructor.name === 'Complex128Array' &&
130
+ value.BYTES_PER_ELEMENT === BYTES_PER_ELEMENT*2
131
+ );
132
+ }
133
+
96
134
 
97
135
  // MAIN //
98
136
 
@@ -100,7 +138,7 @@ function isComplexArrayConstructor( value ) {
100
138
  * 64-bit complex number array constructor.
101
139
  *
102
140
  * @constructor
103
- * @param {(NonNegativeInteger|TypedArray|ArrayLikeObject|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, or buffer
141
+ * @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or an iterable
104
142
  * @param {NonNegativeInteger} [byteOffset=0] - byte offset
105
143
  * @param {NonNegativeInteger} [length] - view length
106
144
  * @throws {RangeError} ArrayBuffer byte length must be a multiple of `8`
@@ -199,34 +237,38 @@ function Complex64Array() {
199
237
  if ( buf === null ) {
200
238
  // We failed and we are now forced to allocate a new array :-(
201
239
  if ( !isEven( len ) ) {
202
- throw new RangeError( 'invalid argument. Array-like object input arguments must have a length which is a multiple of two. Length: `'+len+'`.' );
240
+ throw new RangeError( format( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `%u`.', len ) );
203
241
  }
204
242
  // We failed, so fall back to directly setting values...
205
243
  buf = new Float32Array( arguments[0] );
206
244
  }
207
245
  } else {
208
- if ( !isEven( len ) ) {
209
- throw new RangeError( 'invalid argument. Array-like object and typed array input arguments must have a length which is a multiple of two. Length: `'+len+'`.' );
246
+ if ( isComplex64Array( buf ) ) {
247
+ buf = reinterpret64( buf, 0 );
248
+ } else if ( isComplex128Array( buf ) ) {
249
+ buf = reinterpret128( buf, 0 );
250
+ } else if ( !isEven( len ) ) {
251
+ 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 ) );
210
252
  }
211
253
  buf = new Float32Array( buf );
212
254
  }
213
255
  } else if ( isArrayBuffer( arguments[0] ) ) {
214
256
  buf = arguments[ 0 ];
215
257
  if ( !isInteger( buf.byteLength/BYTES_PER_ELEMENT ) ) {
216
- throw new RangeError( 'invalid argument. ArrayBuffer byte length must be a multiple of '+BYTES_PER_ELEMENT+'. Byte length: `'+buf.byteLength+'`.' );
258
+ throw new RangeError( format( 'invalid argument. ArrayBuffer byte length must be a multiple of %u. Byte length: `%u`.', BYTES_PER_ELEMENT, buf.byteLength ) );
217
259
  }
218
260
  buf = new Float32Array( buf );
219
261
  } else if ( isObject( arguments[0] ) ) {
220
262
  buf = arguments[ 0 ];
221
263
  if ( HAS_ITERATOR_SYMBOL === false ) {
222
- throw new TypeError( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `'+buf+'`.' );
264
+ 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 ) );
223
265
  }
224
266
  if ( !isFunction( buf[ ITERATOR_SYMBOL ] ) ) {
225
- throw new TypeError( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `'+buf+'`.' );
267
+ throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) );
226
268
  }
227
269
  buf = buf[ ITERATOR_SYMBOL ]();
228
270
  if ( !isFunction( buf.next ) ) {
229
- throw new TypeError( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable.' );
271
+ throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) );
230
272
  }
231
273
  buf = fromIterator( buf );
232
274
  if ( buf instanceof Error ) {
@@ -234,49 +276,39 @@ function Complex64Array() {
234
276
  }
235
277
  buf = new Float32Array( buf );
236
278
  } else {
237
- throw new TypeError( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `'+arguments[0]+'`.' );
279
+ throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arguments[0] ) );
238
280
  }
239
281
  } else {
240
282
  buf = arguments[ 0 ];
241
283
  if ( !isArrayBuffer( buf ) ) {
242
- throw new TypeError( 'invalid argument. First argument must be an array buffer. Value: `'+buf+'`.' );
284
+ throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', buf ) );
243
285
  }
244
286
  byteOffset = arguments[ 1 ];
245
287
  if ( !isNonNegativeInteger( byteOffset ) ) {
246
- throw new TypeError( 'invalid argument. Byte offset must be a nonnegative integer. Value: `'+byteOffset+'`.' );
288
+ throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', byteOffset ) );
247
289
  }
248
290
  if ( !isInteger( byteOffset/BYTES_PER_ELEMENT ) ) {
249
- throw new RangeError( 'invalid argument. Byte offset must be a multiple of '+BYTES_PER_ELEMENT+'. Value: `'+byteOffset+'`.' );
291
+ throw new RangeError( format( 'invalid argument. Byte offset must be a multiple of %u. Value: `%u`.', BYTES_PER_ELEMENT, byteOffset ) );
250
292
  }
251
293
  if ( nargs === 2 ) {
252
294
  len = buf.byteLength - byteOffset;
253
295
  if ( !isInteger( len/BYTES_PER_ELEMENT ) ) {
254
- throw new RangeError( 'invalid arguments. ArrayBuffer view byte length must be a multiple of '+BYTES_PER_ELEMENT+'. View byte length: `'+len+'`.' );
296
+ throw new RangeError( format( 'invalid arguments. ArrayBuffer view byte length must be a multiple of %u. View byte length: `%u`.', BYTES_PER_ELEMENT, len ) );
255
297
  }
256
298
  buf = new Float32Array( buf, byteOffset );
257
299
  } else {
258
300
  len = arguments[ 2 ];
259
301
  if ( !isNonNegativeInteger( len ) ) {
260
- throw new TypeError( 'invalid argument. Length must be a nonnegative integer. Value: `'+len+'`.' );
302
+ throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', len ) );
261
303
  }
262
304
  if ( (len*BYTES_PER_ELEMENT) > (buf.byteLength-byteOffset) ) {
263
- throw new RangeError( 'invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `'+(len*BYTES_PER_ELEMENT)+'`.' );
305
+ 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 ) );
264
306
  }
265
307
  buf = new Float32Array( buf, byteOffset, len*2 );
266
308
  }
267
309
  }
268
- defineProperty( this, '_buffer', {
269
- 'configurable': false,
270
- 'enumerable': false,
271
- 'writable': false,
272
- 'value': buf
273
- });
274
- defineProperty( this, '_length', {
275
- 'configurable': false,
276
- 'enumerable': false,
277
- 'writable': false,
278
- 'value': buf.length / 2
279
- });
310
+ setReadOnly( this, '_buffer', buf );
311
+ setReadOnly( this, '_length', buf.length/2 );
280
312
 
281
313
  return this;
282
314
  }
@@ -286,6 +318,7 @@ function Complex64Array() {
286
318
  *
287
319
  * @name BYTES_PER_ELEMENT
288
320
  * @memberof Complex64Array
321
+ * @readonly
289
322
  * @type {PositiveInteger}
290
323
  * @default 8
291
324
  *
@@ -293,18 +326,14 @@ function Complex64Array() {
293
326
  * var nbytes = Complex64Array.BYTES_PER_ELEMENT;
294
327
  * // returns 8
295
328
  */
296
- defineProperty( Complex64Array, 'BYTES_PER_ELEMENT', {
297
- 'configurable': false,
298
- 'enumerable': false,
299
- 'writable': false,
300
- 'value': BYTES_PER_ELEMENT
301
- });
329
+ setReadOnly( Complex64Array, 'BYTES_PER_ELEMENT', BYTES_PER_ELEMENT );
302
330
 
303
331
  /**
304
332
  * Constructor name.
305
333
  *
306
334
  * @name name
307
335
  * @memberof Complex64Array
336
+ * @readonly
308
337
  * @type {string}
309
338
  * @default 'Complex64Array'
310
339
  *
@@ -312,12 +341,7 @@ defineProperty( Complex64Array, 'BYTES_PER_ELEMENT', {
312
341
  * var str = Complex64Array.name;
313
342
  * // returns 'Complex64Array'
314
343
  */
315
- defineProperty( Complex64Array, 'name', {
316
- 'configurable': false,
317
- 'enumerable': false,
318
- 'writable': false,
319
- 'value': 'Complex64Array'
320
- });
344
+ setReadOnly( Complex64Array, 'name', 'Complex64Array' );
321
345
 
322
346
  /**
323
347
  * Creates a new 64-bit complex number array from an array-like object or an iterable.
@@ -325,7 +349,7 @@ defineProperty( Complex64Array, 'name', {
325
349
  * @name from
326
350
  * @memberof Complex64Array
327
351
  * @type {Function}
328
- * @param {(ArrayLikeObject|Iterable)} src - array-like object or iterable
352
+ * @param {(Collection|Iterable)} src - array-like object or iterable
329
353
  * @param {Function} [clbk] - callback to invoke for each source element
330
354
  * @param {*} [thisArg] - context
331
355
  * @throws {TypeError} `this` context must be a constructor
@@ -355,11 +379,11 @@ defineProperty( Complex64Array, 'name', {
355
379
  *
356
380
  * @example
357
381
  * var Complex64 = require( '@stdlib/complex-float32' );
358
- * var real = require( '@stdlib/complex-real' );
359
- * var imag = require( '@stdlib/complex-imag' );
382
+ * var realf = require( '@stdlib/complex-realf' );
383
+ * var imagf = require( '@stdlib/complex-imagf' );
360
384
  *
361
385
  * function clbk( v ) {
362
- * return new Complex64( real(v)*2.0, imag(v)*2.0 );
386
+ * return new Complex64( realf(v)*2.0, imagf(v)*2.0 );
363
387
  * }
364
388
  *
365
389
  * var arr = Complex64Array.from( [ new Complex64( 1.0, 1.0 ) ], clbk );
@@ -368,107 +392,130 @@ defineProperty( Complex64Array, 'name', {
368
392
  * var len = arr.length;
369
393
  * // returns 1
370
394
  */
371
- defineProperty( Complex64Array, 'from', {
372
- 'configurable': false,
373
- 'enumerable': false,
374
- 'writable': false,
375
- 'value': function from( src ) {
376
- var thisArg;
377
- var nargs;
378
- var clbk;
379
- var out;
380
- var buf;
381
- var tmp;
382
- var len;
383
- var flg;
384
- var v;
385
- var i;
386
- var j;
387
- if ( !isFunction( this ) ) {
388
- throw new TypeError( 'invalid invocation. `this` context must be a constructor.' );
395
+ setReadOnly( Complex64Array, 'from', function from( src ) {
396
+ var thisArg;
397
+ var nargs;
398
+ var clbk;
399
+ var out;
400
+ var buf;
401
+ var tmp;
402
+ var get;
403
+ var len;
404
+ var flg;
405
+ var v;
406
+ var i;
407
+ var j;
408
+ if ( !isFunction( this ) ) {
409
+ throw new TypeError( 'invalid invocation. `this` context must be a constructor.' );
410
+ }
411
+ if ( !isComplexArrayConstructor( this ) ) {
412
+ throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
413
+ }
414
+ nargs = arguments.length;
415
+ if ( nargs > 1 ) {
416
+ clbk = arguments[ 1 ];
417
+ if ( !isFunction( clbk ) ) {
418
+ throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) );
389
419
  }
390
- if ( !isComplexArrayConstructor( this ) ) {
391
- throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
420
+ if ( nargs > 2 ) {
421
+ thisArg = arguments[ 2 ];
392
422
  }
393
- nargs = arguments.length;
394
- if ( nargs > 1 ) {
395
- clbk = arguments[ 1 ];
396
- if ( !isFunction( clbk ) ) {
397
- throw new TypeError( 'invalid argument. Second argument must be a function. Value: `'+clbk+'`.' );
398
- }
399
- if ( nargs > 2 ) {
400
- thisArg = arguments[ 2 ];
423
+ }
424
+ if ( isComplexArray( src ) ) {
425
+ len = src.length;
426
+ if ( clbk ) {
427
+ out = new this( len );
428
+ buf = out._buffer; // eslint-disable-line no-underscore-dangle
429
+ j = 0;
430
+ for ( i = 0; i < len; i++ ) {
431
+ v = clbk.call( thisArg, src.get( i ), i );
432
+ if ( isComplexLike( v ) ) {
433
+ buf[ j ] = realf( v );
434
+ buf[ j+1 ] = imagf( v );
435
+ } else if ( isArrayLikeObject( v ) && v.length >= 2 ) {
436
+ buf[ j ] = v[ 0 ];
437
+ buf[ j+1 ] = v[ 1 ];
438
+ } else {
439
+ 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 ) );
440
+ }
441
+ j += 2; // stride
401
442
  }
443
+ return out;
402
444
  }
403
- if ( isCollection( src ) ) {
404
- if ( clbk ) {
405
- // Note: array contents affect how we iterate over a provided data source. If only complex numbers, we can extract real and imaginary components. Otherwise, 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.
445
+ return new this( src );
446
+ }
447
+ if ( isCollection( src ) ) {
448
+ if ( clbk ) {
449
+ // 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.
406
450
 
407
- // Detect whether we've been provided an array of complex numbers...
408
- len = src.length;
409
- for ( i = 0; i < len; i++ ) {
410
- if ( !isComplexLike( src[ i ] ) ) {
411
- flg = true;
412
- break;
413
- }
414
- }
415
- // If an array does not contain only complex numbers, then we assume interleaved real and imaginary components...
416
- if ( flg ) {
417
- if ( !isEven( len ) ) {
418
- throw new RangeError( 'invalid argument. First argument must have a length which is a multiple of two. Length: `'+len+'`.' );
419
- }
420
- out = new this( len/2 );
421
- buf = out._buffer; // eslint-disable-line no-underscore-dangle
422
- for ( i = 0; i < len; i++ ) {
423
- buf[ i ] = clbk.call( thisArg, src[ i ], i );
424
- }
425
- }
426
- // If an array contains only complex numbers, then we need to extract real and imaginary components...
427
- else {
428
- out = new this( len );
429
- buf = out._buffer; // eslint-disable-line no-underscore-dangle
430
- j = 0;
431
- for ( i = 0; i < len; i++ ) {
432
- v = clbk.call( thisArg, src[ i ], i );
433
- if ( isComplexLike( v ) ) {
434
- buf[ j ] = real( v );
435
- buf[ j+1 ] = imag( v );
436
- } else if ( isArrayLikeObject( v ) && v.length >= 2 ) {
437
- buf[ j ] = v[ 0 ];
438
- buf[ j+1 ] = v[ 1 ];
439
- } else {
440
- throw new TypeError( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `'+v+'`.' );
441
- }
442
- j += 2; // stride
443
- }
444
- }
451
+ len = src.length;
452
+ if ( src.get && src.set ) {
453
+ get = accessorGetter( 'default' );
445
454
  } else {
446
- out = new this( src );
447
- }
448
- } else if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len
449
- buf = src[ ITERATOR_SYMBOL ]();
450
- if ( !isFunction( buf.next ) ) {
451
- throw new TypeError( 'invalid argument. First argument must be an array-like object or an iterable.' );
455
+ get = getter( 'default' );
452
456
  }
453
- if ( clbk ) {
454
- tmp = fromIteratorMap( buf, clbk, thisArg );
455
- } else {
456
- tmp = fromIterator( buf );
457
+ // Detect whether we've been provided an array which returns complex number objects...
458
+ for ( i = 0; i < len; i++ ) {
459
+ if ( !isComplexLike( get( src, i ) ) ) {
460
+ flg = true;
461
+ break;
462
+ }
457
463
  }
458
- if ( tmp instanceof Error ) {
459
- throw tmp;
464
+ // If an array does not contain only complex number objects, then we assume interleaved real and imaginary components...
465
+ if ( flg ) {
466
+ if ( !isEven( len ) ) {
467
+ throw new RangeError( format( 'invalid argument. First argument must have a length which is a multiple of %u. Length: `%u`.', 2, len ) );
468
+ }
469
+ out = new this( len/2 );
470
+ buf = out._buffer; // eslint-disable-line no-underscore-dangle
471
+ for ( i = 0; i < len; i++ ) {
472
+ buf[ i ] = clbk.call( thisArg, get( src, i ), i );
473
+ }
474
+ return out;
460
475
  }
461
- len = tmp.length / 2;
476
+ // If an array contains only complex number objects, then we need to extract real and imaginary components...
462
477
  out = new this( len );
463
478
  buf = out._buffer; // eslint-disable-line no-underscore-dangle
479
+ j = 0;
464
480
  for ( i = 0; i < len; i++ ) {
465
- buf[ i ] = tmp[ i ];
481
+ v = clbk.call( thisArg, get( src, i ), i );
482
+ if ( isComplexLike( v ) ) {
483
+ buf[ j ] = realf( v );
484
+ buf[ j+1 ] = imagf( v );
485
+ } else if ( isArrayLikeObject( v ) && v.length >= 2 ) {
486
+ buf[ j ] = v[ 0 ];
487
+ buf[ j+1 ] = v[ 1 ];
488
+ } else {
489
+ 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 ) );
490
+ }
491
+ j += 2; // stride
466
492
  }
493
+ return out;
494
+ }
495
+ return new this( src );
496
+ }
497
+ if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len
498
+ buf = src[ ITERATOR_SYMBOL ]();
499
+ if ( !isFunction( buf.next ) ) {
500
+ throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) );
501
+ }
502
+ if ( clbk ) {
503
+ tmp = fromIteratorMap( buf, clbk, thisArg );
467
504
  } else {
468
- throw new TypeError( 'invalid argument. First argument must be an array-like object or an iterable. Value: `'+src+'`.' );
505
+ tmp = fromIterator( buf );
506
+ }
507
+ if ( tmp instanceof Error ) {
508
+ throw tmp;
509
+ }
510
+ len = tmp.length / 2;
511
+ out = new this( len );
512
+ buf = out._buffer; // eslint-disable-line no-underscore-dangle
513
+ for ( i = 0; i < len; i++ ) {
514
+ buf[ i ] = tmp[ i ];
469
515
  }
470
516
  return out;
471
517
  }
518
+ throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) );
472
519
  });
473
520
 
474
521
  /**
@@ -489,25 +536,20 @@ defineProperty( Complex64Array, 'from', {
489
536
  * var len = arr.length;
490
537
  * // returns 2
491
538
  */
492
- defineProperty( Complex64Array, 'of', {
493
- 'configurable': false,
494
- 'enumerable': false,
495
- 'writable': false,
496
- 'value': function of() {
497
- var args;
498
- var i;
499
- if ( !isFunction( this ) ) {
500
- throw new TypeError( 'invalid invocation. `this` context must be a constructor.' );
501
- }
502
- if ( !isComplexArrayConstructor( this ) ) {
503
- throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
504
- }
505
- args = [];
506
- for ( i = 0; i < arguments.length; i++ ) {
507
- args.push( arguments[ i ] );
508
- }
509
- return new this( args );
539
+ setReadOnly( Complex64Array, 'of', function of() {
540
+ var args;
541
+ var i;
542
+ if ( !isFunction( this ) ) {
543
+ throw new TypeError( 'invalid invocation. `this` context must be a constructor.' );
544
+ }
545
+ if ( !isComplexArrayConstructor( this ) ) {
546
+ throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
547
+ }
548
+ args = [];
549
+ for ( i = 0; i < arguments.length; i++ ) {
550
+ args.push( arguments[ i ] );
510
551
  }
552
+ return new this( args );
511
553
  });
512
554
 
513
555
  /**
@@ -515,6 +557,7 @@ defineProperty( Complex64Array, 'of', {
515
557
  *
516
558
  * @name buffer
517
559
  * @memberof Complex64Array.prototype
560
+ * @readonly
518
561
  * @type {ArrayBuffer}
519
562
  *
520
563
  * @example
@@ -523,12 +566,8 @@ defineProperty( Complex64Array, 'of', {
523
566
  * var buf = arr.buffer;
524
567
  * // returns <ArrayBuffer>
525
568
  */
526
- defineProperty( Complex64Array.prototype, 'buffer', {
527
- 'configurable': false,
528
- 'enumerable': false,
529
- 'get': function get() {
530
- return this._buffer.buffer;
531
- }
569
+ setReadOnlyAccessor( Complex64Array.prototype, 'buffer', function get() {
570
+ return this._buffer.buffer;
532
571
  });
533
572
 
534
573
  /**
@@ -536,6 +575,7 @@ defineProperty( Complex64Array.prototype, 'buffer', {
536
575
  *
537
576
  * @name byteLength
538
577
  * @memberof Complex64Array.prototype
578
+ * @readonly
539
579
  * @type {NonNegativeInteger}
540
580
  *
541
581
  * @example
@@ -544,12 +584,8 @@ defineProperty( Complex64Array.prototype, 'buffer', {
544
584
  * var byteLength = arr.byteLength;
545
585
  * // returns 80
546
586
  */
547
- defineProperty( Complex64Array.prototype, 'byteLength', {
548
- 'configurable': false,
549
- 'enumerable': false,
550
- 'get': function get() {
551
- return this._buffer.byteLength;
552
- }
587
+ setReadOnlyAccessor( Complex64Array.prototype, 'byteLength', function get() {
588
+ return this._buffer.byteLength;
553
589
  });
554
590
 
555
591
  /**
@@ -557,6 +593,7 @@ defineProperty( Complex64Array.prototype, 'byteLength', {
557
593
  *
558
594
  * @name byteOffset
559
595
  * @memberof Complex64Array.prototype
596
+ * @readonly
560
597
  * @type {NonNegativeInteger}
561
598
  *
562
599
  * @example
@@ -565,12 +602,8 @@ defineProperty( Complex64Array.prototype, 'byteLength', {
565
602
  * var byteOffset = arr.byteOffset;
566
603
  * // returns 0
567
604
  */
568
- defineProperty( Complex64Array.prototype, 'byteOffset', {
569
- 'configurable': false,
570
- 'enumerable': false,
571
- 'get': function get() {
572
- return this._buffer.byteOffset;
573
- }
605
+ setReadOnlyAccessor( Complex64Array.prototype, 'byteOffset', function get() {
606
+ return this._buffer.byteOffset;
574
607
  });
575
608
 
576
609
  /**
@@ -578,6 +611,7 @@ defineProperty( Complex64Array.prototype, 'byteOffset', {
578
611
  *
579
612
  * @name BYTES_PER_ELEMENT
580
613
  * @memberof Complex64Array.prototype
614
+ * @readonly
581
615
  * @type {PositiveInteger}
582
616
  * @default 8
583
617
  *
@@ -587,12 +621,7 @@ defineProperty( Complex64Array.prototype, 'byteOffset', {
587
621
  * var nbytes = arr.BYTES_PER_ELEMENT;
588
622
  * // returns 8
589
623
  */
590
- defineProperty( Complex64Array.prototype, 'BYTES_PER_ELEMENT', {
591
- 'configurable': false,
592
- 'enumerable': false,
593
- 'writable': false,
594
- 'value': Complex64Array.BYTES_PER_ELEMENT
595
- });
624
+ setReadOnly( Complex64Array.prototype, 'BYTES_PER_ELEMENT', Complex64Array.BYTES_PER_ELEMENT );
596
625
 
597
626
  /**
598
627
  * Copies a sequence of elements within the array to the position starting at `target`.
@@ -608,8 +637,8 @@ defineProperty( Complex64Array.prototype, 'BYTES_PER_ELEMENT', {
608
637
  *
609
638
  * @example
610
639
  * var Complex64 = require( '@stdlib/complex-float32' );
611
- * var real = require( '@stdlib/complex-real' );
612
- * var imag = require( '@stdlib/complex-imag' );
640
+ * var realf = require( '@stdlib/complex-realf' );
641
+ * var imagf = require( '@stdlib/complex-imagf' );
613
642
  *
614
643
  * var arr = new Complex64Array( 4 );
615
644
  *
@@ -625,28 +654,23 @@ defineProperty( Complex64Array.prototype, 'BYTES_PER_ELEMENT', {
625
654
  * // Get the last array element:
626
655
  * var z = arr.get( 3 );
627
656
  *
628
- * var re = real( z );
657
+ * var re = realf( z );
629
658
  * // returns 2.0
630
659
  *
631
- * var im = imag( z );
660
+ * var im = imagf( z );
632
661
  * // returns 2.0
633
662
  */
634
- defineProperty( Complex64Array.prototype, 'copyWithin', {
635
- 'configurable': false,
636
- 'enumerable': false,
637
- 'writable': false,
638
- 'value': function copyWithin( target, start ) {
639
- if ( !isComplexArray( this ) ) {
640
- throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
641
- }
642
- // FIXME: prefer a functional `copyWithin` implementation which addresses lack of universal browser support (e.g., IE11 and Safari) or ensure that typed arrays are polyfilled
643
- if ( arguments.length === 2 ) {
644
- this._buffer.copyWithin( target*2, start*2 );
645
- } else {
646
- this._buffer.copyWithin( target*2, start*2, arguments[2]*2 );
647
- }
648
- return this;
663
+ setReadOnly( Complex64Array.prototype, 'copyWithin', function copyWithin( target, start ) {
664
+ if ( !isComplexArray( this ) ) {
665
+ throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
649
666
  }
667
+ // FIXME: prefer a functional `copyWithin` implementation which addresses lack of universal browser support (e.g., IE11 and Safari) or ensure that typed arrays are polyfilled
668
+ if ( arguments.length === 2 ) {
669
+ this._buffer.copyWithin( target*2, start*2 );
670
+ } else {
671
+ this._buffer.copyWithin( target*2, start*2, arguments[2]*2 );
672
+ }
673
+ return this;
650
674
  });
651
675
 
652
676
  /**
@@ -684,104 +708,85 @@ defineProperty( Complex64Array.prototype, 'copyWithin', {
684
708
  * var bool = it.next().done;
685
709
  * // returns true
686
710
  */
687
- defineProperty( Complex64Array.prototype, 'entries', {
688
- 'configurable': false,
689
- 'enumerable': false,
690
- 'writable': false,
691
- 'value': function entries() {
692
- var buffer;
693
- var self;
694
- var iter;
695
- var len;
696
- var FLG;
697
- var i;
698
- var j;
699
- if ( !isComplexArray( this ) ) {
700
- throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
701
- }
702
- self = this;
703
- buffer = this._buffer;
704
- len = this._length;
711
+ setReadOnly( Complex64Array.prototype, 'entries', function entries() {
712
+ var buffer;
713
+ var self;
714
+ var iter;
715
+ var len;
716
+ var FLG;
717
+ var i;
718
+ var j;
719
+ if ( !isComplexArray( this ) ) {
720
+ throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
721
+ }
722
+ self = this;
723
+ buffer = this._buffer;
724
+ len = this._length;
705
725
 
706
- // Initialize the iteration indices:
707
- i = -1;
708
- j = -2;
726
+ // Initialize the iteration indices:
727
+ i = -1;
728
+ j = -2;
709
729
 
710
- // Create an iterator protocol-compliant object:
711
- iter = {};
712
- defineProperty( iter, 'next', {
713
- 'configurable': false,
714
- 'enumerable': false,
715
- 'writable': false,
716
- 'value': next
717
- });
718
- defineProperty( iter, 'return', {
719
- 'configurable': false,
720
- 'enumerable': false,
721
- 'writable': false,
722
- 'value': end
723
- });
724
- if ( ITERATOR_SYMBOL ) {
725
- defineProperty( iter, ITERATOR_SYMBOL, {
726
- 'configurable': false,
727
- 'enumerable': false,
728
- 'writable': false,
729
- 'value': factory
730
- });
731
- }
732
- return iter;
730
+ // Create an iterator protocol-compliant object:
731
+ iter = {};
732
+ setReadOnly( iter, 'next', next );
733
+ setReadOnly( iter, 'return', end );
733
734
 
734
- /**
735
- * Returns an iterator protocol-compliant object containing the next iterated value.
736
- *
737
- * @private
738
- * @returns {Object} iterator protocol-compliant object
739
- */
740
- function next() {
741
- var z;
742
- i += 1;
743
- if ( FLG || i >= len ) {
744
- return {
745
- 'done': true
746
- };
747
- }
748
- j += 2;
749
- z = new Complex64( buffer[ j ], buffer[ j+1 ] );
735
+ if ( ITERATOR_SYMBOL ) {
736
+ setReadOnly( iter, ITERATOR_SYMBOL, factory );
737
+ }
738
+ return iter;
739
+
740
+ /**
741
+ * Returns an iterator protocol-compliant object containing the next iterated value.
742
+ *
743
+ * @private
744
+ * @returns {Object} iterator protocol-compliant object
745
+ */
746
+ function next() {
747
+ var z;
748
+ i += 1;
749
+ if ( FLG || i >= len ) {
750
750
  return {
751
- 'value': [ i, z ],
752
- 'done': false
751
+ 'done': true
753
752
  };
754
753
  }
754
+ j += 2;
755
+ z = new Complex64( buffer[ j ], buffer[ j+1 ] );
756
+ return {
757
+ 'value': [ i, z ],
758
+ 'done': false
759
+ };
760
+ }
755
761
 
756
- /**
757
- * Finishes an iterator.
758
- *
759
- * @private
760
- * @param {*} [value] - value to return
761
- * @returns {Object} iterator protocol-compliant object
762
- */
763
- function end( value ) {
764
- FLG = true;
765
- if ( arguments.length ) {
766
- return {
767
- 'value': value,
768
- 'done': true
769
- };
770
- }
762
+ /**
763
+ * Finishes an iterator.
764
+ *
765
+ * @private
766
+ * @param {*} [value] - value to return
767
+ * @returns {Object} iterator protocol-compliant object
768
+ */
769
+ function end( value ) {
770
+ FLG = true;
771
+ if ( arguments.length ) {
771
772
  return {
773
+ 'value': value,
772
774
  'done': true
773
775
  };
774
776
  }
777
+ return {
778
+ 'done': true
779
+ };
780
+ }
775
781
 
776
- /**
777
- * Returns a new iterator.
778
- *
779
- * @private
780
- * @returns {Iterator} iterator
781
- */
782
- function factory() {
783
- return self.entries();
784
- }
782
+ /**
783
+ * Returns a new iterator.
784
+ *
785
+ * @private
786
+ * @returns {Iterator} iterator
787
+ */
788
+ function factory() {
789
+ return self.entries();
785
790
  }
786
791
  });
787
792
 
@@ -791,63 +796,53 @@ defineProperty( Complex64Array.prototype, 'entries', {
791
796
  * @name get
792
797
  * @memberof Complex64Array.prototype
793
798
  * @type {Function}
794
- * @param {ArrayLikeObject} [out] - output array
795
- * @param {NonNegativeInteger} i - element index
799
+ * @param {NonNegativeInteger} idx - element index
796
800
  * @throws {TypeError} `this` must be a complex number array
797
- * @throws {TypeError} index argument must be a nonnegative integer
798
- * @throws {TypeError} output argument must be an array-like object
799
- * @returns {(Complex64|ArrayLikeObject|void)} array element
801
+ * @throws {TypeError} must provide a nonnegative integer
802
+ * @returns {(Complex64|void)} array element
800
803
  *
801
804
  * @example
802
805
  * var arr = new Complex64Array( 10 );
806
+ * var realf = require( '@stdlib/complex-realf' );
807
+ * var imagf = require( '@stdlib/complex-imagf' );
803
808
  *
804
809
  * var z = arr.get( 0 );
805
810
  * // returns <Complex64>
806
811
  *
812
+ * var re = realf( z );
813
+ * // returns 0.0
814
+ *
815
+ * var im = imagf( z );
816
+ * // returns 0.0
817
+ *
807
818
  * arr.set( [ 1.0, -1.0 ], 0 );
808
819
  *
809
- * z = arr.get( [ 0.0, 0.0 ], 0 );
810
- * // returns [ 1.0, -1.0 ]
820
+ * z = arr.get( 0 );
821
+ * // returns <Complex64>
822
+ *
823
+ * re = realf( z );
824
+ * // returns 1.0
825
+ *
826
+ * im = imagf( z );
827
+ * // returns -1.0
811
828
  *
812
829
  * z = arr.get( 100 );
813
830
  * // returns undefined
814
831
  */
815
- defineProperty( Complex64Array.prototype, 'get', {
816
- 'configurable': false,
817
- 'enumerable': false,
818
- 'writable': false,
819
- 'value': function get( i ) {
820
- var idx;
821
- var out;
822
- var buf;
823
-
824
- if ( !isComplexArray( this ) ) {
825
- throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
826
- }
827
- buf = this._buffer;
828
- if ( arguments.length > 1 ) {
829
- idx = arguments[ 1 ];
830
- out = i;
831
- if ( !isArrayLikeObject( out ) || out.length < 2 ) {
832
- throw new TypeError( 'invalid argument. Output argument must be an array-like object. Value: `'+out+'`.' );
833
- }
834
- } else {
835
- idx = i;
836
- }
837
- if ( !isNonNegativeInteger( idx ) ) {
838
- throw new TypeError( 'invalid argument. Index argument must be a nonnegative integer. Value: `'+idx+'`.' );
839
- }
840
- if ( idx >= this._length ) {
841
- return;
842
- }
843
- idx *= 2;
844
- if ( out ) {
845
- out[ 0 ] = buf[ idx ];
846
- out[ 1 ] = buf[ idx+1 ];
847
- return out;
848
- }
849
- return new Complex64( buf[ idx ], buf[ idx+1 ] );
832
+ setReadOnly( Complex64Array.prototype, 'get', function get( idx ) {
833
+ var buf;
834
+ if ( !isComplexArray( this ) ) {
835
+ throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
836
+ }
837
+ if ( !isNonNegativeInteger( idx ) ) {
838
+ throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) );
839
+ }
840
+ if ( idx >= this._length ) {
841
+ return;
850
842
  }
843
+ buf = this._buffer;
844
+ idx *= 2;
845
+ return new Complex64( buf[ idx ], buf[ idx+1 ] );
851
846
  });
852
847
 
853
848
  /**
@@ -855,6 +850,7 @@ defineProperty( Complex64Array.prototype, 'get', {
855
850
  *
856
851
  * @name length
857
852
  * @memberof Complex64Array.prototype
853
+ * @readonly
858
854
  * @type {NonNegativeInteger}
859
855
  *
860
856
  * @example
@@ -863,12 +859,8 @@ defineProperty( Complex64Array.prototype, 'get', {
863
859
  * var len = arr.length;
864
860
  * // returns 10
865
861
  */
866
- defineProperty( Complex64Array.prototype, 'length', {
867
- 'configurable': false,
868
- 'enumerable': false,
869
- 'get': function get() {
870
- return this._length;
871
- }
862
+ setReadOnlyAccessor( Complex64Array.prototype, 'length', function get() {
863
+ return this._length;
872
864
  });
873
865
 
874
866
  /**
@@ -909,18 +901,18 @@ defineProperty( Complex64Array.prototype, 'length', {
909
901
  * @returns {void}
910
902
  *
911
903
  * @example
912
- * var real = require( '@stdlib/complex-real' );
913
- * var imag = require( '@stdlib/complex-imag' );
904
+ * var realf = require( '@stdlib/complex-realf' );
905
+ * var imagf = require( '@stdlib/complex-imagf' );
914
906
  *
915
907
  * var arr = new Complex64Array( 10 );
916
908
  *
917
909
  * var z = arr.get( 0 );
918
910
  * // returns <Complex64>
919
911
  *
920
- * var re = real( z );
912
+ * var re = realf( z );
921
913
  * // returns 0.0
922
914
  *
923
- * var im = imag( z );
915
+ * var im = imagf( z );
924
916
  * // returns 0.0
925
917
  *
926
918
  * arr.set( [ 1.0, -1.0 ], 0 );
@@ -928,54 +920,95 @@ defineProperty( Complex64Array.prototype, 'length', {
928
920
  * z = arr.get( 0 );
929
921
  * // returns <Complex64>
930
922
  *
931
- * re = real( z );
923
+ * re = realf( z );
932
924
  * // returns 1.0
933
925
  *
934
- * im = imag( z );
926
+ * im = imagf( z );
935
927
  * // returns -1.0
936
928
  */
937
- defineProperty( Complex64Array.prototype, 'set', {
938
- 'configurable': false,
939
- 'enumerable': false,
940
- 'writable': false,
941
- 'value': function set( value ) {
942
- /* eslint-disable no-underscore-dangle */
943
- var sbuf;
944
- var idx;
945
- var buf;
946
- var tmp;
947
- var flg;
948
- var N;
949
- var v;
950
- var i;
951
- var j;
952
- if ( !isComplexArray( this ) ) {
953
- throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
929
+ setReadOnly( Complex64Array.prototype, 'set', function set( value ) {
930
+ /* eslint-disable no-underscore-dangle */
931
+ var sbuf;
932
+ var idx;
933
+ var buf;
934
+ var tmp;
935
+ var flg;
936
+ var N;
937
+ var v;
938
+ var i;
939
+ var j;
940
+ if ( !isComplexArray( this ) ) {
941
+ throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
942
+ }
943
+ buf = this._buffer;
944
+ if ( arguments.length > 1 ) {
945
+ idx = arguments[ 1 ];
946
+ if ( !isNonNegativeInteger( idx ) ) {
947
+ throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) );
954
948
  }
955
- buf = this._buffer;
956
- if ( arguments.length > 1 ) {
957
- idx = arguments[ 1 ];
958
- if ( !isNonNegativeInteger( idx ) ) {
959
- throw new TypeError( 'invalid argument. Index argument must be a nonnegative integer. Value: `'+idx+'`.' );
949
+ } else {
950
+ idx = 0;
951
+ }
952
+ if ( isComplexLike( value ) ) {
953
+ if ( idx >= this._length ) {
954
+ throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) );
955
+ }
956
+ idx *= 2;
957
+ buf[ idx ] = realf( value );
958
+ buf[ idx+1 ] = imagf( value );
959
+ return;
960
+ }
961
+ if ( isComplexArray( value ) ) {
962
+ N = value._length;
963
+ if ( idx+N > this._length ) {
964
+ throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
965
+ }
966
+ sbuf = value._buffer;
967
+
968
+ // Check for overlapping memory...
969
+ j = buf.byteOffset + (idx*BYTES_PER_ELEMENT);
970
+ if (
971
+ sbuf.buffer === buf.buffer &&
972
+ (
973
+ sbuf.byteOffset < j &&
974
+ sbuf.byteOffset+sbuf.byteLength > j
975
+ )
976
+ ) {
977
+ // We need to copy source values...
978
+ tmp = new Float32Array( sbuf.length );
979
+ for ( i = 0; i < sbuf.length; i++ ) {
980
+ tmp[ i ] = sbuf[ i ];
960
981
  }
961
- } else {
962
- idx = 0;
982
+ sbuf = tmp;
983
+ }
984
+ idx *= 2;
985
+ j = 0;
986
+ for ( i = 0; i < N; i++ ) {
987
+ buf[ idx ] = sbuf[ j ];
988
+ buf[ idx+1 ] = sbuf[ j+1 ];
989
+ idx += 2; // stride
990
+ j += 2; // stride
963
991
  }
964
- if ( isComplexLike( value ) ) {
965
- if ( idx >= this._length ) {
966
- throw new RangeError( 'invalid argument. Index argument is out-of-bounds. Value: `'+idx+'`.' );
992
+ return;
993
+ }
994
+ if ( isCollection( value ) ) {
995
+ // Detect whether we've been provided an array of complex numbers...
996
+ N = value.length;
997
+ for ( i = 0; i < N; i++ ) {
998
+ if ( !isComplexLike( value[ i ] ) ) {
999
+ flg = true;
1000
+ break;
967
1001
  }
968
- idx *= 2;
969
- buf[ idx ] = real( value );
970
- buf[ idx+1 ] = imag( value );
971
- return;
972
1002
  }
973
- if ( isComplexArray( value ) ) {
974
- N = value._length;
975
- if ( idx+N > this._length ) {
1003
+ // If an array does not contain only complex numbers, then we assume interleaved real and imaginary components...
1004
+ if ( flg ) {
1005
+ if ( !isEven( N ) ) {
1006
+ throw new RangeError( format( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `%u`.', N ) );
1007
+ }
1008
+ if ( idx+(N/2) > this._length ) {
976
1009
  throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
977
1010
  }
978
- sbuf = value._buffer;
1011
+ sbuf = value;
979
1012
 
980
1013
  // Check for overlapping memory...
981
1014
  j = buf.byteOffset + (idx*BYTES_PER_ELEMENT);
@@ -987,13 +1020,14 @@ defineProperty( Complex64Array.prototype, 'set', {
987
1020
  )
988
1021
  ) {
989
1022
  // We need to copy source values...
990
- tmp = new Float32Array( sbuf.length );
991
- for ( i = 0; i < sbuf.length; i++ ) {
1023
+ tmp = new Float32Array( N );
1024
+ for ( i = 0; i < N; i++ ) {
992
1025
  tmp[ i ] = sbuf[ i ];
993
1026
  }
994
1027
  sbuf = tmp;
995
1028
  }
996
1029
  idx *= 2;
1030
+ N /= 2;
997
1031
  j = 0;
998
1032
  for ( i = 0; i < N; i++ ) {
999
1033
  buf[ idx ] = sbuf[ j ];
@@ -1003,69 +1037,22 @@ defineProperty( Complex64Array.prototype, 'set', {
1003
1037
  }
1004
1038
  return;
1005
1039
  }
1006
- if ( isCollection( value ) ) {
1007
- // Detect whether we've been provided an array of complex numbers...
1008
- N = value.length;
1009
- for ( i = 0; i < N; i++ ) {
1010
- if ( !isComplexLike( value[ i ] ) ) {
1011
- flg = true;
1012
- break;
1013
- }
1014
- }
1015
- // If an array does not contain only complex numbers, then we assume interleaved real and imaginary components...
1016
- if ( flg ) {
1017
- if ( !isEven( N ) ) {
1018
- throw new RangeError( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `'+N+'`.' );
1019
- }
1020
- if ( idx+(N/2) > this._length ) {
1021
- throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
1022
- }
1023
- sbuf = value;
1024
-
1025
- // Check for overlapping memory...
1026
- j = buf.byteOffset + (idx*BYTES_PER_ELEMENT);
1027
- if (
1028
- sbuf.buffer === buf.buffer &&
1029
- (
1030
- sbuf.byteOffset < j &&
1031
- sbuf.byteOffset+sbuf.byteLength > j
1032
- )
1033
- ) {
1034
- // We need to copy source values...
1035
- tmp = new Float32Array( N );
1036
- for ( i = 0; i < N; i++ ) {
1037
- tmp[ i ] = sbuf[ i ];
1038
- }
1039
- sbuf = tmp;
1040
- }
1041
- idx *= 2;
1042
- N /= 2;
1043
- j = 0;
1044
- for ( i = 0; i < N; i++ ) {
1045
- buf[ idx ] = sbuf[ j ];
1046
- buf[ idx+1 ] = sbuf[ j+1 ];
1047
- idx += 2; // stride
1048
- j += 2; // stride
1049
- }
1050
- return;
1051
- }
1052
- // If an array contains only complex numbers, then we need to extract real and imaginary components...
1053
- if ( idx+N > this._length ) {
1054
- throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
1055
- }
1056
- idx *= 2;
1057
- for ( i = 0; i < N; i++ ) {
1058
- v = value[ i ];
1059
- buf[ idx ] = real( v );
1060
- buf[ idx+1 ] = imag( v );
1061
- idx += 2; // stride
1062
- }
1063
- return;
1040
+ // If an array contains only complex numbers, then we need to extract real and imaginary components...
1041
+ if ( idx+N > this._length ) {
1042
+ throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
1064
1043
  }
1065
- throw new TypeError( 'invalid argument. First argument must be either a complex number, an array-like object, or a complex number array. Value: `'+value+'`.' );
1066
-
1067
- /* eslint-enable no-underscore-dangle */
1044
+ idx *= 2;
1045
+ for ( i = 0; i < N; i++ ) {
1046
+ v = value[ i ];
1047
+ buf[ idx ] = realf( v );
1048
+ buf[ idx+1 ] = imagf( v );
1049
+ idx += 2; // stride
1050
+ }
1051
+ return;
1068
1052
  }
1053
+ 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 ) );
1054
+
1055
+ /* eslint-enable no-underscore-dangle */
1069
1056
  });
1070
1057
 
1071
1058