3#ifndef AWKWARD_CPP_HEADERS_UTILS_H_
4#define AWKWARD_CPP_HEADERS_UTILS_H_
21 std::cout <<
"Type " <<
typeid(T).name() <<
" is not recognized." << std::endl;
22 return typeid(T).name();
133 type_to_name<std::complex<float>>() {
141 type_to_name<std::complex<double>>() {
147 template <
typename T>
150 return type_to_name<T>();
193 template <
typename,
typename =
void>
198 template <
typename...>
203 template <
typename... T>
206 template <
typename T>
209 decltype(std::declval<T>().end())>> =
true;
211 template <
typename Test,
template <
typename...>
class Ref>
214 template <
template <
typename...>
class Ref,
typename... Args>
222 template <
typename T>
225 if (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos) {
226 return std::string(
"awkward type");
229 std::stringstream form_key;
230 form_key <<
"node" << (form_key_id++);
232 if (std::is_arithmetic<T>::value) {
233 std::string parameters(type_to_name<T>() +
"\", ");
234 if (std::is_same<T, char>::value) {
235 parameters = std::string(
236 "uint8\", \"parameters\": { \"__array__\": \"char\" }, ");
238 return "{\"class\": \"NumpyArray\", \"primitive\": \"" + parameters +
239 "\"form_key\": \"" + form_key.str() +
"\"}";
241 return "{\"class\": \"NumpyArray\", \"primitive\": \"" +
242 type_to_name<T>() +
"\", \"form_key\": \"" + form_key.str() +
246 typedef typename T::value_type value_type;
248 if (is_iterable<T>) {
249 std::string parameters(
"");
250 if (std::is_same<value_type, char>::value) {
252 std::string(
" \"parameters\": { \"__array__\": \"string\" }, ");
254 return "{\"class\": \"ListOffsetArray\", \"offsets\": \"i64\", "
256 type_to_form<value_type>(form_key_id) +
", " + parameters +
257 "\"form_key\": \"" + form_key.str() +
"\"}";
259 return "unsupported type";
263 template <
typename T>
266 return (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos);
274 template <
size_t INDEX>
281 template <
typename CONTENT,
typename FUNCTION>
283 visit(CONTENT& contents,
size_t index, FUNCTION fun) {
284 if (index == INDEX - 1) {
285 fun(std::get<INDEX - 1>(contents));
296 template <
typename CONTENT,
typename FUNCTION>
298 visit(CONTENT& ,
size_t , FUNCTION ) {
304 template <
typename FUNCTION,
typename... CONTENTs>
306 visit_at(std::tuple<CONTENTs...>
const& contents,
size_t index, FUNCTION fun) {
307 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
311 template <
typename FUNCTION,
typename... CONTENTs>
313 visit_at(std::tuple<CONTENTs...>& contents,
size_t index, FUNCTION fun) {
314 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
Definition: ArrayBuilder.h:14
const std::string type_to_numpy_like< uint8_t >()
Returns numpy-like character code of a primitive type as a string.
Definition: utils.h:157
const std::string type_to_name< double >()
Returns float32 string when the primitive type is a double floating point.
Definition: utils.h:117
const std::string type_to_name< char >()
Returns char string when the primitive type is a character.
Definition: utils.h:125
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:165
const std::string type_to_name< uint64_t >()
Returns uint64 string when the primitive type is a 64-bit unsigned integer.
Definition: utils.h:101
const std::string type_to_numpy_like()
Returns char string when the primitive type is a character.
Definition: utils.h:149
const std::string type_to_name< uint32_t >()
Returns uint32 string when the primitive type is a 32-bit unsigned integer.
Definition: utils.h:93
const std::string type_to_name< uint16_t >()
Returns uint16 string when the primitive type is a 16-bit unsigned integer.
Definition: utils.h:85
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:224
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:189
bool is_awkward_type()
Check if an RDataFrame column is an Awkward Array.
Definition: utils.h:265
const std::string type_to_name< Long64_t >()
Returns int64 string when the primitive type is a 64-bit signed integer.
Definition: utils.h:69
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition: utils.h:306
constexpr bool is_iterable
Definition: utils.h:194
typename voider< T... >::type void_t
Definition: utils.h:204
const std::string type_to_name< float >()
Returns float32 string when the primitive type is a floating point.
Definition: utils.h:109
const std::string type_to_name< int32_t >()
Returns int32 string when the primitive type is a 32-bit signed integer.
Definition: utils.h:53
const std::string type_to_name< uint8_t >()
Returns uint8 string when the primitive type is an 8-bit unsigned integer.
Definition: utils.h:77
const std::string type_to_name< int8_t >()
Returns int8 string when the primitive type is an 8-bit signed integer.
Definition: utils.h:37
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:173
const std::string type_to_name()
Returns the name of a primitive type as a string.
Definition: utils.h:20
const std::string type_to_name< int64_t >()
Returns int64 string when the primitive type is a 64-bit signed integer.
Definition: utils.h:61
const std::string type_to_name< int16_t >()
Returns int16 string when the primitive type is a 16-bit signed integer.
Definition: utils.h:45
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:181
const std::string type_to_name< bool >()
Returns bool string when the primitive type is boolean.
Definition: utils.h:29
static void visit(CONTENT &, size_t, FUNCTION)
Definition: utils.h:298
Class to index tuple at runtime.
Definition: utils.h:275
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:283
void type
Definition: utils.h:200