3#ifndef AWKWARD_CPP_HEADERS_UTILS_H_
4#define AWKWARD_CPP_HEADERS_UTILS_H_
22 inline const std::string
24 if (std::is_integral_v<T>) {
25 if (std::is_signed_v<T>) {
29 else if (
sizeof(T) == 2) {
32 else if (
sizeof(T) == 4) {
35 else if (
sizeof(T) == 8) {
43 else if (
sizeof(T) == 2) {
46 else if (
sizeof(T) == 4) {
49 else if (
sizeof(T) == 8) {
54 else if (std::is_same_v<T, float>) {
57 else if (std::is_same_v<T, double>) {
60 else if (std::is_same_v<T, std::complex<float>>) {
63 else if (std::is_same_v<T, std::complex<double>>) {
69 return std::string(
"unsupported primitive type: ") +
typeid(T).name();
73 inline const std::string
81 inline const std::string
92 inline const std::string
100 inline const std::string
108 inline const std::string
116 inline const std::string
124 inline const std::string
132 inline const std::string
137 template <
typename,
typename =
void>
140 template <
typename T>
142 std::void_t<decltype(std::declval<T>().begin()),
143 decltype(std::declval<T>().end())>> =
true;
145 template <
typename Test,
template <
typename...>
class Ref>
148 template <
template <
typename...>
class Ref,
typename... Args>
156 template <
typename T,
typename OFFSETS>
159 if (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos) {
160 return std::string(
"awkward type");
163 std::stringstream form_key;
164 form_key <<
"node" << (form_key_id++);
166 if constexpr (std::is_arithmetic<T>::value) {
168 if (std::is_same<T, char>::value) {
169 parameters = std::string(
170 "uint8\", \"parameters\": { \"__array__\": \"char\" }, ");
172 return "{\"class\": \"NumpyArray\", \"primitive\": \"" + parameters +
173 "\"form_key\": \"" + form_key.str() +
"\"}";
175 return "{\"class\": \"NumpyArray\", \"primitive\": \"" +
179 typedef typename T::value_type value_type;
182 std::string parameters(
"");
183 if (std::is_same<value_type, char>::value) {
185 std::string(
" \"parameters\": { \"__array__\": \"string\" }, ");
187 return "{\"class\": \"ListOffsetArray\", \"offsets\": \"" +
191 "\"form_key\": \"" + form_key.str() +
"\"}";
193 return "unsupported type";
198 template <
typename T>
201 return (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos);
209 template <
size_t INDEX>
216 template <
typename CONTENT,
typename FUNCTION>
218 visit(CONTENT& contents,
size_t index, FUNCTION fun) {
219 if (index == INDEX - 1) {
220 fun(std::get<INDEX - 1>(contents));
231 template <
typename CONTENT,
typename FUNCTION>
233 visit(CONTENT& ,
size_t , FUNCTION ) {
239 template <
typename FUNCTION,
typename... CONTENTs>
241 visit_at(std::tuple<CONTENTs...>
const& contents,
size_t index, FUNCTION fun) {
242 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
246 template <
typename FUNCTION,
typename... CONTENTs>
248 visit_at(std::tuple<CONTENTs...>& contents,
size_t index, FUNCTION fun) {
249 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
255 template<
typename LayoutBuilder>
257 std::map <std::string, size_t> names_nbytes = {};
258 std::vector<std::string> buffer_name;
259 builder->buffer_nbytes(names_nbytes);
260 for (
auto it: names_nbytes) {
261 buffer_name.push_back(it.first);
269 template<
typename LayoutBuilder>
271 std::map <std::string, size_t> names_nbytes = {};
272 std::vector<size_t> buffer_size;
273 builder->buffer_nbytes(names_nbytes);
274 for (
auto it: names_nbytes) {
275 buffer_size.push_back(it.second);
283 template<
typename LayoutBuilder>
285 std::map <std::string, size_t> names_nbytes = {};
286 builder->buffer_nbytes(names_nbytes);
287 return names_nbytes.size();
Definition LayoutBuilder.h:22
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:101
const std::string type_to_name< char >()
Definition utils.h:82
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:109
const std::string type_to_numpy_like()
Returns char string when the primitive type is a character.
Definition utils.h:93
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:133
bool is_awkward_type()
Check if an RDataFrame column is an Awkward Array.
Definition utils.h:200
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:241
constexpr bool is_iterable
Definition utils.h:138
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:158
std::vector< size_t > buffer_size_helper(const LayoutBuilder *builder)
Helper function to retrieve the sizes (in bytes) of the buffers.
Definition utils.h:270
size_t num_buffers_helper(const LayoutBuilder *builder)
Helper function to retrieve the number of the buffers.
Definition utils.h:284
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:117
const std::string type_to_name()
Returns the name of a primitive type as a string.
Definition utils.h:23
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:125
const std::string type_to_name< bool >()
Definition utils.h:74
std::vector< std::string > buffer_name_helper(const LayoutBuilder *builder)
Helper function to retrieve the names of the buffers.
Definition utils.h:256
static void visit(CONTENT &, size_t, FUNCTION)
Definition utils.h:233
Class to index tuple at runtime.
Definition utils.h:210
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:218