ndarray.js (2287B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 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 // VARIABLES // 22 23 var M = 8; 24 25 26 // MAIN // 27 28 /** 29 * Copies values from `x` into `y`. 30 * 31 * @param {PositiveInteger} N - number of values to copy 32 * @param {Float64Array} x - input array 33 * @param {integer} strideX - `x` stride length 34 * @param {NonNegativeInteger} offsetX - starting `x` index 35 * @param {Float64Array} y - destination array 36 * @param {integer} strideY - `y` stride length 37 * @param {NonNegativeInteger} offsetY - starting `y` index 38 * @returns {Float64Array} `y` 39 * 40 * @example 41 * var Float64Array = require( '@stdlib/array/float64' ); 42 * 43 * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); 44 * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); 45 * 46 * dcopy( x.length, x, 1, 0, y, 1, 0 ); 47 * // y => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ] 48 */ 49 function dcopy( N, x, strideX, offsetX, y, strideY, offsetY ) { 50 var ix; 51 var iy; 52 var m; 53 var i; 54 if ( N <= 0 ) { 55 return y; 56 } 57 ix = offsetX; 58 iy = offsetY; 59 60 // Use unrolled loops if both strides are equal to `1`... 61 if ( strideX === 1 && strideY === 1 ) { 62 m = N % M; 63 64 // If we have a remainder, run a clean-up loop... 65 if ( m > 0 ) { 66 for ( i = 0; i < m; i++ ) { 67 y[ iy ] = x[ ix ]; 68 ix += strideX; 69 iy += strideY; 70 } 71 } 72 if ( N < M ) { 73 return y; 74 } 75 for ( i = m; i < N; i += M ) { 76 y[ iy ] = x[ ix ]; 77 y[ iy+1 ] = x[ ix+1 ]; 78 y[ iy+2 ] = x[ ix+2 ]; 79 y[ iy+3 ] = x[ ix+3 ]; 80 y[ iy+4 ] = x[ ix+4 ]; 81 y[ iy+5 ] = x[ ix+5 ]; 82 y[ iy+6 ] = x[ ix+6 ]; 83 y[ iy+7 ] = x[ ix+7 ]; 84 ix += M; 85 iy += M; 86 } 87 return y; 88 } 89 for ( i = 0; i < N; i++ ) { 90 y[ iy ] = x[ ix ]; 91 ix += strideX; 92 iy += strideY; 93 } 94 return y; 95 } 96 97 98 // EXPORTS // 99 100 module.exports = dcopy;