-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement vectorize helper with similar semantics to that of NumPy #500
Conversation
1954083
to
f6521eb
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #500 +/- ##
==========================================
+ Coverage 80.75% 80.77% +0.01%
==========================================
Files 161 162 +1
Lines 46078 46105 +27
Branches 11258 11266 +8
==========================================
+ Hits 37212 37240 +28
- Misses 6637 6638 +1
+ Partials 2229 2227 -2
|
pytensor/tensor/functional.py
Outdated
def vectorize(func: Callable, signature: Optional[str] = None) -> Callable: | ||
"""Equivalent to numpy.vectorize. | ||
|
||
If you have an existing graph you wish to vectorize, use `pytensor.graph.replace.vectorize_graph` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a note further down below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would you put it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After Returns a new heading Notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to comment on this too; it's just not so clear what it means (since a priori everything in pytensor is a graph).
Maybe:
Vectorize a python function with symbolic pytensor inputs and outputs according to a function signature, equivalent to numpy.vectorize.
Note that this function cannot operate on pytensor variables that represent computational graphs. To vectorize an existing pytensor graph, use `pytensor.graph.replace.vectorize`.
pytensor/tensor/functional.py
Outdated
func: Callable | ||
Function that returns PyTensor varibales from TensorVariable inputs. | ||
signature: str, optional | ||
String that specifies the number and dimension of inputs and outputs in the core case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be a bit better explained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think people will be familiar with how it works in numpy, and if not they can check it. We just borrowed their API
f6521eb
to
225f429
Compare
Updated docstrings @twiecki @jessegrabowski |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10/10 will use
Just a difference between providing a function or working on an existing graph.
Creating dummy inputs may not be intuitive to many users, so this helps with that. Also behaves more like NumPy.