@stdlib/array-complex64 0.2.1 → 0.3.1
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 +446 -124
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/docs/types/index.d.ts +343 -61
- package/lib/from_array.js +2 -2
- package/lib/from_iterator.js +2 -2
- package/lib/from_iterator_map.js +2 -2
- package/lib/index.js +1 -1
- package/lib/main.js +599 -68
- package/package.json +30 -29
package/lib/main.js
CHANGED
|
@@ -28,6 +28,7 @@ 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 isStringArray = require( '@stdlib/assert-is-string-array' ).primitives;
|
|
31
32
|
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
|
|
32
33
|
var isFunction = require( '@stdlib/assert-is-function' );
|
|
33
34
|
var isComplexLike = require( '@stdlib/assert-is-complex-like' );
|
|
@@ -40,10 +41,10 @@ var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' );
|
|
|
40
41
|
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
41
42
|
var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );
|
|
42
43
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
43
|
-
var Complex64 = require( '@stdlib/complex-float32' );
|
|
44
|
+
var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
44
45
|
var format = require( '@stdlib/string-format' );
|
|
45
|
-
var realf = require( '@stdlib/complex-
|
|
46
|
-
var imagf = require( '@stdlib/complex-
|
|
46
|
+
var realf = require( '@stdlib/complex-float32-real' );
|
|
47
|
+
var imagf = require( '@stdlib/complex-float32-imag' );
|
|
47
48
|
var floor = require( '@stdlib/math-base-special-floor' );
|
|
48
49
|
var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' );
|
|
49
50
|
var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' );
|
|
@@ -354,7 +355,7 @@ setReadOnly( Complex64Array, 'name', 'Complex64Array' );
|
|
|
354
355
|
* // returns 1
|
|
355
356
|
*
|
|
356
357
|
* @example
|
|
357
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
358
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
358
359
|
*
|
|
359
360
|
* var arr = Complex64Array.from( [ new Complex64( 1.0, 1.0 ) ] );
|
|
360
361
|
* // returns <Complex64Array>
|
|
@@ -363,9 +364,9 @@ setReadOnly( Complex64Array, 'name', 'Complex64Array' );
|
|
|
363
364
|
* // returns 1
|
|
364
365
|
*
|
|
365
366
|
* @example
|
|
366
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
367
|
-
* var realf = require( '@stdlib/complex-
|
|
368
|
-
* var imagf = require( '@stdlib/complex-
|
|
367
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
368
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
369
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
369
370
|
*
|
|
370
371
|
* function clbk( v ) {
|
|
371
372
|
* return new Complex64( realf(v)*2.0, imagf(v)*2.0 );
|
|
@@ -550,8 +551,8 @@ setReadOnly( Complex64Array, 'of', function of() {
|
|
|
550
551
|
*
|
|
551
552
|
* @example
|
|
552
553
|
* var arr = new Complex64Array( 10 );
|
|
553
|
-
* var realf = require( '@stdlib/complex-
|
|
554
|
-
* var imagf = require( '@stdlib/complex-
|
|
554
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
555
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
555
556
|
*
|
|
556
557
|
* var z = arr.at( 0 );
|
|
557
558
|
* // returns <Complex64>
|
|
@@ -690,9 +691,9 @@ setReadOnly( Complex64Array.prototype, 'BYTES_PER_ELEMENT', Complex64Array.BYTES
|
|
|
690
691
|
* @returns {Complex64Array} modified array
|
|
691
692
|
*
|
|
692
693
|
* @example
|
|
693
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
694
|
-
* var realf = require( '@stdlib/complex-
|
|
695
|
-
* var imagf = require( '@stdlib/complex-
|
|
694
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
695
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
696
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
696
697
|
*
|
|
697
698
|
* var arr = new Complex64Array( 4 );
|
|
698
699
|
*
|
|
@@ -737,7 +738,7 @@ setReadOnly( Complex64Array.prototype, 'copyWithin', function copyWithin( target
|
|
|
737
738
|
* @returns {Iterator} iterator
|
|
738
739
|
*
|
|
739
740
|
* @example
|
|
740
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
741
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
741
742
|
*
|
|
742
743
|
* var arr = [
|
|
743
744
|
* new Complex64( 1.0, 1.0 ),
|
|
@@ -763,23 +764,21 @@ setReadOnly( Complex64Array.prototype, 'copyWithin', function copyWithin( target
|
|
|
763
764
|
* // returns true
|
|
764
765
|
*/
|
|
765
766
|
setReadOnly( Complex64Array.prototype, 'entries', function entries() {
|
|
766
|
-
var buffer;
|
|
767
767
|
var self;
|
|
768
768
|
var iter;
|
|
769
769
|
var len;
|
|
770
|
+
var buf;
|
|
770
771
|
var FLG;
|
|
771
772
|
var i;
|
|
772
|
-
var j;
|
|
773
773
|
if ( !isComplexArray( this ) ) {
|
|
774
774
|
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
775
775
|
}
|
|
776
776
|
self = this;
|
|
777
|
-
|
|
777
|
+
buf = this._buffer;
|
|
778
778
|
len = this._length;
|
|
779
779
|
|
|
780
|
-
// Initialize
|
|
780
|
+
// Initialize an iteration index:
|
|
781
781
|
i = -1;
|
|
782
|
-
j = -2;
|
|
783
782
|
|
|
784
783
|
// Create an iterator protocol-compliant object:
|
|
785
784
|
iter = {};
|
|
@@ -798,17 +797,14 @@ setReadOnly( Complex64Array.prototype, 'entries', function entries() {
|
|
|
798
797
|
* @returns {Object} iterator protocol-compliant object
|
|
799
798
|
*/
|
|
800
799
|
function next() {
|
|
801
|
-
var z;
|
|
802
800
|
i += 1;
|
|
803
801
|
if ( FLG || i >= len ) {
|
|
804
802
|
return {
|
|
805
803
|
'done': true
|
|
806
804
|
};
|
|
807
805
|
}
|
|
808
|
-
j += 2;
|
|
809
|
-
z = new Complex64( buffer[ j ], buffer[ j+1 ] );
|
|
810
806
|
return {
|
|
811
|
-
'value': [ i,
|
|
807
|
+
'value': [ i, getComplex64( buf, i ) ],
|
|
812
808
|
'done': false
|
|
813
809
|
};
|
|
814
810
|
}
|
|
@@ -857,8 +853,8 @@ setReadOnly( Complex64Array.prototype, 'entries', function entries() {
|
|
|
857
853
|
* @returns {boolean} boolean indicating whether all elements pass a test
|
|
858
854
|
*
|
|
859
855
|
* @example
|
|
860
|
-
* var realf = require( '@stdlib/complex-
|
|
861
|
-
* var imagf = require( '@stdlib/complex-
|
|
856
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
857
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
862
858
|
*
|
|
863
859
|
* function predicate( v ) {
|
|
864
860
|
* return ( realf( v ) === imagf( v ) );
|
|
@@ -904,10 +900,11 @@ setReadOnly( Complex64Array.prototype, 'every', function every( predicate, thisA
|
|
|
904
900
|
* @throws {TypeError} first argument must be a complex number
|
|
905
901
|
* @throws {TypeError} second argument must be an integer
|
|
906
902
|
* @throws {TypeError} third argument must be an integer
|
|
903
|
+
* @returns {Complex64Array} modified array
|
|
907
904
|
*
|
|
908
905
|
* @example
|
|
909
|
-
* var realf = require( '@stdlib/complex-
|
|
910
|
-
* var imagf = require( '@stdlib/complex-
|
|
906
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
907
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
911
908
|
*
|
|
912
909
|
* var arr = new Complex64Array( 3 );
|
|
913
910
|
*
|
|
@@ -922,7 +919,7 @@ setReadOnly( Complex64Array.prototype, 'every', function every( predicate, thisA
|
|
|
922
919
|
* var im = imagf( z );
|
|
923
920
|
* // returns 1.0
|
|
924
921
|
*
|
|
925
|
-
* z = arr.get(
|
|
922
|
+
* z = arr.get( 2 );
|
|
926
923
|
* // returns <Complex64>
|
|
927
924
|
*
|
|
928
925
|
* re = realf( z );
|
|
@@ -999,8 +996,8 @@ setReadOnly( Complex64Array.prototype, 'fill', function fill( value, start, end
|
|
|
999
996
|
* @returns {Complex64Array} complex number array
|
|
1000
997
|
*
|
|
1001
998
|
* @example
|
|
1002
|
-
* var realf = require( '@stdlib/complex-
|
|
1003
|
-
* var imagf = require( '@stdlib/complex-
|
|
999
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1000
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1004
1001
|
*
|
|
1005
1002
|
* function predicate( v ) {
|
|
1006
1003
|
* return ( realf( v ) === imagf( v ) );
|
|
@@ -1062,9 +1059,9 @@ setReadOnly( Complex64Array.prototype, 'filter', function filter( predicate, thi
|
|
|
1062
1059
|
* @returns {(Complex64|void)} array element or undefined
|
|
1063
1060
|
*
|
|
1064
1061
|
* @example
|
|
1065
|
-
* var realf = require( '@stdlib/complex-
|
|
1066
|
-
* var imagf = require( '@stdlib/complex-
|
|
1067
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1062
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1063
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1064
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1068
1065
|
*
|
|
1069
1066
|
* function predicate( v ) {
|
|
1070
1067
|
* return ( realf( v ) === imagf( v ) );
|
|
@@ -1117,9 +1114,9 @@ setReadOnly( Complex64Array.prototype, 'find', function find( predicate, thisArg
|
|
|
1117
1114
|
* @returns {integer} index or -1
|
|
1118
1115
|
*
|
|
1119
1116
|
* @example
|
|
1120
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1121
|
-
* var realf = require( '@stdlib/complex-
|
|
1122
|
-
* var imagf = require( '@stdlib/complex-
|
|
1117
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1118
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1119
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1123
1120
|
*
|
|
1124
1121
|
* function predicate( v ) {
|
|
1125
1122
|
* return ( realf( v ) === imagf( v ) );
|
|
@@ -1167,9 +1164,9 @@ setReadOnly( Complex64Array.prototype, 'findIndex', function findIndex( predicat
|
|
|
1167
1164
|
* @returns {(Complex64|void)} array element or undefined
|
|
1168
1165
|
*
|
|
1169
1166
|
* @example
|
|
1170
|
-
* var realf = require( '@stdlib/complex-
|
|
1171
|
-
* var imagf = require( '@stdlib/complex-
|
|
1172
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1167
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1168
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1169
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1173
1170
|
*
|
|
1174
1171
|
* function predicate( v ) {
|
|
1175
1172
|
* return ( realf( v ) === imagf( v ) );
|
|
@@ -1222,9 +1219,9 @@ setReadOnly( Complex64Array.prototype, 'findLast', function findLast( predicate,
|
|
|
1222
1219
|
* @returns {integer} index or -1
|
|
1223
1220
|
*
|
|
1224
1221
|
* @example
|
|
1225
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1226
|
-
* var realf = require( '@stdlib/complex-
|
|
1227
|
-
* var imagf = require( '@stdlib/complex-
|
|
1222
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1223
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1224
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1228
1225
|
*
|
|
1229
1226
|
* function predicate( v ) {
|
|
1230
1227
|
* return ( realf( v ) === imagf( v ) );
|
|
@@ -1271,7 +1268,7 @@ setReadOnly( Complex64Array.prototype, 'findLastIndex', function findLastIndex(
|
|
|
1271
1268
|
* @throws {TypeError} first argument must be a function
|
|
1272
1269
|
*
|
|
1273
1270
|
* @example
|
|
1274
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1271
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1275
1272
|
*
|
|
1276
1273
|
* function log( v, i ) {
|
|
1277
1274
|
* console.log( '%s: %s', i, v.toString() );
|
|
@@ -1315,8 +1312,8 @@ setReadOnly( Complex64Array.prototype, 'forEach', function forEach( fcn, thisArg
|
|
|
1315
1312
|
*
|
|
1316
1313
|
* @example
|
|
1317
1314
|
* var arr = new Complex64Array( 10 );
|
|
1318
|
-
* var realf = require( '@stdlib/complex-
|
|
1319
|
-
* var imagf = require( '@stdlib/complex-
|
|
1315
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1316
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1320
1317
|
*
|
|
1321
1318
|
* var z = arr.get( 0 );
|
|
1322
1319
|
* // returns <Complex64>
|
|
@@ -1368,7 +1365,7 @@ setReadOnly( Complex64Array.prototype, 'get', function get( idx ) {
|
|
|
1368
1365
|
* @returns {boolean} boolean indicating whether an array includes a provided value
|
|
1369
1366
|
*
|
|
1370
1367
|
* @example
|
|
1371
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1368
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1372
1369
|
*
|
|
1373
1370
|
* var arr = new Complex64Array( 5 );
|
|
1374
1371
|
*
|
|
@@ -1438,7 +1435,7 @@ setReadOnly( Complex64Array.prototype, 'includes', function includes( searchElem
|
|
|
1438
1435
|
* @returns {integer} index or -1
|
|
1439
1436
|
*
|
|
1440
1437
|
* @example
|
|
1441
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1438
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1442
1439
|
*
|
|
1443
1440
|
* var arr = new Complex64Array( 10 );
|
|
1444
1441
|
*
|
|
@@ -1540,6 +1537,107 @@ setReadOnly( Complex64Array.prototype, 'join', function join( separator ) {
|
|
|
1540
1537
|
return out.join( sep );
|
|
1541
1538
|
});
|
|
1542
1539
|
|
|
1540
|
+
/**
|
|
1541
|
+
* Returns an iterator for iterating over each index key in a typed array.
|
|
1542
|
+
*
|
|
1543
|
+
* @name keys
|
|
1544
|
+
* @memberof Complex64Array.prototype
|
|
1545
|
+
* @type {Function}
|
|
1546
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1547
|
+
* @returns {Iterator} iterator
|
|
1548
|
+
*
|
|
1549
|
+
* @example
|
|
1550
|
+
* var arr = new Complex64Array( 2 );
|
|
1551
|
+
*
|
|
1552
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
1553
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1554
|
+
*
|
|
1555
|
+
* var iter = arr.keys();
|
|
1556
|
+
*
|
|
1557
|
+
* var v = iter.next().value;
|
|
1558
|
+
* // returns 0
|
|
1559
|
+
*
|
|
1560
|
+
* v = iter.next().value;
|
|
1561
|
+
* // returns 1
|
|
1562
|
+
*
|
|
1563
|
+
* var bool = iter.next().done;
|
|
1564
|
+
* // returns true
|
|
1565
|
+
*/
|
|
1566
|
+
setReadOnly( Complex64Array.prototype, 'keys', function keys() {
|
|
1567
|
+
var self;
|
|
1568
|
+
var iter;
|
|
1569
|
+
var len;
|
|
1570
|
+
var FLG;
|
|
1571
|
+
var i;
|
|
1572
|
+
if ( !isComplexArray( this ) ) {
|
|
1573
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1574
|
+
}
|
|
1575
|
+
self = this;
|
|
1576
|
+
len = this._length;
|
|
1577
|
+
|
|
1578
|
+
// Initialize an iteration index:
|
|
1579
|
+
i = -1;
|
|
1580
|
+
|
|
1581
|
+
// Create an iterator protocol-compliant object:
|
|
1582
|
+
iter = {};
|
|
1583
|
+
setReadOnly( iter, 'next', next );
|
|
1584
|
+
setReadOnly( iter, 'return', end );
|
|
1585
|
+
|
|
1586
|
+
if ( ITERATOR_SYMBOL ) {
|
|
1587
|
+
setReadOnly( iter, ITERATOR_SYMBOL, factory );
|
|
1588
|
+
}
|
|
1589
|
+
return iter;
|
|
1590
|
+
|
|
1591
|
+
/**
|
|
1592
|
+
* Returns an iterator protocol-compliant object containing the next iterated value.
|
|
1593
|
+
*
|
|
1594
|
+
* @private
|
|
1595
|
+
* @returns {Object} iterator protocol-compliant object
|
|
1596
|
+
*/
|
|
1597
|
+
function next() {
|
|
1598
|
+
i += 1;
|
|
1599
|
+
if ( FLG || i >= len ) {
|
|
1600
|
+
return {
|
|
1601
|
+
'done': true
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
return {
|
|
1605
|
+
'value': i,
|
|
1606
|
+
'done': false
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
/**
|
|
1611
|
+
* Finishes an iterator.
|
|
1612
|
+
*
|
|
1613
|
+
* @private
|
|
1614
|
+
* @param {*} [value] - value to return
|
|
1615
|
+
* @returns {Object} iterator protocol-compliant object
|
|
1616
|
+
*/
|
|
1617
|
+
function end( value ) {
|
|
1618
|
+
FLG = true;
|
|
1619
|
+
if ( arguments.length ) {
|
|
1620
|
+
return {
|
|
1621
|
+
'value': value,
|
|
1622
|
+
'done': true
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
return {
|
|
1626
|
+
'done': true
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* Returns a new iterator.
|
|
1632
|
+
*
|
|
1633
|
+
* @private
|
|
1634
|
+
* @returns {Iterator} iterator
|
|
1635
|
+
*/
|
|
1636
|
+
function factory() {
|
|
1637
|
+
return self.keys();
|
|
1638
|
+
}
|
|
1639
|
+
});
|
|
1640
|
+
|
|
1543
1641
|
/**
|
|
1544
1642
|
* Returns the last index at which a given element can be found.
|
|
1545
1643
|
*
|
|
@@ -1554,7 +1652,7 @@ setReadOnly( Complex64Array.prototype, 'join', function join( separator ) {
|
|
|
1554
1652
|
* @returns {integer} index or -1
|
|
1555
1653
|
*
|
|
1556
1654
|
* @example
|
|
1557
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1655
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1558
1656
|
*
|
|
1559
1657
|
* var arr = new Complex64Array( 5 );
|
|
1560
1658
|
*
|
|
@@ -1643,9 +1741,9 @@ setReadOnlyAccessor( Complex64Array.prototype, 'length', function get() {
|
|
|
1643
1741
|
* @returns {Complex64Array} complex number array
|
|
1644
1742
|
*
|
|
1645
1743
|
* @example
|
|
1646
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
1647
|
-
* var realf = require( '@stdlib/complex-
|
|
1648
|
-
* var imagf = require( '@stdlib/complex-
|
|
1744
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
1745
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1746
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1649
1747
|
*
|
|
1650
1748
|
* function scale( v, i ) {
|
|
1651
1749
|
* return new Complex64( 2.0*realf( v ), 2.0*imagf( v ) );
|
|
@@ -1713,9 +1811,9 @@ setReadOnly( Complex64Array.prototype, 'map', function map( fcn, thisArg ) {
|
|
|
1713
1811
|
* @returns {*} accumulated result
|
|
1714
1812
|
*
|
|
1715
1813
|
* @example
|
|
1716
|
-
* var realf = require( '@stdlib/complex-
|
|
1717
|
-
* var imagf = require( '@stdlib/complex-
|
|
1718
|
-
* var caddf = require( '@stdlib/
|
|
1814
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1815
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1816
|
+
* var caddf = require( '@stdlib/complex-float32-base-add' );
|
|
1719
1817
|
*
|
|
1720
1818
|
* var arr = new Complex64Array( 3 );
|
|
1721
1819
|
*
|
|
@@ -1764,6 +1862,71 @@ setReadOnly( Complex64Array.prototype, 'reduce', function reduce( reducer, initi
|
|
|
1764
1862
|
return acc;
|
|
1765
1863
|
});
|
|
1766
1864
|
|
|
1865
|
+
/**
|
|
1866
|
+
* Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion.
|
|
1867
|
+
*
|
|
1868
|
+
* @name reduceRight
|
|
1869
|
+
* @memberof Complex64Array.prototype
|
|
1870
|
+
* @type {Function}
|
|
1871
|
+
* @param {Function} reducer - callback function
|
|
1872
|
+
* @param {*} [initialValue] - initial value
|
|
1873
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
1874
|
+
* @throws {TypeError} first argument must be a function
|
|
1875
|
+
* @throws {Error} if not provided an initial value, the array must have at least one element
|
|
1876
|
+
* @returns {*} accumulated result
|
|
1877
|
+
*
|
|
1878
|
+
* @example
|
|
1879
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1880
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1881
|
+
* var caddf = require( '@stdlib/complex-float32-base-add' );
|
|
1882
|
+
*
|
|
1883
|
+
* var arr = new Complex64Array( 3 );
|
|
1884
|
+
*
|
|
1885
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
1886
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
1887
|
+
* arr.set( [ 3.0, 3.0 ], 2 );
|
|
1888
|
+
*
|
|
1889
|
+
* var z = arr.reduceRight( caddf );
|
|
1890
|
+
* // returns <Complex64>
|
|
1891
|
+
*
|
|
1892
|
+
* var re = realf( z );
|
|
1893
|
+
* // returns 6.0
|
|
1894
|
+
*
|
|
1895
|
+
* var im = imagf( z );
|
|
1896
|
+
* // returns 6.0
|
|
1897
|
+
*/
|
|
1898
|
+
setReadOnly( Complex64Array.prototype, 'reduceRight', function reduceRight( reducer, initialValue ) {
|
|
1899
|
+
var buf;
|
|
1900
|
+
var acc;
|
|
1901
|
+
var len;
|
|
1902
|
+
var v;
|
|
1903
|
+
var i;
|
|
1904
|
+
|
|
1905
|
+
if ( !isComplexArray( this ) ) {
|
|
1906
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
1907
|
+
}
|
|
1908
|
+
if ( !isFunction( reducer ) ) {
|
|
1909
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) );
|
|
1910
|
+
}
|
|
1911
|
+
buf = this._buffer;
|
|
1912
|
+
len = this._length;
|
|
1913
|
+
if ( arguments.length > 1 ) {
|
|
1914
|
+
acc = initialValue;
|
|
1915
|
+
i = len-1;
|
|
1916
|
+
} else {
|
|
1917
|
+
if ( len === 0 ) {
|
|
1918
|
+
throw new Error( 'invalid operation. If not provided an initial value, an array must contain at least one element.' );
|
|
1919
|
+
}
|
|
1920
|
+
acc = getComplex64( buf, len-1 );
|
|
1921
|
+
i = len-2;
|
|
1922
|
+
}
|
|
1923
|
+
for ( ; i >= 0; i-- ) {
|
|
1924
|
+
v = getComplex64( buf, i );
|
|
1925
|
+
acc = reducer( acc, v, i, this );
|
|
1926
|
+
}
|
|
1927
|
+
return acc;
|
|
1928
|
+
});
|
|
1929
|
+
|
|
1767
1930
|
/**
|
|
1768
1931
|
* Reverses an array in-place.
|
|
1769
1932
|
*
|
|
@@ -1774,8 +1937,8 @@ setReadOnly( Complex64Array.prototype, 'reduce', function reduce( reducer, initi
|
|
|
1774
1937
|
* @returns {Complex64Array} reversed array
|
|
1775
1938
|
*
|
|
1776
1939
|
* @example
|
|
1777
|
-
* var realf = require( '@stdlib/complex-
|
|
1778
|
-
* var imagf = require( '@stdlib/complex-
|
|
1940
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
1941
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1779
1942
|
*
|
|
1780
1943
|
* var arr = new Complex64Array( 3 );
|
|
1781
1944
|
*
|
|
@@ -1875,8 +2038,8 @@ setReadOnly( Complex64Array.prototype, 'reverse', function reverse() {
|
|
|
1875
2038
|
* @returns {void}
|
|
1876
2039
|
*
|
|
1877
2040
|
* @example
|
|
1878
|
-
* var realf = require( '@stdlib/complex-
|
|
1879
|
-
* var imagf = require( '@stdlib/complex-
|
|
2041
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2042
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
1880
2043
|
*
|
|
1881
2044
|
* var arr = new Complex64Array( 10 );
|
|
1882
2045
|
*
|
|
@@ -2043,8 +2206,8 @@ setReadOnly( Complex64Array.prototype, 'set', function set( value ) {
|
|
|
2043
2206
|
* @returns {Complex64Array} complex number array
|
|
2044
2207
|
*
|
|
2045
2208
|
* @example
|
|
2046
|
-
* var realf = require( '@stdlib/complex-
|
|
2047
|
-
* var imagf = require( '@stdlib/complex-
|
|
2209
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2210
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
2048
2211
|
*
|
|
2049
2212
|
* var arr = new Complex64Array( 5 );
|
|
2050
2213
|
*
|
|
@@ -2172,8 +2335,8 @@ setReadOnly( Complex64Array.prototype, 'slice', function slice( start, end ) {
|
|
|
2172
2335
|
* @returns {boolean} boolean indicating whether at least one element passes a test
|
|
2173
2336
|
*
|
|
2174
2337
|
* @example
|
|
2175
|
-
* var realf = require( '@stdlib/complex-
|
|
2176
|
-
* var imagf = require( '@stdlib/complex-
|
|
2338
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2339
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
2177
2340
|
*
|
|
2178
2341
|
* function predicate( v ) {
|
|
2179
2342
|
* return ( realf( v ) === imagf( v ) );
|
|
@@ -2206,6 +2369,108 @@ setReadOnly( Complex64Array.prototype, 'some', function some( predicate, thisArg
|
|
|
2206
2369
|
return false;
|
|
2207
2370
|
});
|
|
2208
2371
|
|
|
2372
|
+
/**
|
|
2373
|
+
* Sorts an array in-place.
|
|
2374
|
+
*
|
|
2375
|
+
* @name sort
|
|
2376
|
+
* @memberof Complex64Array.prototype
|
|
2377
|
+
* @type {Function}
|
|
2378
|
+
* @param {Function} compareFcn - comparison function
|
|
2379
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2380
|
+
* @throws {TypeError} first argument must be a function
|
|
2381
|
+
* @returns {Complex64Array} sorted array
|
|
2382
|
+
*
|
|
2383
|
+
* @example
|
|
2384
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2385
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
2386
|
+
*
|
|
2387
|
+
* function compare( a, b ) {
|
|
2388
|
+
* var re1;
|
|
2389
|
+
* var re2;
|
|
2390
|
+
* var im1;
|
|
2391
|
+
* var im2;
|
|
2392
|
+
* re1 = realf( a );
|
|
2393
|
+
* re2 = realf( b );
|
|
2394
|
+
* if ( re1 < re2 ) {
|
|
2395
|
+
* return -1;
|
|
2396
|
+
* }
|
|
2397
|
+
* if ( re1 > re2 ) {
|
|
2398
|
+
* return 1;
|
|
2399
|
+
* }
|
|
2400
|
+
* im1 = imagf( a );
|
|
2401
|
+
* im2 = imagf( b );
|
|
2402
|
+
* if ( im1 < im2 ) {
|
|
2403
|
+
* return -1;
|
|
2404
|
+
* }
|
|
2405
|
+
* if ( im1 > im2 ) {
|
|
2406
|
+
* return 1;
|
|
2407
|
+
* }
|
|
2408
|
+
* return 0;
|
|
2409
|
+
* }
|
|
2410
|
+
*
|
|
2411
|
+
* var arr = new Complex64Array( 3 );
|
|
2412
|
+
*
|
|
2413
|
+
* arr.set( [ 3.0, -3.0 ], 0 );
|
|
2414
|
+
* arr.set( [ 1.0, -1.0 ], 1 );
|
|
2415
|
+
* arr.set( [ 2.0, -2.0 ], 2 );
|
|
2416
|
+
*
|
|
2417
|
+
* var out = arr.sort( compare );
|
|
2418
|
+
* // returns <Complex64Array>
|
|
2419
|
+
*
|
|
2420
|
+
* var z = out.get( 0 );
|
|
2421
|
+
* // returns <Complex64>
|
|
2422
|
+
*
|
|
2423
|
+
* var re = realf( z );
|
|
2424
|
+
* // returns 1.0
|
|
2425
|
+
*
|
|
2426
|
+
* var im = imagf( z );
|
|
2427
|
+
* // returns -1.0
|
|
2428
|
+
*
|
|
2429
|
+
* z = out.get( 1 );
|
|
2430
|
+
* // returns <Complex64>
|
|
2431
|
+
*
|
|
2432
|
+
* re = realf( z );
|
|
2433
|
+
* // returns 2.0
|
|
2434
|
+
*
|
|
2435
|
+
* im = imagf( z );
|
|
2436
|
+
* // returns -2.0
|
|
2437
|
+
*
|
|
2438
|
+
* z = out.get( 2 );
|
|
2439
|
+
* // returns <Complex64>
|
|
2440
|
+
*
|
|
2441
|
+
* re = realf( z );
|
|
2442
|
+
* // returns 3.0
|
|
2443
|
+
*
|
|
2444
|
+
* im = imagf( z );
|
|
2445
|
+
* // returns -3.0
|
|
2446
|
+
*/
|
|
2447
|
+
setReadOnly( Complex64Array.prototype, 'sort', function sort( compareFcn ) {
|
|
2448
|
+
var tmp;
|
|
2449
|
+
var buf;
|
|
2450
|
+
var len;
|
|
2451
|
+
var i;
|
|
2452
|
+
var j;
|
|
2453
|
+
if ( !isComplexArray( this ) ) {
|
|
2454
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2455
|
+
}
|
|
2456
|
+
if ( !isFunction( compareFcn ) ) {
|
|
2457
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) );
|
|
2458
|
+
}
|
|
2459
|
+
buf = this._buffer;
|
|
2460
|
+
len = this._length;
|
|
2461
|
+
tmp = [];
|
|
2462
|
+
for ( i = 0; i < len; i++ ) {
|
|
2463
|
+
tmp.push( getComplex64( buf, i ) );
|
|
2464
|
+
}
|
|
2465
|
+
tmp.sort( compareFcn );
|
|
2466
|
+
for ( i = 0; i < len; i++ ) {
|
|
2467
|
+
j = 2 * i;
|
|
2468
|
+
buf[ j ] = realf( tmp[i] );
|
|
2469
|
+
buf[ j+1 ] = imagf( tmp[i] );
|
|
2470
|
+
}
|
|
2471
|
+
return this;
|
|
2472
|
+
});
|
|
2473
|
+
|
|
2209
2474
|
/**
|
|
2210
2475
|
* Creates a new typed array view over the same underlying `ArrayBuffer` and with the same underlying data type as the host array.
|
|
2211
2476
|
*
|
|
@@ -2220,8 +2485,8 @@ setReadOnly( Complex64Array.prototype, 'some', function some( predicate, thisArg
|
|
|
2220
2485
|
* @returns {Complex64Array} subarray
|
|
2221
2486
|
*
|
|
2222
2487
|
* @example
|
|
2223
|
-
* var realf = require( '@stdlib/complex-
|
|
2224
|
-
* var imagf = require( '@stdlib/complex-
|
|
2488
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2489
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
2225
2490
|
*
|
|
2226
2491
|
* var arr = new Complex64Array( 5 );
|
|
2227
2492
|
*
|
|
@@ -2330,6 +2595,59 @@ setReadOnly( Complex64Array.prototype, 'subarray', function subarray( begin, end
|
|
|
2330
2595
|
return new this.constructor( buf.buffer, offset, ( len < 0 ) ? 0 : len );
|
|
2331
2596
|
});
|
|
2332
2597
|
|
|
2598
|
+
/**
|
|
2599
|
+
* Serializes an array as a locale-specific string.
|
|
2600
|
+
*
|
|
2601
|
+
* @name toLocaleString
|
|
2602
|
+
* @memberof Complex64Array.prototype
|
|
2603
|
+
* @type {Function}
|
|
2604
|
+
* @param {(string|Array<string>)} [locales] - locale identifier(s)
|
|
2605
|
+
* @param {Object} [options] - configuration options
|
|
2606
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2607
|
+
* @throws {TypeError} first argument must be a string or an array of strings
|
|
2608
|
+
* @throws {TypeError} options argument must be an object
|
|
2609
|
+
* @returns {string} string representation
|
|
2610
|
+
*
|
|
2611
|
+
* @example
|
|
2612
|
+
* var arr = new Complex64Array( 2 );
|
|
2613
|
+
*
|
|
2614
|
+
* arr.set( [ 1.0, 1.0 ], 0 );
|
|
2615
|
+
* arr.set( [ 2.0, 2.0 ], 1 );
|
|
2616
|
+
*
|
|
2617
|
+
* var str = arr.toLocaleString();
|
|
2618
|
+
* // returns '1 + 1i,2 + 2i'
|
|
2619
|
+
*/
|
|
2620
|
+
setReadOnly( Complex64Array.prototype, 'toLocaleString', function toLocaleString( locales, options ) {
|
|
2621
|
+
var opts;
|
|
2622
|
+
var loc;
|
|
2623
|
+
var out;
|
|
2624
|
+
var buf;
|
|
2625
|
+
var i;
|
|
2626
|
+
if ( !isComplexArray( this ) ) {
|
|
2627
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2628
|
+
}
|
|
2629
|
+
if ( arguments.length === 0 ) {
|
|
2630
|
+
loc = [];
|
|
2631
|
+
} else if ( isString( locales ) || isStringArray( locales ) ) {
|
|
2632
|
+
loc = locales;
|
|
2633
|
+
} else {
|
|
2634
|
+
throw new TypeError( format( 'invalid argument. First argument must be a string or an array of strings. Value: `%s`.', locales ) );
|
|
2635
|
+
}
|
|
2636
|
+
if ( arguments.length < 2 ) {
|
|
2637
|
+
opts = {};
|
|
2638
|
+
} else if ( isObject( options ) ) {
|
|
2639
|
+
opts = options;
|
|
2640
|
+
} else {
|
|
2641
|
+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
2642
|
+
}
|
|
2643
|
+
buf = this._buffer;
|
|
2644
|
+
out = [];
|
|
2645
|
+
for ( i = 0; i < this._length; i++ ) {
|
|
2646
|
+
out.push( getComplex64( buf, i ).toLocaleString( loc, opts ) );
|
|
2647
|
+
}
|
|
2648
|
+
return out.join( ',' );
|
|
2649
|
+
});
|
|
2650
|
+
|
|
2333
2651
|
/**
|
|
2334
2652
|
* Returns a new typed array containing the elements in reversed order.
|
|
2335
2653
|
*
|
|
@@ -2340,8 +2658,8 @@ setReadOnly( Complex64Array.prototype, 'subarray', function subarray( begin, end
|
|
|
2340
2658
|
* @returns {Complex64Array} reversed array
|
|
2341
2659
|
*
|
|
2342
2660
|
* @example
|
|
2343
|
-
* var realf = require( '@stdlib/complex-
|
|
2344
|
-
* var imagf = require( '@stdlib/complex-
|
|
2661
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2662
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
2345
2663
|
*
|
|
2346
2664
|
* var arr = new Complex64Array( 3 );
|
|
2347
2665
|
*
|
|
@@ -2401,6 +2719,102 @@ setReadOnly( Complex64Array.prototype, 'toReversed', function toReversed() {
|
|
|
2401
2719
|
return out;
|
|
2402
2720
|
});
|
|
2403
2721
|
|
|
2722
|
+
/**
|
|
2723
|
+
* Returns a new typed array containing the elements in sorted order.
|
|
2724
|
+
*
|
|
2725
|
+
* @name toSorted
|
|
2726
|
+
* @memberof Complex64Array.prototype
|
|
2727
|
+
* @type {Function}
|
|
2728
|
+
* @param {Function} compareFcn - comparison function
|
|
2729
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2730
|
+
* @throws {TypeError} first argument must be a function
|
|
2731
|
+
* @returns {Complex64Array} sorted array
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2735
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
2736
|
+
*
|
|
2737
|
+
* function compare( a, b ) {
|
|
2738
|
+
* var re1;
|
|
2739
|
+
* var re2;
|
|
2740
|
+
* var im1;
|
|
2741
|
+
* var im2;
|
|
2742
|
+
* re1 = realf( a );
|
|
2743
|
+
* re2 = realf( b );
|
|
2744
|
+
* if ( re1 < re2 ) {
|
|
2745
|
+
* return -1;
|
|
2746
|
+
* }
|
|
2747
|
+
* if ( re1 > re2 ) {
|
|
2748
|
+
* return 1;
|
|
2749
|
+
* }
|
|
2750
|
+
* im1 = imagf( a );
|
|
2751
|
+
* im2 = imagf( b );
|
|
2752
|
+
* if ( im1 < im2 ) {
|
|
2753
|
+
* return -1;
|
|
2754
|
+
* }
|
|
2755
|
+
* if ( im1 > im2 ) {
|
|
2756
|
+
* return 1;
|
|
2757
|
+
* }
|
|
2758
|
+
* return 0;
|
|
2759
|
+
* }
|
|
2760
|
+
*
|
|
2761
|
+
* var arr = new Complex64Array( 3 );
|
|
2762
|
+
*
|
|
2763
|
+
* arr.set( [ 3.0, -3.0 ], 0 );
|
|
2764
|
+
* arr.set( [ 1.0, -1.0 ], 1 );
|
|
2765
|
+
* arr.set( [ 2.0, -2.0 ], 2 );
|
|
2766
|
+
*
|
|
2767
|
+
* var out = arr.sort( compare );
|
|
2768
|
+
* // returns <Complex64Array>
|
|
2769
|
+
*
|
|
2770
|
+
* var z = out.get( 0 );
|
|
2771
|
+
* // returns <Complex64>
|
|
2772
|
+
*
|
|
2773
|
+
* var re = realf( z );
|
|
2774
|
+
* // returns 1.0
|
|
2775
|
+
*
|
|
2776
|
+
* var im = imagf( z );
|
|
2777
|
+
* // returns -1.0
|
|
2778
|
+
*
|
|
2779
|
+
* z = out.get( 1 );
|
|
2780
|
+
* // returns <Complex64>
|
|
2781
|
+
*
|
|
2782
|
+
* re = realf( z );
|
|
2783
|
+
* // returns 2.0
|
|
2784
|
+
*
|
|
2785
|
+
* im = imagf( z );
|
|
2786
|
+
* // returns -2.0
|
|
2787
|
+
*
|
|
2788
|
+
* z = out.get( 2 );
|
|
2789
|
+
* // returns <Complex64>
|
|
2790
|
+
*
|
|
2791
|
+
* re = realf( z );
|
|
2792
|
+
* // returns 3.0
|
|
2793
|
+
*
|
|
2794
|
+
* im = imagf( z );
|
|
2795
|
+
* // returns -3.0
|
|
2796
|
+
*/
|
|
2797
|
+
setReadOnly( Complex64Array.prototype, 'toSorted', function toSorted( compareFcn ) {
|
|
2798
|
+
var tmp;
|
|
2799
|
+
var buf;
|
|
2800
|
+
var len;
|
|
2801
|
+
var i;
|
|
2802
|
+
if ( !isComplexArray( this ) ) {
|
|
2803
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2804
|
+
}
|
|
2805
|
+
if ( !isFunction( compareFcn ) ) {
|
|
2806
|
+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) );
|
|
2807
|
+
}
|
|
2808
|
+
buf = this._buffer;
|
|
2809
|
+
len = this._length;
|
|
2810
|
+
tmp = [];
|
|
2811
|
+
for ( i = 0; i < len; i++ ) {
|
|
2812
|
+
tmp.push( getComplex64( buf, i ) );
|
|
2813
|
+
}
|
|
2814
|
+
tmp.sort( compareFcn );
|
|
2815
|
+
return new Complex64Array( tmp );
|
|
2816
|
+
});
|
|
2817
|
+
|
|
2404
2818
|
/**
|
|
2405
2819
|
* Serializes an array as a string.
|
|
2406
2820
|
*
|
|
@@ -2434,6 +2848,123 @@ setReadOnly( Complex64Array.prototype, 'toString', function toString() {
|
|
|
2434
2848
|
return out.join( ',' );
|
|
2435
2849
|
});
|
|
2436
2850
|
|
|
2851
|
+
/**
|
|
2852
|
+
* Returns an iterator for iterating over each value in a typed array.
|
|
2853
|
+
*
|
|
2854
|
+
* @name values
|
|
2855
|
+
* @memberof Complex64Array.prototype
|
|
2856
|
+
* @type {Function}
|
|
2857
|
+
* @throws {TypeError} `this` must be a complex number array
|
|
2858
|
+
* @returns {Iterator} iterator
|
|
2859
|
+
*
|
|
2860
|
+
* @example
|
|
2861
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2862
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
2863
|
+
* var arr = new Complex64Array( 2 );
|
|
2864
|
+
*
|
|
2865
|
+
* arr.set( [ 1.0, -1.0 ], 0 );
|
|
2866
|
+
* arr.set( [ 2.0, -2.0 ], 1 );
|
|
2867
|
+
*
|
|
2868
|
+
* var iter = arr.values();
|
|
2869
|
+
*
|
|
2870
|
+
* var v = iter.next().value;
|
|
2871
|
+
* // returns <Complex64>
|
|
2872
|
+
*
|
|
2873
|
+
* var re = realf( v );
|
|
2874
|
+
* // returns 1.0
|
|
2875
|
+
*
|
|
2876
|
+
* var im = imagf( v );
|
|
2877
|
+
* // returns -1.0
|
|
2878
|
+
*
|
|
2879
|
+
* v = iter.next().value;
|
|
2880
|
+
* // returns <Complex64>
|
|
2881
|
+
*
|
|
2882
|
+
* re = realf( v );
|
|
2883
|
+
* // returns 2.0
|
|
2884
|
+
*
|
|
2885
|
+
* im = imagf( v );
|
|
2886
|
+
* // returns -2.0
|
|
2887
|
+
*
|
|
2888
|
+
* var bool = iter.next().done;
|
|
2889
|
+
* // returns true
|
|
2890
|
+
*/
|
|
2891
|
+
setReadOnly( Complex64Array.prototype, 'values', function values() {
|
|
2892
|
+
var iter;
|
|
2893
|
+
var self;
|
|
2894
|
+
var len;
|
|
2895
|
+
var FLG;
|
|
2896
|
+
var buf;
|
|
2897
|
+
var i;
|
|
2898
|
+
if ( !isComplexArray( this ) ) {
|
|
2899
|
+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
|
|
2900
|
+
}
|
|
2901
|
+
self = this;
|
|
2902
|
+
buf = this._buffer;
|
|
2903
|
+
len = this._length;
|
|
2904
|
+
|
|
2905
|
+
// Initialize an iteration index:
|
|
2906
|
+
i = -1;
|
|
2907
|
+
|
|
2908
|
+
// Create an iterator protocol-compliant object:
|
|
2909
|
+
iter = {};
|
|
2910
|
+
setReadOnly( iter, 'next', next );
|
|
2911
|
+
setReadOnly( iter, 'return', end );
|
|
2912
|
+
|
|
2913
|
+
if ( ITERATOR_SYMBOL ) {
|
|
2914
|
+
setReadOnly( iter, ITERATOR_SYMBOL, factory );
|
|
2915
|
+
}
|
|
2916
|
+
return iter;
|
|
2917
|
+
|
|
2918
|
+
/**
|
|
2919
|
+
* Returns an iterator protocol-compliant object containing the next iterated value.
|
|
2920
|
+
*
|
|
2921
|
+
* @private
|
|
2922
|
+
* @returns {Object} iterator protocol-compliant object
|
|
2923
|
+
*/
|
|
2924
|
+
function next() {
|
|
2925
|
+
i += 1;
|
|
2926
|
+
if ( FLG || i >= len ) {
|
|
2927
|
+
return {
|
|
2928
|
+
'done': true
|
|
2929
|
+
};
|
|
2930
|
+
}
|
|
2931
|
+
return {
|
|
2932
|
+
'value': getComplex64( buf, i ),
|
|
2933
|
+
'done': false
|
|
2934
|
+
};
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
/**
|
|
2938
|
+
* Finishes an iterator.
|
|
2939
|
+
*
|
|
2940
|
+
* @private
|
|
2941
|
+
* @param {*} [value] - value to return
|
|
2942
|
+
* @returns {Object} iterator protocol-compliant object
|
|
2943
|
+
*/
|
|
2944
|
+
function end( value ) {
|
|
2945
|
+
FLG = true;
|
|
2946
|
+
if ( arguments.length ) {
|
|
2947
|
+
return {
|
|
2948
|
+
'value': value,
|
|
2949
|
+
'done': true
|
|
2950
|
+
};
|
|
2951
|
+
}
|
|
2952
|
+
return {
|
|
2953
|
+
'done': true
|
|
2954
|
+
};
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
/**
|
|
2958
|
+
* Returns a new iterator.
|
|
2959
|
+
*
|
|
2960
|
+
* @private
|
|
2961
|
+
* @returns {Iterator} iterator
|
|
2962
|
+
*/
|
|
2963
|
+
function factory() {
|
|
2964
|
+
return self.values();
|
|
2965
|
+
}
|
|
2966
|
+
});
|
|
2967
|
+
|
|
2437
2968
|
/**
|
|
2438
2969
|
* Returns a new typed array with the element at a provided index replaced with a provided value.
|
|
2439
2970
|
*
|
|
@@ -2449,9 +2980,9 @@ setReadOnly( Complex64Array.prototype, 'toString', function toString() {
|
|
|
2449
2980
|
* @returns {Complex64Array} new typed array
|
|
2450
2981
|
*
|
|
2451
2982
|
* @example
|
|
2452
|
-
* var realf = require( '@stdlib/complex-
|
|
2453
|
-
* var imagf = require( '@stdlib/complex-
|
|
2454
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
2983
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
2984
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
2985
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
2455
2986
|
*
|
|
2456
2987
|
* var arr = new Complex64Array( 3 );
|
|
2457
2988
|
*
|