Skip to content

Commit 14273c8

Browse files
committed
MAINT: move ufunc.__name__ and __qualname__ to the decorator
1 parent a11c041 commit 14273c8

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

torch_np/_ufuncs.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def wrapped(
4747
result = torch_func(*tensors)
4848
return result
4949

50+
wrapped.__qualname__ = torch_func.__name__
51+
wrapped.__name__ = torch_func.__name__
52+
5053
return wrapped
5154

5255

@@ -81,6 +84,10 @@ def matmul(
8184
return result
8285

8386

87+
matmul.__qualname__ = "matmul"
88+
matmul.__name__ = "matmul"
89+
90+
8491
def divmod(
8592
x1: ArrayLike,
8693
x2: ArrayLike,
@@ -116,16 +123,17 @@ def divmod(
116123
return quot, rem
117124

118125

126+
divmod.__qualname__ = "divmod"
127+
divmod.__name__ = "divmod"
128+
129+
119130
#
120131
# For each torch ufunc implementation, decorate and attach the decorated name
121132
# to this module. Its contents is then exported to the public namespace in __init__.py
122133
#
123134
for name in _binary:
124135
ufunc = getattr(_binary_ufuncs_impl, name)
125136
decorated = normalizer(deco_binary_ufunc(ufunc))
126-
127-
decorated.__qualname__ = name # XXX: is this really correct?
128-
decorated.__name__ = name
129137
vars()[name] = decorated
130138

131139

@@ -134,6 +142,10 @@ def modf(x, /, *args, **kwds):
134142
return rem, quot
135143

136144

145+
modf.__qualname__ = "modf"
146+
modf.__name__ = "modf"
147+
148+
137149
_binary = _binary + ["divmod", "modf", "matmul"]
138150

139151

@@ -178,6 +190,9 @@ def wrapped(
178190
result = torch_func(*tensors)
179191
return result
180192

193+
wrapped.__qualname__ = torch_func.__name__
194+
wrapped.__name__ = torch_func.__name__
195+
181196
return wrapped
182197

183198

@@ -188,9 +203,6 @@ def wrapped(
188203
for name in _unary:
189204
ufunc = getattr(_unary_ufuncs_impl, name)
190205
decorated = normalizer(deco_unary_ufunc(ufunc))
191-
192-
decorated.__qualname__ = name # XXX: is this really correct?
193-
decorated.__name__ = name
194206
vars()[name] = decorated
195207

196208

0 commit comments

Comments
 (0)