time-to-botec

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

ndarray.native.js (2632B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2021 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( './smskceil.native.js' );
     26 
     27 
     28 // MAIN //
     29 
     30 /**
     31 * Rounds each element in a single-precision floating-point strided array `x` toward positive infinity according to a strided mask array and assigns the results to elements in a single-precision floating-point strided array `y`.
     32 *
     33 * @param {NonNegativeInteger} N - number of indexed elements
     34 * @param {Float32Array} x - input array
     35 * @param {integer} sx - `x` stride length
     36 * @param {NonNegativeInteger} ox - starting `x` index
     37 * @param {Uint8Array} m - mask array
     38 * @param {integer} sm - `m` stride length
     39 * @param {NonNegativeInteger} om - starting `m` index
     40 * @param {Float32Array} y - destination array
     41 * @param {integer} sy - `y` stride length
     42 * @param {NonNegativeInteger} oy - starting `y` index
     43 * @returns {Float32Array} `y`
     44 *
     45 * @example
     46 * var Float32Array = require( '@stdlib/array/float32' );
     47 * var Uint8Array = require( '@stdlib/array/uint8' );
     48 *
     49 * var x = new Float32Array( [ 1.1, 2.5, -3.5, 4.0, -5.9 ] );
     50 * var m = new Uint8Array( [ 0, 0, 1, 0, 1 ] );
     51 * var y = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
     52 *
     53 * smskceil( x.length, x, 1, 0, m, 1, 0, y, 1, 0 );
     54 * // y => <Float32Array>[ 2.0, 3.0, 0.0, 4.0, 0.0 ]
     55 */
     56 function smskceil( N, x, sx, ox, m, sm, om, y, sy, oy ) {
     57 	var viewX;
     58 	var viewM;
     59 	var viewY;
     60 	if ( sx < 0 ) {
     61 		ox += (N-1) * sx;
     62 	}
     63 	if ( sm < 0 ) {
     64 		om += (N-1) * sm;
     65 	}
     66 	if ( sy < 0 ) {
     67 		oy += (N-1) * sy;
     68 	}
     69 	viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*ox), x.length-ox ); // eslint-disable-line max-len
     70 	viewM = new Uint8Array( m.buffer, m.byteOffset+(m.BYTES_PER_ELEMENT*om), m.length-om ); // eslint-disable-line max-len
     71 	viewY = new Float32Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*oy), y.length-oy ); // eslint-disable-line max-len
     72 	addon( N, viewX, sx, viewM, sm, viewY, sy );
     73 	return y;
     74 }
     75 
     76 
     77 // EXPORTS //
     78 
     79 module.exports = smskceil;