@@ -133,7 +133,21 @@ def __init__(self, factor):
133133 self .multipliers = factor
134134
135135 def _forward (self , im , indices ):
136- return im * self .multipliers [indices ]
136+ if self .multipliers .size == 1 :
137+ return im * self .multipliers
138+ else :
139+ return im * self .multipliers [indices ]
140+
141+ def __str__ (self ):
142+ """
143+ Show class name and related scaling information
144+ :return: A string of class name and related information
145+ """
146+ if self .multipliers .size == 1 :
147+ return (self .__class__ .__name__ + ' by same number of '
148+ + str (self .multipliers ))
149+ else :
150+ return self .__class__ .__name__ + ' by difference numbers'
137151
138152
139153class Shift (LinearXform ):
@@ -151,10 +165,27 @@ def __init__(self, shifts):
151165 self .n = shifts .shape [0 ]
152166
153167 def _forward (self , im , indices ):
154- return im .shift (self .shifts [indices ])
168+ if self .n == 1 :
169+ return im .shift (self .shifts )
170+ else :
171+ return im .shift (self .shifts [indices ])
155172
156173 def _adjoint (self , im , indices ):
157- return im .shift (- self .shifts [indices ])
174+ if self .n == 1 :
175+ return im .shift (- self .shifts )
176+ else :
177+ return im .shift (- self .shifts [indices ])
178+
179+ def __str__ (self ):
180+ """
181+ Show class name and related shift information
182+ :return: A string of class name and related information
183+ """
184+ if self .n == 1 :
185+ return (self .__class__ .__name__ + ' by same number of '
186+ + str (self .shifts ))
187+ else :
188+ return self .__class__ .__name__ + ' by difference numbers'
158189
159190
160191class Downsample (LinearXform ):
@@ -219,7 +250,21 @@ def __init__(self, addend):
219250 self .addend = addend
220251
221252 def _forward (self , im , indices ):
222- return im + self .addend [indices ]
253+ if self .addend .size == 1 :
254+ return im + self .addend
255+ else :
256+ return im + self .addend [indices ]
257+
258+ def __str__ (self ):
259+ """
260+ Show class name and related Add information
261+ :return: A string of class name and related information
262+ """
263+ if self .addend .size == 1 :
264+ return (self .__class__ .__name__ + ' with same number of '
265+ + str (self .addend ))
266+ else :
267+ return self .__class__ .__name__ + ' with different numbers'
223268
224269
225270class FlipXform (Xform ):
0 commit comments