time-to-botec

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

main.js (1947B)


      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 // MODULES //
     22 
     23 var isSingleSegmentCompatible = require( './../../../../base/assert/is-single-segment-compatible' );
     24 var iterationOrder = require( './../../../../base/iteration-order' );
     25 var isRowMajor = require( './../../../../base/assert/is-row-major' );
     26 
     27 
     28 // MAIN //
     29 
     30 /**
     31 * Returns a boolean indicating if an array is row-major contiguous.
     32 *
     33 * @param {NonNegativeIntegerArray} shape - array shape
     34 * @param {IntegerArray} strides - stride array
     35 * @param {NonNegativeInteger} offset - index offset
     36 * @returns {boolean} boolean indicating if an array is row-major contiguous
     37 *
     38 * @example
     39 * var shape = [ 2, 2 ];
     40 * var strides = [ 2, 1 ];
     41 * var offset = 0;
     42 *
     43 * var bool = isRowMajorContiguous( shape, strides, offset );
     44 * // returns true
     45 *
     46 * @example
     47 * var shape = [ 2, 2 ];
     48 * var strides = [ -2, 1 ];
     49 * var offset = 2;
     50 *
     51 * var bool = isRowMajorContiguous( shape, strides, offset );
     52 * // returns false
     53 *
     54 * @example
     55 * var shape = [ 2, 2 ];
     56 * var strides = [ 2, 2 ];
     57 * var offset = 0;
     58 *
     59 * var bool = isRowMajorContiguous( shape, strides, offset );
     60 * // returns false
     61 */
     62 function isRowMajorContiguous( shape, strides, offset ) {
     63 	return (
     64 		iterationOrder( strides ) !== 0 &&
     65 		isRowMajor( strides ) &&
     66 		isSingleSegmentCompatible( shape, strides, offset )
     67 	);
     68 }
     69 
     70 
     71 // EXPORTS //
     72 
     73 module.exports = isRowMajorContiguous;