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: fix in-out aliasing issue in OperatorSum, closes #1181 #1225

Merged
merged 3 commits into from
Nov 11, 2017

Conversation

kohr-h
Copy link
Member

@kohr-h kohr-h commented Nov 10, 2017

No description provided.

@kohr-h
Copy link
Member Author

kohr-h commented Nov 10, 2017

I guess I should add a test.

@kohr-h kohr-h force-pushed the issue-1181__op_aliasing_bug branch from 5951a30 to 876b8c2 Compare November 11, 2017 01:16
@kohr-h
Copy link
Member Author

kohr-h commented Nov 11, 2017

Operator tests adapted for that, and they surfaced the same issue with OperatorPointwiseProduct.

@kohr-h
Copy link
Member Author

kohr-h commented Nov 11, 2017

Numpy <1.13 apparently has an issue with np.dot(matrix, x, out=x). Workaround in place.

@kohr-h kohr-h force-pushed the issue-1181__op_aliasing_bug branch from 876b8c2 to 7cd1c4b Compare November 11, 2017 02:11
Copy link
Member

@adler-j adler-j left a comment

Choose a reason for hiding this comment

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

Minor stuff you can fix, then merge

self.matrix.dot(x, out=out_arr)
if (parse_version(np.__version__) < parse_version('1.13.0') and
x is out):
# Workaround for bug in Numpy < 1.13 with aliased in and
Copy link
Member

Choose a reason for hiding this comment

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

wait, do we even allow np>=1.13 atm? or is this future profing?

Copy link
Member Author

@kohr-h kohr-h Nov 11, 2017

Choose a reason for hiding this comment

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

No, not currently. But since the last conda update (an ASTRA update) it has become notoriously hard to install a lower version, also since they forgot to add Numpy 1.12 with nomkl.

So it's easier than ever to install the wrong version 1.13 of Numpy. That will break some of the tests, but at least there are no extra bugs. And the aliased version gives a speedup that would be nice to have when not broken.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, how much is left until we have tensors in and can handle this "natively" so to say?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's one bug with the Huber functional that breaks the large-scale test, and it's not on master. Need to check. Then there is the breakage of the tensorflow contrib code which I imagine is not unimportant :-). You know what to change there I guess, I only did the obvious stuff (size -> shape roughly). Then, I'll check again the examples. Other than that, it's ready I think.

Copy link
Member

Choose a reason for hiding this comment

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

Well getting this fixed before the course would be great so we have better TF interop for then, I suggest we try to rush that and get it somewhat battle-tested before the 12:th next month

with writable_array(out) as out_arr:
self.matrix.dot(x, out=out_arr)
if (parse_version(np.__version__) < parse_version('1.13.0') and
x is out):
Copy link
Member

Choose a reason for hiding this comment

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

This does not catch all cases, e.g. we could have to containers that are possibly alliased, overall this is a rather hard problem to solve, see e.g.

https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.shares_memory.html
https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.may_share_memory.html

but I guess this solves some of the cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

True, this isn't a perfect fix, but for our current classes it should handle everything. In particular since we don't support MatrixOperator on product spaces (where things can become hairy).

assert all_almost_equal(out, expected)
def test_operator_call(dom_eq_ran):
"""Check operator evaluation against NumPy reference."""
if dom_eq_ran:
Copy link
Member

Choose a reason for hiding this comment

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

prefer adding a "shape" fixture?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would make it quite complicated, e.g., when testing op1 + op2 shapes must be the same, when testing op1 * op2 you have another requirement, etc. This fixture is really only intended to generate a test case where aliased input and output are checked.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add a comment in the test.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@kohr-h
Copy link
Member Author

kohr-h commented Nov 11, 2017

I'll rebase, and unless the concerns with the fixture are significant I'll merge the fix.

@kohr-h kohr-h force-pushed the issue-1181__op_aliasing_bug branch from 7cd1c4b to 9b5e1b9 Compare November 11, 2017 14:48
@kohr-h kohr-h merged commit 72b7fc8 into odlgroup:master Nov 11, 2017
@kohr-h kohr-h deleted the issue-1181__op_aliasing_bug branch November 11, 2017 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants