3#ifndef AWKWARD_CPP_HEADERS_UTILS_H_
4#define AWKWARD_CPP_HEADERS_UTILS_H_
28 template<
class T,
class U >
29 constexpr bool is_same_v = std::is_same<T, U>::value;
33 inline const std::string
35 if (is_integral_v<T>) {
40 else if (
sizeof(T) == 2) {
43 else if (
sizeof(T) == 4) {
46 else if (
sizeof(T) == 8) {
54 else if (
sizeof(T) == 2) {
57 else if (
sizeof(T) == 4) {
60 else if (
sizeof(T) == 8) {
65 else if (is_same_v<T, float>) {
68 else if (is_same_v<T, double>) {
71 else if (
is_same_v<T, std::complex<float>>) {
74 else if (
is_same_v<T, std::complex<double>>) {
80 return std::string(
"unsupported primitive type: ") +
typeid(T).name();
84 inline const std::string
92 inline const std::string
102 template <
typename T>
103 inline const std::string
105 return type_to_name<T>();
111 inline const std::string
119 inline const std::string
127 inline const std::string
135 inline const std::string
143 inline const std::string
148 template <
typename,
typename =
void>
153 template <
typename...>
158 template <
typename... T>
161 template <
typename T>
164 decltype(std::declval<T>().end())>> =
true;
166 template <
typename Test,
template <
typename...>
class Ref>
169 template <
template <
typename...>
class Ref,
typename... Args>
177 template <
typename T,
typename OFFSETS>
180 if (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos) {
181 return std::string(
"awkward type");
184 std::stringstream form_key;
185 form_key <<
"node" << (form_key_id++);
187 if (std::is_arithmetic<T>::value) {
188 std::string parameters(type_to_name<T>() +
"\", ");
189 if (std::is_same<T, char>::value) {
190 parameters = std::string(
191 "uint8\", \"parameters\": { \"__array__\": \"char\" }, ");
193 return "{\"class\": \"NumpyArray\", \"primitive\": \"" + parameters +
194 "\"form_key\": \"" + form_key.str() +
"\"}";
196 return "{\"class\": \"NumpyArray\", \"primitive\": \"" +
197 type_to_name<T>() +
"\", \"form_key\": \"" + form_key.str() +
201 typedef typename T::value_type value_type;
203 if (is_iterable<T>) {
204 std::string parameters(
"");
205 if (std::is_same<value_type, char>::value) {
207 std::string(
" \"parameters\": { \"__array__\": \"string\" }, ");
209 return "{\"class\": \"ListOffsetArray\", \"offsets\": \"" +
210 type_to_numpy_like<OFFSETS>() +
"\", "
212 type_to_form<value_type, OFFSETS>(form_key_id) +
", " + parameters +
213 "\"form_key\": \"" + form_key.str() +
"\"}";
215 return "unsupported type";
219 template <
typename T>
222 return (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos);
230 template <
size_t INDEX>
237 template <
typename CONTENT,
typename FUNCTION>
239 visit(CONTENT& contents,
size_t index, FUNCTION fun) {
240 if (index == INDEX - 1) {
241 fun(std::get<INDEX - 1>(contents));
252 template <
typename CONTENT,
typename FUNCTION>
254 visit(CONTENT& ,
size_t , FUNCTION ) {
260 template <
typename FUNCTION,
typename... CONTENTs>
262 visit_at(std::tuple<CONTENTs...>
const& contents,
size_t index, FUNCTION fun) {
263 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
267 template <
typename FUNCTION,
typename... CONTENTs>
269 visit_at(std::tuple<CONTENTs...>& contents,
size_t index, FUNCTION fun) {
270 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:112
constexpr bool is_signed_v
Definition utils.h:26
const std::string type_to_name< char >()
Definition utils.h:93
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:120
const std::string type_to_numpy_like()
Returns char string when the primitive type is a character.
Definition utils.h:104
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:144
bool is_awkward_type()
Check if an RDataFrame column is an Awkward Array.
Definition utils.h:221
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:262
constexpr bool is_iterable
Definition utils.h:149
constexpr bool is_integral_v
Definition utils.h:23
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:179
typename voider< T... >::type void_t
Definition utils.h:159
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:128
const std::string type_to_name()
Returns the name of a primitive type as a string.
Definition utils.h:34
constexpr bool is_same_v
Definition utils.h:29
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:136
const std::string type_to_name< bool >()
Definition utils.h:85
static void visit(CONTENT &, size_t, FUNCTION)
Definition utils.h:254
Class to index tuple at runtime.
Definition utils.h:231
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:239
void type
Definition utils.h:155