@@ -700,115 +700,6 @@ def convolve_image_no_blurring_for_mapping(self, image, mask, jax_method="direct
700700
701701 return Array2D (values = convolved_array_1d , mask = mask )
702702
703- # def convolve_mapping_matrix(self, mapping_matrix, mask, jax_method="direct", chan_chunk=128):
704- # """
705- # mapping_matrix : (N_masked, S) rows correspond to mask == False in row-major order
706- # mask : (H, W) boolean (False = kept, True = masked)
707- # chan_chunk : number of source columns processed at once (avoid large workspaces)
708- # to_f32 : cast inputs to float32 for smaller workspace & faster conv
709- # returns : (N_masked, S) convolved, re-masked mapping matrix
710- # """
711- # H, W = mask.shape
712- # S = mapping_matrix.shape[1]
713- # N = H * W
714- #
715- # psf_kernel = self.stored_native.array
716- #
717- # # Indices of kept pixels (False in the mask), STATIC size for jit
718- # flat_mask = mask.reshape(-1)
719- # K = mapping_matrix.shape[0] # number of unmasked pixels
720- # keep_idx = jnp.where(~flat_mask, size=K, fill_value=0)[0] # (K,)
721- #
722- # # Expand to full grid (N, S): zeros everywhere, fill only kept rows
723- # full = jnp.zeros((N, S), dtype=mapping_matrix.dtype)
724- # full = full.at[keep_idx, :].set(mapping_matrix)
725- #
726- # out_cols = []
727- # kH, kW = psf_kernel.shape
728- #
729- # for c0 in range(0, S, chan_chunk):
730- # c1 = min(c0 + chan_chunk, S)
731- # G = c1 - c0 # groups in this chunk
732- #
733- # # Treat the G columns as G input channels: images shape [1, G, H, W]
734- # imgs = full[:, c0:c1].T.reshape(1, G, H, W)
735- #
736- # # Depthwise/grouped conv: kernel shape [G, 1, kH, kW]
737- # # Use broadcast_to to avoid actual data replication.
738- # kernel = jnp.broadcast_to(psf_kernel[None, None, :, :], (G, 1, kH, kW))
739- #
740- # y = lax.conv_general_dilated(
741- # imgs,
742- # kernel,
743- # window_strides=(1, 1),
744- # padding="SAME",
745- # dimension_numbers=("NCHW", "OIHW", "NCHW"),
746- # feature_group_count=G, # depthwise: each channel convolved independently
747- # ) # [1, G, H, W]
748- #
749- # # Back to (N, G) then re-mask
750- # y_full = y.reshape(G, N).T
751- # y_masked = y_full[keep_idx, :] # (K, G)
752- # out_cols.append(y_masked)
753- #
754- # return jnp.concatenate(out_cols, axis=1) # (K, S)
755- #
756- #
757- # def convolve_mapping_matrix(self, mapping_matrix, mask, jax_method="direct"):
758- # """
759- # mapping_matrix: [N_masked, S] (rows correspond to mask==False in row-major order)
760- # mask : [H, W] boolean (False=kept, True=masked)
761- # returns : [N_masked, S] convolved, re-masked mapping matrix
762- # """
763- # psf_kernel = self.stored_native.array
764- # H, W = mask.shape
765- # S = mapping_matrix.shape[1]
766- # N = H * W
767- #
768- # # Indices of kept pixels (False in the mask), with STATIC size for jit.
769- # flat_mask = mask.reshape(-1)
770- # K = mapping_matrix.shape[0] # number of unmasked pixels
771- # keep_idx = jnp.where(~flat_mask, size=K, fill_value=0)[0] # shape (K,)
772- #
773- # # Expand to full grid: zeros everywhere, fill only kept rows.
774- # full = jnp.zeros((N, S), dtype=mapping_matrix.dtype)
775- # full = full.at[keep_idx, :].set(mapping_matrix)
776- #
777- # # Batch conv: [S, 1, H, W] * [1, 1, kH, kW] -> [S, 1, H, W]
778- # images = full.T.reshape(S, 1, H, W)
779- # kernel = psf_kernel[jnp.newaxis, jnp.newaxis, :, :]
780- #
781- # convolved = lax.conv_general_dilated(
782- # images,
783- # kernel,
784- # window_strides=(1, 1),
785- # padding="SAME",
786- # dimension_numbers=("NCHW", "OIHW", "NCHW"),
787- # )
788- #
789- # # Back to masked slim grid
790- # convolved_full = convolved.reshape(S, N).T
791- # convolved_masked = convolved_full[keep_idx, :] # shape (K, S)
792- #
793- # return convolved_masked
794-
795-
796- # def convolve_mapping_matrix(self, mapping_matrix, mask, jax_method="direct"):
797-
798- # mapping_matrix_list = []
799- #
800- # for i in range(mapping_matrix.shape[1]):
801- #
802- # blurred_image_2d = self.convolve_image_no_blurring_for_mapping(
803- # image=mapping_matrix[:,i],
804- # mask=mask
805- # )
806- #
807- # mapping_matrix_list.append(blurred_image_2d.array)
808- #
809- # return jnp.stack(mapping_matrix_list, axis=1)
810-
811-
812703 def convolve_mapping_matrix (self , mapping_matrix , mask , jax_method = "direct" ):
813704 """For a given 1D array and blurring array, convolve the two using this psf.
814705
0 commit comments