time-to-botec

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

main.c (2369B)


      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/bytes_per_element.h"
     20 #include "stdlib/ndarray/dtypes.h"
     21 #include <stdint.h>
     22 
     23 /**
     24 * Returns the number of bytes per element for a given data type.
     25 *
     26 * ## Notes
     27 *
     28 * -   If unable to resolve a provided data type, the function returns `0`.
     29 *
     30 * @param dtype  data type (number)
     31 * @return       number of bytes per element
     32 *
     33 * @example
     34 * #include "stdlib/ndarray/base/bytes_per_element.h"
     35 * #include "stdlib/ndarray/dtypes.h"
     36 * #include <stdint.h>
     37 *
     38 * int64_t nbytes = stdlib_ndarray_bytes_per_element( STDLIB_NDARRAY_FLOAT64 );
     39 * // returns 8
     40 */
     41 int64_t stdlib_ndarray_bytes_per_element( enum STDLIB_NDARRAY_DTYPE dtype ) {
     42 	switch ( dtype ) {
     43 	case STDLIB_NDARRAY_FLOAT64:
     44 		return STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT;
     45 	case STDLIB_NDARRAY_FLOAT32:
     46 		return STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT;
     47 	case STDLIB_NDARRAY_INT8:
     48 		return STDLIB_NDARRAY_INT8_BYTES_PER_ELEMENT;
     49 	case STDLIB_NDARRAY_UINT8:
     50 		return STDLIB_NDARRAY_UINT8_BYTES_PER_ELEMENT;
     51 	case STDLIB_NDARRAY_UINT8C:
     52 		return STDLIB_NDARRAY_UINT8C_BYTES_PER_ELEMENT;
     53 	case STDLIB_NDARRAY_INT16:
     54 		return STDLIB_NDARRAY_INT16_BYTES_PER_ELEMENT;
     55 	case STDLIB_NDARRAY_UINT16:
     56 		return STDLIB_NDARRAY_UINT16_BYTES_PER_ELEMENT;
     57 	case STDLIB_NDARRAY_INT32:
     58 		return STDLIB_NDARRAY_INT32_BYTES_PER_ELEMENT;
     59 	case STDLIB_NDARRAY_UINT32:
     60 		return STDLIB_NDARRAY_UINT32_BYTES_PER_ELEMENT;
     61 	case STDLIB_NDARRAY_INT64:
     62 		return STDLIB_NDARRAY_INT64_BYTES_PER_ELEMENT;
     63 	case STDLIB_NDARRAY_UINT64:
     64 		return STDLIB_NDARRAY_UINT64_BYTES_PER_ELEMENT;
     65 	case STDLIB_NDARRAY_BOOL:
     66 		return STDLIB_NDARRAY_BOOL_BYTES_PER_ELEMENT;
     67 	case STDLIB_NDARRAY_BINARY:
     68 		return STDLIB_NDARRAY_BINARY_BYTES_PER_ELEMENT;
     69 	default:
     70 		return 0; // data type is not currently supported
     71 	}
     72 }