71#include "runtime/types.h"
93constexpr inline std::size_t
dsizeof(type type) {
95 case boolean:
return 0;
96 case int8:
return sizeof(int8_t);
97 case int16:
return sizeof(int16_t);
98 case int32:
return sizeof(int32_t);
99 case int64:
return sizeof(int64_t);
100 case float32:
return sizeof(float);
101 case float64:
return sizeof(double);
102 case complex64:
return 2 *
sizeof(float);
103 case complex128:
return 2 *
sizeof(double);
127constexpr inline std::size_t
nbytesof(type dtype, std::size_t nelements) {
128 if (dtype ==
boolean) {
129 return (nelements + 7) / 8;
131 return dsizeof(dtype) * nelements;
146constexpr inline std::string
dnameof(type type) {
148 case boolean:
return "boolean";
149 case int8:
return "int8";
150 case int16:
return "int16";
151 case int32:
return "int32";
152 case int64:
return "int64";
153 case float32:
return "float32";
154 case float64:
return "float64";
155 case complex64:
return "complex64";
156 case complex128:
return "complex128";
157 default:
return "none";
184 case boolean:
return 1;
185 case int8:
return 12;
186 case int16:
return 13;
187 case int32:
return 14;
188 case int64:
return 15;
189 case float32:
return 24;
190 case float64:
return 25;
191 case complex64:
return 35;
192 case complex128:
return 36;
210 case 1 :
return boolean;
211 case 12:
return int8;
212 case 13:
return int16;
213 case 14:
return int32;
214 case 15:
return int64;
215 case 24:
return float32;
216 case 25:
return float64;
217 case 35:
return complex64;
218 case 36:
return complex128;
219 default:
return unknown;
225 if constexpr (std::is_same_v<T, bool>)
return boolean;
226 else if constexpr (std::is_same_v<T, int8_t>)
return int8;
227 else if constexpr (std::is_same_v<T, int16_t>)
return int16;
228 else if constexpr (std::is_same_v<T, int32_t>)
return int32;
229 else if constexpr (std::is_same_v<T, int64_t>)
return int64;
230 else if constexpr (std::is_same_v<T, float>)
return float32;
231 else if constexpr (std::is_same_v<T, double>)
return float64;
232 else if constexpr (std::is_same_v<T, std::complex<float>>)
return complex64;
233 else if constexpr (std::is_same_v<T, std::complex<double>>)
return complex128;
237inline std::ostream&
operator<<(std::ostream& ostream, type type) {
238 return ostream <<
dnameof(type);
Definition: buffer.hpp:41
constexpr std::string dnameof(type type)
Returns the string name of a given tensor data type.
Definition: types.hpp:146
constexpr type dtypeof()
Definition: types.hpp:224
constexpr uint8_t dcodeof(type type)
Returns the numeric code used for serialization of a data type.
Definition: types.hpp:182
std::ostream & operator<<(std::ostream &os, Shape const &shape)
Definition: shape.hpp:313
constexpr std::size_t nbytesof(type dtype, std::size_t nelements)
Returns the total number of bytes required to store nelements elements of the given data type.
Definition: types.hpp:127
constexpr std::size_t dsizeof(type type)
Returns the size in bytes of a given tensor data type.
Definition: types.hpp:93