Conversation
| # this occurs is with comparison operators, e.g. | ||
| # "return x > 0" which simply gives 'True' for a | ||
| # non-empty tuple (in Python 2). We raise TypeError | ||
| # to trigger the call with x[0]. |
There was a problem hiding this comment.
It wasn't even tested for, but i.m.o. we shouldnt interfere with user code. If the user wants to do that test, they should.
Silently failing like this will only be problematic (and stops scalar output from beeing valid, as shown when @ozanoktem tried making a function like lambda x : 1.0).
There was a problem hiding this comment.
Then it would be good to have an FAQ entry that describes the issue with the 1D function lambda x: x > 0 returning all ones in Python 2.
There was a problem hiding this comment.
It doesnt
>>> X = odl.uniform_discr(-1, 1, 5)
>>> X.element(lambda x: x>0)
uniform_discr(-1.0, 1.0, 5).element([0.0, 0.0, 0.0, 1.0, 1.0])need an example in that case.
There was a problem hiding this comment.
Update:
It seems we return a 2d array for the 1d case (instead of a tuple as in the higher dimensional cases), this cheeses this problem since the above evaluates as expected.
There was a problem hiding this comment.
Not quite sure to be frank, this piece of code is a rather deep rabbit hole.
Apparently it is here.
There was a problem hiding this comment.
That looks indeed like the culprit. Maybe one needs to squeeze before returning. But if it works, better not touch it :-)
|
bump for review |
odl/discr/lp_discr.py
Outdated
| The input data to create an element from. It needs to be | ||
| understood by either the `sampling` operator of this | ||
| instance or by its ``dspace.element`` method. | ||
| The input data to create an element from. |
|
Done. Some stuff to think about, else good. |
vectorizedparameter.lambda x: 1.0) as input toDiscreteLp.element.DiscreteLp.elementthat disallowed specifically the above (but only in 1d).