1#ifndef XPED_STORAGE_TYPE_VEC_OF_MAT_HPP_
2#define XPED_STORAGE_TYPE_VEC_OF_MAT_HPP_
10template <
typename Scalar, std::
size_t Rank, std::
size_t CoRank,
typename Symmetry,
typename AllocationPolicy>
16 using qType =
typename Symmetry::qType;
22 using DictType = std::unordered_map<
qType,
26 typename AllocationPolicy::template Allocator<std::pair<const qType, std::size_t>>>;
34 : m_uncoupled_domain(basis_domain)
35 , m_uncoupled_codomain(basis_codomain)
48 : m_uncoupled_domain(basis_domain)
49 , m_uncoupled_codomain(basis_codomain)
54 initialized_resize(
data, size);
78 return std::accumulate(m_data.cbegin(), m_data.cend(), 0, [](std::size_t cur,
const MatrixType& mat) { return cur + mat.size(); });
83 m_data.reserve(std::max(m_domain.
Nq(), m_codomain.
Nq()));
85 for(
const auto& [q, dim, plain] : m_domain) {
87 m_sector.push_back(q);
88 m_dict.insert(std::make_pair(q, m_sector.size() - 1));
89 MatrixType Mtmp = PlainInterface::construct<Scalar>(m_domain.inner_dim(q), m_codomain.
inner_dim(q), m_world);
90 m_data.push_back(Mtmp);
95 m_data.shrink_to_fit();
100 assert(i < m_data.size());
106 assert(i < m_data.size());
112 auto it = m_dict.find(q);
113 assert(it != m_dict.end());
114 return m_data[it->second];
119 auto it = m_dict.find(q);
120 assert(it != m_dict.end());
121 return m_data[it->second];
124 const DictType&
dict()
const {
return m_dict; }
125 DictType&
dict() {
return m_dict; }
127 const std::vector<qType, typename AllocationPolicy::template Allocator<qType>>&
sector()
const {
return m_sector; }
130 const std::array<Qbasis<Symmetry, 1, AllocationPolicy>, Rank>&
uncoupledDomain()
const {
return m_uncoupled_domain; }
131 const std::array<Qbasis<Symmetry, 1, AllocationPolicy>, CoRank>&
uncoupledCodomain()
const {
return m_uncoupled_codomain; }
138 m_sector.push_back(q);
139 m_dict.insert(std::make_pair(q, m_sector.size() - 1));
143 void reserve(std::size_t size) { m_data.reserve(size); }
165 std::vector<MatrixType, typename AllocationPolicy::template Allocator<MatrixType>> m_data;
168 std::vector<qType, typename AllocationPolicy::template Allocator<qType>> m_sector;
170 std::array<Qbasis<Symmetry, 1, AllocationPolicy>, Rank> m_uncoupled_domain;
171 std::array<Qbasis<Symmetry, 1, AllocationPolicy>, CoRank> m_uncoupled_codomain;
177 void initialized_resize(
const Scalar*
data, std::size_t size)
179 m_data.reserve(std::min(m_domain.
Nq(), m_codomain.
Nq()));
181 std::size_t current_dim = 0;
182 for(
const auto& [q, dim, plain] : m_domain) {
184 m_sector.push_back(q);
185 m_dict.insert(std::make_pair(q, m_sector.size() - 1));
187 m_data.emplace_back(tmp);
188 current_dim += m_domain.inner_dim(q) * m_codomain.
inner_dim(q);
191 assert(current_dim == size and
"You specified an incompatible data array for this tensor.");
193 m_data.shrink_to_fit();
Definition: Qbasis.hpp:39
std::size_t Nq() const
Definition: Qbasis.hpp:97
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
Definition: VecOfMatIterator.hpp:14
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_vecofmat.hpp:134
const Qbasis< Symmetry, Rank, AllocationPolicy > & coupledDomain() const
Definition: StorageType_vecofmat.hpp:133
typename Symmetry::qType qType
Definition: StorageType_contiguous.hpp:18
VecOfMatIterator< Scalar > begin()
Definition: StorageType_vecofmat.hpp:151
MatrixType & block(std::size_t i)
Definition: StorageType_vecofmat.hpp:104
void push_back(const qType &q, const MatrixType &M)
Definition: StorageType_vecofmat.hpp:136
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_vecofmat.hpp:31
const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, CoRank > & uncoupledCodomain() const
Definition: StorageType_vecofmat.hpp:131
static constexpr bool IS_CONTIGUOUS()
Definition: StorageType_vecofmat.hpp:74
std::size_t plainSize() const
Definition: StorageType_vecofmat.hpp:76
PlainInterface::MType< Scalar > MatrixType
Definition: StorageType_contiguous.hpp:15
const MatrixType & block(std::size_t i) const
Definition: StorageType_vecofmat.hpp:98
DictType & dict()
Definition: StorageType_vecofmat.hpp:125
void reserve(std::size_t size)
Definition: StorageType_vecofmat.hpp:143
PlainInterface::MapMType< Scalar > MapMatrixType
Definition: StorageType_contiguous.hpp:16
const std::vector< qType, typename AllocationPolicy::template Allocator< qType > > & sector() const
Definition: StorageType_vecofmat.hpp:127
qType sector(std::size_t i) const
Definition: StorageType_vecofmat.hpp:128
PlainInterface::cMapMType< Scalar > cMapMatrixType
Definition: StorageType_contiguous.hpp:17
void clear()
Definition: StorageType_vecofmat.hpp:145
MatrixType & block(qType q)
Definition: StorageType_vecofmat.hpp:117
const Scalar * data() const
Definition: StorageType_contiguous.hpp:133
const std::array< Qbasis< Symmetry, 1, AllocationPolicy >, Rank > & uncoupledDomain() const
Definition: StorageType_vecofmat.hpp:130
MapMatrixType MatrixReturnType
Definition: StorageType_contiguous.hpp:20
StorageType(const StorageType< Scalar, Rank, CoRank, Symmetry, AllocationPolicy > &other)=default
void resize()
Definition: StorageType_vecofmat.hpp:81
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_vecofmat.hpp:43
cMapMatrixType ConstMatrixReturnType
Definition: StorageType_contiguous.hpp:21
VecOfMatIterator< Scalar > end()
Definition: StorageType_vecofmat.hpp:156
const MatrixType & block(qType q) const
Definition: StorageType_vecofmat.hpp:110
const DictType & dict() const
Definition: StorageType_vecofmat.hpp:124