@stdlib/array-complex64 0.0.5 → 0.0.6
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/NOTICE +1 -1
- package/README.md +259 -117
- package/docs/types/index.d.ts +26 -48
- package/docs/types/test.ts +3 -3
- package/lib/from_array.js +4 -4
- package/lib/from_iterator.js +10 -12
- package/lib/from_iterator_map.js +11 -14
- package/lib/index.js +2 -2
- package/lib/main.js +398 -417
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ limitations under the License.
|
|
|
20
20
|
|
|
21
21
|
# Complex64Array
|
|
22
22
|
|
|
23
|
-
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url]
|
|
23
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
24
24
|
|
|
25
25
|
> 64-bit complex number array.
|
|
26
26
|
|
|
@@ -75,9 +75,24 @@ var len = arr.length;
|
|
|
75
75
|
// returns 10
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
#### Complex64Array( complexarray )
|
|
79
|
+
|
|
80
|
+
Creates a 64-bit complex number array from another complex number array.
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
var arr1 = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); // [ re, im, re, im ]
|
|
84
|
+
// returns <Complex64Array>
|
|
85
|
+
|
|
86
|
+
var arr2 = new Complex64Array( arr1 );
|
|
87
|
+
// returns <Complex64Array>
|
|
88
|
+
|
|
89
|
+
var len = arr2.length;
|
|
90
|
+
// returns 2
|
|
91
|
+
```
|
|
92
|
+
|
|
78
93
|
#### Complex64Array( typedarray )
|
|
79
94
|
|
|
80
|
-
Creates a 64-bit complex number array from a [typed array][@stdlib/array/typed] containing
|
|
95
|
+
Creates a 64-bit complex number array from a [typed array][@stdlib/array/typed] containing interleaved real and imaginary components.
|
|
81
96
|
|
|
82
97
|
```javascript
|
|
83
98
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
@@ -94,7 +109,7 @@ var len = arr.length;
|
|
|
94
109
|
|
|
95
110
|
#### Complex64Array( obj )
|
|
96
111
|
|
|
97
|
-
Creates a 64-bit complex number array from an array-like
|
|
112
|
+
Creates a 64-bit complex number array from an array-like object or iterable.
|
|
98
113
|
|
|
99
114
|
```javascript
|
|
100
115
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
@@ -254,7 +269,7 @@ var len = arr.length;
|
|
|
254
269
|
|
|
255
270
|
#### Complex64Array.from( src\[, clbk\[, thisArg]] )
|
|
256
271
|
|
|
257
|
-
Creates a new 64-bit complex number array from an array-like
|
|
272
|
+
Creates a new 64-bit complex number array from an array-like object or an iterable.
|
|
258
273
|
|
|
259
274
|
```javascript
|
|
260
275
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
@@ -274,13 +289,13 @@ len = arr.length;
|
|
|
274
289
|
// returns 1
|
|
275
290
|
```
|
|
276
291
|
|
|
277
|
-
The iterator returned by an iterable must return either a complex number or an array-like
|
|
292
|
+
The iterator returned by an iterable must return either a complex number or an array-like object containing a real and imaginary component.
|
|
278
293
|
|
|
279
294
|
```javascript
|
|
280
295
|
var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' );
|
|
281
296
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
282
|
-
var
|
|
283
|
-
var
|
|
297
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
298
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
284
299
|
|
|
285
300
|
var iter;
|
|
286
301
|
var arr;
|
|
@@ -330,23 +345,23 @@ if ( ITERATOR_SYMBOL === null ) {
|
|
|
330
345
|
z = arr.get( 0 );
|
|
331
346
|
// returns <Complex64>
|
|
332
347
|
|
|
333
|
-
re =
|
|
348
|
+
re = realf( z );
|
|
334
349
|
// returns 1.0
|
|
335
350
|
|
|
336
|
-
im =
|
|
351
|
+
im = imagf( z );
|
|
337
352
|
// returns -1.0
|
|
338
353
|
}
|
|
339
354
|
```
|
|
340
355
|
|
|
341
|
-
To invoke a function for each `src` value, provide a callback function. If `src` is an iterable or an array-like
|
|
356
|
+
To invoke a function for each `src` value, provide a callback function. If `src` is an iterable or an array-like object containing complex numbers, the callback must return either a complex number
|
|
342
357
|
|
|
343
358
|
```javascript
|
|
344
359
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
345
|
-
var
|
|
346
|
-
var
|
|
360
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
361
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
347
362
|
|
|
348
363
|
function map( z ) {
|
|
349
|
-
return new Complex64(
|
|
364
|
+
return new Complex64( realf(z)*2.0, imagf(z)*2.0 );
|
|
350
365
|
}
|
|
351
366
|
|
|
352
367
|
// Create a source array:
|
|
@@ -362,20 +377,20 @@ var len = arr.length;
|
|
|
362
377
|
var z = arr.get( 0 );
|
|
363
378
|
// returns <Complex64>
|
|
364
379
|
|
|
365
|
-
var re =
|
|
380
|
+
var re = realf( z );
|
|
366
381
|
// returns 2.0
|
|
367
382
|
|
|
368
|
-
var im =
|
|
383
|
+
var im = imagf( z );
|
|
369
384
|
// returns -2.0
|
|
370
385
|
```
|
|
371
386
|
|
|
372
|
-
or an array-like
|
|
387
|
+
or an array-like object containing real and imaginary components
|
|
373
388
|
|
|
374
389
|
```javascript
|
|
375
390
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
376
391
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
377
|
-
var
|
|
378
|
-
var
|
|
392
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
393
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
379
394
|
|
|
380
395
|
// Return a callback which reuses allocated memory...
|
|
381
396
|
function mapFcn() {
|
|
@@ -383,8 +398,8 @@ function mapFcn() {
|
|
|
383
398
|
return map;
|
|
384
399
|
|
|
385
400
|
function map( z ) {
|
|
386
|
-
buf[ 0 ] =
|
|
387
|
-
buf[ 1 ] =
|
|
401
|
+
buf[ 0 ] = realf( z ) * 2.0;
|
|
402
|
+
buf[ 1 ] = imagf( z ) * 2.0;
|
|
388
403
|
return buf;
|
|
389
404
|
}
|
|
390
405
|
}
|
|
@@ -402,29 +417,29 @@ var len = arr.length;
|
|
|
402
417
|
var z = arr.get( 0 );
|
|
403
418
|
// returns <Complex64>
|
|
404
419
|
|
|
405
|
-
var re =
|
|
420
|
+
var re = realf( z );
|
|
406
421
|
// returns 2.0
|
|
407
422
|
|
|
408
|
-
var im =
|
|
423
|
+
var im = imagf( z );
|
|
409
424
|
// returns -2.0
|
|
410
425
|
|
|
411
426
|
z = arr.get( 1 );
|
|
412
427
|
// returns <Complex64>
|
|
413
428
|
|
|
414
|
-
re =
|
|
429
|
+
re = realf( z );
|
|
415
430
|
// returns 4.0
|
|
416
431
|
|
|
417
|
-
im =
|
|
432
|
+
im = imagf( z );
|
|
418
433
|
// returns -4.0
|
|
419
434
|
```
|
|
420
435
|
|
|
421
|
-
If `src` is an array-like
|
|
436
|
+
If `src` is an array-like object containing interleaved real and imaginary components, the callback is invoked for each component and should return the transformed component value.
|
|
422
437
|
|
|
423
438
|
```javascript
|
|
424
439
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
425
440
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
426
|
-
var
|
|
427
|
-
var
|
|
441
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
442
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
428
443
|
|
|
429
444
|
function map( v ) {
|
|
430
445
|
return v * 2.0;
|
|
@@ -443,28 +458,28 @@ var len = arr.length;
|
|
|
443
458
|
var z = arr.get( 0 );
|
|
444
459
|
// returns <Complex64>
|
|
445
460
|
|
|
446
|
-
var re =
|
|
461
|
+
var re = realf( z );
|
|
447
462
|
// returns 2.0
|
|
448
463
|
|
|
449
|
-
var im =
|
|
464
|
+
var im = imagf( z );
|
|
450
465
|
// returns -2.0
|
|
451
466
|
```
|
|
452
467
|
|
|
453
468
|
A callback function is provided two arguments:
|
|
454
469
|
|
|
455
|
-
-
|
|
456
|
-
-
|
|
470
|
+
- **value**: source value.
|
|
471
|
+
- **index**: source index.
|
|
457
472
|
|
|
458
473
|
To set the callback execution context, provide a `thisArg`.
|
|
459
474
|
|
|
460
475
|
```javascript
|
|
461
476
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
462
|
-
var
|
|
463
|
-
var
|
|
477
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
478
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
464
479
|
|
|
465
480
|
function map( z ) {
|
|
466
481
|
this.count += 1;
|
|
467
|
-
return new Complex64(
|
|
482
|
+
return new Complex64( realf(z)*2.0, imagf(z)*2.0 );
|
|
468
483
|
}
|
|
469
484
|
|
|
470
485
|
// Create a source array:
|
|
@@ -519,6 +534,8 @@ Copies a sequence of elements within the array starting at `start` and ending at
|
|
|
519
534
|
|
|
520
535
|
```javascript
|
|
521
536
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
537
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
538
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
522
539
|
|
|
523
540
|
var arr = new Complex64Array( 4 );
|
|
524
541
|
|
|
@@ -529,29 +546,55 @@ arr.set( new Complex64( 3.0, -3.0 ), 2 );
|
|
|
529
546
|
arr.set( new Complex64( 4.0, -4.0 ), 3 );
|
|
530
547
|
|
|
531
548
|
// Get the first array element:
|
|
532
|
-
var z = arr.get(
|
|
533
|
-
// returns
|
|
549
|
+
var z = arr.get( 0 );
|
|
550
|
+
// returns <Complex64>
|
|
551
|
+
|
|
552
|
+
var re = realf( z );
|
|
553
|
+
// returns 1.0
|
|
554
|
+
|
|
555
|
+
var im = imagf( z );
|
|
556
|
+
// returns -1.0
|
|
534
557
|
|
|
535
558
|
// Get the second array element:
|
|
536
|
-
z = arr.get(
|
|
537
|
-
// returns
|
|
559
|
+
z = arr.get( 1 );
|
|
560
|
+
// returns <Complex64>
|
|
561
|
+
|
|
562
|
+
re = realf( z );
|
|
563
|
+
// returns 2.0
|
|
564
|
+
|
|
565
|
+
im = imagf( z );
|
|
566
|
+
// returns -2.0
|
|
538
567
|
|
|
539
568
|
// Copy the last two elements to the first two elements:
|
|
540
569
|
arr.copyWithin( 0, 2 );
|
|
541
570
|
|
|
542
571
|
// Get the first array element:
|
|
543
|
-
z = arr.get(
|
|
544
|
-
// returns
|
|
572
|
+
z = arr.get( 0 );
|
|
573
|
+
// returns <Complex64>
|
|
574
|
+
|
|
575
|
+
re = realf( z );
|
|
576
|
+
// returns 3.0
|
|
577
|
+
|
|
578
|
+
im = imagf( z );
|
|
579
|
+
// returns -3.0
|
|
545
580
|
|
|
546
581
|
// Get the second array element:
|
|
547
|
-
z = arr.get(
|
|
548
|
-
// returns
|
|
582
|
+
z = arr.get( 1 );
|
|
583
|
+
// returns <Complex64>
|
|
584
|
+
|
|
585
|
+
re = realf( z );
|
|
586
|
+
// returns 4.0
|
|
587
|
+
|
|
588
|
+
im = imagf( z );
|
|
589
|
+
// returns -4.0
|
|
549
590
|
```
|
|
550
591
|
|
|
551
592
|
By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument.
|
|
552
593
|
|
|
553
594
|
```javascript
|
|
554
595
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
596
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
597
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
555
598
|
|
|
556
599
|
var arr = new Complex64Array( 4 );
|
|
557
600
|
|
|
@@ -562,29 +605,55 @@ arr.set( new Complex64( 3.0, -3.0 ), 2 );
|
|
|
562
605
|
arr.set( new Complex64( 4.0, -4.0 ), 3 );
|
|
563
606
|
|
|
564
607
|
// Get the third array element:
|
|
565
|
-
var z = arr.get(
|
|
566
|
-
// returns
|
|
608
|
+
var z = arr.get( 2 );
|
|
609
|
+
// returns <Complex64>
|
|
610
|
+
|
|
611
|
+
var re = realf( z );
|
|
612
|
+
// returns 3.0
|
|
613
|
+
|
|
614
|
+
var im = imagf( z );
|
|
615
|
+
// returns -3.0
|
|
567
616
|
|
|
568
617
|
// Get the last array element:
|
|
569
|
-
z = arr.get(
|
|
570
|
-
// returns
|
|
618
|
+
z = arr.get( 3 );
|
|
619
|
+
// returns <Complex64>
|
|
620
|
+
|
|
621
|
+
re = realf( z );
|
|
622
|
+
// returns 4.0
|
|
623
|
+
|
|
624
|
+
im = imagf( z );
|
|
625
|
+
// returns -4.0
|
|
571
626
|
|
|
572
627
|
// Copy the first two elements to the last two elements:
|
|
573
628
|
arr.copyWithin( 2, 0, 2 );
|
|
574
629
|
|
|
575
630
|
// Get the third array element:
|
|
576
|
-
z = arr.get(
|
|
577
|
-
// returns
|
|
631
|
+
z = arr.get( 2 );
|
|
632
|
+
// returns <Complex64>
|
|
633
|
+
|
|
634
|
+
re = realf( z );
|
|
635
|
+
// returns 1.0
|
|
636
|
+
|
|
637
|
+
im = imagf( z );
|
|
638
|
+
// returns -1.0
|
|
578
639
|
|
|
579
640
|
// Get the last array element:
|
|
580
|
-
z = arr.get(
|
|
581
|
-
// returns
|
|
641
|
+
z = arr.get( 3 );
|
|
642
|
+
// returns <Complex64>
|
|
643
|
+
|
|
644
|
+
re = realf( z );
|
|
645
|
+
// returns 2.0
|
|
646
|
+
|
|
647
|
+
im = imagf( z );
|
|
648
|
+
// returns -2.0
|
|
582
649
|
```
|
|
583
650
|
|
|
584
651
|
When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example:
|
|
585
652
|
|
|
586
653
|
```javascript
|
|
587
654
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
655
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
656
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
588
657
|
|
|
589
658
|
var arr = new Complex64Array( 4 );
|
|
590
659
|
|
|
@@ -595,23 +664,47 @@ arr.set( new Complex64( 3.0, -3.0 ), 2 );
|
|
|
595
664
|
arr.set( new Complex64( 4.0, -4.0 ), 3 );
|
|
596
665
|
|
|
597
666
|
// Get the third array element:
|
|
598
|
-
var z = arr.get(
|
|
599
|
-
// returns
|
|
667
|
+
var z = arr.get( 2 );
|
|
668
|
+
// returns <Complex64>
|
|
669
|
+
|
|
670
|
+
var re = realf( z );
|
|
671
|
+
// returns 3.0
|
|
672
|
+
|
|
673
|
+
var im = imagf( z );
|
|
674
|
+
// returns -3.0
|
|
600
675
|
|
|
601
676
|
// Get the last array element:
|
|
602
|
-
z = arr.get(
|
|
603
|
-
// returns
|
|
677
|
+
z = arr.get( 3 );
|
|
678
|
+
// returns <Complex64>
|
|
679
|
+
|
|
680
|
+
re = realf( z );
|
|
681
|
+
// returns 4.0
|
|
682
|
+
|
|
683
|
+
im = imagf( z );
|
|
684
|
+
// returns -4.0
|
|
604
685
|
|
|
605
686
|
// Copy the first two elements to the last two elements using negative indices:
|
|
606
687
|
arr.copyWithin( -2, -4, -2 );
|
|
607
688
|
|
|
608
689
|
// Get the third array element:
|
|
609
|
-
z = arr.get(
|
|
610
|
-
// returns
|
|
690
|
+
z = arr.get( 2 );
|
|
691
|
+
// returns <Complex64>
|
|
692
|
+
|
|
693
|
+
re = realf( z );
|
|
694
|
+
// returns 1.0
|
|
695
|
+
|
|
696
|
+
im = imagf( z );
|
|
697
|
+
// returns -1.0
|
|
611
698
|
|
|
612
699
|
// Get the last array element:
|
|
613
|
-
z = arr.get(
|
|
614
|
-
// returns
|
|
700
|
+
z = arr.get( 3 );
|
|
701
|
+
// returns <Complex64>
|
|
702
|
+
|
|
703
|
+
re = realf( z );
|
|
704
|
+
// returns 2.0
|
|
705
|
+
|
|
706
|
+
im = imagf( z );
|
|
707
|
+
// returns -2.0
|
|
615
708
|
```
|
|
616
709
|
|
|
617
710
|
<a name="method-entries"></a>
|
|
@@ -622,8 +715,8 @@ Returns an iterator for iterating over array key-value pairs.
|
|
|
622
715
|
|
|
623
716
|
```javascript
|
|
624
717
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
625
|
-
var
|
|
626
|
-
var
|
|
718
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
719
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
627
720
|
|
|
628
721
|
var arr = [
|
|
629
722
|
new Complex64( 1.0, -1.0 ),
|
|
@@ -639,28 +732,28 @@ var it = arr.entries();
|
|
|
639
732
|
var v = it.next().value;
|
|
640
733
|
// returns [ 0, <Complex64> ]
|
|
641
734
|
|
|
642
|
-
var re =
|
|
735
|
+
var re = realf( v[ 1 ] );
|
|
643
736
|
// returns 1.0
|
|
644
737
|
|
|
645
|
-
var im =
|
|
738
|
+
var im = imagf( v[ 1 ] );
|
|
646
739
|
// returns -1.0
|
|
647
740
|
|
|
648
741
|
v = it.next().value;
|
|
649
742
|
// returns [ 1, <Complex64> ]
|
|
650
743
|
|
|
651
|
-
re =
|
|
744
|
+
re = realf( v[ 1 ] );
|
|
652
745
|
// returns 2.0
|
|
653
746
|
|
|
654
|
-
im =
|
|
747
|
+
im = imagf( v[ 1 ] );
|
|
655
748
|
// returns -2.0
|
|
656
749
|
|
|
657
750
|
v = it.next().value;
|
|
658
751
|
// returns [ 2, <Complex64> ]
|
|
659
752
|
|
|
660
|
-
re =
|
|
753
|
+
re = realf( v[ 1 ] );
|
|
661
754
|
// returns 3.0
|
|
662
755
|
|
|
663
|
-
im =
|
|
756
|
+
im = imagf( v[ 1 ] );
|
|
664
757
|
// returns -3.0
|
|
665
758
|
|
|
666
759
|
var bool = it.next().done;
|
|
@@ -669,13 +762,13 @@ var bool = it.next().done;
|
|
|
669
762
|
|
|
670
763
|
<a name="method-get"></a>
|
|
671
764
|
|
|
672
|
-
#### Complex64Array.prototype.get(
|
|
765
|
+
#### Complex64Array.prototype.get( i )
|
|
673
766
|
|
|
674
767
|
Returns an array element located at position (index) `i`.
|
|
675
768
|
|
|
676
769
|
```javascript
|
|
677
|
-
var
|
|
678
|
-
var
|
|
770
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
771
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
679
772
|
|
|
680
773
|
var arr = new Complex64Array( 10 );
|
|
681
774
|
|
|
@@ -686,32 +779,13 @@ arr.set( [ 1.0, -1.0 ], 0 );
|
|
|
686
779
|
var z = arr.get( 0 );
|
|
687
780
|
// returns <Complex64>
|
|
688
781
|
|
|
689
|
-
var re =
|
|
782
|
+
var re = realf( z );
|
|
690
783
|
// returns 1.0
|
|
691
784
|
|
|
692
|
-
var im =
|
|
785
|
+
var im = imagf( z );
|
|
693
786
|
// returns -1.0
|
|
694
787
|
```
|
|
695
788
|
|
|
696
|
-
By default, the method returns a [64-bit complex number][@stdlib/complex/float32]. To return real and imaginary components separately, provide an array-like `object` as the first argument.
|
|
697
|
-
|
|
698
|
-
```javascript
|
|
699
|
-
var arr = new Complex64Array( 10 );
|
|
700
|
-
|
|
701
|
-
// Set the first element:
|
|
702
|
-
arr.set( [ 1.0, -1.0 ], 0 );
|
|
703
|
-
|
|
704
|
-
// Define an output array:
|
|
705
|
-
var out = [ 0.0, 0.0 ];
|
|
706
|
-
|
|
707
|
-
// Get the first element:
|
|
708
|
-
var z = arr.get( out, 0 );
|
|
709
|
-
// returns [ 1.0, -1.0 ]
|
|
710
|
-
|
|
711
|
-
var bool = ( out === z );
|
|
712
|
-
// returns true
|
|
713
|
-
```
|
|
714
|
-
|
|
715
789
|
If provided an out-of-bounds index, the method returns `undefined`.
|
|
716
790
|
|
|
717
791
|
```javascript
|
|
@@ -719,14 +793,6 @@ var arr = new Complex64Array( 10 );
|
|
|
719
793
|
|
|
720
794
|
var z = arr.get( 100 );
|
|
721
795
|
// returns undefined
|
|
722
|
-
|
|
723
|
-
var out = [ 0.0, 0.0 ];
|
|
724
|
-
|
|
725
|
-
z = arr.get( out, 100 );
|
|
726
|
-
// returns undefined
|
|
727
|
-
|
|
728
|
-
var bool = ( out === z );
|
|
729
|
-
// returns false
|
|
730
796
|
```
|
|
731
797
|
|
|
732
798
|
<a name="method-set"></a>
|
|
@@ -737,44 +803,74 @@ Sets one or more array elements.
|
|
|
737
803
|
|
|
738
804
|
```javascript
|
|
739
805
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
806
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
807
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
740
808
|
|
|
741
809
|
var arr = new Complex64Array( 10 );
|
|
742
810
|
|
|
743
811
|
// Get the first element:
|
|
744
|
-
var z = arr.get(
|
|
745
|
-
// returns
|
|
812
|
+
var z = arr.get( 0 );
|
|
813
|
+
// returns <Complex64>
|
|
814
|
+
|
|
815
|
+
var re = realf( z );
|
|
816
|
+
// returns 0.0
|
|
817
|
+
|
|
818
|
+
var im = imagf( z );
|
|
819
|
+
// returns 0.0
|
|
746
820
|
|
|
747
821
|
// Set the first element:
|
|
748
822
|
arr.set( new Complex64( 1.0, -1.0 ) );
|
|
749
823
|
|
|
750
824
|
// Get the first element:
|
|
751
|
-
z = arr.get(
|
|
752
|
-
// returns
|
|
825
|
+
z = arr.get( 0 );
|
|
826
|
+
// returns <Complex64>
|
|
827
|
+
|
|
828
|
+
re = realf( z );
|
|
829
|
+
// returns 1.0
|
|
830
|
+
|
|
831
|
+
im = imagf( z );
|
|
832
|
+
// returns -1.0
|
|
753
833
|
```
|
|
754
834
|
|
|
755
835
|
By default, the method sets array elements starting at position (index) `i = 0`. To set elements starting elsewhere in the array, provide an index argument `i`.
|
|
756
836
|
|
|
757
837
|
```javascript
|
|
758
838
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
839
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
840
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
759
841
|
|
|
760
842
|
var arr = new Complex64Array( 10 );
|
|
761
843
|
|
|
762
844
|
// Get the fifth element:
|
|
763
|
-
var z = arr.get(
|
|
764
|
-
// returns
|
|
845
|
+
var z = arr.get( 4 );
|
|
846
|
+
// returns <Complex64>
|
|
847
|
+
|
|
848
|
+
var re = realf( z );
|
|
849
|
+
// returns 0.0
|
|
850
|
+
|
|
851
|
+
var im = imagf( z );
|
|
852
|
+
// returns 0.0
|
|
765
853
|
|
|
766
854
|
// Set the fifth element:
|
|
767
855
|
arr.set( new Complex64( 1.0, -1.0 ), 4 );
|
|
768
856
|
|
|
769
857
|
// Get the fifth element:
|
|
770
|
-
z = arr.get(
|
|
771
|
-
// returns
|
|
858
|
+
z = arr.get( 4 );
|
|
859
|
+
// returns <Complex64>
|
|
860
|
+
|
|
861
|
+
re = realf( z );
|
|
862
|
+
// returns 1.0
|
|
863
|
+
|
|
864
|
+
im = imagf( z );
|
|
865
|
+
// returns -1.0
|
|
772
866
|
```
|
|
773
867
|
|
|
774
|
-
In addition to providing a complex number, to set one or more array elements, provide an array-like
|
|
868
|
+
In addition to providing a complex number, to set one or more array elements, provide an array-like object containing either complex numbers
|
|
775
869
|
|
|
776
870
|
```javascript
|
|
777
871
|
var Complex64 = require( '@stdlib/complex-float32' );
|
|
872
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
873
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
778
874
|
|
|
779
875
|
var arr = new Complex64Array( 10 );
|
|
780
876
|
|
|
@@ -789,14 +885,22 @@ var buf = [
|
|
|
789
885
|
arr.set( buf, 4 );
|
|
790
886
|
|
|
791
887
|
// Get the sixth element:
|
|
792
|
-
var z = arr.get(
|
|
793
|
-
// returns
|
|
888
|
+
var z = arr.get( 5 );
|
|
889
|
+
// returns <Complex64>
|
|
890
|
+
|
|
891
|
+
var re = realf( z );
|
|
892
|
+
// returns 2.0
|
|
893
|
+
|
|
894
|
+
var im = imagf( z );
|
|
895
|
+
// returns -2.0
|
|
794
896
|
```
|
|
795
897
|
|
|
796
898
|
or interleaved real and imaginary components
|
|
797
899
|
|
|
798
900
|
```javascript
|
|
799
901
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
902
|
+
var realf = require( '@stdlib/complex-realf' );
|
|
903
|
+
var imagf = require( '@stdlib/complex-imagf' );
|
|
800
904
|
|
|
801
905
|
var arr = new Complex64Array( 10 );
|
|
802
906
|
|
|
@@ -807,8 +911,14 @@ var buf = new Float32Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] );
|
|
|
807
911
|
arr.set( buf, 4 );
|
|
808
912
|
|
|
809
913
|
// Get the sixth element:
|
|
810
|
-
var z = arr.get(
|
|
811
|
-
// returns
|
|
914
|
+
var z = arr.get( 5 );
|
|
915
|
+
// returns <Complex64>
|
|
916
|
+
|
|
917
|
+
var re = realf( z );
|
|
918
|
+
// returns 2.0
|
|
919
|
+
|
|
920
|
+
var im = imagf( z );
|
|
921
|
+
// returns -2.0
|
|
812
922
|
```
|
|
813
923
|
|
|
814
924
|
A few notes:
|
|
@@ -855,15 +965,12 @@ var Complex64 = require( '@stdlib/complex-float32' );
|
|
|
855
965
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
856
966
|
var Complex64Array = require( '@stdlib/array-complex64' );
|
|
857
967
|
|
|
858
|
-
var arr;
|
|
859
|
-
var out;
|
|
860
|
-
|
|
861
968
|
// Create a complex array by specifying a length:
|
|
862
|
-
out = new Complex64Array( 3 );
|
|
969
|
+
var out = new Complex64Array( 3 );
|
|
863
970
|
console.log( out );
|
|
864
971
|
|
|
865
972
|
// Create a complex array from an array of complex numbers:
|
|
866
|
-
arr = [
|
|
973
|
+
var arr = [
|
|
867
974
|
new Complex64( 1.0, -1.0 ),
|
|
868
975
|
new Complex64( -3.14, 3.14 ),
|
|
869
976
|
new Complex64( 0.5, 0.5 )
|
|
@@ -899,6 +1006,22 @@ console.log( out );
|
|
|
899
1006
|
|
|
900
1007
|
<!-- /.references -->
|
|
901
1008
|
|
|
1009
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
1010
|
+
|
|
1011
|
+
<section class="related">
|
|
1012
|
+
|
|
1013
|
+
* * *
|
|
1014
|
+
|
|
1015
|
+
## See Also
|
|
1016
|
+
|
|
1017
|
+
- <span class="package-name">[`@stdlib/array/complex128`][@stdlib/array/complex128]</span><span class="delimiter">: </span><span class="description">Complex128Array.</span>
|
|
1018
|
+
- <span class="package-name">[`@stdlib/complex/cmplx`][@stdlib/complex/cmplx]</span><span class="delimiter">: </span><span class="description">create a complex number.</span>
|
|
1019
|
+
- <span class="package-name">[`@stdlib/complex/float32`][@stdlib/complex/float32]</span><span class="delimiter">: </span><span class="description">64-bit complex number.</span>
|
|
1020
|
+
|
|
1021
|
+
</section>
|
|
1022
|
+
|
|
1023
|
+
<!-- /.related -->
|
|
1024
|
+
|
|
902
1025
|
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
903
1026
|
|
|
904
1027
|
|
|
@@ -925,7 +1048,7 @@ See [LICENSE][stdlib-license].
|
|
|
925
1048
|
|
|
926
1049
|
## Copyright
|
|
927
1050
|
|
|
928
|
-
Copyright © 2016-
|
|
1051
|
+
Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
929
1052
|
|
|
930
1053
|
</section>
|
|
931
1054
|
|
|
@@ -944,9 +1067,20 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
944
1067
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-complex64/main.svg
|
|
945
1068
|
[coverage-url]: https://codecov.io/github/stdlib-js/array-complex64?branch=main
|
|
946
1069
|
|
|
1070
|
+
<!--
|
|
1071
|
+
|
|
947
1072
|
[dependencies-image]: https://img.shields.io/david/stdlib-js/array-complex64.svg
|
|
948
1073
|
[dependencies-url]: https://david-dm.org/stdlib-js/array-complex64/main
|
|
949
1074
|
|
|
1075
|
+
-->
|
|
1076
|
+
|
|
1077
|
+
[umd]: https://github.com/umdjs/umd
|
|
1078
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
1079
|
+
|
|
1080
|
+
[deno-url]: https://github.com/stdlib-js/array-complex64/tree/deno
|
|
1081
|
+
[umd-url]: https://github.com/stdlib-js/array-complex64/tree/umd
|
|
1082
|
+
[esm-url]: https://github.com/stdlib-js/array-complex64/tree/esm
|
|
1083
|
+
|
|
950
1084
|
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
951
1085
|
[chat-url]: https://gitter.im/stdlib-js/stdlib/
|
|
952
1086
|
|
|
@@ -962,6 +1096,14 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
962
1096
|
|
|
963
1097
|
[@stdlib/complex/float32]: https://www.npmjs.com/package/@stdlib/complex-float32
|
|
964
1098
|
|
|
1099
|
+
<!-- <related-links> -->
|
|
1100
|
+
|
|
1101
|
+
[@stdlib/array/complex128]: https://www.npmjs.com/package/@stdlib/array-complex128
|
|
1102
|
+
|
|
1103
|
+
[@stdlib/complex/cmplx]: https://www.npmjs.com/package/@stdlib/complex-cmplx
|
|
1104
|
+
|
|
1105
|
+
<!-- </related-links> -->
|
|
1106
|
+
|
|
965
1107
|
</section>
|
|
966
1108
|
|
|
967
1109
|
<!-- /.links -->
|