Skip to content

Commit 62a8d80

Browse files
committed
Revert "optional index cleanup commit"
This reverts commit 27d89b4.
1 parent f069f3f commit 62a8d80

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

src/aspire/covariance/covar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def src_backward(self, mean_vol, noise_variance, shrink_method=None):
179179
(batch_n, self.src.L, self.src.L, self.src.L), dtype=self.dtype
180180
)
181181
for j in range(batch_n):
182-
im_centered_b[j] = self.src.im_backward([i + j], im_centered[j])
182+
im_centered_b[j] = self.src.im_backward(im_centered[j], i + j)
183183
im_centered_b = Volume(im_centered_b).to_vec()
184184

185185
covar_b += (im_centered_b.T @ im_centered_b).reshape(

src/aspire/reconstruction/mean.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ def src_backward(self):
175175
)
176176

177177
for i in range(0, self.src.n, self.batch_size):
178-
idx = np.arange(i, min(self.src.n, i + self.batch_size), dtype=int)
179-
im = self.src.images[idx]
180178
for k in range(self.r):
179+
im = self.src.images[i : i + self.batch_size]
180+
181181
batch_vol_rhs = self.src.im_backward(
182-
idx,
183182
im,
183+
i,
184184
self.weights[:, k],
185185
symmetry_group=symmetry_group,
186186
) / (self.src.n * sym_order)

src/aspire/source/image.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -937,38 +937,31 @@ def normalize_background(self, bg_radius=1.0, do_ramp=True):
937937
LambdaXform(normalize_bg, bg_radius=bg_radius, do_ramp=do_ramp)
938938
)
939939

940-
def im_backward(self, idx, im=None, weights=None, symmetry_group=None):
940+
def im_backward(self, im, start, weights=None, symmetry_group=None):
941941
"""
942-
Apply adjoint mapping to set of images identified by indices `idx`.
942+
Apply adjoint mapping to set of images
943943
944-
:param idx: Source indices corresponding to a set of images.
945-
:param im: An Image instance to which we wish to apply the
946-
adjoint of the forward model. When `None`, infers
947-
`im=self.images[idx]`.
944+
:param im: An Image instance to which we wish to apply the adjoint of the forward model.
945+
:param start: Start index of image to consider
948946
:param weights: Optional vector of weights to apply to images.
949947
Weights should be length `self.n`.
950948
:param symmetry_group: A SymmetryGroup instance. If supplied, uses symmetry to increase
951949
number of images used in back-projectioon.
952950
:return: An L-by-L-by-L volume containing the sum of the adjoint mappings applied to the start+num-1 images.
953951
"""
952+
num = im.n_images
954953

955-
if im is None:
956-
im = self.images[idx]
957-
elif im.n_images != len(idx):
958-
raise RuntimeError(
959-
f"`im_backward` n_images != len(idx): {im.n_images} != {len(idx)}"
960-
)
961-
962-
im *= self.amplitudes[idx, np.newaxis, np.newaxis]
963-
im = im.shift(-self.offsets[idx, :])
964-
im = self._apply_source_filters(im, idx)
954+
all_idx = np.arange(start, min(start + num, self.n))
955+
im *= self.amplitudes[all_idx, np.newaxis, np.newaxis]
956+
im = im.shift(-self.offsets[all_idx, :])
957+
im = self._apply_source_filters(im, all_idx)
965958

966959
if weights is not None:
967-
im *= weights[idx, np.newaxis, np.newaxis]
960+
im *= weights[all_idx, np.newaxis, np.newaxis]
968961

969-
vol = im.backproject(self.rotations[idx, :, :], symmetry_group=symmetry_group)[
970-
0
971-
]
962+
vol = im.backproject(
963+
self.rotations[start : start + num, :, :], symmetry_group=symmetry_group
964+
)[0]
972965

973966
return vol
974967

0 commit comments

Comments
 (0)