3#ifndef AWKWARD_CPP_HEADERS_UTILS_H_
4#define AWKWARD_CPP_HEADERS_UTILS_H_
23 inline const std::string
25 if (std::is_integral_v<T>) {
26 if (std::is_signed_v<T>) {
30 else if (
sizeof(T) == 2) {
33 else if (
sizeof(T) == 4) {
36 else if (
sizeof(T) == 8) {
44 else if (
sizeof(T) == 2) {
47 else if (
sizeof(T) == 4) {
50 else if (
sizeof(T) == 8) {
55 else if (std::is_same_v<T, float>) {
58 else if (std::is_same_v<T, double>) {
61 else if (std::is_same_v<T, std::complex<float>>) {
64 else if (std::is_same_v<T, std::complex<double>>) {
70 return std::string(
"unsupported primitive type: ") +
typeid(T).name();
74 inline const std::string
82 inline const std::string
93 inline const std::string
101 inline const std::string
109 inline const std::string
117 inline const std::string
125 inline const std::string
133 inline const std::string
138 template <
typename,
typename =
void>
141 template <
typename T>
143 std::void_t<decltype(std::declval<T>().begin()),
144 decltype(std::declval<T>().end())>> =
true;
146 template <
typename Test,
template <
typename...>
class Ref>
149 template <
template <
typename...>
class Ref,
typename... Args>
157 template <
typename T,
typename OFFSETS>
160 if (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos) {
161 return std::string(
"awkward type");
164 std::stringstream form_key;
165 form_key <<
"node" << (form_key_id++);
167 if constexpr (std::is_arithmetic<T>::value) {
169 if (std::is_same<T, char>::value) {
170 parameters = std::string(
171 "uint8\", \"parameters\": { \"__array__\": \"char\" }, ");
173 return "{\"class\": \"NumpyArray\", \"primitive\": \"" + parameters +
174 "\"form_key\": \"" + form_key.str() +
"\"}";
176 return "{\"class\": \"NumpyArray\", \"primitive\": \"" +
180 typedef typename T::value_type value_type;
183 std::string parameters(
"");
184 if (std::is_same<value_type, char>::value) {
186 std::string(
" \"parameters\": { \"__array__\": \"string\" }, ");
188 return "{\"class\": \"ListOffsetArray\", \"offsets\": \"" +
192 "\"form_key\": \"" + form_key.str() +
"\"}";
194 return "unsupported type";
199 template <
typename T>
202 return (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos);
210 template <
size_t INDEX>
217 template <
typename CONTENT,
typename FUNCTION>
219 visit(CONTENT& contents,
size_t index, FUNCTION fun) {
220 if (index == INDEX - 1) {
221 fun(std::get<INDEX - 1>(contents));
232 template <
typename CONTENT,
typename FUNCTION>
234 visit(CONTENT& ,
size_t , FUNCTION ) {
240 template <
typename FUNCTION,
typename... CONTENTs>
242 visit_at(std::tuple<CONTENTs...>
const& contents,
size_t index, FUNCTION fun) {
243 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
247 template <
typename FUNCTION,
typename... CONTENTs>
249 visit_at(std::tuple<CONTENTs...>& contents,
size_t index, FUNCTION fun) {
250 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
256 template<
typename LayoutBuilder>
258 std::map <std::string, size_t> names_nbytes = {};
259 std::vector<std::string> buffer_name;
260 builder->buffer_nbytes(names_nbytes);
261 for (
auto it: names_nbytes) {
262 buffer_name.push_back(it.first);
270 template<
typename LayoutBuilder>
272 std::map <std::string, size_t> names_nbytes = {};
273 std::vector<size_t> buffer_size;
274 builder->buffer_nbytes(names_nbytes);
275 for (
auto it: names_nbytes) {
276 buffer_size.push_back(it.second);
284 template<
typename LayoutBuilder>
286 std::map <std::string, size_t> names_nbytes = {};
287 builder->buffer_nbytes(names_nbytes);
288 return names_nbytes.size();
Definition LayoutBuilder.h:23
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:102
const std::string type_to_name< char >()
Definition utils.h:83
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:110
const std::string type_to_numpy_like()
Returns char string when the primitive type is a character.
Definition utils.h:94
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:134
bool is_awkward_type()
Check if an RDataFrame column is an Awkward Array.
Definition utils.h:201
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:242
constexpr bool is_iterable
Definition utils.h:139
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:159
std::vector< size_t > buffer_size_helper(const LayoutBuilder *builder)
Helper function to retrieve the sizes (in bytes) of the buffers.
Definition utils.h:271
size_t num_buffers_helper(const LayoutBuilder *builder)
Helper function to retrieve the number of the buffers.
Definition utils.h:285
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:118
const std::string type_to_name()
Returns the name of a primitive type as a string.
Definition utils.h:24
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:126
const std::string type_to_name< bool >()
Definition utils.h:75
std::vector< std::string > buffer_name_helper(const LayoutBuilder *builder)
Helper function to retrieve the names of the buffers.
Definition utils.h:257
static void visit(CONTENT &, size_t, FUNCTION)
Definition utils.h:234
Class to index tuple at runtime.
Definition utils.h:211
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:219