Skip to content

Commit

Permalink
seed: simplify logic; typo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Oct 19, 2022
1 parent 9966da0 commit d1a4662
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/gstools/field/cond_srf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __call__(
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
the seed of the random number generator.
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
the actual seed will be kept. Default: :any:`Ellipsis`
the current seed will be kept. Default: :any:`Ellipsis`
mesh_type : :class:`str`
'structured' / 'unstructured'
post_process : :class:`bool`, optional
Expand Down
19 changes: 8 additions & 11 deletions src/gstools/field/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def update(self, model=None, seed=...):
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
the seed of the random number generator.
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
the actual seed will be kept. Default: :any:`Ellipsis`
the current seed will be kept. Default: :any:`Ellipsis`
"""

@abstractmethod
Expand Down Expand Up @@ -250,21 +250,18 @@ def update(self, model=None, seed=...):
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
the seed of the random number generator.
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
the actual seed will be kept. Default: :any:`Ellipsis`
the current seed will be kept. Default: :any:`Ellipsis`
"""
# check if a new model is given
if isinstance(model, CovModel):
if self.model != model:
self._model = dcp(model)
if seed is None or seed is not Ellipsis:
self.reset_seed(seed)
else:
self.reset_seed(self._seed)
self.reset_seed(self._seed if seed is Ellipsis else seed)
# just update the seed, if its a new one
elif seed is None or seed is not Ellipsis:
elif seed is not Ellipsis:
self.seed = seed
# or just update the seed, when no model is given
elif model is None and (seed is None or seed is not Ellipsis):
elif model is None and seed is not Ellipsis:
if isinstance(self._model, CovModel):
self.seed = seed
else:
Expand Down Expand Up @@ -302,13 +299,13 @@ def reset_seed(self, seed=...):
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
the seed of the random number generator.
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
the actual seed will be kept. Default: :any:`Ellipsis`
the current seed will be kept. Default: :any:`Ellipsis`
Notes
-----
Even if the given seed is the present one, modes will be recalculated.
"""
if seed is None or seed is not Ellipsis:
if seed is not Ellipsis:
self._seed = seed
self._rng = RNG(self._seed)
# normal distributed samples for randmeth
Expand Down Expand Up @@ -357,7 +354,7 @@ def seed(self):

@seed.setter
def seed(self, new_seed):
if new_seed is not self._seed:
if new_seed != self._seed:
self.reset_seed(new_seed)

@property
Expand Down
2 changes: 1 addition & 1 deletion src/gstools/field/srf.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __call__(
seed : :class:`int` or :any:`None` or :any:`Ellipsis`, optional
the seed of the random number generator.
If :any:`None`, a random seed is used. If :any:`Ellipsis`,
the actual seed will be kept. Default: :any:`Ellipsis`
the current seed will be kept. Default: :any:`Ellipsis`
point_volumes : :class:`float` or :class:`numpy.ndarray`
If your evaluation points for the field are coming from a mesh,
they are probably representing a certain element volume.
Expand Down

0 comments on commit d1a4662

Please sign in to comment.