Little-endian numpy type string for an element type, when numpy has one.
Definition at line 158 of file TensorCodec.cpp.
159{
160 if (dtype.
lanes != 1)
161 return std::nullopt;
162
163 const auto sized = [&](char code) -> std::optional<std::string> {
164 const unsigned size = dtype.
bits / 8U;
165 return std::string(size == 1 ? "|" : "<") + code + std::to_string(size);
166 };
167
168 switch (dtype.
kind) {
169 case Kind::FLOAT:
170 return (dtype.
bits == 16 || dtype.
bits == 32 || dtype.
bits == 64) ? sized(
'f') :
std::nullopt;
171 case Kind::INT:
172 return (dtype.
bits == 8 || dtype.
bits == 16 || dtype.
bits == 32 || dtype.
bits == 64) ? sized(
'i') :
std::nullopt;
173 case Kind::UINT:
174 return (dtype.
bits == 8 || dtype.
bits == 16 || dtype.
bits == 32 || dtype.
bits == 64) ? sized(
'u') :
std::nullopt;
175 case Kind::BOOL:
176 return dtype.
bits == 8 ? std::optional<std::string> {
"|b1" } : std::nullopt;
177 case Kind::COMPLEX:
178 return (dtype.
bits == 64 || dtype.
bits == 128) ? sized(
'c') :
std::nullopt;
179 default:
180 return std::nullopt;
181 }
182}
References MayaFlux::Kakshya::TensorDType::bits, MayaFlux::Kakshya::TensorDType::kind, and MayaFlux::Kakshya::TensorDType::lanes.
Referenced by encode_npy().