@@ -206,41 +206,60 @@ def test_Image_basic():
206206 assert im1 (galsim .PositionI (x ,y )) == value
207207 assert im1a (x + 3 ,y + 6 ) == value
208208 assert im1b (x - 1 ,y - 1 ) == value
209- assert im1 .view ()(x ,y ) == value
210- assert im1 .view ()(galsim .PositionI (x ,y )) == value
211- assert im1 .view (make_const = True )(x ,y ) == value
212- assert im2 (x ,y ) == value
213- assert im2_view (x ,y ) == value
214- assert im2_cview (x ,y ) == value
209+ if is_jax_galsim ():
210+ assert im1 .copy ()(x ,y ) == value
211+ assert im1 .copy ()(galsim .PositionI (x ,y )) == value
212+ assert im1 .copy (make_const = True )(x ,y ) == value
213+ else :
214+ assert im1 .view ()(x ,y ) == value
215+ assert im1 .view ()(galsim .PositionI (x ,y )) == value
216+ assert im1 .view (make_const = True )(x ,y ) == value
217+ assert im2 (x ,y ) == value
218+ assert im2_view (x ,y ) == value
219+ assert im2_cview (x ,y ) == value
215220 assert im1 .conjugate (x ,y ) == value
216221 if tchar [i ][0 ] == 'C' :
217222 # complex conjugate is not a view into the original.
218223 assert im2_conj (x ,y ) == 23
219- assert im2 .conjugate (x ,y ) == value
224+ if not is_jax_galsim ():
225+ assert im2 .conjugate (x ,y ) == value
220226 else :
221- assert im2_conj (x ,y ) == value
227+ if not is_jax_galsim ():
228+ assert im2_conj (x ,y ) == value
222229
223230 value2 = 53 + 12 * x - 19 * y
224231 if tchar [i ] in ['US' , 'UI' ]:
225232 value2 = abs (value2 )
226233 im1 [x ,y ] = value2
227234 im2_view [galsim .PositionI (x ,y )] = value2
228235 assert im1 .getValue (x ,y ) == value2
229- assert im1 .view ().getValue (x = x , y = y ) == value2
230- assert im1 .view (make_const = True ).getValue (x ,y ) == value2
231- assert im2 .getValue (x = x , y = y ) == value2
232- assert im2_view .getValue (x ,y ) == value2
233- assert im2_cview ._getValue (x ,y ) == value2
236+ if is_jax_galsim ():
237+ assert im1 .copy ().getValue (x = x , y = y ) == value2
238+ assert im1 .copy (make_const = True ).getValue (x ,y ) == value2
239+ else :
240+ assert im1 .view ().getValue (x = x , y = y ) == value2
241+ assert im1 .view (make_const = True ).getValue (x ,y ) == value2
242+ assert im2 .getValue (x = x , y = y ) == value2
243+ assert im2_view .getValue (x ,y ) == value2
244+ assert im2_cview ._getValue (x ,y ) == value2
234245
235246 assert im1 .real (x ,y ) == value2
236- assert im1 .view ().real (x ,y ) == value2
237- assert im1 .view (make_const = True ).real (x ,y ) == value2 .real
238- assert im2 .real (x ,y ) == value2 .real
239- assert im2_view .real (x ,y ) == value2 .real
240- assert im2_cview .real (x ,y ) == value2 .real
247+ if is_jax_galsim ():
248+ assert im1 .copy ().real (x ,y ) == value2
249+ assert im1 .copy (make_const = True ).real (x ,y ) == value2 .real
250+ else :
251+ assert im1 .view ().real (x ,y ) == value2
252+ assert im1 .view (make_const = True ).real (x ,y ) == value2 .real
253+ assert im2 .real (x ,y ) == value2 .real
254+ assert im2_view .real (x ,y ) == value2 .real
255+ assert im2_cview .real (x ,y ) == value2 .real
241256 assert im1 .imag (x ,y ) == 0
242- assert im1 .view ().imag (x ,y ) == 0
243- assert im1 .view (make_const = True ).imag (x ,y ) == 0
257+ if is_jax_galsim ():
258+ assert im1 .copy ().imag (x ,y ) == 0
259+ assert im1 .copy (make_const = True ).imag (x ,y ) == 0
260+ else :
261+ assert im1 .view ().imag (x ,y ) == 0
262+ assert im1 .view (make_const = True ).imag (x ,y ) == 0
244263 assert im2 .imag (x ,y ) == 0
245264 assert im2_view .imag (x ,y ) == 0
246265 assert im2_cview .imag (x ,y ) == 0
@@ -249,40 +268,62 @@ def test_Image_basic():
249268 im1 .addValue (x ,y , np .int64 (value3 - value2 ))
250269 im2_view [x ,y ] += np .int64 (value3 - value2 )
251270 assert im1 [galsim .PositionI (x ,y )] == value3
252- assert im1 .view ()[x ,y ] == value3
253- assert im1 .view (make_const = True )[galsim .PositionI (x ,y )] == value3
254- assert im2 [x ,y ] == value3
255- assert im2_view [galsim .PositionI (x ,y )] == value3
256- assert im2_cview [x ,y ] == value3
271+ if is_jax_galsim ():
272+ assert im1 .copy ()[x ,y ] == value3
273+ assert im1 .copy (make_const = True )[galsim .PositionI (x ,y )] == value3
274+ else :
275+ assert im1 .view ()[x ,y ] == value3
276+ assert im1 .view (make_const = True )[galsim .PositionI (x ,y )] == value3
277+ assert im2 [x ,y ] == value3
278+ assert im2_view [galsim .PositionI (x ,y )] == value3
279+ assert im2_cview [x ,y ] == value3
257280
258281 # Setting or getting the value outside the bounds should throw an exception.
259282 assert_raises (galsim .GalSimBoundsError ,im1 .setValue ,0 ,0 ,1 )
260283 assert_raises (galsim .GalSimBoundsError ,im1 .addValue ,0 ,0 ,1 )
261284 assert_raises (galsim .GalSimBoundsError ,im1 .__call__ ,0 ,0 )
262285 assert_raises (galsim .GalSimBoundsError ,im1 .__getitem__ ,0 ,0 )
263286 assert_raises (galsim .GalSimBoundsError ,im1 .__setitem__ ,0 ,0 ,1 )
264- assert_raises (galsim .GalSimBoundsError ,im1 .view ().setValue ,0 ,0 ,1 )
265- assert_raises (galsim .GalSimBoundsError ,im1 .view ().__call__ ,0 ,0 )
266- assert_raises (galsim .GalSimBoundsError ,im1 .view ().__getitem__ ,0 ,0 )
267- assert_raises (galsim .GalSimBoundsError ,im1 .view ().__setitem__ ,0 ,0 ,1 )
287+ if is_jax_galsim ():
288+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().setValue ,0 ,0 ,1 )
289+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().__call__ ,0 ,0 )
290+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().__getitem__ ,0 ,0 )
291+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().__setitem__ ,0 ,0 ,1 )
292+ else :
293+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().setValue ,0 ,0 ,1 )
294+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().__call__ ,0 ,0 )
295+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().__getitem__ ,0 ,0 )
296+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().__setitem__ ,0 ,0 ,1 )
268297
269298 assert_raises (galsim .GalSimBoundsError ,im1 .setValue ,ncol + 1 ,0 ,1 )
270299 assert_raises (galsim .GalSimBoundsError ,im1 .addValue ,ncol + 1 ,0 ,1 )
271300 assert_raises (galsim .GalSimBoundsError ,im1 .__call__ ,ncol + 1 ,0 )
272- assert_raises (galsim .GalSimBoundsError ,im1 .view ().setValue ,ncol + 1 ,0 ,1 )
273- assert_raises (galsim .GalSimBoundsError ,im1 .view ().__call__ ,ncol + 1 ,0 )
301+ if is_jax_galsim ():
302+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().setValue ,ncol + 1 ,0 ,1 )
303+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().__call__ ,ncol + 1 ,0 )
304+ else :
305+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().setValue ,ncol + 1 ,0 ,1 )
306+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().__call__ ,ncol + 1 ,0 )
274307
275308 assert_raises (galsim .GalSimBoundsError ,im1 .setValue ,0 ,nrow + 1 ,1 )
276309 assert_raises (galsim .GalSimBoundsError ,im1 .addValue ,0 ,nrow + 1 ,1 )
277310 assert_raises (galsim .GalSimBoundsError ,im1 .__call__ ,0 ,nrow + 1 )
278- assert_raises (galsim .GalSimBoundsError ,im1 .view ().setValue ,0 ,nrow + 1 ,1 )
279- assert_raises (galsim .GalSimBoundsError ,im1 .view ().__call__ ,0 ,nrow + 1 )
311+ if is_jax_galsim ():
312+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().setValue ,0 ,nrow + 1 ,1 )
313+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().__call__ ,0 ,nrow + 1 )
314+ else :
315+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().setValue ,0 ,nrow + 1 ,1 )
316+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().__call__ ,0 ,nrow + 1 )
280317
281318 assert_raises (galsim .GalSimBoundsError ,im1 .setValue ,ncol + 1 ,nrow + 1 ,1 )
282319 assert_raises (galsim .GalSimBoundsError ,im1 .addValue ,ncol + 1 ,nrow + 1 ,1 )
283320 assert_raises (galsim .GalSimBoundsError ,im1 .__call__ ,ncol + 1 ,nrow + 1 )
284- assert_raises (galsim .GalSimBoundsError ,im1 .view ().setValue ,ncol + 1 ,nrow + 1 ,1 )
285- assert_raises (galsim .GalSimBoundsError ,im1 .view ().__call__ ,ncol + 1 ,nrow + 1 )
321+ if is_jax_galsim ():
322+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().setValue ,ncol + 1 ,nrow + 1 ,1 )
323+ assert_raises (galsim .GalSimBoundsError ,im1 .copy ().__call__ ,ncol + 1 ,nrow + 1 )
324+ else :
325+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().setValue ,ncol + 1 ,nrow + 1 ,1 )
326+ assert_raises (galsim .GalSimBoundsError ,im1 .view ().__call__ ,ncol + 1 ,nrow + 1 )
286327
287328 assert_raises (galsim .GalSimBoundsError ,im1 .__getitem__ ,galsim .BoundsI (0 ,ncol ,1 ,nrow ))
288329 assert_raises (galsim .GalSimBoundsError ,im1 .__getitem__ ,galsim .BoundsI (1 ,ncol ,0 ,nrow ))
@@ -317,9 +358,14 @@ def test_Image_basic():
317358 galsim .Image (ncol + 2 ,nrow + 2 , init_value = 10 ))
318359
319360 # Also, setting values in something that should be const
320- assert_raises (galsim .GalSimImmutableError ,im1 .view (make_const = True ).setValue ,1 ,1 ,1 )
321- assert_raises (galsim .GalSimImmutableError ,im1 .view (make_const = True ).real .setValue ,1 ,1 ,1 )
322- assert_raises (galsim .GalSimImmutableError ,im1 .view (make_const = True ).imag .setValue ,1 ,1 ,1 )
361+ if is_jax_galsim ():
362+ assert_raises (galsim .GalSimImmutableError ,im1 .copy (make_const = True ).setValue ,1 ,1 ,1 )
363+ assert_raises (galsim .GalSimImmutableError ,im1 .copy (make_const = True ).real .setValue ,1 ,1 ,1 )
364+ assert_raises (galsim .GalSimImmutableError ,im1 .copy (make_const = True ).imag .setValue ,1 ,1 ,1 )
365+ else :
366+ assert_raises (galsim .GalSimImmutableError ,im1 .view (make_const = True ).setValue ,1 ,1 ,1 )
367+ assert_raises (galsim .GalSimImmutableError ,im1 .view (make_const = True ).real .setValue ,1 ,1 ,1 )
368+ assert_raises (galsim .GalSimImmutableError ,im1 .view (make_const = True ).imag .setValue ,1 ,1 ,1 )
323369 if tchar [i ][0 ] != 'C' :
324370 assert_raises (galsim .GalSimImmutableError ,im1 .imag .setValue ,1 ,1 ,1 )
325371
@@ -336,7 +382,10 @@ def test_Image_basic():
336382 im5_view = galsim .Image (ref_array .astype (np_array_type ).tolist (), dtype = array_type )
337383 im6_view = galsim .Image (ref_array .astype (np_array_type ), xmin = 4 , ymin = 7 )
338384 im7_view = galsim .Image (ref_array .astype (np_array_type ), xmin = 0 , ymin = 0 )
339- im8_view = galsim .Image (ref_array ).view (dtype = np_array_type )
385+ if is_jax_galsim ():
386+ im8_view = galsim .Image (ref_array ).copy (dtype = np_array_type )
387+ else :
388+ im8_view = galsim .Image (ref_array ).view (dtype = np_array_type )
340389 for y in range (1 ,nrow + 1 ):
341390 for x in range (1 ,ncol + 1 ):
342391 value3 = 10 * x + y
@@ -348,7 +397,10 @@ def test_Image_basic():
348397 assert im8_view (x ,y ) == value3
349398
350399 # Check shift ops
351- im1_view = im1 .view () # View with old bounds
400+ if is_jax_galsim ():
401+ im1_view = im1 .copy ()
402+ else :
403+ im1_view = im1 .view () # View with old bounds
352404 dx = 31
353405 dy = 16
354406 im1 .shift (dx ,dy )
@@ -364,19 +416,12 @@ def test_Image_basic():
364416 assert im2 .bounds == bounds
365417 for y in range (1 ,nrow + 1 ):
366418 for x in range (1 ,ncol + 1 ):
367- if is_jax_galsim ():
368- value3 = 10 * x + y + 111
369- else :
370- value3 = 10 * x + y
419+ value3 = 10 * x + y
371420 assert im1 (x + dx ,y + dy ) == value3
372421 assert im1_view (x ,y ) == value3
373- if is_jax_galsim ():
374- assert im2 (x ,y ) != value3
375- else :
422+ if not is_jax_galsim ():
376423 assert im2 (x ,y ) == value3
377424 assert im2_view (x + dx ,y + dy ) == value3
378- if is_jax_galsim ():
379- value3 = 10 * x + y
380425 assert im3_view (x + dx ,y + dy ) == value3
381426
382427 assert_raises (TypeError , im1 .shift , dx )
0 commit comments