Skip to content

Commit d69258e

Browse files
committed
fix array dim bug involving convolution of non-square matrix-valued functions
1 parent 618ae7c commit d69258e

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

c++/cppdlr/dlr_imtime.hpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,14 @@ namespace cppdlr {
388388

389389
} else if (Tg::rank == 3) { // Matrix-valued Green's function
390390

391-
if (fconv.shape(1) != g.shape(0) * g.shape(1)) throw std::runtime_error("Input array dimensions incompatible.");
391+
if (fconv.shape(1) != r * g.shape(1)) throw std::runtime_error("Input array dimensions incompatible.");
392392

393-
int norb1 = g.shape(1);
394-
int norb2 = g.shape(2);
393+
int norb1 = fconv.shape(0) / r;
394+
int norb2 = g.shape(1);
395+
int norb3 = g.shape(2);
395396

396-
auto h = nda::array<S, 3>(r, norb1, norb2);
397-
reshape(h, r * norb1, norb2) = matmul(fconv, reshape(g, r * norb1, norb2));
397+
auto h = nda::array<S, 3>(r, norb1, norb3);
398+
reshape(h, r * norb1, norb3) = matmul(fconv, reshape(g, r * norb2, norb3));
398399

399400
return h;
400401

@@ -441,11 +442,11 @@ namespace cppdlr {
441442
* in practice.
442443
*
443444
* \note In the case of matrix-valued Green's functions, we think of the
444-
* matrix of convolution by f as an r*norb x r*norb matrix, or a block r x r
445-
* matrix of norb x norb blocks. Here r is the DLR rank and norb is the
446-
* number of orbital indices. This matrix would then be applied to a Green's
447-
* function g, represented as an r*norb x norb matrix, or a block r x 1
448-
* matrix of norb x norb blocks.
445+
* matrix of convolution by f as an r*norb1 x r*norb2 matrix, or a block r x
446+
* r matrix of norb1 x norb2 blocks. Here r is the DLR rank and norb1, norb2
447+
* are the number of row and column orbital indices, respectively. This
448+
* matrix would then be applied to a Green's function g, represented as an
449+
* r*norb2 x r*norb3 matrix, or a block r x 1 matrix of norb2 x norb3 blocks.
449450
* */
450451
template <nda::MemoryArray T, nda::Scalar S = nda::get_value_t<T>>
451452
nda::matrix<S> convmat(double beta, statistic_t statistic, T const &fc, bool time_order = false) const {
@@ -511,11 +512,11 @@ namespace cppdlr {
511512
* in practice.
512513
*
513514
* \note In the case of matrix-valued Green's functions, we think of the
514-
* matrix of convolution by f as an r*norb x r*norb matrix, or a block r x r
515-
* matrix of norb x norb blocks. Here r is the DLR rank and norb is the
516-
* number of orbital indices. This matrix would then be applied to a Green's
517-
* function g, represented as an r*norb x norb matrix, or a block r x 1
518-
* matrix of norb x norb blocks.
515+
* matrix of convolution by f as an r*norb1 x r*norb2 matrix, or a block r x
516+
* r matrix of norb1 x norb2 blocks. Here r is the DLR rank and norb1, norb2
517+
* are the number of row and column orbital indices, respectively. This
518+
* matrix would then be applied to a Green's function g, represented as an
519+
* r*norb2 x r*norb3 matrix, or a block r x 1 matrix of norb2 x norb3 blocks.
519520
* */
520521
template <nda::MemoryArray T, nda::Scalar S = nda::get_value_t<T>>
521522
void convmat_inplace(nda::matrix_view<S, nda::C_layout> fconv, double beta, statistic_t statistic, T const &fc, bool time_order = false) const {
@@ -572,7 +573,7 @@ namespace cppdlr {
572573
if (fconv.shape(0) != r * norb1 || fconv.shape(1) != r * norb2)
573574
throw std::runtime_error("Matrix shape must be equal to DLR rank times norbs (r*norb1,r*norb2).");
574575

575-
auto fconv_rs = nda::reshape(fconv, r, norb1, r, norb2); // Array view to index into fconv for conevenience
576+
auto fconv_rs = nda::reshape(fconv, r, norb1, r, norb2); // Array view to index into fconv for convenience
576577

577578
// Diagonal contribution (given by diag(tau_k) * K(tau_k, om_l) * diag(fc_l))
578579
for (int k = 0; k < r; ++k) {

0 commit comments

Comments
 (0)