7 #ifndef ALPSCORE_GF_TENSORBASE_H 8 #define ALPSCORE_GF_TENSORBASE_H 26 template<typename T, typename Cont = std::vector<typename std::remove_const<T>::type> >
34 template<
typename T2,
typename C2>
35 data_storage(
const data_storage<T2, C2> & storage) : data_(storage.size()) {
36 std::copy(storage.data(), storage.data() + storage.size(), data());
38 template<
typename T2,
typename C2>
39 data_storage(data_storage<T2, C2> && storage) : data_(storage.size()) {
40 std::copy(storage.data(), storage.data() + storage.size(), data());
44 data_storage(
const data_storage<T, Cont>& rhs) : data_(rhs.data_) {};
46 data_storage(data_storage<T, Cont>&& rhs) : data_(rhs.data_) {};
48 data_storage<T, Cont>& operator=(
const data_storage<T, Cont>& rhs) {
49 if(
size() != rhs.size()) {
52 std::copy(rhs.data(), rhs.data() + rhs.size(), data());
56 data_storage<T, Cont>& operator=(data_storage<T, Cont>&& rhs) {
57 if(
size() != rhs.size()) {
60 std::copy(rhs.data(), rhs.data() + rhs.size(), data());
70 template<
typename T2,
typename C2>
71 data_storage<T, Cont>& operator=(
const data_storage<T2, C2>& rhs) {
72 static_assert(std::is_convertible<T2, T>::value,
"Can not perform assignment: T2 can not be cast into T");
73 if(
size() != rhs.size()) {
76 std::copy(rhs.data(), rhs.data() + rhs.size(), data());
81 data_storage(
const data_view<T2> & view) : data_(view.size()) {
82 static_assert(std::is_convertible<T2, T>::value,
"View type can not be converted into storage");
83 std::copy(view.data(), view.data() + view.size(), data());
87 data_storage(data_view<T2> && view) noexcept : data_(view.size()){
88 std::copy(view.data(), view.data() + view.size(), data());
91 data_storage(
const T *data,
size_t size) : data_(size) {
92 std::copy(data, data + size, this->data());
95 explicit data_storage(
size_t size) : data_(size) {
96 std::fill(data(), data()+size, T(0));
100 inline T& data(
size_t i) {
104 inline const T& data(
size_t i)
const {
return data_[i];};
106 inline const T& operator()(
size_t i)
const {
return data_[i];};
107 inline T& operator()(
size_t i) {
111 size_t size()
const {
return data_.size();}
113 const T* data()
const {
return data_.data();}
115 T* data() {
return data_.data();}
117 void resize(
size_t new_size) {
118 data_.resize(new_size);
129 template<
typename T2,
typename C2>
130 bool operator==(
const data_storage<T2, C2> &
r)
const {
131 return r.size() ==
size() && std::equal(r.data(), r.data() + r.size(), data());
135 template<
typename T2>
136 bool operator==(
const data_view<T2>& r)
const {
146 #endif //ALPSCORE_GF_TENSORBASE_H std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
bool operator==(const dictionary &lhs, const dictionary &rhs)
detail::data_storage< T, std::vector< T > > simple_storage
T r(T x, T y=T(), T z=T())