time-to-botec

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

ndarray.native.js (2389B)


      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 var Uint8Array = require( '@stdlib/array/uint8' );
     25 var addon = require( './snanmskmin.native.js' );
     26 
     27 
     28 // MAIN //
     29 
     30 /**
     31 * Computes the minimum value of a single-precision floating-point strided array according to a mask, ignoring `NaN` values.
     32 *
     33 * @param {PositiveInteger} N - number of indexed elements
     34 * @param {Float32Array} x - input array
     35 * @param {integer} strideX - `x` stride length
     36 * @param {NonNegativeInteger} offsetX - `x` starting index
     37 * @param {Uint8Array} mask - mask array
     38 * @param {integer} strideMask - `mask` stride length
     39 * @param {NonNegativeInteger} offsetMask - `mask` starting index
     40 * @returns {number} minimum value
     41 *
     42 * @example
     43 * var Float32Array = require( '@stdlib/array/float32' );
     44 * var Uint8Array = require( '@stdlib/array/uint8' );
     45 * var floor = require( '@stdlib/math/base/special/floor' );
     46 *
     47 * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, -5.0, -6.0 ] );
     48 * var mask = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ] );
     49 * var N = floor( x.length / 2 );
     50 *
     51 * var v = snanmskmin( N, x, 2, 1, mask, 2, 1 );
     52 * // returns -2.0
     53 */
     54 function snanmskmin( N, x, strideX, offsetX, mask, strideMask, offsetMask ) {
     55 	var viewX;
     56 	var viewM;
     57 	if ( strideX < 0 ) {
     58 		offsetX += (N-1) * strideX;
     59 	}
     60 	if ( strideMask < 0 ) {
     61 		offsetMask += (N-1) * strideMask;
     62 	}
     63 	viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len
     64 	viewM = new Uint8Array( mask.buffer, mask.byteOffset+(mask.BYTES_PER_ELEMENT*offsetMask), mask.length-offsetMask ); // eslint-disable-line max-len
     65 	return addon( N, viewX, strideX, viewM, strideMask );
     66 }
     67 
     68 
     69 // EXPORTS //
     70 
     71 module.exports = snanmskmin;