time-to-botec

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

main.js (2654B)


      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 isFloat64VectorLike = require( '@stdlib/assert/is-float64vector-like' );
     24 var swap = require( './../../base/dswap' ).ndarray;
     25 
     26 
     27 // MAIN //
     28 
     29 /**
     30 * Interchanges two double-precision floating-point vectors.
     31 *
     32 * @param {VectorLike} x - first input array
     33 * @param {VectorLike} y - second input array
     34 * @throws {TypeError} first argument must be a 1-dimensional ndarray containing double-precision floating-point numbers
     35 * @throws {TypeError} second argument must be a 1-dimensional ndarray containing double-precision floating-point numbers
     36 * @throws {RangeError} input arrays must be the same length
     37 * @returns {VectorLike} `y`
     38 *
     39 * @example
     40 * var Float64Array = require( '@stdlib/array/float64' );
     41 * var array = require( '@stdlib/ndarray/array' );
     42 *
     43 * var x = array( new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ) );
     44 * var y = array( new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) );
     45 *
     46 * dswap( x, y );
     47 *
     48 * var xbuf = x.data;
     49 * // returns <Float64Array>[ 2.0, 6.0, -1.0, -4.0, 8.0 ]
     50 *
     51 * var ybuf = y.data;
     52 * // returns <Float64Array>[ 4.0, 2.0, -3.0, 5.0, -1.0 ]
     53 */
     54 function dswap( x, y ) {
     55 	if ( !isFloat64VectorLike( x ) ) {
     56 		throw new TypeError( 'invalid argument. First argument must be a 1-dimensional ndarray containing double-precision floating-point numbers (i.e., an ndarray whose underlying data buffer is a Float64Array). Value: `' + x + '`.' );
     57 	}
     58 	if ( !isFloat64VectorLike( y ) ) {
     59 		throw new TypeError( 'invalid argument. Second argument must be a 1-dimensional ndarray containing double-precision floating-point numbers (i.e., an ndarray whose underlying data buffer is a Float64Array). Value: `' + y + '`.' );
     60 	}
     61 	if ( x.length !== y.length ) {
     62 		throw new RangeError( 'invalid argument. Arrays must be the same length. First argument length: ' + x.length + '. Second argument length: ' + y.length + '.' );
     63 	}
     64 	swap( x.length, x.data, x.strides[ 0 ], x.offset, y.data, y.strides[ 0 ], y.offset ); // eslint-disable-line max-len
     65 	return y;
     66 }
     67 
     68 
     69 // EXPORTS //
     70 
     71 module.exports = dswap;