is_contiguous.js (1666B)
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 minmaxViewBufferIndex = require( './../../../base/minmax-view-buffer-index' ); 24 25 26 // MAIN // 27 28 /** 29 * Determines if an array is contiguous. 30 * 31 * @private 32 * @param {NonNegativeInteger} len - array length 33 * @param {NonNegativeIntegerArray} shape - array shape 34 * @param {IntegerArray} strides - stride array 35 * @param {NonNegativeInteger} offset - index offset 36 * @param {integer} iterationOrder - iteration order 37 * @returns {boolean} boolean indicating if an array is contiguous 38 */ 39 function isContiguous( len, shape, strides, offset, iterationOrder ) { 40 var buf; 41 42 // If an array does not contain any elements, then no data to store, and, if the array is unordered, adjacent array elements are not guaranteed to be stored next to each other. 43 if ( len === 0 || iterationOrder === 0 ) { 44 return false; 45 } 46 // Ensure that the array is compatible with a single memory segment: 47 buf = minmaxViewBufferIndex( shape, strides, offset ); 48 return ( len === ( buf[1]-buf[0]+1 ) ); 49 } 50 51 52 // EXPORTS // 53 54 module.exports = isContiguous;