Awkward Array: include/awkward/util.h Source File

Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
2
3#ifndef AWKWARD_UTIL_H_
4#define AWKWARD_UTIL_H_
5
6#include <string>
7#include <vector>
8#include <map>
9#include <memory>
10
11#include "awkward/common.h"
12
13#ifndef _MSC_VER
14 #include "dlfcn.h"
15#endif
16
17namespace awkward {
18 class Identities;
19 template <typename T>
20 class IndexOf;
21
22 namespace util {
26 enum class dtype {
27 NOT_PRIMITIVE,
28 boolean,
29 int8,
30 int16,
31 int32,
32 int64,
33 uint8,
34 uint16,
35 uint32,
36 uint64,
37 float16,
38 float32,
39 float64,
40 float128,
41 complex64,
42 complex128,
43 complex256,
44 datetime64,
45 timedelta64,
46 size
47 };
48
50 dtype
51 name_to_dtype(const std::string& name);
52
54 const std::string
55 dtype_to_name(dtype dt);
56
58 dtype
59 format_to_dtype(const std::string& format, int64_t itemsize);
60
62 const std::string
63 dtype_to_format(dtype dt, const std::string& format = "");
64
66 int64_t
67 dtype_to_itemsize(dtype dt);
68
70 bool
71 is_integer(dtype dt);
72
74 bool
75 is_signed(dtype dt);
76
78 bool
79 is_unsigned(dtype dt);
80
82 bool
83 is_real(dtype dt);
84
86 bool
87 is_complex(dtype dt);
88
97 void
98 handle_error(const struct Error &err,
99 const std::string &classname = std::string(""),
100 const Identities *id = nullptr);
101
112 std::string
113 quote(const std::string& x);
114
118 template <typename T>
119 IndexOf <T>
120 make_starts(const IndexOf <T> &offsets);
121
125 template <typename T>
126 IndexOf<T>
127 make_stops(const IndexOf<T>& offsets);
128
129 using RecordLookup = std::vector<std::string>;
130 using RecordLookupPtr = std::shared_ptr<RecordLookup>;
131
136 RecordLookupPtr
137 init_recordlookup(int64_t numfields);
138
141 int64_t
142 fieldindex(const RecordLookupPtr& recordlookup,
143 const std::string& key,
144 int64_t numfields);
145
148 const std::string
149 key(const RecordLookupPtr& recordlookup,
150 int64_t fieldindex,
151 int64_t numfields);
152
155 bool
156 haskey(const RecordLookupPtr& recordlookup,
157 const std::string& key,
158 int64_t numfields);
159
162 const std::vector<std::string>
163 keys(const RecordLookupPtr& recordlookup, int64_t numfields);
164
165 using Parameters = std::map<std::string, std::string>;
166
169 bool
170 json_equals(const std::string &myvalue, const std::string &value);
171
178 bool
179 parameter_equals(const Parameters& parameters,
180 const std::string& key,
181 const std::string& value);
182
192 bool
193 parameters_equal(const Parameters& self, const Parameters& other, bool check_all);
194
197 void
198 merge_parameters(Parameters& output, const Parameters& input);
199
202 bool
203 parameter_isstring(const Parameters& parameters, const std::string& key);
204
207 bool
208 parameter_isname(const Parameters& parameters, const std::string& key);
209
212 const std::string
213 parameter_asstring(const Parameters& parameters, const std::string& key);
214
215 using TypeStrs = std::map<std::string, std::string>;
216
219 std::string
220 gettypestr(const Parameters& parameters,
221 const TypeStrs& typestrs);
222
224 enum class ForthError {
225 // execution can continue
226 none,
227
228 // execution cannot continue
229 not_ready,
230 is_done,
231 user_halt,
232 recursion_depth_exceeded,
233 stack_underflow,
234 stack_overflow,
235 read_beyond,
236 seek_beyond,
237 skip_beyond,
238 rewind_beyond,
239 division_by_zero,
240 varint_too_big,
241 text_number_missing,
242 quoted_string_missing,
243 enumeration_missing,
244
245 size
246 };
247
248 }
249}
250
251#endif // AWKWARD_UTIL_H_
awkward::Identities
A contiguous, two-dimensional array of integers and a list of strings used to represent a path from t...
Definition: Identities.h:57
awkward::IndexOf
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition: Index.h:82
common.h
awkward::util::parameter_asstring
const std::string parameter_asstring(const Parameters &parameters, const std::string &key)
Returns the parameter associated with key as a string if parameter_isstring; raises an error otherwis...
awkward::util::is_signed
bool is_signed(dtype dt)
True if the dtype is a signed integer.
awkward::util::make_stops
IndexOf< T > make_stops(const IndexOf< T > &offsets)
Converts an offsets index (from ListOffsetArray, for instance) into a stops index by viewing it with ...
awkward::util::format_to_dtype
dtype format_to_dtype(const std::string &format, int64_t itemsize)
Convert a NumPy format string and itemsize into a dtype enum.
awkward::util::parameters_equal
bool parameters_equal(const Parameters &self, const Parameters &other, bool check_all)
Returns true if all key-value pairs in self is equal to all key-value pairs in other.
awkward::util::Parameters
std::map< std::string, std::string > Parameters
Definition: util.h:165
awkward::util::parameter_equals
bool parameter_equals(const Parameters &parameters, const std::string &key, const std::string &value)
Returns true if the value associated with a key in parameters is equal to the specified value.
awkward::util::key
const std::string key(const RecordLookupPtr &recordlookup, int64_t fieldindex, int64_t numfields)
Returns the key associated with a field index, given a RecordLookup and a number of fields.
awkward::util::parameter_isname
bool parameter_isname(const Parameters &parameters, const std::string &key)
Returns true if the parameter associated with key is a string that matches [A-Za-z_][A-Za-z_0-9]*; fa...
awkward::util::parameter_isstring
bool parameter_isstring(const Parameters &parameters, const std::string &key)
Returns true if the parameter associated with key is a string; false otherwise.
awkward::util::json_equals
bool json_equals(const std::string &myvalue, const std::string &value)
Returns true if myvalue is equal to value when interpreted as JSON.
awkward::util::is_complex
bool is_complex(dtype dt)
True if the dtype is a complex number.
awkward::util::is_unsigned
bool is_unsigned(dtype dt)
True if the dtype is an unsigned integer.
awkward::util::quote
std::string quote(const std::string &x)
Puts quotation marks around a string and escapes the appropriate characters.
awkward::util::fieldindex
int64_t fieldindex(const RecordLookupPtr &recordlookup, const std::string &key, int64_t numfields)
Returns the field index associated with a key, given a RecordLookup and a number of fields.
awkward::util::name_to_dtype
dtype name_to_dtype(const std::string &name)
Returns the name associated with a given dtype.
awkward::util::RecordLookupPtr
std::shared_ptr< RecordLookup > RecordLookupPtr
Definition: util.h:130
awkward::util::value
Mapping::value_type::value_type value(Mapping a, const std::string &name)
Definition: datetime_util.h:49
awkward::util::RecordLookup
std::vector< std::string > RecordLookup
Definition: util.h:129
awkward::util::merge_parameters
void merge_parameters(Parameters &output, const Parameters &input)
Merges a set of input parameters with output, keeping only those that are common to all sets.
awkward::util::ForthError
ForthError
Exhaustive list of runtime errors possible in the ForthMachine.
Definition: util.h:224
awkward::util::ForthError::skip_beyond
@ skip_beyond
awkward::util::ForthError::varint_too_big
@ varint_too_big
awkward::util::ForthError::text_number_missing
@ text_number_missing
awkward::util::ForthError::none
@ none
awkward::util::ForthError::seek_beyond
@ seek_beyond
awkward::util::ForthError::user_halt
@ user_halt
awkward::util::ForthError::rewind_beyond
@ rewind_beyond
awkward::util::ForthError::read_beyond
@ read_beyond
awkward::util::ForthError::recursion_depth_exceeded
@ recursion_depth_exceeded
awkward::util::ForthError::stack_overflow
@ stack_overflow
awkward::util::ForthError::stack_underflow
@ stack_underflow
awkward::util::ForthError::is_done
@ is_done
awkward::util::ForthError::quoted_string_missing
@ quoted_string_missing
awkward::util::ForthError::not_ready
@ not_ready
awkward::util::ForthError::enumeration_missing
@ enumeration_missing
awkward::util::ForthError::division_by_zero
@ division_by_zero
awkward::util::is_integer
bool is_integer(dtype dt)
True if the dtype is a non-boolean integer (signed or unsigned).
awkward::util::TypeStrs
std::map< std::string, std::string > TypeStrs
Definition: util.h:215
awkward::util::make_starts
IndexOf< T > make_starts(const IndexOf< T > &offsets)
Converts an offsets index (from ListOffsetArray, for instance) into a starts index by viewing it with...
awkward::util::dtype_to_name
const std::string dtype_to_name(dtype dt)
Returns the name associated with a given dtype.
awkward::util::gettypestr
std::string gettypestr(const Parameters &parameters, const TypeStrs &typestrs)
Extracts a custom type string from typestrs if required by one of the parameters or an empty string i...
awkward::util::init_recordlookup
RecordLookupPtr init_recordlookup(int64_t numfields)
Initializes a RecordLookup by assigning each element with a string representation of its field index ...
awkward::util::dtype
dtype
NumPy dtypes that can be interpreted within Awkward C++ (only the primitive, fixed-width types)....
Definition: util.h:26
awkward::util::dtype::int32
@ int32
awkward::util::dtype::float16
@ float16
awkward::util::dtype::int8
@ int8
awkward::util::dtype::uint64
@ uint64
awkward::util::dtype::uint32
@ uint32
awkward::util::dtype::float128
@ float128
awkward::util::dtype::complex256
@ complex256
awkward::util::dtype::uint8
@ uint8
awkward::util::dtype::complex128
@ complex128
awkward::util::dtype::boolean
@ boolean
awkward::util::dtype::complex64
@ complex64
awkward::util::dtype::uint16
@ uint16
awkward::util::dtype::datetime64
@ datetime64
awkward::util::dtype::timedelta64
@ timedelta64
awkward::util::dtype::int16
@ int16
awkward::util::dtype::float32
@ float32
awkward::util::dtype::size
@ size
awkward::util::dtype::NOT_PRIMITIVE
@ NOT_PRIMITIVE
awkward::util::dtype::float64
@ float64
awkward::util::dtype::int64
@ int64
awkward::util::haskey
bool haskey(const RecordLookupPtr &recordlookup, const std::string &key, int64_t numfields)
Returns true if a RecordLookup has a given key; false otherwise.
awkward::util::keys
const std::vector< std::string > keys(const RecordLookupPtr &recordlookup, int64_t numfields)
Returns a given RecordLookup as keys or generate anonymous ones form a number of fields.
awkward::util::handle_error
void handle_error(const struct Error &err, const std::string &classname=std::string(""), const Identities *id=nullptr)
If the Error struct contains an error message (from a cpu-kernel through the C interface),...
awkward::util::dtype_to_format
const std::string dtype_to_format(dtype dt, const std::string &format="")
Convert a dtype enum into a NumPy format string.
awkward::util::dtype_to_itemsize
int64_t dtype_to_itemsize(dtype dt)
Convert a dtype enum into an itemsize.
awkward::util::name
std::string name(Mapping a, V value)
Definition: datetime_util.h:39
awkward::util::is_real
bool is_real(dtype dt)
True if the dtype is a non-complex floating point number.
awkward
Definition: BitMaskedArray.h:15
Error
Definition: common.h:57