time-to-botec

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

main.c (1514B)


      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_column_major.h"
     20 #include <stdint.h>
     21 #include <stdlib.h>
     22 
     23 /**
     24 * Determines if an array is column-major based on a provided stride array.
     25 *
     26 * ## Notes
     27 *
     28 * -   The function returns `1` if column-major and `0` otherwise.
     29 *
     30 * @param ndims    number of dimensions
     31 * @param strides  array strides
     32 * @return         value indicating if column-major
     33 *
     34 * @example
     35 * #include "stdlib/ndarray/base/assert/is_column_major.h"
     36 *
     37 * int64_t ndims = 2;
     38 * int64_t strides[] = { 1, 10 };
     39 *
     40 * int8_t b = stdlib_ndarray_is_column_major( ndims, strides );
     41 * // returns 1
     42 */
     43 int8_t stdlib_ndarray_is_column_major( int64_t ndims, int64_t *strides ) {
     44 	int64_t s1;
     45 	int64_t s2;
     46 	int64_t i;
     47 
     48 	if ( ndims == 0 ) {
     49 		return 0;
     50 	}
     51 	s1 = llabs( strides[ 0 ] );
     52 	for ( i = 1; i < ndims; i++ ) {
     53 		s2 = llabs( strides[ i ] );
     54 		if ( s2 < s1 ) {
     55 			return 0;
     56 		}
     57 		s1 = s2;
     58 	}
     59 	return 1;
     60 }