main.c (1669B)
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_buffer_length_compatible_shape.h" 20 #include "stdlib/ndarray/base/numel.h" 21 #include <stdint.h> 22 23 /** 24 * Determines if a buffer length is compatible with a provided shape array. 25 * 26 * ## Notes 27 * 28 * - The function returns `1` if the buffer length is compatible and `0` otherwise. 29 * 30 * @param len number of elements in data buffer 31 * @param ndims number of dimensions 32 * @param shape array shape (dimensions) 33 * @return value indicating if a buffer length is compatible 34 * 35 * @example 36 * #include "stdlib/ndarray/base/assert/is_buffer_length_compatible_shape.h" 37 * 38 * int64_t ndims = 2; 39 * int64_t shape[] = { 10, 10 }; 40 * 41 * int8_t b = stdlib_ndarray_is_buffer_length_compatible_shape( 1000, ndims, shape ); 42 * // returns 1 43 * 44 * int8_t b = stdlib_ndarray_is_buffer_length_compatible_shape( 10, ndims, shape ); 45 * // returns 0 46 */ 47 int8_t stdlib_ndarray_is_buffer_length_compatible_shape( int64_t len, int64_t ndims, int64_t *shape ) { 48 if ( len > stdlib_ndarray_numel( ndims, shape ) ) { 49 return 1; 50 } 51 return 0; 52 }