main.c (1865B)
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 #include "stdlib/ndarray/base/assert/is_contiguous.h" 20 #include "stdlib/ndarray/base/iteration_order.h" 21 #include "stdlib/ndarray/base/assert/is_single_segment_compatible.h" 22 #include "stdlib/ndarray/dtypes.h" 23 #include <stdint.h> 24 25 /** 26 * Determines if an array is contiguous. 27 * 28 * ## Notes 29 * 30 * - The function returns `1` if contiguous and `0` otherwise. 31 * 32 * @param dtype data type 33 * @param ndims number of dimensions 34 * @param shape array shape (dimensions) 35 * @param strides array strides (in bytes) 36 * @param offset index offset 37 * @return value indicating if contiguous 38 * 39 * @example 40 * #include "stdlib/ndarray/base/assert/is_contiguous.h" 41 * #include "stdlib/ndarray/dtypes.h" 42 * 43 * int64_t ndims = 2; 44 * int64_t shape[] = { 10, 10 }; 45 * int64_t strides[] = { 10, 1 }; 46 * int64_t offset = 0; 47 * 48 * int8_t b = stdlib_ndarray_is_contiguous( STDLIB_NDARRAY_UINT8, ndims, shape, strides, offset ); 49 * // returns 1 50 */ 51 int8_t stdlib_ndarray_is_contiguous( enum STDLIB_NDARRAY_DTYPE dtype, int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset ) { 52 if ( 53 stdlib_ndarray_iteration_order( ndims, strides ) != 0 && 54 stdlib_ndarray_is_single_segment_compatible( dtype, ndims, shape, strides, offset ) != 0 55 ) { 56 return 1; 57 } 58 return 0; 59 }