Skip to content

Improvements to DiscreteLp.element#476

Merged
adler-j merged 3 commits intomasterfrom
non_vectorized_discretelp_vector
Jul 4, 2016
Merged

Improvements to DiscreteLp.element#476
adler-j merged 3 commits intomasterfrom
non_vectorized_discretelp_vector

Conversation

@adler-j
Copy link
Member

@adler-j adler-j commented Jul 1, 2016

  • Allow non-vectorized input by exposing the vectorized parameter.
  • Allow scalar functions (e.g. lambda x: 1.0) as input to DiscreteLp.element.
  • Also removed the old check in DiscreteLp.element that disallowed specifically the above (but only in 1d).

# 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].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the x > 0 issue unaffected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

@adler-j adler-j Jul 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return from where? The meshgrid?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure to be frank, this piece of code is a rather deep rabbit hole.

Apparently it is here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks indeed like the culprit. Maybe one needs to squeeze before returning. But if it works, better not touch it :-)

@adler-j
Copy link
Member Author

adler-j commented Jul 4, 2016

bump for review

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The

@kohr-h
Copy link
Member

kohr-h commented Jul 4, 2016

Done. Some stuff to think about, else good.

@adler-j adler-j merged commit 60e2af8 into master Jul 4, 2016
@adler-j adler-j deleted the non_vectorized_discretelp_vector branch July 4, 2016 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants