GalSim icon indicating copy to clipboard operation
GalSim copied to clipboard

Add a GalSim deviates (partial) drop-in replacement for numpy.RandomState.

Open jmeyers314 opened this issue 5 years ago • 3 comments

In numpy, if I want a random array uniformly distributed between -0.6 and +0.6 with 100 elements, I'd write:

rng = numpy.random.RandomState(seed)
array = rng.uniform(-0.6, 0.6, 100)

Using GalSim deviates, I'd do something like:

ud = galsim.UniformDeviate(seed)
array = np.empty(100)
ud.generate(array)
array = array*1.2 - 0.6

I find the former easier to read. I don't think it'd be too difficult to create an object based on GalSim deviates with methods like .uniform, .normal=.gaussian, .binomial, .poisson, etc that have the same syntax as numpy. Making a drop-in replacement also means that it's easier for external packages (e.g., imsim, batoid, ...) to switch from numpy random numbers to Galsim random numbers with their stronger guarantee of stability over time.

jmeyers314 avatar Dec 01 '19 06:12 jmeyers314

Sounds good. I wouldn't make a new class for this though. These can be methods of BaseDeviate I think.

rmjarvis avatar Dec 01 '19 15:12 rmjarvis

I thought about that. The only awkward part is that then UniformDeviate will have an inherited method .poisson and so on. Maybe that's fine though.

jmeyers314 avatar Dec 01 '19 20:12 jmeyers314

Doesn't bother me. :) But either way. If you prefer to make a new subclass of BaseDeviate that would enable these various driver methods, that's also fine.

rmjarvis avatar Dec 02 '19 20:12 rmjarvis

Done via #1179

rmjarvis avatar Aug 24 '22 17:08 rmjarvis