time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

ccopy.js (2390B)


      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 {Complex64Array} y - destination array
     35 * @param {integer} strideY - `y` stride length
     36 * @returns {Complex64Array} `y`
     37 *
     38 * @example
     39 * var Complex64Array = require( '@stdlib/array/complex64' );
     40 * var real = require( '@stdlib/complex/real' );
     41 * var imag = require( '@stdlib/complex/imag' );
     42 *
     43 * var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
     44 * var y = new Complex64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
     45 *
     46 * ccopy( x.length, x, 1, y, 1 );
     47 *
     48 * var z = y.get( 0 );
     49 * // returns <Complex64>
     50 *
     51 * var re = real( z );
     52 * // returns 1.0
     53 *
     54 * var im = imag( z );
     55 * // returns 2.0
     56 */
     57 function ccopy( N, x, strideX, y, strideY ) {
     58 	var viewX;
     59 	var viewY;
     60 	var sx;
     61 	var sy;
     62 	var ix;
     63 	var iy;
     64 	var i;
     65 
     66 	if ( N <= 0 ) {
     67 		return y;
     68 	}
     69 	viewX = new Float32Array( x.buffer, x.byteOffset, x.length*2 );
     70 	viewY = new Float32Array( y.buffer, y.byteOffset, y.length*2 );
     71 	if ( strideX === 1 && strideY === 1 ) {
     72 		for ( i = 0; i < N*2; i += 2 ) {
     73 			viewY[ i ] = viewX[ i ];
     74 			viewY[ i+1 ] = viewX[ i+1 ];
     75 		}
     76 		return y;
     77 	}
     78 	if ( strideX < 0 ) {
     79 		ix = 2 * (1-N) * strideX;
     80 	} else {
     81 		ix = 0;
     82 	}
     83 	if ( strideY < 0 ) {
     84 		iy = 2 * (1-N) * strideY;
     85 	} else {
     86 		iy = 0;
     87 	}
     88 	sx = strideX * 2;
     89 	sy = strideY * 2;
     90 	for ( i = 0; i < N; i++ ) {
     91 		viewY[ iy ] = viewX[ ix ];
     92 		viewY[ iy+1 ] = viewX[ ix+1 ];
     93 		ix += sx;
     94 		iy += sy;
     95 	}
     96 	return y;
     97 }
     98 
     99 
    100 // EXPORTS //
    101 
    102 module.exports = ccopy;