|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# zcopy |
| 22 | + |
| 23 | +> Copy values from one complex double-precision floating-point vector to another complex double-precision floating-point vector. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var zcopy = require( '@stdlib/blas/base/zcopy' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### zcopy( N, x, strideX, y, strideY ) |
| 34 | + |
| 35 | +Copies values from `x` into `y`. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 39 | +var real = require( '@stdlib/complex/real' ); |
| 40 | +var imag = require( '@stdlib/complex/imag' ); |
| 41 | + |
| 42 | +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 43 | +var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 44 | + |
| 45 | +zcopy( x.length, x, 1, y, 1 ); |
| 46 | + |
| 47 | +var z = y.get( 0 ); |
| 48 | +// returns <Complex128> |
| 49 | + |
| 50 | +var re = real( z ); |
| 51 | +// returns 1.0 |
| 52 | + |
| 53 | +var im = imag( z ); |
| 54 | +// returns 2.0 |
| 55 | +``` |
| 56 | + |
| 57 | +The function has the following parameters: |
| 58 | + |
| 59 | +- **N**: number of indexed elements. |
| 60 | +- **x**: input [`Complex128Array`][@stdlib/array/complex128]. |
| 61 | +- **strideX**: index increment for `x`. |
| 62 | +- **y**: destination [`Complex128Array`][@stdlib/array/complex128]. |
| 63 | +- **strideY**: index increment for `y`. |
| 64 | + |
| 65 | +The `N` and stride parameters determine how values from `x` are copied into `y`. For example, to copy in reverse order every other value in `x` into the first `N` elements of `y`, |
| 66 | + |
| 67 | +```javascript |
| 68 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 69 | +var real = require( '@stdlib/complex/real' ); |
| 70 | +var imag = require( '@stdlib/complex/imag' ); |
| 71 | + |
| 72 | +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 73 | +var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 74 | + |
| 75 | +zcopy( 2, x, -2, y, 1 ); |
| 76 | + |
| 77 | +var z = y.get( 0 ); |
| 78 | +// returns <Complex128> |
| 79 | + |
| 80 | +var re = real( z ); |
| 81 | +// returns 5.0 |
| 82 | + |
| 83 | +var im = imag( z ); |
| 84 | +// returns 6.0 |
| 85 | +``` |
| 86 | + |
| 87 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 88 | + |
| 89 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 90 | + |
| 91 | +```javascript |
| 92 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 93 | +var real = require( '@stdlib/complex/real' ); |
| 94 | +var imag = require( '@stdlib/complex/imag' ); |
| 95 | + |
| 96 | +// Initial arrays... |
| 97 | +var x0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 98 | +var y0 = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 99 | + |
| 100 | +// Create offset views... |
| 101 | +var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 102 | +var y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element |
| 103 | + |
| 104 | +// Copy in reverse order every other value from `x1` into `y1`... |
| 105 | +zcopy( 2, x1, -2, y1, 1 ); |
| 106 | + |
| 107 | +var z = y0.get( 2 ); |
| 108 | +// returns <Complex128> |
| 109 | + |
| 110 | +var re = real( z ); |
| 111 | +// returns 7.0 |
| 112 | + |
| 113 | +var im = imag( z ); |
| 114 | +// returns 8.0 |
| 115 | +``` |
| 116 | + |
| 117 | +#### zcopy.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) |
| 118 | + |
| 119 | +Copies values from `x` into `y` using alternative indexing semantics. |
| 120 | + |
| 121 | +```javascript |
| 122 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 123 | +var real = require( '@stdlib/complex/real' ); |
| 124 | +var imag = require( '@stdlib/complex/imag' ); |
| 125 | + |
| 126 | +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 127 | +var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 128 | + |
| 129 | +zcopy.ndarray( x.length, x, 1, 0, y, 1, 0 ); |
| 130 | + |
| 131 | +var z = y.get( 0 ); |
| 132 | +// returns <Complex128> |
| 133 | + |
| 134 | +var re = real( z ); |
| 135 | +// returns 1.0 |
| 136 | + |
| 137 | +var im = imag( z ); |
| 138 | +// returns 2.0 |
| 139 | +``` |
| 140 | + |
| 141 | +The function has the following additional parameters: |
| 142 | + |
| 143 | +- **offsetX**: starting index for `x`. |
| 144 | +- **offsetY**: starting index for `y`. |
| 145 | + |
| 146 | +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to copy every other value in `x` starting from the second value into the last `N` elements in `y` where `x[i] = y[n]`, `x[i+2] = y[n-1]`,..., |
| 147 | + |
| 148 | +```javascript |
| 149 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 150 | +var real = require( '@stdlib/complex/real' ); |
| 151 | +var imag = require( '@stdlib/complex/imag' ); |
| 152 | + |
| 153 | +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 154 | +var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 155 | + |
| 156 | +zcopy.ndarray( 2, x, 2, 1, y, -1, y.length-1 ); |
| 157 | + |
| 158 | +var z = y.get( y.length-1 ); |
| 159 | +// returns <Complex128> |
| 160 | + |
| 161 | +var re = real( z ); |
| 162 | +// returns 3.0 |
| 163 | + |
| 164 | +var im = imag( z ); |
| 165 | +// returns 4.0 |
| 166 | +``` |
| 167 | + |
| 168 | +</section> |
| 169 | + |
| 170 | +<!-- /.usage --> |
| 171 | + |
| 172 | +<section class="notes"> |
| 173 | + |
| 174 | +## Notes |
| 175 | + |
| 176 | +- If `N <= 0`, both functions return `y` unchanged. |
| 177 | +- `zcopy()` corresponds to the [BLAS][blas] level 1 function [`zcopy`][zcopy]. |
| 178 | + |
| 179 | +</section> |
| 180 | + |
| 181 | +<!-- /.notes --> |
| 182 | + |
| 183 | +<section class="examples"> |
| 184 | + |
| 185 | +## Examples |
| 186 | + |
| 187 | +<!-- eslint no-undef: "error" --> |
| 188 | + |
| 189 | +```javascript |
| 190 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 191 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); |
| 192 | +var Complex128 = require( '@stdlib/complex/float64' ); |
| 193 | +var zcopy = require( '@stdlib/blas/base/zcopy' ); |
| 194 | + |
| 195 | +function rand() { |
| 196 | + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); |
| 197 | +} |
| 198 | + |
| 199 | +var x = filledarrayBy( 10, 'complex128', rand ); |
| 200 | +console.log( x.get( 0 ).toString() ); |
| 201 | + |
| 202 | +var y = filledarrayBy( 10, 'complex128', rand ); |
| 203 | +console.log( y.get( 0 ).toString() ); |
| 204 | + |
| 205 | +// Copy elements from `x` into `y` starting from the end of `y`: |
| 206 | +zcopy( x.length, x, 1, y, -1 ); |
| 207 | +console.log( y.get( y.length-1 ).toString() ); |
| 208 | +``` |
| 209 | + |
| 210 | +</section> |
| 211 | + |
| 212 | +<!-- /.examples --> |
| 213 | + |
| 214 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 215 | + |
| 216 | +<section class="links"> |
| 217 | + |
| 218 | +[blas]: http://www.netlib.org/blas |
| 219 | + |
| 220 | +[zcopy]: https://www.netlib.org/lapack/explore-html/d5/d2b/group__copy_gaca1a115319081adeb0a9b80ec37ce626.html#gaca1a115319081adeb0a9b80ec37ce626 |
| 221 | + |
| 222 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 223 | + |
| 224 | +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128 |
| 225 | + |
| 226 | +</section> |
| 227 | + |
| 228 | +<!-- /.links --> |
0 commit comments