Merge branch 'new-random-style' into 'development'

new style for numpy random numbers

See merge request damask/DAMASK!224
This commit is contained in:
Vitesh 2020-09-16 11:12:55 +02:00
commit ca689193f6
1 changed files with 20 additions and 4 deletions

View File

@ -613,13 +613,29 @@ class Rotation:
return Rotation.from_quaternion(np.real(vec.T[eig.argmax()]),accept_homomorph = True)
@staticmethod
def from_random(shape=None):
def from_random(shape=None,seed=None):
"""
Draw random rotation.
Rotations are uniformly distributed.
Parameters
----------
shape : tuple of ints, optional
Shape of the sample. Defaults to None which gives a
single rotation
seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional
A seed to initialize the BitGenerator. Defaults to None.
If None, then fresh, unpredictable entropy will be pulled from the OS.
"""
rng = np.random.default_rng(seed)
if shape is None:
r = np.random.random(3)
r = rng.random(3)
elif hasattr(shape, '__iter__'):
r = np.random.random(tuple(shape)+(3,))
r = rng.random(tuple(shape)+(3,))
else:
r = np.random.rand(shape,3)
r = rng.random((shape,3))
A = np.sqrt(r[...,2])
B = np.sqrt(1.0-r[...,2])