30 #include "index_map/index_maps.hpp"
31 #include "../utilities.hpp"
32 #include "array_selection.hpp"
33 #include "array_view_utils.hpp"
34 #include "../algorithms.hpp"
61 template<
typename ATYPE>
119 _parray(
std::ref(a)),
121 _imap(
map_utils<map_type>::create(_selection.
shape<index_type>())),
139 _parray(
std::ref(a)),
140 _selection(
std::move(s)),
141 _imap(
map_utils<map_type>::create(_selection.
shape<index_type>())),
154 _selection(c._selection),
157 _is_contiguous(c._is_contiguous),
158 _start_offset(c._start_offset)
166 _parray(
std::move(c._parray)),
167 _selection(
std::move(c._selection)),
168 _imap(
std::move(c._imap)),
169 _index(
std::move(c._index)),
170 _is_contiguous(c._is_contiguous),
171 _start_offset(c._start_offset)
178 template<
typename ETYPE>
181 if((
void*)
this == (
void*)&e)
return *
this;
184 std::copy(e.begin(),e.end(),this->
begin());
196 if(
this == &a)
return *
this;
198 _parray = std::move(a._parray);
199 _selection = std::move(a._selection);
200 _imap = std::move(a._imap);
201 _index = std::move(a._index);
202 _is_contiguous = a._is_contiguous;
203 _start_offset = a._start_offset;
223 typename =
typename enable_element_cont<CTYPE>::type
227 typedef typename ATYPE::map_type omap_type;
228 auto &ref = _parray.get();
231 return ref[_start_offset + _imap.
offset(index)];
234 auto map =
const_cast<omap_type&
>(ref.map());
255 typename =
typename enable_element_cont<CTYPE>::type
259 typedef typename ATYPE::map_type omap_type;
260 auto &ref = _parray.get();
263 return ref[_start_offset + _imap.
offset(index)];
266 auto map =
const_cast<omap_type&
>(ref.map());
286 template<
typename ...ITypes>
294 typedef typename ATYPE::map_type omap_type;
295 auto &ref = _parray.get();
298 return ref[_start_offset +
299 _imap.
offset(IDX_ARRAY(ITypes,indices))];
302 auto map =
const_cast<omap_type&
>(ref.map());
303 size_t o =
map.
offset(_selection,IDX_ARRAY(ITypes,indices));
322 template<
typename ...ITypes>
331 typedef typename ATYPE::map_type omap_type;
332 auto &ref = _parray.get();
335 return ref[_start_offset +
336 _imap.
offset(IDX_ARRAY(ITypes,indices))];
340 auto map =
const_cast<omap_type&
>(ref.map());
341 return ref[
map.
offset(_selection,IDX_ARRAY(ITypes,indices))];
355 template<
typename CTYPE> CTYPE
shape()
const
357 return _selection.template shape<CTYPE>();
381 auto index = _imap.template index<index_type>(i);
382 return (*
this)(index);
409 auto index = _imap.template index<index_type>(i);
410 return (*
this)(index);
433 "Selection view is not contiguous!");
455 "Selection view is not contiguous!");
471 value_type &
at(
size_t i)
490 value_type
at(
size_t i)
const
506 void insert(
size_t i,
const value_type &v) {
at(i) = v; }
541 return _selection.
size();
554 return _selection.
rank();
617 storage_type::inplace_arithmetic::add(*
this,s);
634 template<
typename RTYPE>
642 storage_type::inplace_arithmetic::add(*
this,v);
664 storage_type::inplace_arithmetic::sub(*
this,s);
682 template<
typename RTYPE>
690 storage_type::inplace_arithmetic::sub(*
this,v);
712 storage_type::inplace_arithmetic::mult(*
this,s);
729 template<
typename RTYPE>
737 storage_type::inplace_arithmetic::mult(*
this,v);
759 storage_type::inplace_arithmetic::div(*
this,s);
776 template<
typename RTYPE>
784 storage_type::inplace_arithmetic::div(*
this,v);
792 const map_type &
map()
const
820 template<
typename ATYPE>
835 template<
typename ATYPE>
861 template<
typename ATYPE>
864 if(a.size()!=b.size())
866 "Array view sizes do not match!");
868 return std::equal(a.begin(),a.end(),b.begin());
884 template<
typename ATYPE>
902 template<
typename ATYPE>
903 std::ostream &operator<<(std::ostream &stream,const array_view<ATYPE> &v)
905 for(
auto x: v) stream<<x<<
" ";
922 template<
typename ATYPE>
925 for(
auto &x: v) stream>>x;
array_type & operator*=(value_type s)
unary multiplication of a scalar
Definition: array_view.hpp:710
bool check_index_in_dim(size_t index, size_t dimsize)
check index in dim
std::shared_ptr< array_type > shared_ptr
shared pointer type
Definition: array_view.hpp:74
array_view(array_type &&c)
move constructor
Definition: array_view.hpp:165
Size mismatch error.
Definition: exceptions.hpp:399
size_t size() const
get selection size
Definition: array_selection.hpp:290
ATYPE::inplace_arithmetic inplace_arithmetic
inplace arithetic type
Definition: array_view.hpp:86
value_type & front()
return reference to the first element
Definition: array_view.hpp:512
size_t size() const
get size
Definition: array_view.hpp:539
array_view(storage_type &a, array_selection &&s)
constructor
Definition: array_view.hpp:138
#define EXCEPTION_RECORD
macro creating an instance of ExceptionRecord
Definition: exceptions.hpp:48
value_type operator()(const CTYPE &index) const
access with container index
Definition: array_view.hpp:257
array_type & operator+=(value_type s)
unary addition of a scalar
Definition: array_view.hpp:615
Shape mismatch error.
Definition: exceptions.hpp:360
index_type _index
local index buffer for index calculations
Definition: array_view.hpp:101
std::reference_wrapper< ATYPE > _parray
parent array from which to draw data
Definition: array_view.hpp:94
array_type & operator-=(const RTYPE &v)
unary subtraction of an array
Definition: array_view.hpp:688
bool operator==(const array_view< ATYPE > &a, const array_view< ATYPE > &b)
compare two array views
Definition: array_view.hpp:862
iterator type
Definition: container_iterator.hpp:59
value_type back() const
return value of last element
Definition: array_view.hpp:530
container_iterator< const array_type > const_iterator
const iterator type
Definition: array_view.hpp:80
array_view(const array_type &c)
copy constructor
Definition: array_view.hpp:152
size_t rank() const
get effective rank
Definition: array_selection.hpp:252
static const bool is_random_access
by default false
Definition: container_trait.hpp:60
array_type & operator=(const ETYPE &e)
copy assignment operator
Definition: array_view.hpp:179
std::unique_ptr< array_type > unique_ptr
unique pointer type
Definition: array_view.hpp:76
std::istream & operator>>(std::istream &stream, array_view< ATYPE > &v)
input operator for view
Definition: array_view.hpp:923
value_type operator[](size_t i) const
linearized access
Definition: array_view.hpp:399
static const type_id_t type_id
type id of the value_type
Definition: array_view.hpp:91
array_view(storage_type &a, const array_selection &s)
constructor
Definition: array_view.hpp:118
value_type at(size_t i) const
get value at index i
Definition: array_view.hpp:490
static const bool is_contiguous
by default false
Definition: container_trait.hpp:64
array_type & operator/=(const RTYPE &v)
unary division of an array
Definition: array_view.hpp:782
selection from a multidimensional array
Definition: array_selection.hpp:72
utility class for index maps
Definition: index_maps.hpp:100
bool is_contiguous() const
check if contiguous
Definition: array_view.hpp:804
container trait
Definition: container_trait.hpp:57
size_t start_offset(const MAPT &map, const array_selection &s)
compute first element offset
Definition: array_selection.hpp:535
value_type operator()(ITypes...indices) const
multidimensional access to data
Definition: array_view.hpp:329
Definition: add_op.hpp:29
array_type & operator-=(value_type s)
unary subtraction of a scalar
Definition: array_view.hpp:662
array_type & operator+=(const RTYPE &v)
unary addition of an array
Definition: array_view.hpp:640
type_id_t type_id(const array_view< ATYPE > &)
specialization for type_id
Definition: array_view.hpp:821
bool operator!=(const array_view< ATYPE > &a, const array_view< ATYPE > &b)
compare two array views
Definition: array_view.hpp:885
static const bool is_multidim
by default false
Definition: container_trait.hpp:66
static const bool is_iterable
by default false
Definition: container_trait.hpp:62
map from a type to type_id
Definition: type_id_map.hpp:55
container_iterator< array_type > iterator
iterator type
Definition: array_view.hpp:78
value_type * data()
get pointer to data
Definition: array_view.hpp:449
array_view< storage_type > array_type
type of the view
Definition: array_view.hpp:72
const value_type * data() const
get pointer to data
Definition: array_view.hpp:427
value_type & operator()(const CTYPE &index)
access with container index
Definition: array_view.hpp:225
std::vector< size_t > index_type
index type
Definition: array_view.hpp:84
map_type _imap
local index map - only used internally, this map describes the
Definition: array_view.hpp:99
size_t _start_offset
offset of the first element
Definition: array_view.hpp:106
value_type & operator[](size_t i)
linearzed access
Definition: array_view.hpp:371
iterator end()
iterator to last element
Definition: array_view.hpp:573
array_type & operator/=(value_type s)
unary division of a scalar
Definition: array_view.hpp:757
ATYPE storage_type
storage type
Definition: array_view.hpp:68
array_type & operator=(array_type &&a)
move assignment operator
Definition: array_view.hpp:194
bool _is_contiguous
check if selection is contiguous
Definition: array_view.hpp:103
value_type & operator()(ITypes...indices)
multidimensional access to data
Definition: array_view.hpp:292
void insert(size_t i, const value_type &v)
insert value at i
Definition: array_view.hpp:506
value_type & at(size_t i)
get value at index i
Definition: array_view.hpp:471
type_id_t
type codes for PNI data types
Definition: types/types.hpp:148
size_t rank() const
get rank of the view
Definition: array_view.hpp:552
value_type front() const
return value of first element
Definition: array_view.hpp:518
value_type & back()
return reference ot the last vlaue
Definition: array_view.hpp:524
array_selection _selection
selection object for index transformation
Definition: array_view.hpp:96
const_iterator begin() const
const iterator to first element
Definition: array_view.hpp:584
array_view< array_type > view_type
view type
Definition: array_view.hpp:82
index_map< index_type, typename ATYPE::map_type::implementation_type > map_type
map type
Definition: array_view.hpp:88
const_iterator end() const
const iterator to last element
Definition: array_view.hpp:596
ATYPE::value_type value_type
type of the data values
Definition: array_view.hpp:70
CTYPE shape() const
get shape of the view
Definition: array_view.hpp:355
const map_type & map() const
return reference to index map
Definition: array_view.hpp:792
size_t offset(const CTYPE &index) const
compute the offset
Definition: index_map.hpp:259
array_type & operator*=(const RTYPE &v)
unary multiplication of an array
Definition: array_view.hpp:735
iterator begin()
iterator to first element
Definition: array_view.hpp:564
provides a view on a part of an array
Definition: add_op.hpp:32