From 4b2e104f0303735ccf2a89bd5c5811d3eafcfb54 Mon Sep 17 00:00:00 2001 From: Daniel Otto de Mentock Date: Wed, 2 Feb 2022 12:52:59 +0100 Subject: [PATCH 1/2] added new type for rng_seed in _typehints module --- python/damask/_typehints.py | 2 ++ python/damask/seeds.py | 7 ++++--- python/damask/util.py | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/python/damask/_typehints.py b/python/damask/_typehints.py index 67e920957..b8232a752 100644 --- a/python/damask/_typehints.py +++ b/python/damask/_typehints.py @@ -9,3 +9,5 @@ import numpy as np FloatSequence = Union[np.ndarray,Sequence[float]] IntSequence = Union[np.ndarray,Sequence[int]] FileHandle = Union[TextIO, str, Path] + +NumpyRngSeed = Union[int, IntSequence, np.random.SeedSequence, np.random.BitGenerator, np.random.Generator] diff --git a/python/damask/seeds.py b/python/damask/seeds.py index 47e34d871..943d1bfd9 100644 --- a/python/damask/seeds.py +++ b/python/damask/seeds.py @@ -1,3 +1,4 @@ + """Functionality for generation of seed points for Voronoi or Laguerre tessellation.""" from typing import Tuple as _Tuple @@ -5,7 +6,7 @@ from typing import Tuple as _Tuple from scipy import spatial as _spatial import numpy as _np -from ._typehints import FloatSequence as _FloatSequence, IntSequence as _IntSequence +from ._typehints import FloatSequence as _FloatSequence, IntSequence as _IntSequence, NumpyRngSeed from . import util as _util from . import grid_filters as _grid_filters @@ -13,7 +14,7 @@ from . import grid_filters as _grid_filters def from_random(size: _FloatSequence, N_seeds: int, cells: _IntSequence = None, - rng_seed=None) -> _np.ndarray: + rng_seed: NumpyRngSeed = None) -> _np.ndarray: """ Place seeds randomly in space. @@ -53,7 +54,7 @@ def from_Poisson_disc(size: _FloatSequence, N_candidates: int, distance: float, periodic: bool = True, - rng_seed=None) -> _np.ndarray: + rng_seed: NumpyRngSeed = None) -> _np.ndarray: """ Place seeds according to a Poisson disc distribution. diff --git a/python/damask/util.py b/python/damask/util.py index b4c287884..fc3f8ea8f 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -16,7 +16,7 @@ import numpy as np import h5py from . import version -from ._typehints import IntSequence, FloatSequence +from ._typehints import FloatSequence, NumpyRngSeed # limit visibility __all__=[ @@ -396,7 +396,7 @@ def execution_stamp(class_name: str, def hybrid_IA(dist: np.ndarray, N: int, - rng_seed: Union[int, IntSequence] = None) -> np.ndarray: + rng_seed: NumpyRngSeed = None) -> np.ndarray: """ Hybrid integer approximation. From 8fead8e306158ff8466fbd784e1d85ac4b8831d5 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 2 Feb 2022 13:28:17 +0100 Subject: [PATCH 2/2] relaxed tolerances for optimized code, the last digit might differ --- src/polynomials.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/polynomials.f90 b/src/polynomials.f90 index 49a46e2e4..155f54bf8 100644 --- a/src/polynomials.f90 +++ b/src/polynomials.f90 @@ -163,7 +163,7 @@ subroutine selfTest 'T_ref: '//trim(adjustl(x_ref_s))//IO_EOL Dict => YAML_parse_str(trim(YAML_s)) p2 = polynomial(dict%asDict(),'C','T') - if (dNeq(p1%at(x),p2%at(x),1.0e-12_pReal)) error stop 'polynomials: init' + if (dNeq(p1%at(x),p2%at(x),1.0e-10_pReal)) error stop 'polynomials: init' p1 = polynomial(coef*[0.0_pReal,1.0_pReal,0.0_pReal],x_ref) if (dNeq(p1%at(x_ref+x),-p1%at(x_ref-x),1.0e-10_pReal)) error stop 'polynomials: eval(odd)'