1#ifndef XPED_MATLAB_HPP_
2#define XPED_MATLAB_HPP_
4#include <highfive/H5File.hpp>
9template <
typename Scalar, std::
size_t Rank, std::
size_t CoRank,
typename Symmetry,
typename AllocationPolicy>
12 const HighFive::Group& base,
13 std::array<bool, Rank + CoRank> conj = std::array<bool, Rank + CoRank>{},
16 constexpr std::size_t full_rank = Rank + CoRank;
17 auto get_indices = [](
auto combined_index, std::array<std::size_t, full_rank> dims) ->
auto
19 std::array<std::size_t, dims.size()> out{};
20 std::size_t divisor = combined_index;
21 std::size_t count = 0;
23 std::size_t tmp = divisor / dims[count];
24 std::size_t remainder = divisor % dims[count];
25 assert(count < dims.size());
26 out[count] = remainder;
33 std::array<Qbasis<Symmetry, 1>, full_rank> basis;
34 std::array<std::size_t, full_rank> dims;
36 auto charges_ref_dat = t.getDataSet(
"charges");
37 std::vector<HighFive::Reference> charges_ref;
38 charges_ref_dat.read(charges_ref);
39 std::array<std::vector<std::vector<double>>, full_rank> charges;
40 for(std::size_t r = 0; r < full_rank; ++r) {
41 auto ch_dat = charges_ref[r].template dereference<HighFive::DataSet>(base);
42 std::vector<std::vector<double>> ch;
45 for(std::size_t j = 0; j < ch[0].size(); ++j) {
46 basis[r].push_back({(qn_scale *
static_cast<int>(std::round(ch[0][j]))) % Symmetry::MOD_N[0]}, ch[1][j]);
50 for(
auto& [q, trees] : basis[r].allTrees()) {
51 for(
auto& tree : trees) { tree.IS_DUAL[0] =
true; }
55 dims[r] = ch[0].size();
58 auto raw_dat = t.getDataSet(
"vdat");
59 std::vector<double> raw;
62 auto off_dat = t.getDataSet(
"voffs");
63 std::vector<std::vector<Scalar>> off;
66 Tensor<Scalar, full_rank, 0, Symmetry, false, AllocationPolicy> tmp(basis, {{}});
68 for(std::size_t i = 0; i < off.size(); ++i) {
69 auto indices = get_indices(off[i][0], dims);
70 FusionTree<full_rank, Symmetry> tree;
71 tree.q_coupled = Symmetry::qvacuum();
72 for(std::size_t r = 0; r < full_rank; ++r) {
73 tree.q_uncoupled[r] = {(qn_scale *
static_cast<int>(std::round(charges[r][0][indices[r]]))) % Symmetry::MOD_N[0]};
74 tree.dims[r] = charges[r][1][indices[r]];
75 if(conj[r]) { tree.IS_DUAL[r] =
true; }
78 tree.computeIntermediates();
86 FusionTree<0, Symmetry> trivial;
88 trivial.q_coupled = Symmetry::qvacuum();
90 auto submatrix = tmp.subMatrix(tree, trivial);
91 std::size_t begin = off[i][1];
92 std::size_t end = (i == off.size() - 1) ? raw.size() : off[i + 1][1];
95 return tmp.template
permute<full_rank - Rank>(seq::make<std::size_t, full_rank>{});
Definition: Tensor.hpp:40
Tensor< Scalar, Rank, CoRank, Symmetry, false, AllocationPolicy > loadMatlabTensor(const HighFive::Group &t, const HighFive::Group &base, std::array< bool, Rank+CoRank > conj=std::array< bool, Rank+CoRank >{}, int qn_scale=1)
Definition: Matlab.hpp:11
std::unordered_map< std::pair< FusionTree< Rank - shift, Symmetry >, FusionTree< CoRank+shift, Symmetry > >, typename Symmetry::Scalar > permute(const FusionTree< Rank, Symmetry > &t1, const FusionTree< CoRank, Symmetry > &t2, const util::Permutation &p)
Definition: treepair.cpp:141
static void setVal(MType< Scalar > &M, const MIndextype row, const MIndextype col, const Scalar &val)