time-to-botec

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

main.js (1790B)


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