112
112
113
113
from collections .abc import Callable
114
114
from functools import partial
115
- from scipy ._lib ._util import _asarray_validated
115
+ from scipy ._lib ._util import _asarray_validated , _transition_to_rng
116
116
from scipy ._lib .deprecation import _deprecated
117
117
118
118
from . import _distance_wrap
@@ -309,7 +309,8 @@ def _validate_weights(w, dtype=np.float64):
309
309
return w
310
310
311
311
312
- def directed_hausdorff (u , v , seed = 0 ):
312
+ @_transition_to_rng ('seed' , position_num = 2 , replace_doc = False )
313
+ def directed_hausdorff (u , v , rng = 0 ):
313
314
"""
314
315
Compute the directed Hausdorff distance between two 2-D arrays.
315
316
@@ -321,10 +322,35 @@ def directed_hausdorff(u, v, seed=0):
321
322
Input array with M points in N dimensions.
322
323
v : (O,N) array_like
323
324
Input array with O points in N dimensions.
324
- seed : int or `numpy.random.Generator` or None, optional
325
- Local `numpy.random.RandomState` seed. Default is 0, a random
326
- shuffling of u and v that guarantees reproducibility. Also
327
- accepts a `numpy.random.Generator` object.
325
+ rng : int or `numpy.random.Generator` or None, optional
326
+ Pseudorandom number generator state. Default is 0 so the
327
+ shuffling of `u` and `v` is reproducible.
328
+
329
+ If `rng` is passed by keyword, types other than `numpy.random.Generator` are
330
+ passed to `numpy.random.default_rng` to instantiate a ``Generator``.
331
+ If `rng` is already a ``Generator`` instance, then the provided instance is
332
+ used.
333
+
334
+ If this argument is passed by position or `seed` is passed by keyword,
335
+ legacy behavior for the argument `seed` applies:
336
+
337
+ - If `seed` is None, a new ``RandomState`` instance is used. The state is
338
+ initialized using data from ``/dev/urandom`` (or the Windows analogue)
339
+ if available or from the system clock otherwise.
340
+ - If `seed` is an int, a new ``RandomState`` instance is used,
341
+ seeded with `seed`.
342
+ - If `seed` is already a ``Generator`` or ``RandomState`` instance, then
343
+ that instance is used.
344
+
345
+ .. versionchanged:: 1.15.0
346
+ As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
347
+ transition from use of `numpy.random.RandomState` to
348
+ `numpy.random.Generator`, this keyword was changed from `seed` to `rng`.
349
+ For an interim period, both keywords will continue to work, although only
350
+ one may be specified at a time. After the interim period, function calls
351
+ using the `seed` keyword will emit warnings. The behavior of both `seed`
352
+ and `rng` are outlined above, but only the `rng` keyword should be used in
353
+ new code.
328
354
329
355
Returns
330
356
-------
@@ -407,7 +433,7 @@ def directed_hausdorff(u, v, seed=0):
407
433
if u .shape [1 ] != v .shape [1 ]:
408
434
raise ValueError ('u and v need to have the same '
409
435
'number of columns' )
410
- result = _hausdorff .directed_hausdorff (u , v , seed )
436
+ result = _hausdorff .directed_hausdorff (u , v , rng )
411
437
return result
412
438
413
439
0 commit comments