Skip to content
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

BUG: Correct OperatorRightVectorMult.derivative, closes #1330. #1331

Merged
merged 5 commits into from
Apr 27, 2018

Conversation

sbanert
Copy link
Contributor

@sbanert sbanert commented Apr 26, 2018

No description provided.

@@ -2165,7 +2165,7 @@ def derivative(self, x):
if self.is_linear:
return self
else:
return self.operator.derivative(x) * self.vector
return self.operator.derivative(self.vector * x) * self.vector
Copy link
Member

Choose a reason for hiding this comment

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

Apparently I wasn't fast enough :-)
Please first check if we have to multiply. This is a hot code path and we need to do our best to reduce wasted effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I improved this by not checking for linearity, but if the derivative coincides with the operator itself. I checked that it works for odl.RealPart, and all the tests pass.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, this was my first thought as well, but I discarded it because of the potential extra cost to generate the derivative twice.
We need to be a bit careful with this since derivative(x) may actually do some potentially expensive computation, and then the benefit from doing the check for some operators like RealPart may not outweigh the cost of having to generate the derivative twice for other nonlinear ones.
Opinions, @aringh, @adler-j, @olivierverdier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussion with @olivierverdier: What about setting the linear flag for the RealPart to True?

Copy link
Member

Choose a reason for hiding this comment

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

That would also be okay for me, it's the more practical approach anyway. In that case, please revert the changes I made in ce89155 as well, and the part of the documentation mentioning this trade-off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope, I got everything. Since the linear flag was used for other stuff in the RealPart and ImagPart operators, I introduced some additional flag for them.

Copy link
Member

@kohr-h kohr-h left a comment

Choose a reason for hiding this comment

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

One nitpick, and please also check the text in the docs of RealPart and friends, whether it also needs some slight reframing. Probably you already checked that though.

@@ -238,6 +238,6 @@ but

Therefore, ODL takes the following pragmatic approach for complex <-> real operators:

- Derivatives are taken in the real sense, but linearity is always set to `False` since this refers to linearity in the sense of the involved vector spaces.
- Even for formally non-linear derivative operators, an adjoint can be defined, which will also not be linear.
- Derivatives are taken in the real sense. Linearity is set to `True` for an operator :math:`A: X \to Y` if :math:`A'(x) = A` for all :math:`x\in X`. This property can be used to optimize calculations with derivatives, since the derivative operator does not depend on the point. Linearity in the sense of complex vector spaces is currently not reflected by any flag in ODL.
Copy link
Member

Choose a reason for hiding this comment

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

Please put the sentences on one line each, RST will still output it as a paragraph. The reason is that it works better with Git's line based content tracking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@sbanert
Copy link
Contributor Author

sbanert commented Apr 26, 2018

I have not found any false statements in RealPart and ImagPart. However, I was missing an operator like ComplexConj, which would also belong to the category mentioned here.

@kohr-h
Copy link
Member

kohr-h commented Apr 27, 2018

Yes, ComplexConj would be a good candidate for a follow-up PR 😉

I'll merge this in the meanwhile, LGTM

@kohr-h kohr-h merged commit eff7129 into odlgroup:master Apr 27, 2018
@sbanert sbanert deleted the issue_1330 branch June 12, 2018 11:30
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