@@ -780,16 +780,15 @@ def _radial_convolve_weights(self, b):
780780
781781 return a
782782
783- # def filter_to_basis_mat(self, f, **kwargs):
784- # """
785- # See `SteerableBasis2D.filter_stack_to_basis_mats`.
786- # """
787- # if len(f) != 1:
788- # raise RuntimeError("Unexpected filter length.")
789- # return self._filter_stack_to_basis_mats(f, **kwargs)[0]
790-
791- # XXX TODO, convert to _filter_stack_to_basis_mats via broadcasting.
792783 def filter_to_basis_mat (self , f , ** kwargs ):
784+ """
785+ See `SteerableBasis2D.filter_stack_to_basis_mats`.
786+ """
787+ if len (f ) != 1 :
788+ raise RuntimeError ("Unexpected filter length." )
789+ return self ._filter_stack_to_basis_mats (f , ** kwargs )
790+
791+ def _filter_stack_to_basis_mats (self , f , ** kwargs ):
793792 """
794793 See `SteerableBasis2D.filter_to_basis_mat`.
795794
@@ -840,20 +839,28 @@ def filter_to_basis_mat(self, f, **kwargs):
840839
841840 h_vals2d = (
842841 xp .asarray (h_fun (omega , pixel_size = pixel_size ))
843- .reshape (n_k , n_theta )
842+ .reshape (len ( f ), n_k , n_theta )
844843 .astype (self .dtype , copy = False )
845844 )
846- h_vals = xp .sum (h_vals2d , axis = 1 ) / n_theta
845+ h_vals = xp .sum (h_vals2d , axis = - 1 ) / n_theta
847846
848- h_basis = xp .zeros (self .count , dtype = self .dtype )
849- # For now we just need to handle 1D (stack of one ctf)
847+ h_basis = xp .zeros ((len (f ), self .count ), dtype = self .dtype )
848+ # shape gymnastics to get a broadcast with csr A3
849+ h_vals = h_vals .T
850850 for j in range (self .ell_p_max + 1 ):
851- h_basis [self .idx_list [j ]] = self .A3 [j ] @ h_vals
851+ h_basis [:, self .idx_list [j ]] = ( self .A3 [j ] @ h_vals ). T
852852
853853 # Convert from internal FLE ordering to FB convention
854- h_basis = h_basis [self ._fle_to_fb_indices ]
854+ h_basis = h_basis [:, self ._fle_to_fb_indices ]
855+ # who needs this as a list?
856+
857+ coefs = xp .asnumpy (h_basis )
858+ if len (coefs ) > 1 :
859+ coefs = [DiagMatrix (c ) for c in coefs ]
860+ else :
861+ coefs = DiagMatrix (coefs .flatten ())
855862
856- return DiagMatrix ( xp . asnumpy ( h_basis ))
863+ return coefs
857864
858865 def expand_radial_vec (self , radial_vec , ** kwargs ):
859866 """
0 commit comments