ndarray.js (2269B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2020 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var Float32Array = require( '@stdlib/array/float32' ); 24 25 26 // MAIN // 27 28 /** 29 * Copies values from one complex single-precision floating-point vector to another complex single-precision floating-point vector. 30 * 31 * @param {PositiveInteger} N - number of values to copy 32 * @param {Complex64Array} x - input array 33 * @param {integer} strideX - `x` stride length 34 * @param {NonNegativeInteger} offsetX - starting `x` index 35 * @param {Complex64Array} y - destination array 36 * @param {integer} strideY - `y` stride length 37 * @param {NonNegativeInteger} offsetY - starting `y` index 38 * @returns {Complex64Array} `y` 39 * 40 * @example 41 * var Complex64Array = require( '@stdlib/array/complex64' ); 42 * var real = require( '@stdlib/complex/real' ); 43 * var imag = require( '@stdlib/complex/imag' ); 44 * 45 * var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); 46 * var y = new Complex64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); 47 * 48 * ccopy( x.length, x, 1, 0, y, 1, 0 ); 49 * 50 * var z = y.get( 0 ); 51 * // returns <Complex64> 52 * 53 * var re = real( z ); 54 * // returns 1.0 55 * 56 * var im = imag( z ); 57 * // returns 2.0 58 */ 59 function ccopy( N, x, strideX, offsetX, y, strideY, offsetY ) { 60 var viewX; 61 var viewY; 62 var sx; 63 var sy; 64 var ix; 65 var iy; 66 var i; 67 68 if ( N <= 0 ) { 69 return y; 70 } 71 viewX = new Float32Array( x.buffer, x.byteOffset, x.length*2 ); 72 viewY = new Float32Array( y.buffer, y.byteOffset, y.length*2 ); 73 sx = strideX * 2; 74 sy = strideY * 2; 75 ix = offsetX * 2; 76 iy = offsetY * 2; 77 for ( i = 0; i < N; i++ ) { 78 viewY[ iy ] = viewX[ ix ]; 79 viewY[ iy+1 ] = viewX[ ix+1 ]; 80 ix += sx; 81 iy += sy; 82 } 83 return y; 84 } 85 86 87 // EXPORTS // 88 89 module.exports = ccopy;