38 #include "../error/exception_utils.hpp"
39 #include "../types/types.hpp"
40 #include "../utilities.hpp"
42 #include "array_view.hpp"
43 #include "array_factory.hpp"
44 #include "array_view_utils.hpp"
45 #include "index_map/index_maps.hpp"
46 #include "../algorithms.hpp"
63 typename IMAP=dynamic_cindex_map,
64 typename IPA =inplace_arithmetics
79 typedef typename storage_type::iterator
iterator;
85 typedef typename storage_type::const_reverse_iterator
150 template<
typename ATYPE>
155 std::copy(view.
begin(),view.
end(),_data.begin());
170 template<
typename ...MDARGS>
176 for(
size_t i=0;i<array.
size();++i) (*
this)[i] = array[i];
191 template<
typename ...ARGS>
192 static array_type
create(ARGS... arguments)
196 return factory_type::create(std::forward<ARGS>(arguments)...);
216 static array_type
create(
const std::initializer_list<T1> &l1,
217 const std::initializer_list<T2> &l2)
221 return factory_type::create(l1,l2);
238 template<
typename ...MDARGS>
241 if((
void*)
this == (
void*)&array)
return *
this;
243 size_t s = array.
size();
244 for(
size_t i=0;i<s;++i) (*
this)[i] = array[i];
262 array_type &
operator=(
const std::initializer_list<value_type> &l)
264 if(l.size() != this->
size())
266 "Size of array and initializer list do not match");
268 std::copy(l.begin(),l.end(),this->
begin());
280 const map_type &
map()
const {
return this->
_imap; }
292 template<
typename CTYPE> CTYPE
shape()
const
295 std::copy(_imap.begin(),_imap.end(),c.begin());
373 value_type &
at(
size_t i)
379 catch(std::out_of_range &error)
381 std::stringstream ss;
382 ss<<
"Index "<<i<<
" is out of range ("<<
size()<<
")!";
398 value_type
at(
size_t i)
const
404 catch(std::out_of_range &error)
406 std::stringstream ss;
407 ss<<
"Index "<<i<<
" is out of range ("<<
size()<<
")!";
442 typename =
typename enable_element_cont<CTYPE>::type
446 return _data[_imap.offset(index)];
464 typename =
typename enable_element_cont<CTYPE>::type
468 return _data[_imap.offset(index)];
484 typename =
typename enable_view_cont<CTYPE>::type
508 typename =
typename enable_view_cont<CTYPE>::type
536 typename =
typename enable_valid_index<ITYPES...>::type
543 return provider_type::get_reference(*
this,_imap,indexes...);
564 typename =
typename enable_valid_index<ITYPES...>::type
611 value_type &
front() {
return _data.front(); }
622 value_type
front()
const {
return _data.front(); }
633 value_type &
back() {
return _data.back(); }
644 value_type
back()
const {
return _data.back(); }
653 iterator
begin() {
return _data.begin(); }
663 iterator
end() {
return _data.end(); }
672 const_iterator
begin()
const {
return _data.begin(); }
682 const_iterator
end()
const {
return _data.end(); }
688 reverse_iterator
rbegin() {
return _data.rbegin(); }
700 reverse_iterator
rend() {
return this->_data.rend(); }
739 template<
typename ATYPE>
781 template<
typename ATYPE>
823 template<
typename ATYPE>
865 template<
typename ATYPE>
910 template<
typename STORAGE,
typename IMAP,
typename IPA>
929 std::ostream &operator<<(std::ostream &o,const mdarray<STORAGE,IMAP,IPA> &a)
931 for(
auto iter = a.begin();iter!=a.end();++iter)
954 for(
auto iter=a.
begin();iter!=a.
end();++iter)
static container_type create(size_t n, value_type default_value=value_type())
create container of given size
Definition: container_utils.hpp:85
mdarray(const mdarray< MDARGS...> &array)
construction from an other array
Definition: mdarray.hpp:171
IPA inplace_arithmetic
inplace arithmetics type
Definition: mdarray.hpp:88
storage_type::const_iterator const_iterator
const iterator type
Definition: mdarray.hpp:81
storage_type::const_reverse_iterator const_reverse_iterator
const reverse iterator
Definition: mdarray.hpp:86
value_type & operator()(const CTYPE &index)
return element reference
Definition: mdarray.hpp:444
value_type operator[](size_t i) const
get value at i
Definition: mdarray.hpp:353
Size mismatch error.
Definition: exceptions.hpp:399
reverse_iterator rbegin()
return reverse iterator to last element
Definition: mdarray.hpp:688
mdarray(const map_type &map, const storage_type &s)
construct from map and storage
Definition: mdarray.hpp:119
value_type operator()(const CTYPE &index) const
return element value
Definition: mdarray.hpp:466
const map_type & map() const
get index map
Definition: mdarray.hpp:280
bool operator==(const mdarray< STORAGE, IMAP, IPA > &b1, const mdarray< STORAGE, IMAP, IPA > &b2)
equality comparison operator
Definition: mdarray.hpp:978
#define EXCEPTION_RECORD
macro creating an instance of ExceptionRecord
Definition: exceptions.hpp:48
type erasure array types
Definition: array.hpp:74
void insert(size_t i, const value_type &value)
insert value at index i
Definition: mdarray.hpp:423
size_t size_type
type used for size
Definition: mdarray.hpp:94
iterator end()
iterator to last element
Definition: mdarray.hpp:663
std::istream & operator>>(std::istream &is, mdarray< STORAGE, IMAP, IPA > &a)
input stream operator
Definition: mdarray.hpp:952
const_reverse_iterator rbegin() const
return const reverse iterator to last element
Definition: mdarray.hpp:694
IMAP map_type
index map type
Definition: mdarray.hpp:75
array_type & operator/=(value_type s)
unary division of a scalar
Definition: mdarray.hpp:848
array_type & operator+=(value_type s)
unary addition of a scalar
Definition: mdarray.hpp:722
STORAGE storage_type
type of the buffer object
Definition: mdarray.hpp:71
static const bool is_random_access
by default false
Definition: container_trait.hpp:60
value_type at(size_t i) const
get value at i
Definition: mdarray.hpp:398
mdarray< storage_type, map_type, IPA > array_type
type of the array
Definition: mdarray.hpp:77
value_type & at(size_t i)
get value at i
Definition: mdarray.hpp:373
array_view< const array_type > operator()(const CTYPE &slices) const
return array view
Definition: mdarray.hpp:487
storage_type::value_type value_type
arrays element type
Definition: mdarray.hpp:73
mdarray()
default constructor
Definition: mdarray.hpp:109
view_type_trait< const array_type, ITYPES...>::const_type operator()(ITYPES...indexes) const
multiindex access
Definition: mdarray.hpp:567
reverse_iterator rend()
return reverse iterator to 0-1 element
Definition: mdarray.hpp:700
container utility
Definition: container_utils.hpp:59
static const bool is_contiguous
by default false
Definition: container_trait.hpp:64
utility class for index maps
Definition: index_maps.hpp:100
array_view< array_type > view_type
view type
Definition: mdarray.hpp:90
index error
Definition: exceptions.hpp:437
iterator begin()
iterator to first element
Definition: mdarray.hpp:653
Definition: array_view_utils.hpp:299
container trait
Definition: container_trait.hpp:57
view_type_trait< array_type, ITYPES...>::type operator()(ITYPES...indexes)
multiindex access
Definition: mdarray.hpp:539
Definition: add_op.hpp:29
storage_type::reverse_iterator reverse_iterator
reverse iterator
Definition: mdarray.hpp:83
view trait
Definition: array_view_utils.hpp:238
const_iterator begin() const
const-iterator to first element
Definition: mdarray.hpp:672
static array_type create(ARGS...arguments)
generic construction function
Definition: mdarray.hpp:192
mdarray(const array_view< ATYPE > &view)
constrcut from a view
Definition: mdarray.hpp:151
IMAP _imap
Index map of the array.
Definition: mdarray.hpp:102
static const bool is_multidim
by default false
Definition: container_trait.hpp:66
template for a multi-dimensional array class
Definition: mdarray.hpp:66
value_type * data()
return pointer
Definition: mdarray.hpp:597
array factory
Definition: array_factory.hpp:50
CTYPE shape() const
shape to container
Definition: mdarray.hpp:292
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
value_type & back()
reference to last element
Definition: mdarray.hpp:633
STORAGE _data
instance of STORAGE
Definition: mdarray.hpp:104
storage_type::iterator iterator
iterator type
Definition: mdarray.hpp:79
value_type & operator[](size_t i)
get referece to element i
Definition: mdarray.hpp:334
static const type_id_t type_id
type ID of the element type
Definition: mdarray.hpp:99
array_view< const array_type > const_view_type
const view type
Definition: mdarray.hpp:92
value_type & front()
reference to first element
Definition: mdarray.hpp:611
T get_value(PTR holder_ptr)
get value from holder
Definition: utils.hpp:196
array_view< array_type > operator()(const CTYPE &slices)
return array view
Definition: mdarray.hpp:511
array_type & operator-=(const ATYPE &v)
unary subtraction of an array
Definition: mdarray.hpp:786
iterator end()
iterator to last element
Definition: array_view.hpp:573
static array_type create(const std::initializer_list< T1 > &l1, const std::initializer_list< T2 > &l2)
construction from initializer list
Definition: mdarray.hpp:216
size_t size() const
get size of array
Definition: mdarray.hpp:306
const_reverse_iterator rend() const
return const reverse iterator to 0-1 element
Definition: mdarray.hpp:706
array_type & operator=(const std::initializer_list< value_type > &l)
assignment from an initializer list
Definition: mdarray.hpp:262
array_type & operator/=(const ATYPE &v)
unary division of an array
Definition: mdarray.hpp:870
value_type back() const
value of last element
Definition: mdarray.hpp:644
mdarray(map_type &&map, storage_type &&s)
move construct from map and storage
Definition: mdarray.hpp:134
array_type & operator=(const mdarray< MDARGS...> &array)
assignment from a different array type
Definition: mdarray.hpp:239
const_iterator end() const
const-iterator to last element
Definition: mdarray.hpp:682
type_id_t
type codes for PNI data types
Definition: types/types.hpp:148
array_type & operator-=(value_type s)
unary subtraction of a scalar
Definition: mdarray.hpp:764
const value_type * data() const
return const pointer
Definition: mdarray.hpp:584
type erasure for POD data
Definition: value.hpp:46
checks for view index
Definition: array_view_utils.hpp:126
size_t rank() const
get number of dimensions
Definition: mdarray.hpp:319
array_type & operator*=(value_type s)
unary multiplication of a scalar
Definition: mdarray.hpp:806
bool operator!=(const mdarray< STORAGE, IMAP, IPA > &b1, const mdarray< STORAGE, IMAP, IPA > &b2)
inequality comparison operator
Definition: mdarray.hpp:1001
array_type & operator*=(const ATYPE &v)
unary multiplication of an array
Definition: mdarray.hpp:828
value_type front() const
value of first element
Definition: mdarray.hpp:622
iterator begin()
iterator to first element
Definition: array_view.hpp:564
static array_selection create(const CTYPE &s)
static creation function
Definition: array_selection.hpp:215
provides a view on a part of an array
Definition: add_op.hpp:32
array_type & operator+=(const ATYPE &v)
unary addition of an array
Definition: mdarray.hpp:744