Skip to content

Commit 8c77647

Browse files
committed
Updates to account for changes in nda
- getrs requries B to be F-layout - eigenelements was rename to eigh and moved to nda/linalg/eigh.hpp
1 parent ec2ac92 commit 8c77647

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

c++/cppdlr/dlr_dyson.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <cppdlr/dlr_imtime.hpp>
2121
#include <cppdlr/dlr_kernels.hpp>
2222

23-
#include <nda/linalg/eigenelements.hpp>
23+
#include <nda/linalg/eigh.hpp>
2424
#include <type_traits>
2525

2626
namespace cppdlr {
@@ -86,7 +86,7 @@ namespace cppdlr {
8686
* \note Hamiltonian must either be a symmetric matrix, a Hermitian matrix,
8787
* or a real scalar.
8888
*/
89-
dyson_it(double beta, imtime_ops itops, Ht const &h, bool time_order) : dyson_it(beta, itops, h, 0, time_order){};
89+
dyson_it(double beta, imtime_ops itops, Ht const &h, bool time_order) : dyson_it(beta, itops, h, 0, time_order) {};
9090

9191
/**
9292
* @brief Solve Dyson equation for given self-energy
@@ -121,7 +121,7 @@ namespace cppdlr {
121121
auto g = Tg(sig.shape()); // Declare Green's function
122122
g = rhs; // Get right hand side of Dyson equation
123123
auto g_rs = nda::matrix_view<nda::get_value_t<Tg>>(nda::reshape(g, norb, r * norb)); // Reshape g to be compatible w/ LAPACK
124-
nda::lapack::getrs(sysmat, g_rs, ipiv); // Back solve
124+
nda::lapack::getrs(sysmat, transpose(g_rs), ipiv); // Back solve
125125
if constexpr (std::floating_point<Ht>) { // If h is scalar, g is scalar-valued
126126
return g;
127127
} else { // Otherwise, g is matrix-valued, and need to transpose some indices after solve to undo LAPACK formatting
@@ -181,7 +181,7 @@ namespace cppdlr {
181181
int norb = h.shape(0);
182182

183183
// Diagonalize Hamiltonian
184-
auto [eval, evec] = nda::linalg::eigenelements(h);
184+
auto [eval, evec] = nda::linalg::eigh(h);
185185

186186
// Get free Green's function
187187
auto g = nda::array<nda::get_value_t<Ht>, 3>(r, norb, norb);

c++/cppdlr/dlr_imtime.hpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,12 @@ namespace cppdlr {
580580
fconv += matmul(cf2it, tmp2);
581581

582582
// Then precompose with DLR grid values to DLR coefficients matrix
583-
if constexpr (nda::is_complex_v<S>) { // getrs requires matrix and rhs to have same value type
584-
nda::lapack::getrs(transpose(it2cf.zlu), fconv, it2cf.piv); // Note: lapack effectively tranposes fconv by fortran reordering here
583+
if constexpr (nda::is_complex_v<S>) { // getrs requires matrix and rhs to have same value type
584+
nda::lapack::getrs(transpose(it2cf.zlu), transpose(fconv),
585+
it2cf.piv); // Note: lapack effectively tranposes fconv by fortran reordering here
585586
} else {
586587
// getrs requires matrix and rhs to have same value type
587-
nda::lapack::getrs(transpose(it2cf.lu), fconv, it2cf.piv);
588+
nda::lapack::getrs(transpose(it2cf.lu), transpose(fconv), it2cf.piv);
588589
}
589590

590591
fconv *= beta;
@@ -627,11 +628,12 @@ namespace cppdlr {
627628
}
628629

629630
// Do the solve
630-
if constexpr (nda::is_complex_v<S>) { // getrs requires matrix and rhs to have same value type
631-
nda::lapack::getrs(transpose(it2cf.zlu), fconvtmp, it2cf.piv); // Note: lapack effectively tranposes fconv by fortran reordering here
631+
if constexpr (nda::is_complex_v<S>) { // getrs requires matrix and rhs to have same value type
632+
nda::lapack::getrs(transpose(it2cf.zlu), transpose(fconvtmp),
633+
it2cf.piv); // Note: lapack effectively tranposes fconv by fortran reordering here
632634
} else {
633635
// getrs requires matrix and rhs to have same value type
634-
nda::lapack::getrs(transpose(it2cf.lu), fconvtmp, it2cf.piv);
636+
nda::lapack::getrs(transpose(it2cf.lu), transpose(fconvtmp), it2cf.piv);
635637
}
636638

637639
// Transpose back
@@ -903,7 +905,7 @@ namespace cppdlr {
903905
}
904906

905907
// Precompose with DLR values to coefficients matrix
906-
nda::lapack::getrs(transpose(it2cf.lu), refl, it2cf.piv); // Lapack effectively transposes refl by fortran reordering here
908+
nda::lapack::getrs(transpose(it2cf.lu), transpose(refl), it2cf.piv); // Lapack effectively transposes refl by fortran reordering here
907909
}
908910

909911
private:
@@ -946,7 +948,7 @@ namespace cppdlr {
946948
* @param[in] ar Archive to serialize into
947949
*/
948950
void serialize(auto &ar) const {
949-
ar &lambda_ &r &dlr_rf &dlr_it &cf2it &it2cf.lu &it2cf.zlu &it2cf.piv &hilb &tcf2it &thilb &ttcf2it &ipmat &refl;
951+
ar & lambda_ & r & dlr_rf & dlr_it & cf2it & it2cf.lu & it2cf.zlu & it2cf.piv & hilb & tcf2it & thilb & ttcf2it & ipmat & refl;
950952
}
951953

952954
/**
@@ -956,7 +958,9 @@ namespace cppdlr {
956958
*
957959
* @param[in] ar Archive to deserialize from
958960
*/
959-
void deserialize(auto &ar) { ar &lambda_ &r &dlr_rf &dlr_it &cf2it &it2cf.lu &it2cf.zlu &it2cf.piv &hilb &tcf2it &thilb &ttcf2it &ipmat &refl; }
961+
void deserialize(auto &ar) {
962+
ar & lambda_ & r & dlr_rf & dlr_it & cf2it & it2cf.lu & it2cf.zlu & it2cf.piv & hilb & tcf2it & thilb & ttcf2it & ipmat & refl;
963+
}
960964

961965
// -------------------- hdf5 -------------------
962966

test/c++/dyson_it.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ TEST(dyson_it, dyson_vs_ed_real) {
6262
// Get random nxn Hamiltonian w/ eigenvalues in [-1 1]
6363
auto a = nda::matrix<double>(nda::rand<double>(std::array<int, 2>({n, n}))); // Random matrix
6464
a = (a + transpose(a)) / 2; // Make symmetric
65-
auto [eval, u] = nda::linalg::eigenelements(a); // Random orthogonal matrix
65+
auto [eval, u] = nda::linalg::eigh(a); // Random orthogonal matrix
6666
eval = -1 + 2 * nda::rand<double>(std::array<int, 1>({n})); // Random eigenvalues in [-1,1]
6767
auto h = matmul(matmul(u, nda::diag(eval)), transpose(conj(u))); // Random symmetric matrix
6868

@@ -151,7 +151,7 @@ TEST(dyson_it, dyson_vs_ed_cmplx) {
151151
// Get random nxn Hamiltonian w/ eigenvalues in [-1 1]
152152
auto a = nda::matrix<dcomplex>(nda::rand<double>(std::array<int, 2>({n, n})) + 1i * nda::rand<double>(std::array<int, 2>({n, n}))); // Random matrix
153153
a = (a + transpose(conj(a))) / 2; // Make Hermitian
154-
auto [eval, u] = nda::linalg::eigenelements(a); // Random unitary matrix
154+
auto [eval, u] = nda::linalg::eigh(a); // Random unitary matrix
155155
eval = -1 + 2 * nda::rand<double>(std::array<int, 1>({n})); // Random eigenvalues in [-1,1]
156156
auto h = matmul(matmul(u, nda::diag(eval)), transpose(conj(u))); // Random Hermitian matrix
157157

0 commit comments

Comments
 (0)