-
Notifications
You must be signed in to change notification settings - Fork 105
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
Issue 49 matrix representation of linear operator #73
Issue 49 matrix representation of linear operator #73
Conversation
There seems to be two errors in this build, both being more or less them same. However I'm not sure of what the problem is... where is the test supposed to be put? I thought that the structure of the tests was supposed to be the same as for the implementation, and thus I put it in test/discr/utility_test.py. Can either @adler-j or @kohr-h have a look at this, whenever you have time? |
It obviously doesn't like the two identical file names |
I renamed it to operator_utilities. Looks ok? |
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with ODL. If not, see <http://www.gnu.org/licenses/>. | ||
|
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.
A short module header goes here. Basically a few rows about what this module contains.
Almost done, still need |
Maybe you're right. I suggested |
See the comment in #73 (which actually concerns something else but where it was found).
I moved it to The code works for def my_matrix_representation(op):
assert op.is_linear
assert (isinstance(op.domain, odl.space.base_ntuples.FnBase) or
isinstance(op.domain, odl.set.pspace.ProductSpace))
assert (isinstance(op.range, odl.space.base_ntuples.FnBase) or
isinstance(op.range, odl.set.pspace.ProductSpace))
# Get the size of the range, and handle ProductSpace
n = []
op_ran = op.range
if isinstance(op_ran, odl.set.pspace.ProductSpace):
num_ran = op_ran.size
for i in range(num_ran):
n.append(op_ran[i].size)
else:
num_ran = 1
n.appned(op_ran.size)
# Get the size of the domain, and handle ProductSpace
m = []
op_dom = op.domain
if isinstance(op_dom, odl.set.pspace.ProductSpace):
num_dom = op_dom.size
for i in range(num_dom):
m.append(op_dom[i].size)
else:
num_dom = 1
m.appned(op_dom.size)
# Generate the matrix
matrix = np.zeros([np.sum(n), np.sum(m)])
tmp = op_ran.element()
v = op_dom.element()
index = 0
for i in range(num_dom):
for j in range(m[i]):
v.set_zero()
v[i][j] = 1.0
tmp_two = op(v, out=tmp)
tmp_three = []
for k in range(num_ran):
tmp_three = np.concatenate((tmp_three, tmp_two[k].asarray()))
matrix[:, index] = tmp_three
index += 1
return matrix |
Quite sure that code fails for Anyway I also see the purpose of having this for |
2dbed5e
to
316b2f2
Compare
See the comment in #73 (which actually concerns something else but where it was found).
I have rebased this, in order to be able to use |
'representation of it.') | ||
return | ||
|
||
if not (isinstance(op.domain, FnBase) or |
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 can be one instance check: isinstance(op.domain, (FnBase, ProductSpace))
This version of the matrix representation function can handle operators on product spaces, both in range and domain. See #49
Done to not break the build in python 2, see http://odl.readthedocs.org/guide/faq.html#errors-related-to-python-2-3. Issues #49 and #73.
The rebase was needed since commit e98cdc0 changed the interface of it. Moreover, explicit spaces where removed from the call, since this is easily inferred from the matrix dimensions.
9dfd436
to
872df47
Compare
|
Its quite obnoxious, is it not? Maybe disabling the comment function (no idea why it was enabled suddenly). |
Yes, if it gives one comment per push, that's a bit too much. In principle, it can be handy, so we can keep it, I guess. Or maybe codacy is an alternative. |
Fixed the most un-needed warnings. Now it's actually quite useful, if only it wouldn't write actual messages. |
if not (isinstance(op.domain, FnBase) or | ||
(isinstance(op.domain, ProductSpace) and | ||
all(isinstance(spc, FnBase) for spc in op.domain))): | ||
raise TypeError('Operator domain {} is not FnBase, nor ProductSpace' |
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.
Almost good, just one blank missing - it will glue like "[...] nor ProductSpacewith only [...]"
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.
Done!
Comment on an old diff? I don't see any more |
This is on the somewhat parallel landscape messages :) |
Got it! ;-) |
Ok to merge? |
Looks good, let's do it! |
Wait, let me fix two small things. |
Got a nice speedup by 3.3 with these optimizations. Basically trashed the |
Added the function for matrix representation of a linear operator; see issue #49