1#ifndef XPED_STORAGE_TYPE_CONTIGOUS_HPP_
2#define XPED_STORAGE_TYPE_CONTIGOUS_HPP_
4#include "yas/serialize.hpp"
5#include "yas/std_types.hpp"
12template <
typename Scalar, std::
size_t Rank, std::
size_t CoRank,
typename Symmetry,
typename AllocationPolicy>
18 using qType =
typename Symmetry::qType;
24 using DictType = std::unordered_map<
qType,
28 typename AllocationPolicy::template Allocator<std::pair<const qType, std::size_t>>>;
36 : m_uncoupled_domain(basis_domain)
37 , m_uncoupled_codomain(basis_codomain)
50 : m_uncoupled_domain(basis_domain)
51 , m_uncoupled_codomain(basis_codomain)
56 initialized_resize(
data, size);
82 for(
const auto& [q, dim, plain] : m_domain) {
84 m_sector.push_back(q);
85 m_dict.insert(std::make_pair(q, m_sector.size() - 1));
86 m_offsets.push_back(curr);
87 curr += m_domain.inner_dim(q) * m_codomain.
inner_dim(q);
95 assert(m_sector.size() > 0 and
"Block data needs to already set. Use initialized_resize() instead.");
96 assert(m_offsets.size() == m_sector.size() and
"Corrupted storage.");
97 assert(m_dict.size() == m_sector.size() and
"Corrupted storage.");
103 assert(i < m_offsets.size());
109 assert(i < m_offsets.size());
115 auto it = m_dict.find(q);
116 assert(it != m_dict.end());
117 return block(it->second);
122 auto it = m_dict.find(q);
123 assert(it != m_dict.end());
124 return block(it->second);
127 const DictType&
dict()
const {
return m_dict; }
128 DictType&
dict() {
return m_dict; }
130 const std::vector<qType, typename AllocationPolicy::template Allocator<qType>>&
sector()
const {
return m_sector; }
133 const Scalar*
data()
const {
return m_data.data(); }
134 Scalar*
data() {
return m_data.data(); }
136 auto begin() {
return m_data.begin(); }
137 auto end() {
return m_data.end(); }
139 const auto cbegin()
const {
return m_data.cbegin(); }
140 const auto cend()
const {
return m_data.cend(); }
144 const std::array<Qbasis<Symmetry, 1, AllocationPolicy>, Rank>&
uncoupledDomain()
const {
return m_uncoupled_domain; }
145 const std::array<Qbasis<Symmetry, 1, AllocationPolicy>, CoRank>&
uncoupledCodomain()
const {
return m_uncoupled_codomain; }
152 if(m_offsets.size() == 0) {
153 m_offsets.push_back(0);
155 m_offsets.push_back(m_offsets.back() + m_domain.
inner_dim(m_sector.back()) * m_codomain.
inner_dim(m_sector.back()));
157 m_sector.push_back(q);
158 m_dict.insert(std::make_pair(q, m_sector.size() - 1));
159 m_data.insert(m_data.end(), M.data(), M.data() + M.size());
162 void reserve(std::size_t size) { m_data.reserve(size); }
172 template <
typename Ar>
175 ar& YAS_OBJECT_NVP(
"x_storage",
178 (
"sectors", m_sector),
179 (
"uncoupled_domain", m_uncoupled_domain),
180 (
"uncoupled_codomain", m_uncoupled_codomain),
181 (
"domain", m_domain),
182 (
"codomain", m_codomain),
184 (
"offsets", m_offsets));
190 std::vector<Scalar, typename AllocationPolicy::template Allocator<Scalar>> m_data;
193 std::vector<qType, typename AllocationPolicy::template Allocator<qType>> m_sector;
195 std::array<Qbasis<Symmetry, 1, AllocationPolicy>, Rank> m_uncoupled_domain;
196 std::array<Qbasis<Symmetry, 1, AllocationPolicy>, CoRank> m_uncoupled_codomain;
202 std::vector<std::size_t, typename AllocationPolicy::template Allocator<std::size_t>> m_offsets;
204 void initialized_resize(
const Scalar*
data, std::size_t size)
208 std::size_t curr = 0;
209 for(
const auto& [q, dim, plain] : m_domain) {
211 m_sector.push_back(q);
212 m_dict.insert(std::make_pair(q, m_sector.size() - 1));
213 m_offsets.push_back(curr);
214 curr += m_domain.inner_dim(q) * m_codomain.
inner_dim(q);
217 assert(curr == size and
"You specified an incompatible data array for this tensor.");
Definition: Qbasis.hpp:39
size_t inner_dim(const size_t &num_in) const
Definition: Qbasis.cpp:195
bool IS_PRESENT(const qType &q) const
Definition: Qbasis.hpp:133
Qbasis< Symmetry, Rank, AllocationPolicy > build_FusionTree(const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, Rank > &uncoupled)
Definition: TensorHelper.cpp:29
XpedWorld & getUniverse()
Definition: Mpi.hpp:49
CTF::Matrix< Scalar > MapMType
Definition: MatrixInterface_Cyclops_impl.hpp:45
const CTF::Matrix< Scalar > cMapMType
Definition: MatrixInterface_Cyclops_impl.hpp:47
CTF::Matrix< Scalar > MType
Definition: MatrixInterface_Cyclops_impl.hpp:40
Definition: StorageType_contiguous.hpp:14
const mpi::XpedWorld & world() const
Definition: StorageType_contiguous.hpp:187
const Qbasis< Symmetry, CoRank, AllocationPolicy > & coupledCodomain() const
Definition: StorageType_contiguous.hpp:148
const auto cbegin() const
Definition: StorageType_contiguous.hpp:139
const Qbasis< Symmetry, Rank, AllocationPolicy > & coupledDomain() const
Definition: StorageType_contiguous.hpp:147
typename Symmetry::qType qType
Definition: StorageType_contiguous.hpp:18
MapMatrixType block(qType q)
Definition: StorageType_contiguous.hpp:120
void push_back(const qType &q, const MatrixType &M)
Definition: StorageType_contiguous.hpp:150
void serialize(Ar &ar)
Definition: StorageType_contiguous.hpp:173
StorageType(const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, Rank > basis_domain, const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, CoRank > basis_codomain, const mpi::XpedWorld &world=mpi::getUniverse())
Definition: StorageType_contiguous.hpp:33
const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, CoRank > & uncoupledCodomain() const
Definition: StorageType_contiguous.hpp:145
static constexpr bool IS_CONTIGUOUS()
Definition: StorageType_contiguous.hpp:76
std::size_t plainSize() const
Definition: StorageType_contiguous.hpp:142
void set_data(const Scalar *data, std::size_t size)
Definition: StorageType_contiguous.hpp:93
auto begin()
Definition: StorageType_contiguous.hpp:136
PlainInterface::MType< Scalar > MatrixType
Definition: StorageType_contiguous.hpp:15
cMapMatrixType block(std::size_t i) const
Definition: StorageType_contiguous.hpp:101
auto end()
Definition: StorageType_contiguous.hpp:137
DictType & dict()
Definition: StorageType_contiguous.hpp:128
void reserve(std::size_t size)
Definition: StorageType_contiguous.hpp:162
PlainInterface::MapMType< Scalar > MapMatrixType
Definition: StorageType_contiguous.hpp:16
cMapMatrixType block(qType q) const
Definition: StorageType_contiguous.hpp:113
const std::vector< qType, typename AllocationPolicy::template Allocator< qType > > & sector() const
Definition: StorageType_contiguous.hpp:130
qType sector(std::size_t i) const
Definition: StorageType_contiguous.hpp:131
Scalar * data()
Definition: StorageType_contiguous.hpp:134
PlainInterface::cMapMType< Scalar > cMapMatrixType
Definition: StorageType_contiguous.hpp:17
void clear()
Definition: StorageType_contiguous.hpp:164
const Scalar * data() const
Definition: StorageType_contiguous.hpp:133
MapMatrixType block(std::size_t i)
Definition: StorageType_contiguous.hpp:107
const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, Rank > & uncoupledDomain() const
Definition: StorageType_contiguous.hpp:144
MapMatrixType MatrixReturnType
Definition: StorageType_contiguous.hpp:20
StorageType(const StorageType< Scalar, Rank, CoRank, Symmetry, AllocationPolicy > &other)=default
void resize()
Definition: StorageType_contiguous.hpp:78
StorageType(const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, Rank > basis_domain, const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, CoRank > basis_codomain, const Scalar *data, std::size_t size, const mpi::XpedWorld &world=mpi::getUniverse())
Definition: StorageType_contiguous.hpp:45
cMapMatrixType ConstMatrixReturnType
Definition: StorageType_contiguous.hpp:21
const auto cend() const
Definition: StorageType_contiguous.hpp:140
const DictType & dict() const
Definition: StorageType_contiguous.hpp:127