Skip to content

Commit 7583242

Browse files
twieckiclaude
andcommitted
Improved docstrings for Elemwise functions
This PR improves docstrings for Elemwise functions by: 1. Modifying scalar_elemwise to no longer append the generic Elemwise docstring 2. Enhancing docstrings for specific mathematical functions (exp, log, eq) with: - Better formatted NumPy-style documentation - Clear descriptions of functionality - Practical usage examples - Additional notes on potential pitfalls This fixes issue #292 which noted that current Elemwise docstrings are not very helpful due to excessive generic boilerplate. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent 1a220e5 commit 7583242

File tree

2 files changed

+203
-124
lines changed

2 files changed

+203
-124
lines changed

pytensor/tensor/elemwise.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def _c_all(self, node, nodename, inames, onames, sub):
847847
# for each input:
848848
# same as range(ndim), but with 'x' at all broadcastable positions
849849
orders = [
850-
[s == 1 and "x" or i for i, s in enumerate(input.type.shape)]
850+
[(s == 1 and "x") or i for i, s in enumerate(input.type.shape)]
851851
for input in inputs
852852
]
853853

@@ -1671,8 +1671,10 @@ def construct(symbol):
16711671
scalar_op = getattr(scalar, symbolname)
16721672
rval = Elemwise(scalar_op, nfunc_spec=(nfunc and (nfunc, nin, nout)))
16731673

1674+
# Set the docstring to be just the original function's docstring
1675+
# without appending the generic Elemwise docstring
16741676
if getattr(symbol, "__doc__"):
1675-
rval.__doc__ = symbol.__doc__ + "\n\n " + rval.__doc__
1677+
rval.__doc__ = symbol.__doc__
16761678

16771679
# for the meaning of this see the ./epydoc script
16781680
# it makes epydoc display rval as if it were a function, not an object

0 commit comments

Comments
 (0)