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

Add asarray to ProductSpaceElement #1139

Closed
adler-j opened this issue Sep 20, 2017 · 5 comments
Closed

Add asarray to ProductSpaceElement #1139

adler-j opened this issue Sep 20, 2017 · 5 comments

Comments

@adler-j
Copy link
Member

adler-j commented Sep 20, 2017

Currently this works:

>>> np.asarray(vec)

but this does not

>>> vec.asarray()
AttributeError: 'ProductSpaceElement' object has no attribute 'asarray'
@kohr-h
Copy link
Member

kohr-h commented Sep 21, 2017

Currently this works:

np.asarray(vec)

for power spaces.

But yes, we should add it.

@mehrhardt
Copy link
Contributor

I think, this issue is related to the following bug:

import odl

space = odl.uniform_discr(
    min_pt=[-20, -20], max_pt=[20, 20], shape=[10, 10], dtype='float32')

geometry = odl.tomo.parallel_beam_geometry(space, num_angles=10)

G = 10 * odl.BroadcastOperator(
        *[odl.tomo.RayTransform(space, geometry[i::10], impl='astra_cpu')
          for i in range(10)])

Y = G.range
data = Y.one()

f = odl.solvers.KullbackLeibler(Y, data)

f(data)

File "/home/ehrhardt/repositories/git_myODL/odl/solvers/functional/default_functionals.py", line 1114, in _call
scipy.special.xlogy(self.prior, self.prior / x))

ValueError: object array method not producing an array

@adler-j
Copy link
Member Author

adler-j commented Sep 22, 2017

The workaround is clearly

f = odl.solvers.SeparableSum(*[odl.solvers.KullbackLeibler(Y, di) for di in data])

which is actually the "correct" way to do it I guess, but I agree, what you do should work.

@mehrhardt
Copy link
Contributor

mehrhardt commented Sep 22, 2017

Yes, your proposed solution works but then you end up with commands like

f = odl.solvers.SeparableSum(
        *[odl.solvers.KullbackLeibler(Y[i], data[i])
          .translated(-background[i]) for i in range(Y.size)])

and much of ODL's elegance is lost :(

Instead of the nice one:

f = odl.solvers.KullbackLeibler(Y, data).translated(-background)

@adler-j
Copy link
Member Author

adler-j commented Sep 22, 2017

Agree that it is far less elegant :/

adler-j added a commit to adler-j/odl that referenced this issue Sep 22, 2017
adler-j added a commit to adler-j/odl that referenced this issue Sep 24, 2017
@adler-j adler-j mentioned this issue Nov 14, 2017
20 tasks
adler-j added a commit to adler-j/odl that referenced this issue Nov 14, 2017
adler-j added a commit to adler-j/odl that referenced this issue Nov 14, 2017
adler-j added a commit to adler-j/odl that referenced this issue Dec 5, 2017
@adler-j adler-j closed this as completed in 12286b9 Dec 7, 2017
adler-j added a commit that referenced this issue Dec 7, 2017
ENH: Add ProductSpaceElement.asarray, closes #1139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants