ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Inverse_Matrix-test.h
Go to the documentation of this file.
1//=======================
2// AUTHOR : Peize Lin
3// DATE : 2022-08-17
4//=======================
5
6#ifndef INVERSE_MATRIX_TEST_H
7#define INVERSE_MATRIX_TEST_H
8
10#include <LibRI/unittests/global/Tensor-test.h>
11
13{
14 template<typename Tdata>
15 Tensor<Tdata> init_Tensor(const std::vector<size_t> &shape)
16 {
17 Tensor<Tdata> t(shape);
18 for(size_t i=0; i<t.data->size(); ++i)
19 t.ptr()[i] = i;
20 return t;
21 }
22
23 template<typename Tdata>
24 Tensor<Tdata> init_Tensor2(const std::vector<size_t> &shape)
25 {
26 Tensor<Tdata> t(shape);
27 for(size_t i0=0; i0<t.shape[0]; ++i0)
28 for(size_t i1=0; i1<t.shape[1]; ++i1)
29 t(i0,i1) = i0==i1 ? i0+1 : (i0+i1)/10.0;
30 return t;
31 }
32
33 template<typename Tdata>
35 {
37
38 const size_t n_all = 5;
39 const std::vector<size_t> n0 = {2,3};
40 const std::vector<size_t> n1 = {1,2,2};
41
42 Tensor<Tdata> m = init_Tensor<Tdata>({n_all,n_all});
43
44 std::vector<std::vector<Tensor<Tdata>>> ms(n0.size(), std::vector<Tensor<Tdata>>(n1.size()));
45 for(size_t Im0=0; Im0<n0.size(); ++Im0)
46 for(size_t Im1=0; Im1<n1.size(); ++Im1)
47 ms[Im0][Im1] = init_Tensor<Tdata>({n0[Im0], n1[Im1]});
48
49 inv.input(m);
50 std::cout<<inv.output()<<std::endl;
51
52 inv.input(m);
53 std::cout<<inv.output(n0, n1)<<std::endl;
54
55 inv.input(ms);
56 std::cout<<inv.output()<<std::endl;
57
58 inv.input(ms);
59 std::cout<<inv.output(n0, n1)<<std::endl;
60
61 /*
62 0 1 2 3 4
63 5 6 7 8 9
64 10 11 12 13 14
65 15 16 17 18 19
66 20 21 22 23 24
67 */
68 /*
69 0
70 5
71
72 1 2
73 6 7
74
75 3 4
76 8 9
77
78 10
79 15
80 20
81
82 11 12
83 16 17
84 21 22
85
86 13 14
87 18 19
88 23 24
89 */
90 /*
91 0 0 1 0 1
92 1 2 3 2 3
93 0 0 1 0 1
94 1 2 3 2 3
95 2 4 5 4 5
96 */
97 /*
98 0
99 1
100
101 0 1
102 2 3
103
104 0 1
105 2 3
106
107 0
108 1
109 2
110
111 0 1
112 2 3
113 4 5
114
115 0 1
116 2 3
117 4 5
118 */
119 }
120
121 template<typename Tdata>
123 {
124 Tensor<Tdata> t = init_Tensor2<Tdata>({5,5});
126 inv.input(t);
128 //inv.cal_inverse(Inverse_Matrix<Tdata>::Method::syev);
129 Tensor<Tdata> tI = inv.output();
130
131 std::cout<<t<<std::endl;
132 std::cout<<tI<<std::endl;
133 std::cout<<t*tI<<std::endl;
134 std::cout<<tI*t<<std::endl;
135 }
136}
137
138#endif
Definition Inverse_Matrix.h:13
void input(const RI::Tensor< Tdata > &m)
Definition Inverse_Matrix.hpp:63
RI::Tensor< Tdata > output() const
Definition Inverse_Matrix.hpp:117
Definition Inverse_Matrix-test.h:13
Tensor< Tdata > init_Tensor2(const std::vector< size_t > &shape)
Definition Inverse_Matrix-test.h:24
void test_inverse()
Definition Inverse_Matrix-test.h:122
Tensor< Tdata > init_Tensor(const std::vector< size_t > &shape)
Definition Inverse_Matrix-test.h:15
void test_input_output()
Definition Inverse_Matrix-test.h:34