1 #ifndef MF_NDARRAY_VIEW_H_
2 #define MF_NDARRAY_VIEW_H_
8 #include "../utility/misc.h"
10 #include <type_traits>
19 template<std::
size_t Dim,
typename T>
21 return array.
slice(c, 0);
29 template<std::
size_t Dim,
typename T, std::ptrdiff_t I>
30 class ndarray_view_fcall;
65 template<std::
size_t Dim,
typename T>
67 static_assert(Dim >= 1,
"ndarray_view dimension must be >= 1");
91 std::ptrdiff_t
fix_coordinate_(std::ptrdiff_t c, std::ptrdiff_t dim)
const;
124 explicit operator bool () const noexcept {
return !
is_null(); }
134 {
assign(std::forward<Arg>(arg));
return *
this; }
136 {
assign(other);
return *
this; }
163 decltype(
auto) operator[](std::ptrdiff_t c)
const {
164 return detail::get_subscript(*
this, c);
169 return section_(0, start, end, step);
189 template<
typename Arg>
bool operator==(Arg&& arg)
const {
return compare(std::forward<Arg>(arg)); }
190 template<
typename Arg>
bool operator!=(Arg&& arg)
const {
return !
compare(std::forward<Arg>(arg)); }
193 if(a.is_null() && b.is_null())
return true;
194 else return (a.start_ == b.start_) && (a.shape_ == b.shape_) && (a.strides_ == b.strides_);
206 template<std::
size_t New_dim>
217 return vw.swapaxis(0, 1);
strides_type strides_
Definition: ndarray_view.h:86
bool has_default_strides(std::size_t minimal_dimension=0) const noexcept
Check if view has default strides.
Definition: ndarray_view.tcc:51
ndarray_view(const ndarray_view< Dim, std::remove_const_t< T >> &arr)
Copy-construct view.
Definition: ndarray_view.h:119
std::ptrdiff_t contiguous_length_
Definition: ndarray_view.h:88
Mapping between coordinates, indices, and addresses of multi-dimensional data.
Definition: ndarray_view.h:16
void assign(const ndarray_view< Dim, T2 > &) const
Definition: ndarray_view.tcc:138
pointer start_
Definition: ndarray_view.h:84
ndarray_iterator< ndarray_view > iterator
Definition: ndarray_view.h:79
ndarray_view swapaxis(std::size_t axis1, std::size_t axis2) const
Definition: ndarray_view.tcc:250
ndsize< Dim > shape_type
Definition: ndarray_view.h:75
void reset(pointer start, const shape_type &shape)
Definition: ndarray_view.h:130
detail::ndarray_view_fcall< Dim, Elem, 1 > fcall_result
Definition: ndarray_view.h:167
const shape_type & shape() const noexcept
Definition: ndarray_view.h:200
fcall_result operator()(std::ptrdiff_t c) const
Definition: ndarray_view.h:171
static strides_type default_strides(const shape_type &, std::size_t padding=0)
Default strides which correspond to row-major order for specified shape.
Definition: ndarray_view.tcc:39
bool operator==(Arg &&arg) const
Definition: ndarray_view.h:189
static ndarray_view null()
Definition: ndarray_view.h:122
bool operator!=(Arg &&arg) const
Definition: ndarray_view.h:190
std::ptrdiff_t contiguous_length() const noexcept
Definition: ndarray_view.h:202
Elem value_type
Definition: ndarray_view.h:70
ndarray_view()
Create null view.
Definition: ndarray_view.h:109
fcall_result operator()() const
Definition: ndarray_view.h:174
ndarray_view< Dim-1, T > slice(std::ptrdiff_t c, std::ptrdiff_t dimension) const
Create ndarray_view with one less dimension, by fixing coordinate of axis dimension to c...
Definition: ndarray_view.tcc:225
const ndarray_view & operator=(const ndarray_view &other) const
Definition: ndarray_view.h:135
const coordinates_type & end_pos() const noexcept
Definition: ndspan.h:32
ndarray_view section(const span_type &span, const strides_type &steps=strides_type(1)) const
Cuboid section of view, defined using ndspan object.
Definition: ndarray_view.h:153
bool is_null() const noexcept
Definition: ndarray_view.h:123
ndptrdiff< Dim > strides_type
Definition: ndarray_view.h:76
ndarray_view section(const coordinates_type &start, const coordinates_type &end, const strides_type &steps=strides_type(1)) const
Cuboid section of view, with interval in each axis.
Definition: ndarray_view.tcc:214
ndptrdiff< Dim > coordinates_type
Definition: ndarray_view.h:74
Elem * pointer
Definition: ndarray_view.h:71
ndarray_view< New_dim, T > reshape(const ndsize< New_dim > &) const
Definition: ndarray_view.tcc:235
bool compare(const ndarray_view< Dim, T2 > &) const
Definition: ndarray_view.tcc:145
Vector of n-dimensional coordinates.
Definition: ndcoord.h:18
pointer coordinates_to_pointer(const coordinates_type &) const
Definition: ndarray_view.tcc:153
std::size_t size() const
Definition: ndarray_view.h:197
T product() const noexcept
Definition: ndcoord.h:111
std::ptrdiff_t index_type
Definition: ndarray_view.h:73
fcall_result operator()(std::ptrdiff_t start, std::ptrdiff_t end, std::ptrdiff_t step=1) const
Definition: ndarray_view.h:168
Cuboid n-dimensional span delimited by two ndcoord vectors.
Definition: ndspan.h:15
ndarray_view< 1+Dim, T > add_front_axis() const
Definition: ndarray_view.tcc:243
bool compare(const ndarray_view< Dim, const T > &other) const
Definition: ndarray_view.h:187
void reset(pointer start, const shape_type &shape, const strides_type &strides)
Definition: ndarray_view.h:128
shape_type shape_
Definition: ndarray_view.h:85
span_type full_span() const noexcept
Definition: ndarray_view.h:204
coordinates_type index_to_coordinates(const index_type &) const
Definition: ndarray_view.tcc:101
const ndarray_view & operator=(Arg &&arg) const
Definition: ndarray_view.h:133
reference at(const coordinates_type &) const
Definition: ndarray_view.tcc:162
const coordinates_type & start_pos() const noexcept
Definition: ndspan.h:31
ndarray_view< 2, T > flip(const ndarray_view< 2, T > &vw)
Definition: ndarray_view.h:216
iterator begin() const
Definition: ndarray_view.tcc:170
void assign(const ndarray_view< Dim, const T > &other) const
Definition: ndarray_view.h:184
std::size_t default_strides_padding(std::size_t minimal_dimension=0) const
Returns padding of the view which has default strides.
Definition: ndarray_view.tcc:64
ndspan< Dim > span_type
Definition: ndarray_view.h:77
friend bool same(const ndarray_view &a, const ndarray_view &b) noexcept
Definition: ndarray_view.h:192
static constexpr std::size_t dimension
Definition: ndarray_view.h:81
ndarray_view section_(std::ptrdiff_t dim, std::ptrdiff_t start, std::ptrdiff_t end, std::ptrdiff_t step) const
Definition: ndarray_view.tcc:184
index_type coordinates_to_index(const coordinates_type &) const
Definition: ndarray_view.tcc:117
const strides_type & strides() const noexcept
Definition: ndarray_view.h:201
iterator end() const
Definition: ndarray_view.tcc:176
pointer start() const noexcept
Definition: ndarray_view.h:199
void reset() noexcept
Definition: ndarray_view.h:127
Elem & reference
Definition: ndarray_view.h:72
Random access iterator which traverses an ndarray_view.
Definition: ndarray_iterator.h:16
std::ptrdiff_t fix_coordinate_(std::ptrdiff_t c, std::ptrdiff_t dim) const
Definition: ndarray_view.tcc:92