Skip to content

Commit 6c132eb

Browse files
committed
1. update CS_Matrix to adding CS_Matrix::Uplimits
1 parent 6c42b32 commit 6c132eb

File tree

9 files changed

+41
-46
lines changed

9 files changed

+41
-46
lines changed

include/RI/ri/CS_Matrix-filter.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ template<typename TA, typename TC, typename Tdata>
1919
typename CS_Matrix<TA,TC,Tdata>::Step CS_Matrix<TA,TC,Tdata>::set_label_A(
2020
const Label::ab_ab &label_in,
2121
const TA &Aa01, const TAC &Aa2, const TAC &Ab01, const TAC &Ab2,
22-
const TC &period) const
22+
const TC &period,
23+
const std::unordered_map<Label::ab, CS_Matrix<TA,TC,Tdata>::Uplimits> &uplimits) const
2324
{
2425
using namespace Array_Operator;
2526

@@ -44,32 +45,32 @@ typename CS_Matrix<TA,TC,Tdata>::Step CS_Matrix<TA,TC,Tdata>::set_label_A(
4445
}
4546
};
4647
auto get_uplimit_tensor2 = [&get_Aa_Ab](
47-
const std::unordered_map<Label::ab, std::map<TA,std::map<TAC,Tdata>>> &uplimits_tensor2,
48+
const std::unordered_map<Label::ab, CS_Matrix<TA,TC,Tdata>::Uplimits> &uplimits,
4849
const Label::ab label_ab) -> Tdata
4950
{
5051
const int xa = Label::get_a(label_ab);
5152
const int xb = Label::get_b(label_ab);
5253
const std::pair<TA,TAC> &Aa_Ab = get_Aa_Ab(xa,xb);
5354
const TA &Aa=Aa_Ab.first;
5455
const TAC &Ab=Aa_Ab.second;
55-
return Global_Func::find(uplimits_tensor2.at(label_ab), Aa, Ab);
56+
return Global_Func::find(uplimits.at(label_ab).square_tensor2, Aa, Ab);
5657
};
5758

5859
Step step;
5960

6061
step.label = label_in;
6162

6263
const int index_a = Label::get_unused_a(step.label);
63-
step.a_square = Global_Func::find(this->uplimits_square_tensor3.at(Label::ab::a)[index_a], Aa01, Aa2);
64-
step.a_norm = Global_Func::find(this->uplimits_norm_tensor3 .at(Label::ab::a)[index_a], Aa01, Aa2);
64+
step.a_square = Global_Func::find(uplimits.at(Label::ab::a).square_tensor3[index_a], Aa01, Aa2);
65+
step.a_norm = Global_Func::find(uplimits.at(Label::ab::a).norm_tensor3 [index_a], Aa01, Aa2);
6566

6667
const int index_b = get_unused_b(step.label);
67-
step.b_square = Global_Func::find(this->uplimits_square_tensor3.at(Label::ab::b)[index_b], Ab01.first, TAC{Ab2.first, (Ab2.second-Ab01.second)%period});
68-
step.b_norm = Global_Func::find(this->uplimits_norm_tensor3 .at(Label::ab::b)[index_b], Ab01.first, TAC{Ab2.first, (Ab2.second-Ab01.second)%period});
68+
step.b_square = Global_Func::find(uplimits.at(Label::ab::b).square_tensor3[index_b], Ab01.first, TAC{Ab2.first, (Ab2.second-Ab01.second)%period});
69+
step.b_norm = Global_Func::find(uplimits.at(Label::ab::b).norm_tensor3 [index_b], Ab01.first, TAC{Ab2.first, (Ab2.second-Ab01.second)%period});
6970

7071
const std::pair<Label::ab, Label::ab> label_split_tmp = CS_Matrix_Tools::split_label(step.label);
71-
step.first_square = get_uplimit_tensor2(this->uplimits_square_tensor2, label_split_tmp.first);
72-
step.second_square = get_uplimit_tensor2(this->uplimits_square_tensor2, label_split_tmp.second);
72+
step.first_square = get_uplimit_tensor2(uplimits, label_split_tmp.first);
73+
step.second_square = get_uplimit_tensor2(uplimits, label_split_tmp.second);
7374

7475
return step;
7576
}

include/RI/ri/CS_Matrix-set.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,31 @@ void CS_Matrix<TA,TC,Tdata>::set_threshold(const Label::ab_ab &label, const Tdat
3131

3232

3333
template<typename TA, typename TC, typename Tdata> template<typename T>
34-
void CS_Matrix<TA,TC,Tdata>::set_tensor(
34+
CS_Matrix<TA,TC,Tdata>::Uplimits CS_Matrix<TA,TC,Tdata>::cal_uplimits(
3535
const Label::ab &label,
3636
const T &Ds)
3737
{
38+
Uplimits uplimits;
3839
switch(label)
3940
{
4041
case Label::ab::a: case Label::ab::b:
41-
this->uplimits_square_tensor3[label][0] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::square_three_0, Ds);
42-
this->uplimits_square_tensor3[label][1] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::square_three_1, Ds);
43-
this->uplimits_square_tensor3[label][2] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::square_three_2, Ds);
44-
this->uplimits_norm_tensor3[label][0] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::norm_three_0, Ds);
45-
this->uplimits_norm_tensor3[label][1] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::norm_three_1, Ds);
46-
this->uplimits_norm_tensor3[label][2] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::norm_three_2, Ds);
42+
uplimits.square_tensor3[0] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::square_three_0, Ds);
43+
uplimits.square_tensor3[1] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::square_three_1, Ds);
44+
uplimits.square_tensor3[2] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::square_three_2, Ds);
45+
uplimits.norm_tensor3[0] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::norm_three_0, Ds);
46+
uplimits.norm_tensor3[1] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::norm_three_1, Ds);
47+
uplimits.norm_tensor3[2] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::norm_three_2, Ds);
4748
break;
4849
case Label::ab::a0b0: case Label::ab::a0b1: case Label::ab::a0b2:
4950
case Label::ab::a1b0: case Label::ab::a1b1: case Label::ab::a1b2:
5051
case Label::ab::a2b0: case Label::ab::a2b1: case Label::ab::a2b2:
51-
this->uplimits_square_tensor2[label] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::square_two, Ds);
52-
//this->uplimits_norm_tensor2[label] = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::norm_two, Ds);
52+
uplimits.square_tensor2 = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::square_two, Ds);
53+
//uplimits.norm_tensor2 = CS_Matrix_Tools::cal_uplimit(CS_Matrix_Tools::Uplimit_Type::norm_two, Ds);
5354
break;
5455
default:
5556
throw std::invalid_argument("CS_Matrix::set_tensor");
5657
}
58+
return uplimits;
5759
}
5860

5961
}

include/RI/ri/CS_Matrix.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,31 @@ class CS_Matrix
3131
Tdata second_square;
3232
};
3333

34+
struct Uplimits
35+
{
36+
std::array< std::map<TA,std::map<TAC,Tdata>> ,3> square_tensor3;
37+
std::array< std::map<TA,std::map<TAC,Tdata>> ,3> norm_tensor3;
38+
std::map<TA,std::map<TAC,Tdata>> square_tensor2;
39+
//std::map<TA,std::map<TAC,Tdata>> norm_tensor2;
40+
};
41+
3442
std::unordered_map<Label::ab_ab, Tdata> threshold;
3543
CS_Matrix();
3644
void set_threshold(const Tdata &threshold_in);
3745
void set_threshold(const Label::ab_ab &label, const Tdata &threshold_in);
3846

39-
template<typename T> void set_tensor( const Label::ab &label, const T &Ds);
47+
template<typename T> Uplimits cal_uplimits( const Label::ab &label, const T &Ds);
4048

4149
Step set_label_A(
4250
const Label::ab_ab &label_in,
4351
const TA &Aa01, const TAC &Aa2, const TAC &Ab01, const TAC &Ab2,
44-
const TC &period) const;
52+
const TC &period,
53+
const std::unordered_map<Label::ab, CS_Matrix<TA,TC,Tdata>::Uplimits> &uplimits) const;
4554

4655
bool filter_4(const Step &step ) const { return step.a_square * step.first_square * step.second_square * step.b_square < this->threshold.at(step.label); }
4756
bool filter_3(const Step &step, const Tdata &uplimit_norm) const { return uplimit_norm * step.second_square * step.b_square < this->threshold.at(step.label); }
4857
bool filter_2(const Step &step, const Tdata &uplimit_norm) const { return uplimit_norm * step.b_norm < this->threshold.at(step.label); }
4958
bool filter_1(const Step &step, const Tdata &uplimit_norm) const { return uplimit_norm < this->threshold.at(step.label); }
50-
51-
public: // private:
52-
53-
std::unordered_map<Label::ab, std::array< std::map<TA,std::map<TAC,Tdata>> ,3>> uplimits_square_tensor3;
54-
std::unordered_map<Label::ab, std::array< std::map<TA,std::map<TAC,Tdata>> ,3>> uplimits_norm_tensor3;
55-
std::unordered_map<Label::ab, std::map<TA,std::map<TAC,Tdata>>> uplimits_square_tensor2;
56-
//std::unordered_map<Label::ab, std::map<TA,std::map<TAC,Tdata>>> uplimits_norm_tensor2;
5759
};
5860

5961
}

include/RI/ri/LRI-cal-b01.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void LRI<TA,Tcell,Ndim,Tdata>::set_cal_funcs_b01()
3535
if(D_ab_second.empty()) return; \
3636
typename CS_Matrix<TA,TC,Tdata_real>::Step csm_step; \
3737
if(this->csm.threshold.at(label)) \
38-
csm_step = this->csm.set_label_A(label, Aa01, Aa2, Ab01, Ab2, period); \
38+
csm_step = this->csm.set_label_A(label, Aa01, Aa2, Ab01, Ab2, period, this->csm_uplimits); \
3939
\
4040
if(this->csm.threshold.at(label)) \
4141
if(this->csm.filter_4(csm_step)) \

include/RI/ri/LRI-cal-bx2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void LRI<TA,Tcell,Ndim,Tdata>::set_cal_funcs_bx2()
3535
if(D_ab_second.empty()) return; \
3636
typename CS_Matrix<TA,TC,Tdata_real>::Step csm_step; \
3737
if(this->csm.threshold.at(label)) \
38-
csm_step = this->csm.set_label_A(label, Aa01, Aa2, Ab01, Ab2, period); \
38+
csm_step = this->csm.set_label_A(label, Aa01, Aa2, Ab01, Ab2, period, this->csm_uplimits); \
3939
\
4040
if(this->csm.threshold.at(label)) \
4141
if(this->csm.filter_4(csm_step)) \

include/RI/ri/LRI-set.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void LRI<TA,Tcell,Ndim,Tdata>::set_tensors_map2(
4343

4444
this->index_Ds_ab[label] = RI_Tools::get_index(this->Ds_ab[label]);
4545

46-
this->csm.set_tensor(label, this->Ds_ab[label]);
46+
this->csm_uplimits[label] = this->csm.cal_uplimits(label, this->Ds_ab[label]);
4747
}
4848

4949
/*

include/RI/ri/LRI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class LRI
7777

7878
std::unordered_map<Label::ab, std::map<TA, std::map<TAC, Tensor<Tdata>>>> Ds_ab; // Ds_ab[A0][{A1,C1}]
7979
std::unordered_map<Label::ab, std::vector<std::set<TA>>> index_Ds_ab; // index_Ds_ab[0]=A1
80+
std::unordered_map<Label::ab, typename CS_Matrix<TA,TC,Tdata_real>::Uplimits> csm_uplimits;
8081

8182
public: // private:
8283
using T_cal_func = std::function<void(

include/RI/ri/Save_Load.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
2525
class Save_Load
2626
{
2727
public:
28-
using TAC = std::pair<TA,std::array<Tcell,Ndim>>;
28+
using TC = std::array<Tcell,Ndim>;
29+
using TAC = std::pair<TA,TC>;
2930
using Tdata_real = Global_Func::To_Real_t<Tdata>;
3031

3132
Save_Load(LRI<TA,Tcell,Ndim,Tdata> &lri_in): lri(lri_in){}
@@ -43,10 +44,7 @@ class Save_Load
4344
{
4445
std::map<TA, std::map<TAC, Tensor<Tdata>>> Ds_ab;
4546
std::vector<std::set<TA>> index_Ds_ab;
46-
std::array< std::map<TA,std::map<TAC,Tdata_real>> ,3> csm_uplimits_square_tensor3;
47-
std::array< std::map<TA,std::map<TAC,Tdata_real>> ,3> csm_uplimits_norm_tensor3;
48-
std::map<TA,std::map<TAC,Tdata_real>> csm_uplimits_square_tensor2;
49-
//std::map<TA,std::map<TAC,Tdata_real>> csm_uplimits_norm_tensor2;
47+
typename CS_Matrix<TA,TC,Tdata_real>::Uplimits csm_uplimits;
5048
};
5149
std::map<std::string,Info> saves;
5250

include/RI/ri/Save_Load.hpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,18 @@ void Save_Load<TA,Tcell,Ndim,Tdata>::save(const std::string &name, const Label::
1515
{
1616
this->saves[name].Ds_ab = std::move(this->lri.Ds_ab[label]);
1717
this->saves[name].index_Ds_ab = std::move(this->lri.index_Ds_ab[label]);
18-
this->saves[name].csm_uplimits_square_tensor3 = std::move(this->lri.csm.uplimits_square_tensor3[label]);
19-
this->saves[name].csm_uplimits_norm_tensor3 = std::move(this->lri.csm.uplimits_norm_tensor3 [label]);
20-
this->saves[name].csm_uplimits_square_tensor2 = std::move(this->lri.csm.uplimits_square_tensor2[label]);
18+
this->saves[name].csm_uplimits = std::move(this->lri.csm_uplimits[label]);
2119
}
2220

2321
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
2422
void Save_Load<TA,Tcell,Ndim,Tdata>::load(const std::string &name, const Label::ab &label)
2523
{
2624
assert(this->lri.Ds_ab[label].empty());
2725
assert(this->lri.index_Ds_ab[label].empty());
28-
for(std::size_t i=0; i<this->lri.csm.uplimits_square_tensor3[label].size(); ++i)
29-
assert(this->lri.csm.uplimits_square_tensor3[label][i].empty());
30-
for(std::size_t i=0; i<this->lri.csm.uplimits_norm_tensor3[label].size(); ++i)
31-
assert(this->lri.csm.uplimits_norm_tensor3[label][i].empty());
32-
assert(this->lri.csm.uplimits_square_tensor2[label].empty());
3326

3427
this->lri.Ds_ab[label] = std::move(this->saves.at(name).Ds_ab);
3528
this->lri.index_Ds_ab[label] = std::move(this->saves.at(name).index_Ds_ab);
36-
this->lri.csm.uplimits_square_tensor3[label] = std::move(this->saves.at(name).csm_uplimits_square_tensor3);
37-
this->lri.csm.uplimits_norm_tensor3 [label] = std::move(this->saves.at(name).csm_uplimits_norm_tensor3);
38-
this->lri.csm.uplimits_square_tensor2[label] = std::move(this->saves.at(name).csm_uplimits_square_tensor2);
29+
this->lri.csm_uplimits[label] = std::move(this->saves.at(name).csm_uplimits);
3930

4031
// auto save_name_empty = [this]() -> bool
4132
// {

0 commit comments

Comments
 (0)