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
Develop SearchsortedOp to wrap numpy's searchsorted function #4422
Conversation
@@ -147,6 +147,8 @@ def as_tensor_variable(x, name=None, ndim=None): | |||
If an `Apply` with more than one output is fetched. | |||
AsTensorError | |||
If `x` cannot be converted to a TensorType Variable. | |||
TypeError | |||
If `x` cannot be made into a Variable with `ndim` dimensions. |
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 get a value error in that case:
>>> import theano
>>>v=theano.tensor.matrix()
>>> theano.tensor.as_tensor_variable(v, ndim=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "theano/tensor/basic.py", line 182, in as_tensor_variable
% ndim, x.type
ValueError: ('TensorType could not be cast to have 1 dimensions', TensorType(float64, matrix))
In which case you get that error?
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.
In the params doc above, it says:
"""
ndim : None or integer
Return a Variable with this many dimensions. Raise TypeError if it's
not possible.
"""
I'm looking into it
This PR look pretty good. I just got a few questions/comments. thanks |
Thank you Fred. I am working on these comments right now. 2 questions:
|
side don't need to be a dinamic param. But it can be. You can wrap the The other option is to use params. Both change would allow to compile less version of this code. Otherwise, we This isn't a must do to merge this PR, but if we could compile just one
On Fri, Apr 22, 2016 at 3:35 PM, Christos Tsirigotis <
|
|
def searchsorted(x, v, side='left', sorter=None): | ||
"""Find indices where elements should be inserted to maintain order. | ||
|
||
Wraping of numpy.searchsorted. Find the indices into a sorted array |
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.
"Wrapping"
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.
oups.
Ok, I think I completed changes according to your comments and I also added |
General note: could you rebase your changes on top of the master branch, rather than merging with it? Merging brought in unrelated changes in this PR. |
@lamblin, what should be done on the failing test? |
Also, you mean that I should not merge with no-ff into the branch on which I will issue a pull request, right? You do not want e.g. |
For the failing test, I would suggest sampling fewer values, or spanning a larger range, to avoid almost-collisions in the values. |
@lamblin : So far I used to have a |
- Make sure perform outputs an numpy.ndarray. - Add C implementation of searchsorted - Fix PEP8 format - Fix props, make_node, perform of SearchsortedOp - Add searchsorted method (wrapper) on tensor variable - Fix c_code and grad in SearchsortedOp, fix tests - Update documentation
- Fix tests and grad - Add more documentation - Fix doc Raises ValueError in `as_tensor_variable` - Remove 'DebugMode' from tests
- Resolve :215 of test_extra_ops to int explicitly Reason: numpy.uint64 + int -> numpy.float64 for some reason (numpy/numpy@3509704)
I rebased on top of current |
You can rebase on top of the central/master when needed. But you don't need to always do it. Most of the time it isn't needed. But when a rebase/merge is needed, make a rebase as you did here. I'll check again this PR. |
__props__ = ("side", ) | ||
|
||
def __init__(self, side='left'): | ||
self.side = side |
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.
Add an assert that side is "left" or "right".
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.
Maybe I should let numpy's exception to be raised. I will change the c_code implementation to allow this.
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.
It is better to return the error when we build the graph when possible then during execution. So I would add the check here.
@@ -692,6 +692,9 @@ def cumsum(self, axis=None): | |||
def cumprod(self, axis=None): | |||
return theano.tensor.extra_ops.cumprod(self, axis) | |||
|
|||
def searchsorted(self, v, side='left', sorter=None): |
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.
This isn't used in your test. Just change one test to call it by this way. This make sure we won't break/remove that interface by mistake.
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 got very small/comments questions, so we should be able to merge this soon. thanks. |
- Add extra tests for searchsorted
@nouiz I pushed fixes |
@tsirif well done. 👍 |
Includes:
SearchsortedOp
, which includesperform
andc_code
searchsorted
function with numpy-equivalent callsearchsorted
with numpy-equivalent call to ndarray's methodSearchsortedOp
's functionalitiesCurrently,
side
string argument is being given to SearchSortedOp as an init argument. A param version is not implemented in this patch.