4#define IZ(x) int x = 0;
5#define SZ(x) std::size_t x = 0;
9 using TC = std::array<int, 3>;
10 using TAC = std::pair<int, TC>;
12 using TLRI = std::map<int, std::map<TAC, RI::Tensor<T>>>;;
15 inline double absmax(
const RI::Tensor<T>& t)
18 for (
int i = 0;i < t.get_shape_all();++i)
20 double v = std::abs(std::norm(t.ptr()[i]));
21 if (v > res) { res = v; }
23 return std::sqrt(res);
32 infile.open(file_path);
33 infile >> natom >> ncell;
36 while (infile.peek() != EOF)
38 infile >> ia1 >> ia2 >> ic_1 >> ic_2 >> ic_3 >> nw1 >> nw2 >> nabf;
39 const TC& box = { ic_1, ic_2, ic_3 };
40 RI::Tensor<T> tensor_cs({ nabf, nw1, nw2 });
41 for (std::size_t i = 0; i != nw1; i++) {
for (std::size_t j = 0; j != nw2; j++) {
for (std::size_t mu = 0; mu != nabf; mu++) { infile >> tensor_cs(mu, i, j); } } }
43 if (
absmax(tensor_cs) >=
threshold) { Cs[ia1 - 1][{ia2 - 1, box}] = tensor_cs; }
52 std::ofstream outfile;
53 outfile.open(file_path);
54 outfile << Cs.size() <<
" " << Cs.at(0).size() / Cs.size() << std::endl;
57 const int& ia1 = it1.first;
58 for (
auto& it2 : it1.second)
60 const int& ia2 = it2.first.first;
61 const auto& box = it2.first.second;
62 const auto& tensor_cs = it2.second;
63 outfile << ia1 + 1 <<
" " << ia2 + 1 <<
" " << box[0] <<
" " << box[1] <<
" " << box[2] << std::endl;
64 const int& nw1 = tensor_cs.shape[1], nw2 = tensor_cs.shape[2], nabf = tensor_cs.shape[0];
65 outfile << nw1 <<
" " << nw2 <<
" " << nabf << std::endl;
66 for (
int i = 0; i != nw1; i++)
68 for (
int j = 0; j != nw2; j++)
70 for (
int mu = 0; mu != nabf; mu++) { outfile << tensor_cs(mu, i, j) <<
" "; }
85 infile.open(file_path);
86 infile >> natom >> ncell;
89 while (infile.peek() != EOF)
91 infile >> ia1 >> ia2 >> ic_1 >> ic_2 >> ic_3 >> nabf1 >> nabf2;
92 const TC& box = { ic_1, ic_2, ic_3 };
93 RI::Tensor<T> tensor_vs({ nabf1, nabf2 });
94 for (std::size_t i = 0; i != nabf1; i++) {
95 for (std::size_t j = 0; j != nabf2; j++){ infile >> tensor_vs(i, j);}
97 if (
absmax(tensor_vs) >=
threshold) { Vs[ia1 - 1][{ia2 - 1, box}] = tensor_vs; }
104 template <
typename T>
107 std::ofstream outfile;
108 outfile.open(file_path);
109 outfile << Vs.size() <<
" " << Vs.at(0).size() / Vs.size() << std::endl;
110 for (
const auto& it1 : Vs)
112 const int& ia1 = it1.first;
113 for (
const auto& it2 : it1.second)
115 const int& ia2 = it2.first.first;
116 const auto& box = it2.first.second;
117 const auto& tensor_v = it2.second;
118 outfile << ia1 + 1 <<
" " << ia2 + 1 <<
" " << box[0] <<
" " << box[1] <<
" " << box[2] << std::endl;
119 outfile << tensor_v.shape[0] <<
" " << tensor_v.shape[1] << std::endl;
120 for (
int i = 0; i != tensor_v.shape[0]; i++)
122 for (
int j = 0; j != tensor_v.shape[1]; j++) {outfile << tensor_v(i, j) <<
" ";}
123 outfile << std::endl;
std::array< int, 3 > TC
Definition ri_cv_io_test.cpp:9
std::pair< int, TC > TAC
Definition ri_cv_io_test.cpp:10
std::map< int, std::map< TAC, RI::Tensor< T > > > TLRI
Definition ri_cv_io_test.cpp:12
#define threshold
Definition sph_bessel_recursive_test.cpp:4
#define SZ(x)
Definition write_ri_cv.hpp:5
#define IZ(x)
Definition write_ri_cv.hpp:4