Skip to content

Commit 27545a8

Browse files
committed
seed: use Ellipsis to indicate keeping the seed
1 parent 418c584 commit 27545a8

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

src/gstools/field/cond_srf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, krige, generator="RandMeth", **generator_kwargs):
6464
def __call__(
6565
self,
6666
pos=None,
67-
seed=np.nan,
67+
seed=...,
6868
mesh_type="unstructured",
6969
post_process=True,
7070
store=True,
@@ -80,8 +80,10 @@ def __call__(
8080
pos : :class:`list`, optional
8181
the position tuple, containing main direction and transversal
8282
directions
83-
seed : :class:`int`, optional
84-
seed for RNG for resetting. Default: keep seed from generator
83+
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
84+
the seed of the random number generator.
85+
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
86+
the actual seed will be kept. Default: :any:`Ellipsis`
8587
mesh_type : :class:`str`
8688
'structured' / 'unstructured'
8789
post_process : :class:`bool`, optional

src/gstools/field/generator.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, model, **kwargs):
5252
pass
5353

5454
@abstractmethod
55-
def update(self, model=None, seed=np.nan):
55+
def update(self, model=None, seed=...):
5656
"""Update the model and the seed.
5757
5858
If model and seed are not different, nothing will be done.
@@ -61,10 +61,10 @@ def update(self, model=None, seed=np.nan):
6161
----------
6262
model : :any:`CovModel` or :any:`None`, optional
6363
covariance model. Default: :any:`None`
64-
seed : :class:`int` or :any:`None` or :any:`numpy.nan`, optional
64+
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
6565
the seed of the random number generator.
66-
If :any:`None`, a random seed is used. If :any:`numpy.nan`,
67-
the actual seed will be kept. Default: :any:`numpy.nan`
66+
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
67+
the actual seed will be kept. Default: :any:`Ellipsis`
6868
"""
6969

7070
@abstractmethod
@@ -235,7 +235,7 @@ def get_nugget(self, shape):
235235
nugget = 0.0
236236
return nugget
237237

238-
def update(self, model=None, seed=np.nan):
238+
def update(self, model=None, seed=...):
239239
"""Update the model and the seed.
240240
241241
If model and seed are not different, nothing will be done.
@@ -244,33 +244,33 @@ def update(self, model=None, seed=np.nan):
244244
----------
245245
model : :any:`CovModel` or :any:`None`, optional
246246
covariance model. Default: :any:`None`
247-
seed : :class:`int` or :any:`None` or :any:`numpy.nan`, optional
247+
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
248248
the seed of the random number generator.
249-
If :any:`None`, a random seed is used. If :any:`numpy.nan`,
250-
the actual seed will be kept. Default: :any:`numpy.nan`
249+
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
250+
the actual seed will be kept. Default: :any:`Ellipsis`
251251
"""
252252
# check if a new model is given
253253
if isinstance(model, CovModel):
254254
if self.model != model:
255255
self._model = dcp(model)
256-
if seed is None or not np.isnan(seed):
256+
if seed is None or seed is not Ellipsis:
257257
self.reset_seed(seed)
258258
else:
259259
self.reset_seed(self._seed)
260260
# just update the seed, if its a new one
261-
elif seed is None or not np.isnan(seed):
261+
elif seed is None or seed is not Ellipsis:
262262
self.seed = seed
263263
# or just update the seed, when no model is given
264-
elif model is None and (seed is None or not np.isnan(seed)):
264+
elif model is None and (seed is None or seed is not Ellipsis):
265265
if isinstance(self._model, CovModel):
266266
self.seed = seed
267267
else:
268268
raise ValueError(
269269
"gstools.field.generator.RandMeth: no 'model' given"
270270
)
271271
# if the user tries to trick us, we beat him!
272-
elif model is None and np.isnan(seed):
273-
if not (
272+
elif model is None and seed is Ellipsis:
273+
if (
274274
isinstance(self._model, CovModel)
275275
and self._z_1 is not None
276276
and self._z_2 is not None
@@ -287,22 +287,22 @@ def update(self, model=None, seed=np.nan):
287287
"instance of 'gstools.CovModel'"
288288
)
289289

290-
def reset_seed(self, seed=np.nan):
290+
def reset_seed(self, seed=...):
291291
"""
292292
Recalculate the random amplitudes and wave numbers with the given seed.
293293
294294
Parameters
295295
----------
296-
seed : :class:`int` or :any:`None` or :any:`numpy.nan`, optional
296+
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
297297
the seed of the random number generator.
298-
If :any:`None`, a random seed is used. If :any:`numpy.nan`,
299-
the actual seed will be kept. Default: :any:`numpy.nan`
298+
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
299+
the actual seed will be kept. Default: :any:`Ellipsis`
300300
301301
Notes
302302
-----
303303
Even if the given seed is the present one, modes will be recalculated.
304304
"""
305-
if seed is None or not np.isnan(seed):
305+
if seed is None or seed is not Ellipsis:
306306
self._seed = seed
307307
self._rng = RNG(self._seed)
308308
# normal distributed samples for randmeth

src/gstools/field/srf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__(
103103
def __call__(
104104
self,
105105
pos=None,
106-
seed=np.nan,
106+
seed=...,
107107
point_volumes=0.0,
108108
mesh_type="unstructured",
109109
post_process=True,
@@ -118,8 +118,10 @@ def __call__(
118118
pos : :class:`list`, optional
119119
the position tuple, containing main direction and transversal
120120
directions
121-
seed : :class:`int`, optional
122-
seed for RNG for resetting. Default: keep seed from generator
121+
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
122+
the seed of the random number generator.
123+
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
124+
the actual seed will be kept. Default: :any:`Ellipsis`
123125
point_volumes : :class:`float` or :class:`numpy.ndarray`
124126
If your evaluation points for the field are coming from a mesh,
125127
they are probably representing a certain element volume.

0 commit comments

Comments
 (0)