time-to-botec

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

main.js (2529B)


      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 isFloat32VectorLike = require( '@stdlib/assert/is-float32vector-like' );
     24 var dot = require( './../../base/sdot' ).ndarray;
     25 
     26 
     27 // MAIN //
     28 
     29 /**
     30 * Computes the dot product of two single-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 single-precision floating-point numbers
     35 * @throws {TypeError} second argument must be a 1-dimensional ndarray containing single-precision floating-point numbers
     36 * @throws {RangeError} input arrays must be the same length
     37 * @returns {number} dot product
     38 *
     39 * @example
     40 * var Float32Array = require( '@stdlib/array/float32' );
     41 * var array = require( '@stdlib/ndarray/array' );
     42 *
     43 * var x = array( new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ) );
     44 * var y = array( new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) );
     45 *
     46 * var z = sdot( x, y );
     47 * // returns -5.0
     48 */
     49 function sdot( x, y ) {
     50 	if ( !isFloat32VectorLike( x ) ) {
     51 		throw new TypeError( 'invalid argument. First argument must be a 1-dimensional ndarray containing single-precision floating-point numbers (i.e., an ndarray whose underlying data buffer is a Float32Array). Value: `' + x + '`.' );
     52 	}
     53 	if ( !isFloat32VectorLike( y ) ) {
     54 		throw new TypeError( 'invalid argument. Second argument must be a 1-dimensional ndarray containing single-precision floating-point numbers (i.e., an ndarray whose underlying data buffer is a Float32Array). Value: `' + y + '`.' );
     55 	}
     56 	if ( x.length !== y.length ) {
     57 		throw new RangeError( 'invalid argument. Arrays must be the same length. First argument length: ' + x.length + '. Second argument length: ' + y.length + '.' );
     58 	}
     59 	return dot( x.length, x.data, x.strides[ 0 ], x.offset, y.data, y.strides[ 0 ], y.offset ); // eslint-disable-line max-len
     60 }
     61 
     62 
     63 // EXPORTS //
     64 
     65 module.exports = sdot;