3#ifndef AWKWARD_NUMPYARRAY_H_
4#define AWKWARD_NUMPYARRAY_H_
24 const std::vector<int64_t>& inner_shape,
26 const std::string& format,
29 const std::vector<int64_t>
51 tojson(
bool pretty,
bool verbose)
const override;
77 const std::pair<int64_t, int64_t>
80 const std::pair<bool, int64_t>
90 key(int64_t fieldindex)
const override;
93 haskey(
const std::string& key)
const override;
95 const std::vector<std::string>
103 bool check_identities,
104 bool check_parameters,
106 bool compatibility_check)
const override;
115 const std::vector<int64_t> inner_shape_;
117 const std::string format_;
177 const std::shared_ptr<void>& ptr,
178 const std::vector<ssize_t>& shape,
179 const std::vector<ssize_t>& strides,
182 const std::string& format,
198 const std::shared_ptr<void>
220 const std::vector<ssize_t>
233 const std::vector<ssize_t>
325 form(
bool materialize)
const override;
331 caches(std::vector<ArrayCachePtr>& out)
const override;
335 const std::string& pre,
336 const std::string& post)
const override;
353 bool copyidentities)
const override;
378 const Slice& only_fields)
const override;
385 const Slice& only_fields)
const override;
393 const Index64& advanced)
const override;
401 const std::pair<int64_t, int64_t>
404 const std::pair<bool, int64_t>
414 key(int64_t fieldindex)
const override;
417 haskey(
const std::string& key)
const override;
419 const std::vector<std::string>
436 num(int64_t axis, int64_t depth)
const override;
438 const std::pair<Index64, ContentPtr>
457 rpad(int64_t target, int64_t axis, int64_t depth)
const override;
462 int64_t depth)
const override;
472 bool keepdims)
const override;
480 bool stable)
const override;
492 bool stable)
const override;
503 int64_t depth)
const override;
541 const Index64& advanced)
const override;
548 const Index64& advanced)
const override;
555 const Index64& advanced)
const override;
562 const Index64& advanced)
const override;
569 const Index64& advanced)
const override;
576 const Index64& advanced)
const override;
618 int64_t length)
const;
627 int64_t length)
const;
636 int64_t length)
const;
645 int64_t length)
const;
654 int64_t length)
const;
755 const Slice& tail)
const override;
761 const Slice& tail)
const override;
767 const Slice& tail)
const override;
774 template <
typename T>
779 template <
typename T>
784 template <
typename T>
797 const std::shared_ptr<void> index_sort(
const T* data,
807 const std::shared_ptr<void> array_sort(
const T* data,
815 const std::shared_ptr<void> array_unique(
const T* data,
819 int64_t& outlength)
const;
822 const std::shared_ptr<void> string_unique(
const T* data,
826 int64_t& outlength)
const;
829 bool subranges_equal(
const T* data,
835 const std::shared_ptr<void> as_type(
const T* data,
839 template<
typename TO,
typename FROM>
840 const std::shared_ptr<void> cast_to_type(
const FROM* data,
841 int64_t length)
const;
844 sort_data(
bool ascending,
851 std::shared_ptr<void> ptr_;
855 std::vector<ssize_t> shape_;
857 std::vector<ssize_t> strides_;
861 const ssize_t itemsize_;
863 const std::string format_;
Abstract superclass of all array node types (flat hierarchy). Any Content can be nested within any ot...
Definition: Content.h:276
A contiguous, one-dimensional array of integers used to represent data structures,...
Definition: Index.h:82
Represents a rectilinear numerical array that can be converted to and from NumPy without loss of info...
Definition: NumpyArray.h:138
int64_t purelist_depth() const override
The list-depth of this array, not counting any contained within a RecordArray.
const ContentPtr argsort_next(int64_t negaxis, const Index64 &starts, const Index64 &shifts, const Index64 &parents, int64_t outlength, bool ascending, bool stable) const override
This array sorted indices.
bool isempty() const
Returns true if any element of the shape is zero; false otherwise.
void caches(std::vector< ArrayCachePtr > &out) const override
Accumulates all the unique #ArrayCache objects from nested #VirtualArray nodes. (Uniqueness is determ...
const ContentPtr getitem_fields(const std::vector< std::string > &keys) const override
This array with the first nested RecordArray replaced by a RecordArray of a given subset of keys.
const ContentPtr getitem_next_jagged(const Index64 &slicestarts, const Index64 &slicestops, const SliceArray64 &slicecontent, const Slice &tail) const override
Internal function that propagates a jagged array (array with irregular-length dimensions) slice throu...
const ContentPtr getitem_at(int64_t at) const override
Returns the element at a given position in the array, handling negative indexing and bounds-checking ...
void setidentities() override
Assign a surrogate index of Identities to this array (in-place).
const ContentPtr toRegularArray() const
A contiguous version of this array with multidimensional shape replaced by nested RegularArray nodes.
const NumpyArray getitem_bystrides(const SliceNewAxis &newaxis, const Slice &tail, int64_t length) const
Internal function that propagates a generic getitem request through one axis by propagating strides (...
const ContentPtr getitem_field(const std::string &key, const Slice &only_fields) const override
const ContentPtr getitem_next(const SliceArray64 &array, const Slice &tail, const Index64 &advanced) const override
Inhibited general function (see 7 argument getitem_next specific to NumpyArray).
const NumpyArray getitem_bystrides(const SliceAt &at, const Slice &tail, int64_t length) const
Internal function that propagates a generic getitem request through one axis by propagating strides (...
const ContentPtr unique() const override
Returns an array where all components are unique.
const ContentPtr sort_next(int64_t negaxis, const Index64 &starts, const Index64 &parents, int64_t outlength, bool ascending, bool stable) const override
This array sorted.
void tojson_part(ToJson &builder, bool include_beginendlist) const override
Internal function to produce a JSON representation one node at a time.
const NumpyArray getitem_next(const SliceRange &range, const Slice &tail, const Index64 &carry, const Index64 &advanced, int64_t length, int64_t stride, bool first) const
Internal function that propagates a generic getitem request through one axis by building up a carry I...
const ContentPtr getitem_fields(const std::vector< std::string > &keys, const Slice &only_fields) const override
const std::vector< ssize_t > shape() const
Number of elements in each dimension. A one-dimensional array has a shape of length one.
int64_t length() const override
The number of elements in the array.
const NumpyArray getitem_bystrides(const SliceRange &range, const Slice &tail, int64_t length) const
Internal function that propagates a generic getitem request through one axis by propagating strides (...
const ContentPtr deep_copy(bool copyarrays, bool copyindexes, bool copyidentities) const override
Copies this node and all nodes hierarchically nested within it, optionally copying the associated arr...
const std::string validityerror(const std::string &path) const override
Returns an error message if this array is invalid; otherwise, returns an empty string.
const ContentPtr getitem_next(const SliceAt &at, const Slice &tail, const Index64 &advanced) const override
Inhibited general function (see 7 argument getitem_next specific to NumpyArray).
const std::string format() const
String representing the NumPy dtype (as defined by pybind11).
bool istuple() const override
Returns true if the outermost RecordArray is a tuple.
const NumpyArray getitem_next(const SliceAt &at, const Slice &tail, const Index64 &carry, const Index64 &advanced, int64_t length, int64_t stride, bool first) const
Internal function that propagates a generic getitem request through one axis by building up a carry I...
ssize_t itemsize() const
Number of bytes per item; should agree with the format.
const ContentPtr getitem_next(const SliceField &field, const Slice &tail, const Index64 &advanced) const override
Inhibited general function (see 7 argument getitem_next specific to NumpyArray).
const ContentPtr getitem_nothing() const override
Internal function to get an empty slice (with the correct type).
const NumpyArray getitem_bystrides(const SliceEllipsis &ellipsis, const Slice &tail, int64_t length) const
Internal function that propagates a generic getitem request through one axis by propagating strides (...
NumpyArray(const Index32 index)
Creates a NumpyArray from an Index32.
kernel::lib kernels() const override
Returns the kernel library enum for all nested ptr_lib within the array's tree structure....
const ContentPtr carry(const Index64 &carry, bool allow_lazy) const override
Returns an array of the same type with elements filtered, rearranged, and possibly duplicated by the ...
const ContentPtr combinations(int64_t n, bool replacement, const util::RecordLookupPtr &recordlookup, const util::Parameters ¶meters, int64_t axis, int64_t depth) const override
Tuples or records of all n-tuple combinations of list items at some axis depth.
void setidentities(const IdentitiesPtr &identities) override
Assign a specified set of Identities to this array (in-place).
ssize_t ndim() const
The number of dimensions, which is shape.size().
const NumpyArray getitem_next(const SliceEllipsis &ellipsis, const Slice &tail, const Index64 &carry, const Index64 &advanced, int64_t length, int64_t stride, bool first) const
Internal function that propagates a generic getitem request through one axis by building up a carry I...
const std::shared_ptr< void > ptr() const
Reference-counted pointer to the array buffer.
bool isscalar() const override
Returns true if the shape is zero-dimensional; false otherwise.
const ContentPtr localindex(int64_t axis, int64_t depth) const override
A (possibly nested) array of integers indicating the positions of elements within each nested list.
const ContentPtr getitem_range_nowrap(int64_t start, int64_t stop) const override
Subinterval of this array, without handling negative indexing or bounds-checking.
const ContentPtr as_unique_strings(const Index64 &offsets) const
const std::pair< Index64, ContentPtr > offsets_and_flattened(int64_t axis, int64_t depth) const override
Returns (a) an offsets Index and (b) a flattened version of the array at some axis depth.
const ContentPtr getitem(const Slice &where) const override
Entry point for general slicing: Slice represents a tuple of SliceItem nodes applying to each level o...
void tojson_complex(ToJson &builder, bool include_beginendlist) const
Internal function to fill JSON with complex values.
int64_t fieldindex(const std::string &key) const override
The position of a tuple or record key name if this array contains a RecordArray.
void check_for_iteration() const override
Performs up-front validity checks on an array so that they don't have to be checked in getitem_at_now...
const std::vector< std::string > keys() const override
A list of RecordArray keys or an empty list if this array does not contain a RecordArray.
const ContentPtr getitem_field(const std::string &key) const override
This array with the first nested RecordArray replaced by the field at key.
void tojson_string(ToJson &builder, bool include_beginendlist) const
Internal function to fill JSON with string values.
const std::pair< bool, int64_t > branch_depth() const override
Returns (a) whether the list-depth of this array "branches," or differs when followed through differe...
const ContentPtr rpad(int64_t target, int64_t axis, int64_t depth) const override
If axis = 0, returns a view of this array padded on the right with None values to have a minimum leng...
const ContentPtr getitem_next(const SliceItemPtr &head, const Slice &tail, const Index64 &advanced) const override
Internal function that propagates a generic getitem request through one axis (including advanced inde...
const ContentPtr getitem_at_nowrap(int64_t at) const override
Returns the element at a given position in the array, without handling negative indexing or bounds-ch...
void nbytes_part(std::map< size_t, int64_t > &largest) const override
Internal function used to calculate nbytes.
NumpyArray(const Index8 index)
Creates a NumpyArray from an Index8.
const ContentPtr mergemany(const ContentPtrVec &others) const override
Returns an array with this and the others concatenated (in order, this first, others last).
ssize_t byteoffset() const
Location of item zero in the buffer, relative to ptr, measured in bytes, rather than number of elemen...
const std::string key(int64_t fieldindex) const override
The record name associated with a given field index or the tuple index as a string (e....
bool is_subrange_equal(const Index64 &starts, const Index64 &stops) const override
Returns 'true' if subranges are equal.
const ContentPtr shallow_copy() const override
Copies this node without copying any nodes hierarchically nested within it or any array/index/identit...
const std::pair< int64_t, int64_t > minmax_depth() const override
Returns (a) the minimum list-depth and (b) the maximum list-depth of the array, which can differ if t...
bool is_unique() const override
Returns 'true' if all components of the array are unique.
const NumpyArray contiguous() const
A contiguous version of this array (or this array if iscontiguous()).
NumpyArray(const IdentitiesPtr &identities, const util::Parameters ¶meters, const std::shared_ptr< void > &ptr, const std::vector< ssize_t > &shape, const std::vector< ssize_t > &strides, ssize_t byteoffset, ssize_t itemsize, const std::string &format, util::dtype dtype, const kernel::lib ptr_lib)
Creates a NumpyArray from a full set of parameters.
const FormPtr form(bool materialize) const override
Low-level Form describing all the features of this array except the actual data buffers (Index,...
const SliceItemPtr asslice() const override
Converts this array into a SliceItem that can be used in getitem.
const std::string tostring_part(const std::string &indent, const std::string &pre, const std::string &post) const override
Internal function to build an output string for tostring.
const ContentPtr rpad_and_clip(int64_t target, int64_t axis, int64_t depth) const override
If axis = 0, returns a view of this array padded on the right.
void * data() const
Raw pointer to the beginning of data (i.e. offset accounted for).
const ContentPtr getitem_next(const SliceJagged64 &jagged, const Slice &tail, const Index64 &advanced) const override
Inhibited general function (see 7 argument getitem_next specific to NumpyArray).
const ContentPtr getitem_range(int64_t start, int64_t stop) const override
Subinterval of this array, handling negative indexing and bounds-checking like Python.
bool iscontiguous() const
Returns true if this array is contiguous; false otherwise.
NumpyArray(const IndexU8 index)
Creates a NumpyArray from an IndexU8.
uint8_t getbyte(ssize_t at) const
Dereferences a selected item as a uint8_t.
util::dtype dtype() const
NumpyArray(const IndexU32 index)
Creates a NumpyArray from an IndexU32.
const ContentPtr fillna(const ContentPtr &value) const override
Returns this array with None values replaced by a given value.
const NumpyArray getitem_next(const SliceItemPtr &head, const Slice &tail, const Index64 &carry, const Index64 &advanced, int64_t length, int64_t stride, bool first) const
Internal function that propagates a generic getitem request through one axis by building up a carry I...
int64_t numfields() const override
The number of fields in the first nested tuple or records or -1 if this array does not contain a Reco...
bool referentially_equal(const ContentPtr &other) const override
Returns true if this array has all the same buffers and parameters as other; false otherwise.
const TypePtr type(const util::TypeStrs &typestrs) const override
High-level Type describing this array.
const ContentPtr num(int64_t axis, int64_t depth) const override
The length of this array (as a NumpyArray scalar) if axis = 0 or the lengths of subarrays (as an arra...
ssize_t bytelength() const
The length of the array (or scalar, if shape.empty()) in bytes.
void tojson_real(ToJson &builder, bool include_beginendlist) const
Internal function to fill JSON with floating-point values.
const ContentPtr getitem_next(const SliceFields &fields, const Slice &tail, const Index64 &advanced) const override
Inhibited general function (see 7 argument getitem_next specific to NumpyArray).
bool mergeable(const ContentPtr &other, bool mergebool) const override
Returns true if this array can be merged with the other; false otherwise.
bool haskey(const std::string &key) const override
Returns true if the array contains a RecordArray with the specified key; false otherwise.
kernel::lib ptr_lib() const
const NumpyArray getitem_bystrides(const SliceItemPtr &head, const Slice &tail, int64_t length) const
Internal function that propagates a generic getitem request through one axis by propagating strides (...
NumpyArray(const Index64 index)
Creates a NumpyArray from an Index64.
const NumpyArray getitem_next(const SliceNewAxis &newaxis, const Slice &tail, const Index64 &carry, const Index64 &advanced, int64_t length, int64_t stride, bool first) const
Internal function that propagates a generic getitem request through one axis by building up a carry I...
const ContentPtr getitem_next_jagged(const Index64 &slicestarts, const Index64 &slicestops, const SliceJagged64 &slicecontent, const Slice &tail) const override
Internal function that propagates a jagged array (array with irregular-length dimensions) slice throu...
const ContentPtr getitem_next_jagged(const Index64 &slicestarts, const Index64 &slicestops, const SliceMissing64 &slicecontent, const Slice &tail) const override
Internal function that propagates a jagged array (array with irregular-length dimensions) slice throu...
const ContentPtr getitem_next(const SliceRange &range, const Slice &tail, const Index64 &advanced) const override
Inhibited general function (see 7 argument getitem_next specific to NumpyArray).
const ContentPtr shallow_simplify() const override
Returns an equivalent array simplified at one level only using simplify_optiontype if an option-type ...
const NumpyArray getitem_next(const SliceArray64 &array, const Slice &tail, const Index64 &carry, const Index64 &advanced, int64_t length, int64_t stride, bool first) const
Internal function that propagates a generic getitem request through one axis by building up a carry I...
const ContentPtr reduce_next(const Reducer &reducer, int64_t negaxis, const Index64 &starts, const Index64 &shifts, const Index64 &parents, int64_t outlength, bool mask, bool keepdims) const override
This array with one axis removed by applying a Reducer (e.g. "sum", "max", "any", "all).
const std::vector< ssize_t > strides() const
Length of each dimension in number of bytes.
const ContentPtr numbers_to_type(const std::string &name) const override
Change the leaf types to 'totype'.
const std::string classname() const override
User-friendly name of this class: "NumpyArray".
const NumpyArray contiguous_next(const Index64 &bytepos) const
Internal function that propagates the derivation of a contiguous version of this array from one axis ...
void tojson_boolean(ToJson &builder, bool include_beginendlist) const
Internal function to fill JSON with boolean values.
void tojson_integer(ToJson &builder, bool include_beginendlist) const
Internal function to fill JSON with integer values.
const ContentPtr copy_to(kernel::lib ptr_lib) const override
An utility function to create a new instance of NumpyArray on the GPU identical to this one.
Abstract class for all reducer algorithms.
Definition: Reducer.h:20
Represents an array of integers in a slice (possibly converted from an array of booleans).
Definition: Slice.h:229
Represents an integer in a tuple of slices passed to __getitem__ in Python.
Definition: Slice.h:58
Represents a Python Ellipsis object (usual syntax: array[...]).
Definition: Slice.h:169
Represents a single string in a slice tuple, indicating that a RecordArray should be replaced by one ...
Definition: Slice.h:340
Represents an array of nested lists, where the content may be SliceArrayOf, SliceMissingOf,...
Definition: Slice.h:515
Represents a SliceArrayOf, SliceMissingOf, or SliceJaggedOf with missing values: None (no equivalent ...
Definition: Slice.h:435
Represents NumPy's newaxis marker (a.k.a. None), which prompts __getitem__ to insert a length-1 regul...
Definition: Slice.h:197
Represents a Python slice object (usual syntax: array[start:stop:step]).
Definition: Slice.h:93
A sequence of SliceItem objects representing a tuple passed to Python's __getitem__.
Definition: Slice.h:585
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
lib
Definition: kernel-dispatch.h:20
std::map< std::string, std::string > Parameters
Definition: util.h:165
std::shared_ptr< RecordLookup > RecordLookupPtr
Definition: util.h:130
std::map< std::string, std::string > TypeStrs
Definition: util.h:215
dtype
NumPy dtypes that can be interpreted within Awkward C++ (only the primitive, fixed-width types)....
Definition: util.h:26
Definition: BitMaskedArray.h:15
std::shared_ptr< std::string > FormKey
Definition: Content.h:19
std::vector< std::shared_ptr< Content > > ContentPtrVec
Definition: Content.h:16
std::shared_ptr< SliceItem > SliceItemPtr
Definition: Slice.h:15
std::shared_ptr< Content > ContentPtr
Definition: Content.h:15
std::shared_ptr< Form > FormPtr
Definition: Content.h:18
std::shared_ptr< Type > TypePtr
Definition: Content.h:23
std::shared_ptr< Identities > IdentitiesPtr
Definition: Identities.h:16