From ebc45b3dbdf91c1adbbf2635c2a20b7ed8e876d1 Mon Sep 17 00:00:00 2001 From: Timothy Brandt Date: Mon, 10 Jun 2024 22:00:39 -0400 Subject: [PATCH 1/4] Changed p in fit() from a diagonal matrix to a vector to speed up the code --- jwst/nsclean/lib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jwst/nsclean/lib.py b/jwst/nsclean/lib.py index f348c85431..3362ceba6c 100644 --- a/jwst/nsclean/lib.py +++ b/jwst/nsclean/lib.py @@ -134,7 +134,7 @@ def fit(self, data): # Get data and weights for this line d = data[y][self.mask[y]] # unmasked (useable) data - p = np.diag(self.P[y][self.mask[y]]) # Weights + p = self.P[y][self.mask[y]] # Weights # If none of the pixels in this line is useable (all masked out), # skip and move on to the next line. @@ -164,7 +164,7 @@ def fit(self, data): # Compute the Moore-Penrose inverse of A = P*B. # $A^+ = (A^H A)^{-1} A^H$ - A = np.matmul(p, B) + A = B*p[:, np.newaxis] AH = np.conjugate(A.transpose()) # Hermitian transpose of A pinv_PB = np.matmul(np.linalg.inv(np.matmul(AH, A)), AH) @@ -172,7 +172,7 @@ def fit(self, data): # The way that we have done it, this multiplies the input data by the # number of samples used for the fit. rfft = np.zeros(self.nx//2 + 1, dtype=np.complex64) - rfft[:k.shape[1]] = np.matmul(np.matmul(pinv_PB, p), d) + rfft[:k.shape[1]] = np.matmul(pinv_PB, p*d) # Numpy requires that the forward transform multiply # the data by n. Correct normalization. From 4b863a17a38fe717af877ae1fe98a2965bc5d53b Mon Sep 17 00:00:00 2001 From: Timothy Brandt Date: Mon, 10 Jun 2024 22:12:46 -0400 Subject: [PATCH 2/4] Changed p in fit() from a diagonal matrix to a vector to speed up the code --- jwst/nsclean/lib.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jwst/nsclean/lib.py b/jwst/nsclean/lib.py index 3362ceba6c..0316078994 100644 --- a/jwst/nsclean/lib.py +++ b/jwst/nsclean/lib.py @@ -134,6 +134,9 @@ def fit(self, data): # Get data and weights for this line d = data[y][self.mask[y]] # unmasked (useable) data + # The line below uses a vector to represent a diagonal weight matrix. + # Multiplications by this vector later on may be viewed as + # equivalent formulations to multiplication by diag(p). p = self.P[y][self.mask[y]] # Weights # If none of the pixels in this line is useable (all masked out), From 29977ab5d13c73501ef144cfb0d33ac2a7c261db Mon Sep 17 00:00:00 2001 From: Timothy Brandt Date: Tue, 11 Jun 2024 09:20:04 -0400 Subject: [PATCH 3/4] Updated CHANGES.rst to reflect improvements in NSClean.fit() --- CHANGES.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index c7f6e70265..3fd24b2ffe 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -136,6 +136,13 @@ master_background_mos ``slit.source_name`` now contains the string "BKG" instead of "background". [#8533] +nsclean +--------------------- + +- Improved run time of NSClean.fit() by using a vector rather than a large, + sparse matrix to perform linear algebra operations with a diagonal weight + matrix. [#8547] + outlier_detection ----------------- From 31648d760019b1bd38e950e5c365af77cc8a1a91 Mon Sep 17 00:00:00 2001 From: Timothy Brandt Date: Tue, 11 Jun 2024 11:48:28 -0400 Subject: [PATCH 4/4] Adjusted number of dashes in CHANGES.rst --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3fd24b2ffe..e5fa048a9d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -137,7 +137,7 @@ master_background_mos "background". [#8533] nsclean ---------------------- +------- - Improved run time of NSClean.fit() by using a vector rather than a large, sparse matrix to perform linear algebra operations with a diagonal weight