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 Nov 3, 2023
1 parent db96b57 commit bae13af
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 @@ -83,7 +83,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 @@ -64,7 +64,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 @@ -247,21 +247,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 @@ -296,13 +293,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 @@ -351,7 +348,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 @@ -121,7 +121,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 bae13af

Please sign in to comment.