Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

immutability in Image class #38

Open
ismael-mendoza opened this issue Jun 20, 2023 · 1 comment
Open

immutability in Image class #38

ismael-mendoza opened this issue Jun 20, 2023 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@ismael-mendoza
Copy link
Collaborator

ismael-mendoza commented Jun 20, 2023

Reposted from #16 from @EiffL

There are some questions about this though. galsim.Image are mutable objects, which really does not play nicely with JAX, it is simply not possible to assign values to array in jax without making a copy. We can follow the galsim API, but the behavior will be different, it won't be possible to assign values to a view of a larger image.

In particular, we cannot do the following in Jax-GalSim:

gal = galsim.Gaussian(sigma=1)
im = galsim.Image(nx=128, ny=128, scale=0.1)

imview = im.view()

gal.drawImage(imview)

This would not update the original im.

This will become even sharper of a question when we go to the next PR, which implements drawing functions.

Already here, there is a question of whether we want to make all Image immutable explicitly, whether we want to allow this sort of things:

image = galsim.Image(nx=128, ny=128, scale=0.1)
image.wcs = galsim.PixelScale(0.2)
image.setCenter(0.0, 0.)

these are examples of bad OO patterns that do not play nicely at all with the JAX functional spirit, but if we remove them, we break the GalSim API....

@ismael-mendoza ismael-mendoza added the help wanted Extra attention is needed label Jun 22, 2023
@ismael-mendoza
Copy link
Collaborator Author

A couple of methods in the Image class still modify the object, perhaps we should change them so that they return a new object to be more in the JAX spirit?

  • setSubImage
  • setitem
  • resize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant