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 {
28 boolean,
29 int8,
30 int16,
31 int32,
32 int64,
33 uint8,
34 uint16,
35 uint32,
36 uint64,
37 float16,
38 float32,
39 float64,
46 size
47 };
48
50 dtype
51 name_to_dtype(const std::string& name);
52
54 const std::string
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
68
70 bool
72
74 bool
76
78 bool
80
82 bool
84
86 bool
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>
127 make_stops(const IndexOf<T>& offsets);
128
129 using RecordLookup = std::vector<std::string>;
130 using RecordLookupPtr = std::shared_ptr<RecordLookup>;
131
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,
244
245 size
246 };
247
248 }
249}
250
251#endif // AWKWARD_UTIL_H_
A contiguous, two-dimensional array of integers and a list of strings used to represent a path from t...
Definition: Identities.h:57
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition: Index.h:82
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...
bool is_signed(dtype dt)
True if the dtype is a signed integer.
IndexOf< T > make_stops(const IndexOf< T > &offsets)
Converts an offsets index (from ListOffsetArray, for instance) into a stops index by viewing it with ...
dtype format_to_dtype(const std::string &format, int64_t itemsize)
Convert a NumPy format string and itemsize into a dtype enum.
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.
std::map< std::string, std::string > Parameters
Definition: util.h:165
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.
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.
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...
bool parameter_isstring(const Parameters &parameters, const std::string &key)
Returns true if the parameter associated with key is a string; false otherwise.
bool json_equals(const std::string &myvalue, const std::string &value)
Returns true if myvalue is equal to value when interpreted as JSON.
bool is_complex(dtype dt)
True if the dtype is a complex number.
bool is_unsigned(dtype dt)
True if the dtype is an unsigned integer.
std::string quote(const std::string &x)
Puts quotation marks around a string and escapes the appropriate characters.
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.
dtype name_to_dtype(const std::string &name)
Returns the name associated with a given dtype.
std::shared_ptr< RecordLookup > RecordLookupPtr
Definition: util.h:130
Mapping::value_type::value_type value(Mapping a, const std::string &name)
Definition: datetime_util.h:49
std::vector< std::string > RecordLookup
Definition: util.h:129
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.
ForthError
Exhaustive list of runtime errors possible in the ForthMachine.
Definition: util.h:224
bool is_integer(dtype dt)
True if the dtype is a non-boolean integer (signed or unsigned).
std::map< std::string, std::string > TypeStrs
Definition: util.h:215
IndexOf< T > make_starts(const IndexOf< T > &offsets)
Converts an offsets index (from ListOffsetArray, for instance) into a starts index by viewing it with...
const std::string dtype_to_name(dtype dt)
Returns the name associated with a given dtype.
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...
RecordLookupPtr init_recordlookup(int64_t numfields)
Initializes a RecordLookup by assigning each element with a string representation of its field index ...
dtype
NumPy dtypes that can be interpreted within Awkward C++ (only the primitive, fixed-width types)....
Definition: util.h:26
bool haskey(const RecordLookupPtr &recordlookup, const std::string &key, int64_t numfields)
Returns true if a RecordLookup has a given key; false otherwise.
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.
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),...
const std::string dtype_to_format(dtype dt, const std::string &format="")
Convert a dtype enum into a NumPy format string.
int64_t dtype_to_itemsize(dtype dt)
Convert a dtype enum into an itemsize.
std::string name(Mapping a, V value)
Definition: datetime_util.h:39
bool is_real(dtype dt)
True if the dtype is a non-complex floating point number.
Definition: BitMaskedArray.h:15
Definition: common.h:57