9template<
typename Symmetry,
typename Scalar=
double>
13 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic>
MatrixType;
14 static constexpr size_t Nq = Symmetry::Nq;
31 vector<Biped<Symmetry,MatrixType> > &
A;
46template<
typename Symmetry,
typename Scalar>
50 if (HAS_BLOCKED) {
return;}
56template<
typename Symmetry,
typename Scalar>
60 assert (HAS_BLOCKED and
"Only can reblock if the A-tensor got blocked before.");
66template<
typename Symmetry,
typename Scalar>
71 for (
size_t qin=0; qin<inbase.Nq(); ++qin)
74 vector<size_t> svec, qvec, Ncolsvec;
75 for (
size_t s=0; s<qloc.size(); ++s)
76 for (
size_t q=0; q<
A[s].dim; ++q)
78 if (
A[s].in[q] == inbase[qin])
82 Ncolsvec.push_back(
A[s].block[q].cols());
86 if (Ncolsvec.size() > 0)
89 size_t Nrows =
A[svec[0]].block[qvec[0]].rows();
90 for (
size_t i=1; i<svec.size(); ++i)
92 assert(
A[svec[i]].block[qvec[i]].rows() == Nrows);
94 size_t Ncols = accumulate(Ncolsvec.begin(), Ncolsvec.end(), 0);
99 for (
size_t i=0; i<svec.size(); ++i)
101 Mtmp.block(0,stitch, Nrows,Ncolsvec[i]) =
A[svec[i]].block[qvec[i]]* Symmetry::coeff_leftSweep(
A[svec[i]].out[qvec[i]],
102 A[svec[i]].in[qvec[i]]);
103 stitch += Ncolsvec[i];
105 Aclump_.push_back(inbase[qin], inbase[qin], Mtmp);
110template<
typename Symmetry,
typename Scalar>
115 for (
size_t qout=0; qout<outbase.Nq(); ++qout)
118 vector<size_t> svec, qvec, Nrowsvec;
119 for (
size_t s=0; s<qloc.size(); ++s)
120 for (
size_t q=0; q<
A[s].dim; ++q)
122 if (
A[s].out[q] == outbase[qout])
126 Nrowsvec.push_back(
A[s].block[q].rows());
130 if (Nrowsvec.size() > 0)
133 size_t Ncols =
A[svec[0]].block[qvec[0]].cols();
134 for (
size_t i=1; i<svec.size(); ++i)
136 if (
A[svec[i]].block[qvec[i]].cols() != Ncols)
138 cout <<
"A[svec[i]].block[qvec[i]].cols()=" <<
A[svec[i]].block[qvec[i]].cols() <<
", Ncols=" << Ncols << endl;
141 for (
size_t i=1; i<svec.size(); ++i) {assert(
A[svec[i]].block[qvec[i]].cols() == Ncols);}
142 size_t Nrows = accumulate(Nrowsvec.begin(),Nrowsvec.end(),0);
147 for (
size_t i=0; i<svec.size(); ++i)
149 Mtmp.block(stitch,0, Nrowsvec[i],Ncols) =
A[svec[i]].block[qvec[i]];
150 stitch += Nrowsvec[i];
152 Aclump_.push_back(outbase[qout], outbase[qout], Mtmp);
157template<
typename Symmetry,
typename Scalar>
161 vector<Biped<Symmetry,MatrixType> > Aout(qloc.size());
163 for (
size_t qout=0; qout<outbase.Nq(); ++qout)
165 auto it =
B.dict.find({outbase[qout], outbase[qout]});
166 if (it ==
B.dict.end()) {
continue;}
168 size_t qB = it->second;
171 vector<size_t> svec, qvec, Nrowsvec;
172 for (
size_t s=0; s<qloc.size(); ++s)
173 for (
size_t q=0; q<
A[s].dim; ++q)
175 if (
A[s].out[q] == outbase[qout])
179 Nrowsvec.push_back(
A[s].block[q].rows());
184 for (
size_t i=0; i<svec.size(); ++i)
187 Mtmp =
B.block[qB].block(stitch,0, Nrowsvec[i],
B.block[qB].cols());
189 if (Mtmp.size() != 0)
191 Aout[svec[i]].push_back(
A[svec[i]].in[qvec[i]],
A[svec[i]].out[qvec[i]], Mtmp);
193 stitch += Nrowsvec[i];
199template<
typename Symmetry,
typename Scalar>
203 vector<Biped<Symmetry,MatrixType> > Aout(qloc.size());
205 for (
size_t qin=0; qin<inbase.Nq(); ++qin)
207 auto it =
B.dict.find({inbase[qin], inbase[qin]});
208 if (it ==
B.dict.end()) {
continue;}
209 size_t qB = it->second;
212 vector<size_t> svec, qvec, Ncolsvec;
213 for (
size_t s=0; s<qloc.size(); ++s)
214 for (
size_t q=0; q<
A[s].dim; ++q)
216 if (
A[s].in[q] == inbase[qin])
220 Ncolsvec.push_back(
A[s].block[q].cols());
225 for (
size_t i=0; i<svec.size(); ++i)
228 Mtmp =
B.block[qB].block(0,stitch,
B.block[qB].rows(),Ncolsvec[i])*Symmetry::coeff_leftSweep(
A[svec[i]].in[qvec[i]],
229 A[svec[i]].out[qvec[i]]);
231 if (Mtmp.size() != 0)
233 Aout[svec[i]].push_back(
A[svec[i]].in[qvec[i]],
A[svec[i]].out[qvec[i]], Mtmp);
235 stitch += Ncolsvec[i];
void block(DMRG::DIRECTION::OPTION DIR)
Biped< Symmetry, MatrixType > Aclump(DMRG::DIRECTION::OPTION DIR)
vector< Biped< Symmetry, MatrixType > > reblock_right(const Biped< Symmetry, MatrixType > &B)
Qbasis< Symmetry > inbase
vector< Biped< Symmetry, MatrixType > > & A
Biped< Symmetry, MatrixType > Aclump_
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > MatrixType
static constexpr size_t Nq
void FORCE_NEW_BLOCKING()
Blocker(vector< Biped< Symmetry, MatrixType > > &A_in, const vector< qarray< Nq > > &qloc_in, const Qbasis< Symmetry > &inbase_in, const Qbasis< Symmetry > &outbase_in)
vector< Biped< Symmetry, MatrixType > > reblock_left(const Biped< Symmetry, MatrixType > &B)
vector< Biped< Symmetry, MatrixType > > reblock(const Biped< Symmetry, MatrixType > &B, DMRG::DIRECTION::OPTION DIR)
vector< qarray< Nq > > qloc
Qbasis< Symmetry > outbase