5
5
6
6
import numpy as np
7
7
8
- from scipy ._lib ._util import check_random_state , rng_integers
8
+ from scipy ._lib ._util import (check_random_state , rng_integers ,
9
+ _transition_to_rng )
9
10
from scipy .sparse import csc_matrix
10
11
11
12
__all__ = ['clarkson_woodruff_transform' ]
12
13
13
14
14
- def cwt_matrix (n_rows , n_columns , seed = None ):
15
+ def cwt_matrix (n_rows , n_columns , rng = None ):
15
16
r"""
16
17
Generate a matrix S which represents a Clarkson-Woodruff transform.
17
18
@@ -26,13 +27,12 @@ def cwt_matrix(n_rows, n_columns, seed=None):
26
27
Number of rows of S
27
28
n_columns : int
28
29
Number of columns of S
29
- seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
30
- If `seed` is None (or `np.random`), the `numpy.random.RandomState`
31
- singleton is used.
32
- If `seed` is an int, a new ``RandomState`` instance is used,
33
- seeded with `seed`.
34
- If `seed` is already a ``Generator`` or ``RandomState`` instance then
35
- that instance is used.
30
+ rng : `numpy.random.Generator`, optional
31
+ Pseudorandom number generator state. When `rng` is None, a new
32
+ `numpy.random.Generator` is created using entropy from the
33
+ operating system. Types other than `numpy.random.Generator` are
34
+ passed to `numpy.random.default_rng` to instantiate a ``Generator``.
35
+
36
36
37
37
Returns
38
38
-------
@@ -45,15 +45,16 @@ def cwt_matrix(n_rows, n_columns, seed=None):
45
45
.. math:: \|SA\| = (1 \pm \epsilon)\|A\|
46
46
Where the error epsilon is related to the size of S.
47
47
"""
48
- rng = check_random_state (seed )
48
+ rng = check_random_state (rng )
49
49
rows = rng_integers (rng , 0 , n_rows , n_columns )
50
50
cols = np .arange (n_columns + 1 )
51
51
signs = rng .choice ([1 , - 1 ], n_columns )
52
- S = csc_matrix ((signs , rows , cols ),shape = (n_rows , n_columns ))
52
+ S = csc_matrix ((signs , rows , cols ), shape = (n_rows , n_columns ))
53
53
return S
54
54
55
55
56
- def clarkson_woodruff_transform (input_matrix , sketch_size , seed = None ):
56
+ @_transition_to_rng ("seed" , position_num = 2 )
57
+ def clarkson_woodruff_transform (input_matrix , sketch_size , rng = None ):
57
58
r"""
58
59
Applies a Clarkson-Woodruff Transform/sketch to the input matrix.
59
60
@@ -71,13 +72,11 @@ def clarkson_woodruff_transform(input_matrix, sketch_size, seed=None):
71
72
Input matrix, of shape ``(n, d)``.
72
73
sketch_size : int
73
74
Number of rows for the sketch.
74
- seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
75
- If `seed` is None (or `np.random`), the `numpy.random.RandomState`
76
- singleton is used.
77
- If `seed` is an int, a new ``RandomState`` instance is used,
78
- seeded with `seed`.
79
- If `seed` is already a ``Generator`` or ``RandomState`` instance then
80
- that instance is used.
75
+ rng : `numpy.random.Generator`, optional
76
+ Pseudorandom number generator state. When `rng` is None, a new
77
+ `numpy.random.Generator` is created using entropy from the
78
+ operating system. Types other than `numpy.random.Generator` are
79
+ passed to `numpy.random.default_rng` to instantiate a ``Generator``.
81
80
82
81
Returns
83
82
-------
@@ -175,5 +174,5 @@ def clarkson_woodruff_transform(input_matrix, sketch_size, seed=None):
175
174
166.58473879945151
176
175
177
176
"""
178
- S = cwt_matrix (sketch_size , input_matrix .shape [0 ], seed )
177
+ S = cwt_matrix (sketch_size , input_matrix .shape [0 ], rng = rng )
179
178
return S .dot (input_matrix )
0 commit comments