14 for (
int i = shape.size() - 1; i >= 0; --i) {
15 auto q_and_r = ldiv(elem, shape[i]);
16 loc += q_and_r.rem * strides[i];
30 Strides strides(shape.size(), 1);
31 for (
int i = shape.size() - 1; i > 0; i--) {
32 strides[i - 1] = strides[i] * shape[i];
45 const std::vector<Strides>& strides,
46 int64_t size_cap = std::numeric_limits<int32_t>::max());
49 const std::vector<array>& xs,
50 size_t size_cap = std::numeric_limits<int32_t>::max()) {
51 std::vector<Strides> strides;
53 strides.emplace_back(x.strides());
61 std::vector<array>{std::forward<Arrays>(xs)...});
68 int64_t size_cap = std::numeric_limits<int32_t>::max());
71 int64_t size_cap = std::numeric_limits<int32_t>::max());
75 int dims = shape_.size();
80 while (pos_[i] == (shape_[i] - 1) && i > 0) {
82 loc -= (shape_[i] - 1) * strides_[i];
91 for (
int i = shape_.size() - 1; i >= 0; --i) {
92 auto q_and_r = ldiv(n, shape_[i]);
93 loc += q_and_r.rem * strides_[i];
94 pos_[i] = q_and_r.rem;
101 std::fill(pos_.begin(), pos_.end(), 0);
107 : shape_(a.shape()), strides_(a.strides()) {
108 if (!shape_.empty()) {
109 std::tie(shape_, strides_) = collapse_contiguous_dims(shape_, strides_);
110 pos_ = Shape(shape_.size(), 0);
118 : shape_(shape.begin(), shape.begin() + dims),
119 strides_(strides.begin(), strides.begin() + dims) {
120 if (!shape_.empty()) {
121 std::tie(shape_, strides_) = collapse_contiguous_dims(shape_, strides_);
122 pos_ = Shape(shape_.size(), 0);
135 size_t no_broadcast_data_size = 1;
136 int64_t f_stride = 1;
137 int64_t b_stride = 1;
138 bool is_row_contiguous =
true;
139 bool is_col_contiguous =
true;
141 for (
int i = 0, ri = shape.size() - 1; ri >= 0; i++, ri--) {
142 is_col_contiguous &= strides[i] == f_stride || shape[i] == 1;
143 is_row_contiguous &= strides[ri] == b_stride || shape[ri] == 1;
144 f_stride *= shape[i];
145 b_stride *= shape[ri];
146 if (strides[i] > 0) {
147 no_broadcast_data_size *= shape[i];
151 return std::make_tuple(
152 no_broadcast_data_size, is_row_contiguous, is_col_contiguous);
156 constexpr size_t donation_extra = 16384;
const Flags & flags() const
Get the Flags bit-field.
Definition array.h:318
const Shape & shape() const
The shape of the array as a vector of integers.
Definition array.h:103
const Strides & strides() const
The strides of the array.
Definition array.h:117
size_t nbytes() const
The number of bytes in the array.
Definition array.h:93
bool is_donatable() const
True indicates the arrays buffer is safe to reuse.
Definition array.h:283
size_t buffer_size() const
Definition array.h:343
size_t itemsize() const
The size of the array's datatype in bytes.
Definition array.h:83
Strides make_contiguous_strides(const Shape &shape)
Definition utils.h:29
std::tuple< Shape, std::vector< Strides > > collapse_contiguous_dims(const Shape &shape, const std::vector< Strides > &strides, int64_t size_cap=std::numeric_limits< int32_t >::max())
int64_t elem_to_loc(int elem, const Shape &shape, const Strides &strides)
Definition utils.h:12
std::pair< bool, Strides > prepare_reshape(const array &in, const array &out)
std::vector< ShapeElem > Shape
Definition array.h:21
std::vector< int64_t > Strides
Definition array.h:22
void move_or_copy(const array &in, array &out)
void shared_buffer_reshape(const array &in, const Strides &out_strides, array &out)
auto check_contiguity(const Shape &shape, const Strides &strides)
Definition utils.h:134
bool is_donatable(const array &in, const array &out)
Definition utils.h:155
typename std::enable_if_t< is_arrays_v< T... > > enable_for_arrays_t
Definition array.h:630
int64_t loc
Definition utils.h:126
ContiguousIterator()
Definition utils.h:104
ContiguousIterator(const Shape &shape, const Strides &strides, int dims)
Definition utils.h:114
ContiguousIterator(const array &a)
Definition utils.h:106
void step()
Definition utils.h:74
void seek(int64_t n)
Definition utils.h:89
void reset()
Definition utils.h:99
bool row_contiguous
Definition array.h:237