From 4f3a253a88d059140369604bafb1f8577db592ad Mon Sep 17 00:00:00 2001 From: Thomas Christensen Date: Tue, 29 Aug 2017 20:50:43 +0200 Subject: [PATCH 1/4] Fixes to bott.c: initialization of bott number_list & Un and Wn matrix dimension fix before resizing --- mpb/bott.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mpb/bott.c b/mpb/bott.c index 3996fe1d..e851ccc9 100644 --- a/mpb/bott.c +++ b/mpb/bott.c @@ -97,18 +97,26 @@ number_list bott_indices(integer band_start, integer n_bands) for (n = 1; n <= n_bands; ++n) { /* compute n-th bott index */ sqmatrix_copy(Un, U); sqmatrix_copy(Wn, W); + Un.p = n_bands; /* sqmatrix_copy does not change the .p field (but _we_ do at every iteration */ + Wn.p = n_bands; /* when we resize below), so to correct for that we must do it ourselves here */ + sqmatrix_resize(&Un, n, 1); sqmatrix_resize(&Wn, n, 1); - sqmatrix_resize(&S1, n, 0); - sqmatrix_resize(&S2, n, 0); - sqmatrix_AeBC(S1, Wn, 0, Un, 0); + sqmatrix_resize(&S1, n, 0); /*the .p-field-issue has no effect on scratch mat- */ + sqmatrix_resize(&S2, n, 0); /*rices, as their initial value is unimportant */ + + sqmatrix_AeBC(S1, Wn, 0, Un, 0); /*do the matrix products*/ sqmatrix_AeBC(S2, Wn, 1, Un, 1); sqmatrix_AeBC(Un, S1, 0, S2, 0); + sqmatrix_eigenvalues(Un, eigvals); + + bott.items[n-1] = 0; /* initalize/zero (number_list gives random init) */ for (i = 0; i < n; ++i) bott.items[n-1] += scalar_carg(eigvals[i]); - bott.items[i] /= 6.28318530717958647692528676655900; /* twopi */ + bott.items[n-1] /= 6.28318530717958647692528676655900; /* twopi */ } + destroy_sqmatrix(Wn); destroy_sqmatrix(Un); destroy_sqmatrix(S2); From 01fdd06a0931d239b16c0d2b84b9a24305ec10f5 Mon Sep 17 00:00:00 2001 From: Thomas Christensen Date: Wed, 30 Aug 2017 20:08:34 +0200 Subject: [PATCH 2/4] fix comment's line breaking & use chained assignment for .p field --- mpb/bott.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mpb/bott.c b/mpb/bott.c index e851ccc9..90619cf3 100644 --- a/mpb/bott.c +++ b/mpb/bott.c @@ -95,15 +95,15 @@ number_list bott_indices(integer band_start, integer n_bands) bott.num_items = n_bands; CHK_MALLOC(bott.items, number, n_bands); for (n = 1; n <= n_bands; ++n) { /* compute n-th bott index */ + Un.p = Wn.p = n_bands; /* we change the .p field at every iteration (cf. resizing), but sqmatrix expects */ + /* the .p field to match the size of the matrix being copied; fix that here */ sqmatrix_copy(Un, U); sqmatrix_copy(Wn, W); - Un.p = n_bands; /* sqmatrix_copy does not change the .p field (but _we_ do at every iteration */ - Wn.p = n_bands; /* when we resize below), so to correct for that we must do it ourselves here */ sqmatrix_resize(&Un, n, 1); sqmatrix_resize(&Wn, n, 1); - sqmatrix_resize(&S1, n, 0); /*the .p-field-issue has no effect on scratch mat- */ - sqmatrix_resize(&S2, n, 0); /*rices, as their initial value is unimportant */ + sqmatrix_resize(&S1, n, 0); /*the .p-field-issue has no impact on the scratch */ + sqmatrix_resize(&S2, n, 0); /*matrices, as their initial value is unimportant */ sqmatrix_AeBC(S1, Wn, 0, Un, 0); /*do the matrix products*/ sqmatrix_AeBC(S2, Wn, 1, Un, 1); From bdc998c4a3efe8de25d862c87b7047e2bf243cc7 Mon Sep 17 00:00:00 2001 From: Thomas Christensen Date: Wed, 30 Aug 2017 20:13:01 +0200 Subject: [PATCH 3/4] reverted change to sqmatrix_copy() from #225be5678edf65ba144f5bcf3aa341383fb2cb94; i.e. reinstate CHECK --- src/matrices/sqmatrix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matrices/sqmatrix.c b/src/matrices/sqmatrix.c index a256a7ec..f63248e0 100644 --- a/src/matrices/sqmatrix.c +++ b/src/matrices/sqmatrix.c @@ -60,7 +60,7 @@ void sqmatrix_assert_hermitian(sqmatrix A) /* A = B */ void sqmatrix_copy(sqmatrix A, sqmatrix B) { - sqmatrix_resize(&A, B.p, 0); + CHECK("A.p == B.p", "arrays not conformant"); blasglue_copy(A.p * A.p, B.data, 1, A.data, 1); } From 1aa24734dcef1a35d03efca5e6bf3fb981e2c350 Mon Sep 17 00:00:00 2001 From: Thomas Christensen Date: Fri, 15 Sep 2017 01:51:19 +0200 Subject: [PATCH 4/4] When reverting the CHECK issue in sqmatrix(), I had made the boolean into a string; no clue why - this fixes it --- src/matrices/sqmatrix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matrices/sqmatrix.c b/src/matrices/sqmatrix.c index f63248e0..e02cea63 100644 --- a/src/matrices/sqmatrix.c +++ b/src/matrices/sqmatrix.c @@ -60,7 +60,7 @@ void sqmatrix_assert_hermitian(sqmatrix A) /* A = B */ void sqmatrix_copy(sqmatrix A, sqmatrix B) { - CHECK("A.p == B.p", "arrays not conformant"); + CHECK(A.p == B.p, "arrays not conformant"); blasglue_copy(A.p * A.p, B.data, 1, A.data, 1); }