-
-
Notifications
You must be signed in to change notification settings - Fork 810
/
Copy pathmain.c
84 lines (74 loc) · 2.49 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stdlib/ndarray/base/bytes_per_element.h"
#include "stdlib/ndarray/dtypes.h"
#include <stdint.h>
/**
* Returns the number of bytes per element for a given data type.
*
* ## Notes
*
* - If unable to resolve a provided data type, the function returns `0`.
*
* @param dtype data type (number)
* @return number of bytes per element
*
* @example
* #include "stdlib/ndarray/base/bytes_per_element.h"
* #include "stdlib/ndarray/dtypes.h"
* #include <stdint.h>
*
* int64_t nbytes = stdlib_ndarray_bytes_per_element( STDLIB_NDARRAY_FLOAT64 );
* // returns 8
*/
int64_t stdlib_ndarray_bytes_per_element( enum STDLIB_NDARRAY_DTYPE dtype ) {
switch ( dtype ) {
case STDLIB_NDARRAY_FLOAT64:
return STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_FLOAT32:
return STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_INT8:
return STDLIB_NDARRAY_INT8_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_UINT8:
return STDLIB_NDARRAY_UINT8_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_UINT8C:
return STDLIB_NDARRAY_UINT8C_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_INT16:
return STDLIB_NDARRAY_INT16_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_UINT16:
return STDLIB_NDARRAY_UINT16_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_INT32:
return STDLIB_NDARRAY_INT32_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_UINT32:
return STDLIB_NDARRAY_UINT32_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_INT64:
return STDLIB_NDARRAY_INT64_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_UINT64:
return STDLIB_NDARRAY_UINT64_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_BOOL:
return STDLIB_NDARRAY_BOOL_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_BINARY:
return STDLIB_NDARRAY_BINARY_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_COMPLEX64:
return STDLIB_NDARRAY_COMPLEX64_BYTES_PER_ELEMENT;
case STDLIB_NDARRAY_COMPLEX128:
return STDLIB_NDARRAY_COMPLEX128_BYTES_PER_ELEMENT;
default:
return 0; // data type is not currently supported
}
}