|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# Complex128Vector |
| 22 | + |
| 23 | +> Create a double-precision complex floating-point vector (i.e., a one-dimensional [ndarray][@stdlib/ndarray/ctor]). |
| 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 Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### Complex128Vector( \[options] ) |
| 44 | + |
| 45 | +Returns a one-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor]. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var numel = require( '@stdlib/ndarray/numel' ); |
| 49 | + |
| 50 | +var arr = new Complex128Vector(); |
| 51 | +// returns <ndarray> |
| 52 | + |
| 53 | +var len = numel( arr ); |
| 54 | +// returns 0 |
| 55 | +``` |
| 56 | + |
| 57 | +The function accepts the following options: |
| 58 | + |
| 59 | +- **order**: specifies whether an [ndarray][@stdlib/ndarray/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). Default: `'row-major'`. |
| 60 | +- **mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`. |
| 61 | +- **readonly**: boolean indicating whether an array should be **read-only**. Default: `false`. |
| 62 | + |
| 63 | +#### Complex128Vector( length\[, options] ) |
| 64 | + |
| 65 | +Returns a one-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor] having a specified `length`. |
| 66 | + |
| 67 | +```javascript |
| 68 | +var numel = require( '@stdlib/ndarray/numel' ); |
| 69 | + |
| 70 | +var arr = new Complex128Vector( 5 ); |
| 71 | +// returns <ndarray> |
| 72 | + |
| 73 | +var len1 = numel( arr ); |
| 74 | +// returns 5 |
| 75 | +``` |
| 76 | + |
| 77 | +#### Complex128Vector( obj\[, options] ) |
| 78 | + |
| 79 | +Creates a one-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor] from an array-like object or iterable. |
| 80 | + |
| 81 | +```javascript |
| 82 | +var numel = require( '@stdlib/ndarray/numel' ); |
| 83 | + |
| 84 | +var arr = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 85 | +// returns <ndarray> |
| 86 | + |
| 87 | +var len1 = numel( arr ); |
| 88 | +// returns 3 |
| 89 | +``` |
| 90 | + |
| 91 | +#### Complex128Vector( buffer\[, byteOffset\[, length]]\[, options] ) |
| 92 | + |
| 93 | +Returns a one-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor] view of an [`ArrayBuffer`][@stdlib/array/buffer]. |
| 94 | + |
| 95 | +```javascript |
| 96 | +var ArrayBuffer = require( '@stdlib/array/buffer' ); |
| 97 | +var numel = require( '@stdlib/ndarray/numel' ); |
| 98 | + |
| 99 | +var buf = new ArrayBuffer( 64 ); |
| 100 | + |
| 101 | +var arr1 = new Complex128Vector( buf ); |
| 102 | +// returns <ndarray> |
| 103 | + |
| 104 | +var len1 = numel( arr1 ); |
| 105 | +// returns 4 |
| 106 | + |
| 107 | +var arr2 = new Complex128Vector( buf, 16 ); |
| 108 | +// returns <ndarray> |
| 109 | + |
| 110 | +var len2 = numel( arr2 ); |
| 111 | +// returns 3 |
| 112 | + |
| 113 | +var arr3 = new Complex128Vector( buf, 16, 1 ); |
| 114 | +// returns <ndarray> |
| 115 | + |
| 116 | +var len3 = numel( arr3 ); |
| 117 | +// returns 1 |
| 118 | +``` |
| 119 | + |
| 120 | +</section> |
| 121 | + |
| 122 | +<!-- /.usage --> |
| 123 | + |
| 124 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 125 | + |
| 126 | +<section class="notes"> |
| 127 | + |
| 128 | +</section> |
| 129 | + |
| 130 | +<!-- /.notes --> |
| 131 | + |
| 132 | +<!-- Package usage examples. --> |
| 133 | + |
| 134 | +<section class="examples"> |
| 135 | + |
| 136 | +## Examples |
| 137 | + |
| 138 | +<!-- eslint no-undef: "error" --> |
| 139 | + |
| 140 | +```javascript |
| 141 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 142 | +var sum = require( '@stdlib/blas/ext/sum' ); |
| 143 | +var map = require( '@stdlib/ndarray/map' ); |
| 144 | +var real = require( '@stdlib/complex/float64/real' ); |
| 145 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 146 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 147 | +var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); |
| 148 | + |
| 149 | +// Create a vector containing random values: |
| 150 | +var x = new Complex128Vector( discreteUniform( 20, 0, 100 ) ); |
| 151 | + |
| 152 | +// Compute the sum: |
| 153 | +var v = sum( x ); |
| 154 | +console.log( v.get() ); |
| 155 | + |
| 156 | +// Define a function which applies a threshold to real and imaginary components: |
| 157 | +function threshold( v ) { |
| 158 | + if ( real( v ) > 10 && imag( v ) > 10 ) { |
| 159 | + return v; |
| 160 | + } |
| 161 | + return new Complex128( 0.0, 0.0 ); |
| 162 | +} |
| 163 | + |
| 164 | +// Apply threshold: |
| 165 | +var y = map( x, threshold ); |
| 166 | + |
| 167 | +// Recompute the sum: |
| 168 | +v = sum( y ); |
| 169 | +console.log( v.get() ); |
| 170 | +``` |
| 171 | + |
| 172 | +</section> |
| 173 | + |
| 174 | +<!-- /.examples --> |
| 175 | + |
| 176 | +<!-- 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. --> |
| 177 | + |
| 178 | +<section class="references"> |
| 179 | + |
| 180 | +</section> |
| 181 | + |
| 182 | +<!-- /.references --> |
| 183 | + |
| 184 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 185 | + |
| 186 | +<section class="related"> |
| 187 | + |
| 188 | +</section> |
| 189 | + |
| 190 | +<!-- /.related --> |
| 191 | + |
| 192 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 193 | + |
| 194 | +<section class="links"> |
| 195 | + |
| 196 | +[@stdlib/array/buffer]: https://github.com/stdlib-js/array-buffer |
| 197 | + |
| 198 | +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor |
| 199 | + |
| 200 | +</section> |
| 201 | + |
| 202 | +<!-- /.links --> |
0 commit comments