3#ifndef AWKWARD_CPP_HEADERS_UTILS_H_
4#define AWKWARD_CPP_HEADERS_UTILS_H_
29 template<
class T,
class U >
30 constexpr bool is_same_v = std::is_same<T, U>::value;
34 inline const std::string
36 if (is_integral_v<T>) {
41 else if (
sizeof(T) == 2) {
44 else if (
sizeof(T) == 4) {
47 else if (
sizeof(T) == 8) {
55 else if (
sizeof(T) == 2) {
58 else if (
sizeof(T) == 4) {
61 else if (
sizeof(T) == 8) {
66 else if (is_same_v<T, float>) {
69 else if (is_same_v<T, double>) {
72 else if (
is_same_v<T, std::complex<float>>) {
75 else if (
is_same_v<T, std::complex<double>>) {
81 return std::string(
"unsupported primitive type: ") +
typeid(T).name();
85 inline const std::string
93 inline const std::string
103 template <
typename T>
104 inline const std::string
106 return type_to_name<T>();
112 inline const std::string
120 inline const std::string
128 inline const std::string
136 inline const std::string
144 inline const std::string
149 template <
typename,
typename =
void>
154 template <
typename...>
159 template <
typename... T>
162 template <
typename T>
165 decltype(std::declval<T>().end())>> =
true;
167 template <
typename Test,
template <
typename...>
class Ref>
170 template <
template <
typename...>
class Ref,
typename... Args>
178 template <
typename T,
typename OFFSETS>
181 if (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos) {
182 return std::string(
"awkward type");
185 std::stringstream form_key;
186 form_key <<
"node" << (form_key_id++);
188 if (std::is_arithmetic<T>::value) {
189 std::string parameters(type_to_name<T>() +
"\", ");
190 if (std::is_same<T, char>::value) {
191 parameters = std::string(
192 "uint8\", \"parameters\": { \"__array__\": \"char\" }, ");
194 return "{\"class\": \"NumpyArray\", \"primitive\": \"" + parameters +
195 "\"form_key\": \"" + form_key.str() +
"\"}";
197 return "{\"class\": \"NumpyArray\", \"primitive\": \"" +
198 type_to_name<T>() +
"\", \"form_key\": \"" + form_key.str() +
202 typedef typename T::value_type value_type;
204 if (is_iterable<T>) {
205 std::string parameters(
"");
206 if (std::is_same<value_type, char>::value) {
208 std::string(
" \"parameters\": { \"__array__\": \"string\" }, ");
210 return "{\"class\": \"ListOffsetArray\", \"offsets\": \"" +
211 type_to_numpy_like<OFFSETS>() +
"\", "
213 type_to_form<value_type, OFFSETS>(form_key_id) +
", " + parameters +
214 "\"form_key\": \"" + form_key.str() +
"\"}";
216 return "unsupported type";
220 template <
typename T>
223 return (std::string(
typeid(T).name()).find(
"awkward") != std::string::npos);
231 template <
size_t INDEX>
238 template <
typename CONTENT,
typename FUNCTION>
240 visit(CONTENT& contents,
size_t index, FUNCTION fun) {
241 if (index == INDEX - 1) {
242 fun(std::get<INDEX - 1>(contents));
253 template <
typename CONTENT,
typename FUNCTION>
255 visit(CONTENT& ,
size_t , FUNCTION ) {
261 template <
typename FUNCTION,
typename... CONTENTs>
263 visit_at(std::tuple<CONTENTs...>
const& contents,
size_t index, FUNCTION fun) {
264 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
268 template <
typename FUNCTION,
typename... CONTENTs>
270 visit_at(std::tuple<CONTENTs...>& contents,
size_t index, FUNCTION fun) {
271 visit_impl<
sizeof...(CONTENTs)>::visit(contents, index, fun);
277 template<
typename LayoutBuilder>
279 std::map <std::string, size_t> names_nbytes = {};
280 std::vector<std::string> buffer_name;
281 builder->buffer_nbytes(names_nbytes);
282 for (
auto it: names_nbytes) {
283 buffer_name.push_back(it.first);
291 template<
typename LayoutBuilder>
293 std::map <std::string, size_t> names_nbytes = {};
294 std::vector<size_t> buffer_size;
295 builder->buffer_nbytes(names_nbytes);
296 for (
auto it: names_nbytes) {
297 buffer_size.push_back(it.second);
305 template<
typename LayoutBuilder>
307 std::map <std::string, size_t> names_nbytes = {};
308 builder->buffer_nbytes(names_nbytes);
309 return names_nbytes.size();
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:113
constexpr bool is_signed_v
Definition utils.h:27
const std::string type_to_name< char >()
Definition utils.h:94
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:121
const std::string type_to_numpy_like()
Returns char string when the primitive type is a character.
Definition utils.h:105
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:145
bool is_awkward_type()
Check if an RDataFrame column is an Awkward Array.
Definition utils.h:222
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:263
constexpr bool is_iterable
Definition utils.h:150
constexpr bool is_integral_v
Definition utils.h:24
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:180
std::vector< size_t > buffer_size_helper(const LayoutBuilder *builder)
Helper function to retrieve the sizes (in bytes) of the buffers.
Definition utils.h:292
size_t num_buffers_helper(const LayoutBuilder *builder)
Helper function to retrieve the number of the buffers.
Definition utils.h:306
typename voider< T... >::type void_t
Definition utils.h:160
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:129
const std::string type_to_name()
Returns the name of a primitive type as a string.
Definition utils.h:35
constexpr bool is_same_v
Definition utils.h:30
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:137
const std::string type_to_name< bool >()
Definition utils.h:86
std::vector< std::string > buffer_name_helper(const LayoutBuilder *builder)
Helper function to retrieve the names of the buffers.
Definition utils.h:278
static void visit(CONTENT &, size_t, FUNCTION)
Definition utils.h:255
Class to index tuple at runtime.
Definition utils.h:232
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:240
void type
Definition utils.h:156