|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 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 | +# Complex128Matrix |
| 22 | + |
| 23 | +> Create a double-precision complex floating-point matrix (i.e., a two-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 Complex128Matrix = require( '@stdlib/ndarray/matrix/complex128' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### Complex128Matrix( \[options] ) |
| 44 | + |
| 45 | +Returns a two-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor]. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var getShape = require( '@stdlib/ndarray/shape' ); |
| 49 | + |
| 50 | +var arr = new Complex128Matrix(); |
| 51 | +// returns <ndarray> |
| 52 | + |
| 53 | +var len = getShape( arr ); |
| 54 | +// returns [ 0, 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 | +- **submode**: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). If provided fewer modes than dimensions, an [`ndarray`][@stdlib/ndarray/ctor]) instance recycles modes using modulo arithmetic. Default: `[ options.mode ]`. |
| 62 | +- **readonly**: boolean indicating whether an array should be **read-only**. Default: `false`. |
| 63 | + |
| 64 | +#### Complex128Matrix( shape\[, options] ) |
| 65 | + |
| 66 | +Returns a two-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor] having a specified shape. |
| 67 | + |
| 68 | +```javascript |
| 69 | +var getShape = require( '@stdlib/ndarray/shape' ); |
| 70 | + |
| 71 | +var arr = new Complex128Matrix( [ 3, 3 ] ); |
| 72 | +// returns <ndarray> |
| 73 | + |
| 74 | +var sh = getShape( arr ); |
| 75 | +// returns [ 3, 3 ] |
| 76 | +``` |
| 77 | + |
| 78 | +The function accepts the following arguments: |
| 79 | + |
| 80 | +- **shape**: array shape. Must contain exactly two elements. |
| 81 | +- **options**: function options. See above. |
| 82 | + |
| 83 | +#### Complex128Matrix( M, N\[, options] ) |
| 84 | + |
| 85 | +Returns a two-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor] having a specified shape. |
| 86 | + |
| 87 | +```javascript |
| 88 | +var getShape = require( '@stdlib/ndarray/shape' ); |
| 89 | + |
| 90 | +var arr = new Complex128Matrix( 3, 3 ); |
| 91 | +// returns <ndarray> |
| 92 | + |
| 93 | +var sh = getShape( arr ); |
| 94 | +// returns [ 3, 3 ] |
| 95 | +``` |
| 96 | + |
| 97 | +The function accepts the following arguments: |
| 98 | + |
| 99 | +- **M**: number of rows. |
| 100 | +- **N**: number of columns. |
| 101 | +- **options**: function options. See above. |
| 102 | + |
| 103 | +#### Complex128Matrix( obj\[, options] ) |
| 104 | + |
| 105 | +Creates a two-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor] from an array-like object or iterable. |
| 106 | + |
| 107 | +<!-- eslint-disable max-len --> |
| 108 | + |
| 109 | +```javascript |
| 110 | +var getShape = require( '@stdlib/ndarray/shape' ); |
| 111 | + |
| 112 | +var arr = new Complex128Matrix( [ [ 1.0, 2.0, 3.0, 4.0 ], [ 5.0, 6.0, 7.0, 8.0 ] ] ); |
| 113 | +// returns <ndarray> |
| 114 | + |
| 115 | +var sh = getShape( arr ); |
| 116 | +// returns [ 2, 2 ] |
| 117 | +``` |
| 118 | + |
| 119 | +The function accepts the following arguments: |
| 120 | + |
| 121 | +- **obj**: array-like object or iterable from which to generate an [ndarray][@stdlib/ndarray/ctor]. If an array-like object, the value must be a nested array (i.e., an array-like object of array-like objects), where each nested array must have the same number of elements. If an iterable, the iterable must return array- like objects, each of which must have the same number of elements. |
| 122 | +- **options**: function options. See above. |
| 123 | + |
| 124 | +#### Complex128Matrix( buffer\[, byteOffset\[, shape]]\[, options] ) |
| 125 | + |
| 126 | +Returns a two-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor] view of an [`ArrayBuffer`][@stdlib/array/buffer]. |
| 127 | + |
| 128 | +```javascript |
| 129 | +var ArrayBuffer = require( '@stdlib/array/buffer' ); |
| 130 | +var getShape = require( '@stdlib/ndarray/shape' ); |
| 131 | + |
| 132 | +var buf = new ArrayBuffer( 64 ); |
| 133 | + |
| 134 | +var arr1 = new Complex128Matrix( buf ); |
| 135 | +// returns <ndarray> |
| 136 | + |
| 137 | +var sh1 = getShape( arr1 ); |
| 138 | +// returns [ 1, 4 ] |
| 139 | + |
| 140 | +var arr2 = new Complex128Matrix( buf, 16 ); |
| 141 | +// returns <ndarray> |
| 142 | + |
| 143 | +var sh2 = getShape( arr2 ); |
| 144 | +// returns [ 1, 3 ] |
| 145 | + |
| 146 | +var arr3 = new Complex128Matrix( buf, 16, [ 2, 1 ] ); |
| 147 | +// returns <ndarray> |
| 148 | + |
| 149 | +var sh3 = getShape( arr3 ); |
| 150 | +// returns [ 2, 1 ] |
| 151 | +``` |
| 152 | + |
| 153 | +The function accepts the following arguments: |
| 154 | + |
| 155 | +- **buffer**: underlying [`ArrayBuffer`][@stdlib/array/buffer]. |
| 156 | +- **byteOffset**: integer byte offset specifying the location of the first indexed element. Default: `0`. |
| 157 | +- **shape**: array shape. Must contain exactly two elements. |
| 158 | +- **options**: function options. See above. |
| 159 | + |
| 160 | +#### Complex128Matrix( buffer\[, byteOffset\[, M, N]]\[, options] ) |
| 161 | + |
| 162 | +Returns a two-dimensional double-precision complex floating-point [ndarray][@stdlib/ndarray/ctor] view of an [`ArrayBuffer`][@stdlib/array/buffer]. |
| 163 | + |
| 164 | +```javascript |
| 165 | +var ArrayBuffer = require( '@stdlib/array/buffer' ); |
| 166 | +var getShape = require( '@stdlib/ndarray/shape' ); |
| 167 | + |
| 168 | +var buf = new ArrayBuffer( 64 ); |
| 169 | + |
| 170 | +var arr = new Complex128Matrix( buf, 16, 2, 1 ); |
| 171 | +// returns <ndarray> |
| 172 | + |
| 173 | +var sh = getShape( arr ); |
| 174 | +// returns [ 2, 1 ] |
| 175 | +``` |
| 176 | + |
| 177 | +The function accepts the following arguments: |
| 178 | + |
| 179 | +- **buffer**: underlying [`ArrayBuffer`][@stdlib/array/buffer]. |
| 180 | +- **byteOffset**: integer byte offset specifying the location of the first indexed element. Default: `0`. |
| 181 | +- **M**: number of rows. |
| 182 | +- **N**: number of columns. |
| 183 | +- **options**: function options. See above. |
| 184 | + |
| 185 | +</section> |
| 186 | + |
| 187 | +<!-- /.usage --> |
| 188 | + |
| 189 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 190 | + |
| 191 | +<section class="notes"> |
| 192 | + |
| 193 | +## Notes |
| 194 | + |
| 195 | +- Nested arrays are flattened in lexicographic order, such that, for an input nested array `obj`, `obj[i][j]` corresponds to the element `mat.get(i, j)` in the returned two-dimensional ndarray. In other words, an input nested array is assumed to be comprised of rows. Similarly, if `obj` is an iterable, each array returned by the iterable is assumed to correspond to a matrix row. |
| 196 | +- If provided an `ArrayBuffer` without corresponding shape arguments, the leading dimension of the returned ndarray always has a size of one. |
| 197 | + |
| 198 | +</section> |
| 199 | + |
| 200 | +<!-- /.notes --> |
| 201 | + |
| 202 | +<!-- Package usage examples. --> |
| 203 | + |
| 204 | +<section class="examples"> |
| 205 | + |
| 206 | +## Examples |
| 207 | + |
| 208 | +<!-- eslint no-undef: "error" --> |
| 209 | + |
| 210 | +```javascript |
| 211 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 212 | +var sum = require( '@stdlib/blas/ext/sum' ); |
| 213 | +var map = require( '@stdlib/ndarray/map' ); |
| 214 | +var real = require( '@stdlib/complex/float64/real' ); |
| 215 | +var imag = require( '@stdlib/complex/float64/imag' ); |
| 216 | +var Complex128 = require( '@stdlib/complex/float64/ctor' ); |
| 217 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 218 | +var Complex128Matrix = require( '@stdlib/ndarray/matrix/complex128' ); |
| 219 | + |
| 220 | +// Create a matrix containing random values: |
| 221 | +var x = new Complex128Matrix([ |
| 222 | + discreteUniform( 20, 0, 100 ), |
| 223 | + discreteUniform( 20, 0, 20 ) |
| 224 | +]); |
| 225 | + |
| 226 | +// Compute the sum along the columns: |
| 227 | +var v = sum( x, { |
| 228 | + 'dims': [ -1 ] |
| 229 | +}); |
| 230 | +console.log( ndarray2array( v ) ); |
| 231 | + |
| 232 | +// Define a function which applies a threshold to individual values: |
| 233 | +function threshold( v ) { |
| 234 | + if ( real( v ) > 10 && imag( v ) > 10 ) { |
| 235 | + return v; |
| 236 | + } |
| 237 | + return new Complex128( 0.0, 0.0 ); |
| 238 | +} |
| 239 | + |
| 240 | +// Apply threshold: |
| 241 | +var y = map( x, threshold ); |
| 242 | + |
| 243 | +// Recompute the sum along the columns: |
| 244 | +v = sum( y, { |
| 245 | + 'dims': [ -1 ] |
| 246 | +}); |
| 247 | +console.log( ndarray2array( v ) ); |
| 248 | +``` |
| 249 | + |
| 250 | +</section> |
| 251 | + |
| 252 | +<!-- /.examples --> |
| 253 | + |
| 254 | +<!-- 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. --> |
| 255 | + |
| 256 | +<section class="references"> |
| 257 | + |
| 258 | +</section> |
| 259 | + |
| 260 | +<!-- /.references --> |
| 261 | + |
| 262 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 263 | + |
| 264 | +<section class="related"> |
| 265 | + |
| 266 | +</section> |
| 267 | + |
| 268 | +<!-- /.related --> |
| 269 | + |
| 270 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 271 | + |
| 272 | +<section class="links"> |
| 273 | + |
| 274 | +[@stdlib/array/buffer]: https://github.com/stdlib-js/array-buffer |
| 275 | + |
| 276 | +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor |
| 277 | + |
| 278 | +</section> |
| 279 | + |
| 280 | +<!-- /.links --> |
0 commit comments