8
8
__all__ = ['fix' , 'isneginf' , 'isposinf' ]
9
9
10
10
import numpy .core .numeric as nx
11
+ import warnings
12
+ import functools
11
13
12
- def fix (x , y = None ):
14
+ def _deprecate_out_named_y (f ):
15
+ """
16
+ Allow the out argument to be passed as the name `y` (deprecated)
17
+
18
+ In future, this decorator should be removed.
19
+ """
20
+ @functools .wraps (f )
21
+ def func (x , out = None , ** kwargs ):
22
+ if 'y' in kwargs :
23
+ if 'out' in kwargs :
24
+ raise TypeError (
25
+ "{} got multiple values for argument 'out'/'y'"
26
+ .format (f .__name__ )
27
+ )
28
+ out = kwargs .pop ('y' )
29
+ # NumPy 1.13.0, 2017-04-26
30
+ warnings .warn (
31
+ "The name of the out argument to {} has changed from `y` to "
32
+ "`out`, to match other ufuncs." .format (f .__name__ ),
33
+ DeprecationWarning , stacklevel = 3 )
34
+ return f (x , out = out , ** kwargs )
35
+
36
+ return func
E7EE
37
+
38
+
39
+ @_deprecate_out_named_y
40
+ def fix (x , out = None ):
13
41
"""
14
42
Round to nearest integer towards zero.
15
43
@@ -46,12 +74,14 @@ def fix(x, y=None):
46
74
x = nx .asanyarray (x )
47
75
y1 = nx .floor (x )
48
76
y2 = nx .ceil (x )
49
- if y is None :
50
- y = nx .asanyarray (y1 )
51
- y [...] = nx .where (x >= 0 , y1 , y2 )
52
- return y
77
+ if out is None :
78
+ out = nx .asanyarray (y1 )
79
+ out [...] = nx .where (x >= 0 , y1 , y2 )
80
+ return out
53
81
54
- def isposinf (x , y = None ):
82
+
83
+ @_deprecate_out_named_y
84
+ def isposinf (x , out = None ):
55
85
"""
56
86
Test element-wise for positive infinity, return result as bool array.
57
87
@@ -64,7 +94,7 @@ def isposinf(x, y=None):
64
94
65
95
Returns
66
96
-------
67
- y : ndarray
97
+ out : ndarray
68
98
A boolean array with the same dimensions as the input.
69
99
If second argument is not supplied then a boolean array is returned
70
100
with values True where the corresponding element of the input is
@@ -74,7 +104,7 @@ def isposinf(x, y=None):
74
104
If a second argument is supplied the result is stored there. If the
75
105
type of that array is a numeric type the result is represented as zeros
76
106
and ones, if the type is boolean then as False and True.
77
- The return value `y ` is then a refe
23DA
rence to that array.
107
+ The return value `out ` is then a reference to that array.
78
108
79
109
See Also
80
110
--------
@@ -109,25 +139,27 @@ def isposinf(x, y=None):
109
139
"""
110
140
if y is None :
111
141
x = nx .asarray (x )
112
- y = nx .empty (x .shape , dtype = nx .bool_ )
113
- nx .logical_and (nx .isinf (x ), ~ nx .signbit (x ), y )
114
- return y
142
+ out = nx .empty (x .shape , dtype = nx .bool_ )
143
+ nx .logical_and (nx .isinf (x ), ~ nx .signbit (x ), out )
144
+ return out
145
+
115
146
116
- def isneginf (x , y = None ):
147
+ @_deprecate_out_named_y
148
+ def isneginf (x , out = None ):
117
149
"""
118
150
Test element-wise for negative infinity, return result as bool array.
119
151
120
152
Parameters
121
153
----------
122
154
x : array_like
123
155
The input array.
124
- y : array_like, optional
156
+ out : array_like, optional
125
157
A boolean array with the same shape and type as `x` to store the
126
158
result.
127
159
128
160
Returns
129
161
-------
130
- y : ndarray
162
+ out : ndarray
131
163
A boolean array with the same dimensions as the input.
132
164
If second argument is not supplied then a numpy boolean array is
133
165
returned with values True where the corresponding element of the
@@ -137,7 +169,7 @@ def isneginf(x, y=None):
137
169
If a second argument is supplied the result is stored there. If the
138
170
type of that array is a numeric type the result is represented as
139
171
zeros and ones, if the type is boolean then as False and True. The
140
- return value `y ` is then a reference to that array.
172
+ return value `out ` is then a reference to that array.
141
173
142
174
See Also
143
175
--------
@@ -170,8 +202,8 @@ def isneginf(x, y=None):
170
202
array([1, 0, 0])
171
203
172
204
"""
173
- if y is None :
205
+ if out is None :
174
206
x = nx .asarray (x )
175
- y = nx .empty (x .shape , dtype = nx .bool_ )
176
- nx .logical_and (nx .isinf (x ), nx .signbit (x ), y )
177
- return y
207
+ out = nx .empty (x .shape , dtype = nx .bool_ )
208
+ nx .logical_and (nx .isinf (x ), nx .signbit (x ), out )
209
+ return out
0 commit comments