README.md (21276B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Complex64Array 22 23 > 64-bit complex number array. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var Complex64Array = require( '@stdlib/array/complex64' ); 41 ``` 42 43 <a name="constructor"></a> 44 45 #### Complex64Array() 46 47 Creates a 64-bit complex number array. 48 49 ```javascript 50 var arr = new Complex64Array(); 51 // returns <Complex64Array> 52 ``` 53 54 #### Complex64Array( length ) 55 56 Creates a 64-bit complex number array having a specified `length`. 57 58 ```javascript 59 var arr = new Complex64Array( 10 ); 60 // returns <Complex64Array> 61 62 var len = arr.length; 63 // returns 10 64 ``` 65 66 #### Complex64Array( typedarray ) 67 68 Creates a 64-bit complex number array from a [typed array][@stdlib/array/typed] containing interleaves real and imaginary components. 69 70 ```javascript 71 var Float32Array = require( '@stdlib/array/float32' ); 72 73 var buf = new Float32Array( [ 1.0, -1.0, 2.0, -2.0 ] ); // [ re, im, re, im ] 74 // returns <Float32Array>[ 1.0, -1.0, 2.0, -2.0 ] 75 76 var arr = new Complex64Array( buf ); 77 // returns <Complex64Array> 78 79 var len = arr.length; 80 // returns 2 81 ``` 82 83 #### Complex64Array( obj ) 84 85 Creates a 64-bit complex number array from an array-like `object` or iterable. 86 87 ```javascript 88 var Complex64 = require( '@stdlib/complex/float32' ); 89 90 // From an array of interleaved real and imaginary components: 91 var arr1 = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); 92 // returns <Complex64Array> 93 94 var len = arr1.length; 95 // returns 2 96 97 // From an array containing complex numbers: 98 var buf = [ new Complex64( 1.0, -1.0 ), new Complex64( 2.0, -2.0 ) ]; 99 var arr2 = new Complex64Array( buf ); 100 101 len = arr2.length; 102 // returns 2 103 ``` 104 105 #### Complex64Array( buffer\[, byteOffset\[, length]] ) 106 107 Returns a 64-bit complex number array view of an [`ArrayBuffer`][@stdlib/array/buffer]. 108 109 ```javascript 110 var ArrayBuffer = require( '@stdlib/array/buffer' ); 111 var buf = new ArrayBuffer( 240 ); 112 113 var arr1 = new Complex64Array( buf ); 114 // returns <Complex64Array> 115 116 var len = arr1.length; 117 // returns 30 118 119 var arr2 = new Complex64Array( buf, 8 ); 120 // returns <Complex64Array> 121 122 len = arr2.length; 123 // returns 29 124 125 var arr3 = new Complex64Array( buf, 8, 20 ); 126 // returns <Complex64Array> 127 128 len = arr3.length; 129 // returns 20 130 ``` 131 132 * * * 133 134 ### Properties 135 136 <a name="static-prop-bytes-per-element"></a> 137 138 #### Complex64Array.BYTES_PER_ELEMENT 139 140 Static property returning the size (in bytes) of each array element. 141 142 ```javascript 143 var nbytes = Complex64Array.BYTES_PER_ELEMENT; 144 // returns 8 145 ``` 146 147 <a name="static-prop-name"></a> 148 149 #### Complex64Array.name 150 151 Static property returning the constructor name. 152 153 ```javascript 154 var str = Complex64Array.name; 155 // returns 'Complex64Array' 156 ``` 157 158 <a name="prop-buffer"></a> 159 160 #### Complex64Array.prototype.buffer 161 162 Pointer to the underlying data buffer. 163 164 ```javascript 165 var arr = new Complex64Array( 2 ); 166 // returns <Complex64Array> 167 168 var buf = arr.buffer; 169 // returns <ArrayBuffer> 170 ``` 171 172 <a name="prop-byte-length"></a> 173 174 #### Complex64Array.prototype.byteLength 175 176 Size (in bytes) of the array. 177 178 ```javascript 179 var arr = new Complex64Array( 10 ); 180 // returns <Complex64Array> 181 182 var nbytes = arr.byteLength; 183 // returns 80 184 ``` 185 186 <a name="prop-byte-offset"></a> 187 188 #### Complex64Array.prototype.byteOffset 189 190 Offset (in bytes) of the array from the start of its underlying `ArrayBuffer`. 191 192 ```javascript 193 var ArrayBuffer = require( '@stdlib/array/buffer' ); 194 195 var arr = new Complex64Array( 10 ); 196 // returns <Complex64Array> 197 198 var offset = arr.byteOffset; 199 // returns 0 200 201 var buf = new ArrayBuffer( 240 ); 202 arr = new Complex64Array( buf, 64 ); 203 // returns <Complex64Array> 204 205 offset = arr.byteOffset; 206 // returns 64 207 ``` 208 209 <a name="prop-bytes-per-element"></a> 210 211 #### Complex64Array.prototype.BYTES_PER_ELEMENT 212 213 Size (in bytes) of each array element. 214 215 ```javascript 216 var arr = new Complex64Array( 10 ); 217 // returns <Complex64Array> 218 219 var nbytes = arr.BYTES_PER_ELEMENT; 220 // returns 8 221 ``` 222 223 <a name="prop-length"></a> 224 225 #### Complex64Array.prototype.length 226 227 Number of array elements. 228 229 ```javascript 230 var arr = new Complex64Array( 10 ); 231 // returns <Complex64Array> 232 233 var len = arr.length; 234 // returns 10 235 ``` 236 237 * * * 238 239 ### Methods 240 241 <a name="static-method-from"></a> 242 243 #### Complex64Array.from( src\[, clbk\[, thisArg]] ) 244 245 Creates a new 64-bit complex number array from an array-like `object` or an iterable. 246 247 ```javascript 248 var Complex64 = require( '@stdlib/complex/float32' ); 249 250 // Create an array from interleaved real and imaginary components: 251 var arr = Complex64Array.from( [ 1.0, -1.0 ] ); 252 // returns <Complex64Array> 253 254 var len = arr.length; 255 // returns 1 256 257 // Create an array from an array of complex numbers: 258 arr = Complex64Array.from( [ new Complex64( 1.0, -1.0 ) ] ); 259 // returns <Complex64Array> 260 261 len = arr.length; 262 // returns 1 263 ``` 264 265 The iterator returned by an iterable must return either a complex number or an array-like `object` containing a real and imaginary component. 266 267 ```javascript 268 var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); 269 var Float32Array = require( '@stdlib/array/float32' ); 270 var real = require( '@stdlib/complex/real' ); 271 var imag = require( '@stdlib/complex/imag' ); 272 273 var iter; 274 var arr; 275 var len; 276 var re; 277 var im; 278 var z; 279 280 // Define a function which returns an iterator protocol-compliant object... 281 function iterable() { 282 var buf = new Float32Array( 2 ); 283 var i = 0; 284 return { 285 'next': next 286 }; 287 288 function next() { 289 i += 1; 290 if ( i < 3 ) { 291 // Reuse allocated memory... 292 buf[ 0 ] = i; 293 buf[ 1 ] = -i; 294 return { 295 'value': buf 296 }; 297 } 298 return { 299 'done': true 300 }; 301 } 302 } 303 304 if ( ITERATOR_SYMBOL === null ) { 305 console.error( 'Environment does not support iterables.' ); 306 } else { 307 // Create an iterable: 308 iter = {}; 309 iter[ ITERATOR_SYMBOL ] = iterable; 310 311 // Generate a complex number array: 312 arr = Complex64Array.from( iter ); 313 // returns <Complex64Array> 314 315 len = arr.length; 316 // returns 2 317 318 z = arr.get( 0 ); 319 // returns <Complex64> 320 321 re = real( z ); 322 // returns 1.0 323 324 im = imag( z ); 325 // returns -1.0 326 } 327 ``` 328 329 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 330 331 ```javascript 332 var Complex64 = require( '@stdlib/complex/float32' ); 333 var real = require( '@stdlib/complex/real' ); 334 var imag = require( '@stdlib/complex/imag' ); 335 336 function map( z ) { 337 return new Complex64( real(z)*2.0, imag(z)*2.0 ); 338 } 339 340 // Create a source array: 341 var src = [ new Complex64( 1.0, -1.0 ) ]; 342 343 // Create a new complex number array by scaling the source array: 344 var arr = Complex64Array.from( src, map ); 345 // returns <Complex64Array> 346 347 var len = arr.length; 348 // returns 1 349 350 var z = arr.get( 0 ); 351 // returns <Complex64> 352 353 var re = real( z ); 354 // returns 2.0 355 356 var im = imag( z ); 357 // returns -2.0 358 ``` 359 360 or an array-like `object` containing real and imaginary components 361 362 ```javascript 363 var Float32Array = require( '@stdlib/array/float32' ); 364 var Complex64 = require( '@stdlib/complex/float32' ); 365 var real = require( '@stdlib/complex/real' ); 366 var imag = require( '@stdlib/complex/imag' ); 367 368 // Return a callback which reuses allocated memory... 369 function mapFcn() { 370 var buf = new Float32Array( 2 ); 371 return map; 372 373 function map( z ) { 374 buf[ 0 ] = real( z ) * 2.0; 375 buf[ 1 ] = imag( z ) * 2.0; 376 return buf; 377 } 378 } 379 380 // Create a source array: 381 var src = [ new Complex64( 1.0, -1.0 ), new Complex64( 2.0, -2.0 ) ]; 382 383 // Create a new complex number array by scaling the source array: 384 var arr = Complex64Array.from( src, mapFcn() ); 385 // returns <Complex64Array> 386 387 var len = arr.length; 388 // returns 2 389 390 var z = arr.get( 0 ); 391 // returns <Complex64> 392 393 var re = real( z ); 394 // returns 2.0 395 396 var im = imag( z ); 397 // returns -2.0 398 399 z = arr.get( 1 ); 400 // returns <Complex64> 401 402 re = real( z ); 403 // returns 4.0 404 405 im = imag( z ); 406 // returns -4.0 407 ``` 408 409 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. 410 411 ```javascript 412 var Float32Array = require( '@stdlib/array/float32' ); 413 var Complex64 = require( '@stdlib/complex/float32' ); 414 var real = require( '@stdlib/complex/real' ); 415 var imag = require( '@stdlib/complex/imag' ); 416 417 function map( v ) { 418 return v * 2.0; 419 } 420 421 // Create a source array: 422 var src = new Float32Array( [ 1.0, -1.0 ] ); 423 424 // Create a new complex number array by scaling the source array: 425 var arr = Complex64Array.from( src, map ); 426 // returns <Complex64Array> 427 428 var len = arr.length; 429 // returns 1 430 431 var z = arr.get( 0 ); 432 // returns <Complex64> 433 434 var re = real( z ); 435 // returns 2.0 436 437 var im = imag( z ); 438 // returns -2.0 439 ``` 440 441 A callback function is provided two arguments: 442 443 - `value`: source value 444 - `index`: source index 445 446 To set the callback execution context, provide a `thisArg`. 447 448 ```javascript 449 var Complex64 = require( '@stdlib/complex/float32' ); 450 var real = require( '@stdlib/complex/real' ); 451 var imag = require( '@stdlib/complex/imag' ); 452 453 function map( z ) { 454 this.count += 1; 455 return new Complex64( real(z)*2.0, imag(z)*2.0 ); 456 } 457 458 // Create a source array: 459 var src = [ new Complex64( 1.0, -1.0 ), new Complex64( 1.0, -1.0 ) ]; 460 461 // Define an execution context: 462 var ctx = { 463 'count': 0 464 }; 465 466 // Create a new complex number array by scaling the source array: 467 var arr = Complex64Array.from( src, map, ctx ); 468 // returns <Complex64Array> 469 470 var len = arr.length; 471 // returns 2 472 473 var n = ctx.count; 474 // returns 2 475 ``` 476 477 <a name="static-method-of"></a> 478 479 #### Complex64Array.of( element0\[, element1\[, ...elementN]] ) 480 481 Creates a new 64-bit complex number array from a variable number of arguments. 482 483 ```javascript 484 var Complex64 = require( '@stdlib/complex/float32' ); 485 486 var arr = Complex64Array.of( 1.0, -1.0, 2.0, -2.0 ); 487 // returns <Complex64Array> 488 489 var len = arr.length; 490 // returns 2 491 492 var z1 = new Complex64( 1.0, -1.0 ); 493 var z2 = new Complex64( 2.0, -2.0 ); 494 495 arr = Complex64Array.of( z1, z2 ); 496 // returns <Complex64Array> 497 498 len = arr.length; 499 // returns 2 500 ``` 501 502 <a name="method-copy-within"></a> 503 504 #### Complex64Array.prototype.copyWithin( target, start\[, end] ) 505 506 Copies a sequence of elements within the array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`. 507 508 ```javascript 509 var Complex64 = require( '@stdlib/complex/float32' ); 510 511 var arr = new Complex64Array( 4 ); 512 513 // Set the array elements: 514 arr.set( new Complex64( 1.0, -1.0 ), 0 ); 515 arr.set( new Complex64( 2.0, -2.0 ), 1 ); 516 arr.set( new Complex64( 3.0, -3.0 ), 2 ); 517 arr.set( new Complex64( 4.0, -4.0 ), 3 ); 518 519 // Get the first array element: 520 var z = arr.get( [ 0.0, 0.0 ], 0 ); 521 // returns [ 1.0, -1.0 ] 522 523 // Get the second array element: 524 z = arr.get( [ 0.0, 0.0 ], 1 ); 525 // returns [ 2.0, -2.0 ] 526 527 // Copy the last two elements to the first two elements: 528 arr.copyWithin( 0, 2 ); 529 530 // Get the first array element: 531 z = arr.get( [ 0.0, 0.0 ], 0 ); 532 // returns [ 3.0, -3.0 ] 533 534 // Get the second array element: 535 z = arr.get( [ 0.0, 0.0 ], 1 ); 536 // returns [ 4.0, -4.0 ] 537 ``` 538 539 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. 540 541 ```javascript 542 var Complex64 = require( '@stdlib/complex/float32' ); 543 544 var arr = new Complex64Array( 4 ); 545 546 // Set the array elements: 547 arr.set( new Complex64( 1.0, -1.0 ), 0 ); 548 arr.set( new Complex64( 2.0, -2.0 ), 1 ); 549 arr.set( new Complex64( 3.0, -3.0 ), 2 ); 550 arr.set( new Complex64( 4.0, -4.0 ), 3 ); 551 552 // Get the third array element: 553 var z = arr.get( [ 0.0, 0.0 ], 2 ); 554 // returns [ 3.0, -3.0 ] 555 556 // Get the last array element: 557 z = arr.get( [ 0.0, 0.0 ], 3 ); 558 // returns [ 4.0, -4.0 ] 559 560 // Copy the first two elements to the last two elements: 561 arr.copyWithin( 2, 0, 2 ); 562 563 // Get the third array element: 564 z = arr.get( [ 0.0, 0.0 ], 2 ); 565 // returns [ 1.0, -1.0 ] 566 567 // Get the last array element: 568 z = arr.get( [ 0.0, 0.0 ], 3 ); 569 // returns [ 2.0, -2.0 ] 570 ``` 571 572 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: 573 574 ```javascript 575 var Complex64 = require( '@stdlib/complex/float32' ); 576 577 var arr = new Complex64Array( 4 ); 578 579 // Set the array elements: 580 arr.set( new Complex64( 1.0, -1.0 ), 0 ); 581 arr.set( new Complex64( 2.0, -2.0 ), 1 ); 582 arr.set( new Complex64( 3.0, -3.0 ), 2 ); 583 arr.set( new Complex64( 4.0, -4.0 ), 3 ); 584 585 // Get the third array element: 586 var z = arr.get( [ 0.0, 0.0 ], 2 ); 587 // returns [ 3.0, -3.0 ] 588 589 // Get the last array element: 590 z = arr.get( [ 0.0, 0.0 ], 3 ); 591 // returns [ 4.0, -4.0 ] 592 593 // Copy the first two elements to the last two elements using negative indices: 594 arr.copyWithin( -2, -4, -2 ); 595 596 // Get the third array element: 597 z = arr.get( [ 0.0, 0.0 ], 2 ); 598 // returns [ 1.0, -1.0 ] 599 600 // Get the last array element: 601 z = arr.get( [ 0.0, 0.0 ], 3 ); 602 // returns [ 2.0, -2.0 ] 603 ``` 604 605 <a name="method-entries"></a> 606 607 #### Complex64Array.prototype.entries() 608 609 Returns an iterator for iterating over array key-value pairs. 610 611 ```javascript 612 var Complex64 = require( '@stdlib/complex/float32' ); 613 var real = require( '@stdlib/complex/real' ); 614 var imag = require( '@stdlib/complex/imag' ); 615 616 var arr = [ 617 new Complex64( 1.0, -1.0 ), 618 new Complex64( 2.0, -2.0 ), 619 new Complex64( 3.0, -3.0 ) 620 ]; 621 arr = new Complex64Array( arr ); 622 623 // Create an iterator: 624 var it = arr.entries(); 625 626 // Iterate over the key-value pairs... 627 var v = it.next().value; 628 // returns [ 0, <Complex64> ] 629 630 var re = real( v[ 1 ] ); 631 // returns 1.0 632 633 var im = imag( v[ 1 ] ); 634 // returns -1.0 635 636 v = it.next().value; 637 // returns [ 1, <Complex64> ] 638 639 re = real( v[ 1 ] ); 640 // returns 2.0 641 642 im = imag( v[ 1 ] ); 643 // returns -2.0 644 645 v = it.next().value; 646 // returns [ 2, <Complex64> ] 647 648 re = real( v[ 1 ] ); 649 // returns 3.0 650 651 im = imag( v[ 1 ] ); 652 // returns -3.0 653 654 var bool = it.next().done; 655 // returns true 656 ``` 657 658 <a name="method-get"></a> 659 660 #### Complex64Array.prototype.get( \[out,] i ) 661 662 Returns an array element located at position (index) `i`. 663 664 ```javascript 665 var real = require( '@stdlib/complex/real' ); 666 var imag = require( '@stdlib/complex/imag' ); 667 668 var arr = new Complex64Array( 10 ); 669 670 // Set the first element: 671 arr.set( [ 1.0, -1.0 ], 0 ); 672 673 // Get the first element: 674 var z = arr.get( 0 ); 675 // returns <Complex64> 676 677 var re = real( z ); 678 // returns 1.0 679 680 var im = imag( z ); 681 // returns -1.0 682 ``` 683 684 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. 685 686 ```javascript 687 var arr = new Complex64Array( 10 ); 688 689 // Set the first element: 690 arr.set( [ 1.0, -1.0 ], 0 ); 691 692 // Define an output array: 693 var out = [ 0.0, 0.0 ]; 694 695 // Get the first element: 696 var z = arr.get( out, 0 ); 697 // returns [ 1.0, -1.0 ] 698 699 var bool = ( out === z ); 700 // returns true 701 ``` 702 703 If provided an out-of-bounds index, the method returns `undefined`. 704 705 ```javascript 706 var arr = new Complex64Array( 10 ); 707 708 var z = arr.get( 100 ); 709 // returns undefined 710 711 var out = [ 0.0, 0.0 ]; 712 713 z = arr.get( out, 100 ); 714 // returns undefined 715 716 var bool = ( out === z ); 717 // returns false 718 ``` 719 720 <a name="method-set"></a> 721 722 #### Complex64Array.prototype.set( z\[, i] ) 723 724 Sets one or more array elements. 725 726 ```javascript 727 var Complex64 = require( '@stdlib/complex/float32' ); 728 729 var arr = new Complex64Array( 10 ); 730 731 // Get the first element: 732 var z = arr.get( [ 0.0, 0.0 ], 0 ); 733 // returns [ 0.0, 0.0 ] 734 735 // Set the first element: 736 arr.set( new Complex64( 1.0, -1.0 ) ); 737 738 // Get the first element: 739 z = arr.get( [ 0.0, 0.0 ], 0 ); 740 // returns [ 1.0, -1.0 ] 741 ``` 742 743 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`. 744 745 ```javascript 746 var Complex64 = require( '@stdlib/complex/float32' ); 747 748 var arr = new Complex64Array( 10 ); 749 750 // Get the fifth element: 751 var z = arr.get( [ 0.0, 0.0 ], 4 ); 752 // returns [ 0.0, 0.0 ] 753 754 // Set the fifth element: 755 arr.set( new Complex64( 1.0, -1.0 ), 4 ); 756 757 // Get the fifth element: 758 z = arr.get( [ 0.0, 0.0 ], 4 ); 759 // returns [ 1.0, -1.0 ] 760 ``` 761 762 In addition to providing a complex number, to set one or more array elements, provide an array-like `object` containing either complex numbers 763 764 ```javascript 765 var Complex64 = require( '@stdlib/complex/float32' ); 766 767 var arr = new Complex64Array( 10 ); 768 769 // Define an array of complex numbers: 770 var buf = [ 771 new Complex64( 1.0, -1.0 ), 772 new Complex64( 2.0, -2.0 ), 773 new Complex64( 3.0, -3.0 ) 774 ]; 775 776 // Set the fifth, sixth, and seventh elements: 777 arr.set( buf, 4 ); 778 779 // Get the sixth element: 780 var z = arr.get( [ 0.0, 0.0 ], 5 ); 781 // returns [ 2.0, -2.0 ] 782 ``` 783 784 or interleaved real and imaginary components 785 786 ```javascript 787 var Float32Array = require( '@stdlib/array/float32' ); 788 789 var arr = new Complex64Array( 10 ); 790 791 // Define an interleaved array of real and imaginary components: 792 var buf = new Float32Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] ); 793 794 // Set the fifth, sixth, and seventh elements: 795 arr.set( buf, 4 ); 796 797 // Get the sixth element: 798 var z = arr.get( [ 0.0, 0.0 ], 5 ); 799 // returns [ 2.0, -2.0 ] 800 ``` 801 802 A few notes: 803 804 - If `i` is out-of-bounds, the method throws an error. 805 - If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error. 806 - If provided a [typed array][@stdlib/array/typed] which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range. 807 808 </section> 809 810 <!-- /.usage --> 811 812 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 813 814 <section class="notes"> 815 816 * * * 817 818 ## Notes 819 820 - While a `Complex64Array` _strives_ to maintain (but does not **guarantee**) consistency with [typed arrays][@stdlib/array/typed], significant deviations from ECMAScript-defined [typed array][@stdlib/array/typed] behavior are as follows: 821 822 - The constructor does **not** require the `new` operator. 823 - The constructor and associated methods support a broader variety of input argument types in order to better accommodate complex number input. 824 - Accessing array elements using bracket syntax (e.g., `Z[i]`) is **not** supported. Instead, one **must** use the `.get()` method which returns a value compatible with complex number output. 825 - The `set` method has extended behavior in order to support complex numbers. 826 827 </section> 828 829 <!-- /.notes --> 830 831 <!-- Package usage examples. --> 832 833 <section class="examples"> 834 835 * * * 836 837 ## Examples 838 839 <!-- eslint no-undef: "error" --> 840 841 ```javascript 842 var Complex64 = require( '@stdlib/complex/float32' ); 843 var Float32Array = require( '@stdlib/array/float32' ); 844 var Complex64Array = require( '@stdlib/array/complex64' ); 845 846 var arr; 847 var out; 848 849 // Create a complex array by specifying a length: 850 out = new Complex64Array( 3 ); 851 console.log( out ); 852 853 // Create a complex array from an array of complex numbers: 854 arr = [ 855 new Complex64( 1.0, -1.0 ), 856 new Complex64( -3.14, 3.14 ), 857 new Complex64( 0.5, 0.5 ) 858 ]; 859 out = new Complex64Array( arr ); 860 console.log( out ); 861 862 // Create a complex array from an interleaved typed array: 863 arr = new Float32Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); 864 out = new Complex64Array( arr ); 865 console.log( out ); 866 867 // Create a complex array from an array buffer: 868 arr = new Float32Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); 869 out = new Complex64Array( arr.buffer ); 870 console.log( out ); 871 872 // Create a complex array from an array buffer view: 873 arr = new Float32Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); 874 out = new Complex64Array( arr.buffer, 8, 2 ); 875 console.log( out ); 876 ``` 877 878 </section> 879 880 <!-- /.examples --> 881 882 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 883 884 <section class="references"> 885 886 </section> 887 888 <!-- /.references --> 889 890 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 891 892 <section class="links"> 893 894 [@stdlib/array/typed]: https://www.npmjs.com/package/@stdlib/array/tree/main/typed 895 896 [@stdlib/array/buffer]: https://www.npmjs.com/package/@stdlib/array/tree/main/buffer 897 898 [@stdlib/complex/float32]: https://www.npmjs.com/package/@stdlib/complex-float32 899 900 </section> 901 902 <!-- /.links -->