3#ifndef AWKWARD_CPP_HEADERS_UTILS_H_
4#define AWKWARD_CPP_HEADERS_UTILS_H_
20 std::cout <<
"Type " <<
typeid(T).name() <<
" is not recognized." << std::endl;
21 return typeid(T).name();
124 type_to_name<std::complex<float>>() {
132 type_to_name<std::complex<double>>() {
138 template <
typename T>
141 return type_to_name<T>();
184 template <
typename,
typename =
void>
189 template <
typename...>
194 template <
typename... T>
197 template <
typename T>
200 decltype(std::declval<T>().end())>> =
true;
202 template <
typename Test,
template <
typename...>
class Ref>
205 template <
template <
typename...>
class Ref,
typename... Args>
213 template <
typename T>
216 if (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos) {
217 return std::string(
"awkward type");
220 std::stringstream form_key;
221 form_key <<
"node" << (form_key_id++);
223 if (std::is_arithmetic<T>::value) {
224 std::string parameters(type_to_name<T>() +
"\", ");
225 if (std::is_same<T, char>::value) {
226 parameters = std::string(
227 "uint8\", \"parameters\": { \"__array__\": \"char\" }, ");
229 return "{\"class\": \"NumpyArray\", \"primitive\": \"" + parameters +
230 "\"form_key\": \"" + form_key.str() +
"\"}";
232 return "{\"class\": \"NumpyArray\", \"primitive\": \"" +
233 type_to_name<T>() +
"\", \"form_key\": \"" + form_key.str() +
237 typedef typename T::value_type value_type;
239 if (is_iterable<T>) {
240 std::string parameters(
"");
241 if (std::is_same<value_type, char>::value) {
243 std::string(
" \"parameters\": { \"__array__\": \"string\" }, ");
245 return "{\"class\": \"ListOffsetArray\", \"offsets\": \"i64\", "
247 type_to_form<value_type>(form_key_id) +
", " + parameters +
248 "\"form_key\": \"" + form_key.str() +
"\"}";
250 return "unsupported type";
254 template <
typename T>
257 return (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos);
265 template <
size_t INDEX>
272 template <
typename CONTENT,
typename FUNCTION>
275 if (
index == INDEX - 1) {
276 fun(std::get<INDEX - 1>(contents));
287 template <
typename CONTENT,
typename FUNCTION>
289 visit(CONTENT& ,
size_t , FUNCTION ) {
295 template <
typename FUNCTION,
typename... CONTENTs>
297 visit_at(std::tuple<CONTENTs...>
const& contents,
size_t index, FUNCTION fun) {
302 template <
typename FUNCTION,
typename... CONTENTs>
Definition: BitMaskedArray.h:15
const std::string type_to_numpy_like< uint8_t >()
Returns numpy-like character code of a primitive type as a string.
Definition: utils.h:148
const std::string type_to_name< double >()
Returns float32 string when the primitive type is a double floating point.
Definition: utils.h:108
const std::string type_to_name< char >()
Returns char string when the primitive type is a character.
Definition: utils.h:116
const std::string type_to_numpy_like< int8_t >()
Returns numpy-like character code i8, when the primitive type is an 8-bit signed integer.
Definition: utils.h:156
const std::string type_to_name< uint64_t >()
Returns uint64 string when the primitive type is a 64-bit unsigned integer.
Definition: utils.h:92
const std::string type_to_numpy_like()
Returns char string when the primitive type is a character.
Definition: utils.h:140
const std::string type_to_name< uint32_t >()
Returns uint32 string when the primitive type is a 32-bit unsigned integer.
Definition: utils.h:84
const std::string type_to_name< uint16_t >()
Returns uint16 string when the primitive type is a 16-bit unsigned integer.
Definition: utils.h:76
std::string type_to_form(int64_t form_key_id)
Generates a Form, which is a unique description of the Layout Builder and its contents in the form of...
Definition: utils.h:215
const std::string type_to_numpy_like< int64_t >()
Returns numpy-like character code i64, when the primitive type is a 64-bit signed integer.
Definition: utils.h:180
bool is_awkward_type()
Check if an RDataFrame column is an Awkward Array.
Definition: utils.h:256
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition: utils.h:297
constexpr bool is_iterable
Definition: utils.h:185
typename voider< T... >::type void_t
Definition: utils.h:195
const std::string type_to_name< float >()
Returns float32 string when the primitive type is a floating point.
Definition: utils.h:100
const std::string type_to_name< int32_t >()
Returns int32 string when the primitive type is a 32-bit signed integer.
Definition: utils.h:52
const std::string type_to_name< uint8_t >()
Returns uint8 string when the primitive type is an 8-bit unsigned integer.
Definition: utils.h:68
const std::string type_to_name< int8_t >()
Returns int8 string when the primitive type is an 8-bit signed integer.
Definition: utils.h:36
const std::string type_to_numpy_like< uint32_t >()
Returns numpy-like character code u32, when the primitive type is a 32-bit unsigned integer.
Definition: utils.h:164
const std::string type_to_name()
Returns the name of a primitive type as a string.
Definition: utils.h:19
const std::string type_to_name< int64_t >()
Returns int64 string when the primitive type is a 64-bit signed integer.
Definition: utils.h:60
const std::string type_to_name< int16_t >()
Returns int16 string when the primitive type is a 16-bit signed integer.
Definition: utils.h:44
const std::string type_to_numpy_like< int32_t >()
Returns numpy-like character code i32, when the primitive type is a 32-bit signed integer.
Definition: utils.h:172
const std::string type_to_name< bool >()
Returns bool string when the primitive type is boolean.
Definition: utils.h:28
static void visit(CONTENT &, size_t, FUNCTION)
Definition: utils.h:289
Class to index tuple at runtime.
Definition: utils.h:266
static void visit(CONTENT &contents, size_t index, FUNCTION fun)
Accesses the tuple contents at INDEX and calls the given function on it.
Definition: utils.h:274
void type
Definition: utils.h:191