Skip to content

Discrete convolution - #1230

Open
kohr-h wants to merge 17 commits into
odlgroup:masterfrom
kohr-h:issue-209__convolution
Open

Discrete convolution#1230
kohr-h wants to merge 17 commits into
odlgroup:masterfrom
kohr-h:issue-209__convolution

Conversation

@kohr-h

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

Copy link
Copy Markdown
Member

Closes #209

Note: this does not include the discretized continuous convolution, only the fully discrete one. But the former can be expressed in terms of the latter.

TODOs:

  • Address review comments
  • Implement broadcasting of the left operand, e.g., convolution along axes (1, 2) of (1, 5, 5) shaped array with (2, 3, 3) stack of kernels

@kohr-h

kohr-h commented Nov 22, 2017

Copy link
Copy Markdown
Member Author

@pep8speaks check this

@adler-j

adler-j commented Nov 22, 2017

Copy link
Copy Markdown
Member

Review ready?

@kohr-h

kohr-h commented Nov 23, 2017

Copy link
Copy Markdown
Member Author

I'll get the auto-weighting thing out of the way, then yes.

@kohr-h

kohr-h commented Nov 23, 2017

Copy link
Copy Markdown
Member Author

I'll get the auto-weighting thing out of the way, then yes.

Actually I would prefer you have a look at #1177 first, since I don't want to add code here just to fix that missing part.

@adler-j adler-j left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some comments except for the auto weighting stuff

Comment thread odl/oplib/convolution.py

"""Fully discrete convolution with a given kernel."""

def __init__(self, domain, kernel, range=None, axis=None, impl='fft',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we also need some way to specify which fft backend to use?

Comment thread odl/oplib/convolution.py
Does not apply for ``impl='real'``. A sequence is applied per
axis, with padding values corresponding to ``axis`` entries
as provided.
Default: ``min(kernel.shape - 1, 64)``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why this choice?

Comment thread odl/oplib/convolution.py
operator.
Default: ``'forward'``
cache_kernel_ft : bool, optional
If ``True``, store the Fourier transform of the kernel for

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If true, is the non-ft kernel "discarded"?

Comment thread odl/oplib/convolution.py
[ -1., -3., -5.]]
)

Convolution in selected axes can be done either with broadcasting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awsome docktests here, good coverage without being excessive and easy to read.

Comment thread odl/oplib/convolution.py
kernel = ker_space.element(kernel)

if ran is None:
if str(impl).lower() == 'fft':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the first time you "check" the impl parameter, perhaps move the self.impl stuff to above this, would improve error messages.

Comment thread odl/oplib/convolution.py
self.__fft_impl = None
elif self.impl == 'fft':
self.__real_impl = None
self.__fft_impl = 'pyfftw' if PYFFTW_AVAILABLE else 'numpy'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should let users pick this somehow

Comment thread odl/oplib/convolution.py
ifft_x = ifft(x_ft, axes=self.axes, s=s)

# Unpad to get the "relevant" part
slc = [slice(l, n - r) for (l, r), n in zip(paddings, x_prep.shape)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very hard for me to validate this as is, it looks good but I'll have to go by the tests largely.

Comment thread odl/oplib/convolution.py
flags=['FFTW_ESTIMATE'],
threads=multiprocessing.cpu_count())
plan_x(x_prep, x_ft)
plan_x = None # can be gc'ed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't we want to keep the plan?

@@ -0,0 +1,57 @@
"""Example demonstrating the usage of the ``auto_weighting`` decorator."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This reads more like a test than an example, is it possible to make it easier on the eyes?

Comment thread odl/oplib/convolution.py

The adjoint convolution is a convolution with the adjoint
kernel, which is the (complex conjugate of the) original kernel,
(roughly) flipped in the convolution axes. See Notes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

notes where?

@kohr-h
kohr-h force-pushed the issue-209__convolution branch from 4584f6d to d7d1abe Compare January 29, 2018 10:47
@adler-j

adler-j commented Feb 3, 2018

Copy link
Copy Markdown
Member

@ozanoktem walked by my desk and asked how this is going 😄

@kohr-h

kohr-h commented Feb 3, 2018

Copy link
Copy Markdown
Member Author

@ozanoktem walked by my desk and asked how this is going 😄

😄 Well some stuff in the review that needs to be addressed. I also realized (by using the code) that a functional interface would be hugely useful for prototyping. Currently the functions convolve and correlate work by creating an operator and then calling it, but I think I'll do it the other way around, have the operator use the functional interface internally.

@kohr-h
kohr-h force-pushed the issue-209__convolution branch from d7d1abe to 0e758df Compare February 7, 2018 12:05
@kohr-h
kohr-h force-pushed the issue-209__convolution branch from 0e758df to c88ebff Compare June 10, 2018 11:40
@adler-j

adler-j commented Jun 28, 2018

Copy link
Copy Markdown
Member

Well hello! How are we doing today?

@kohr-h

kohr-h commented Jun 28, 2018

Copy link
Copy Markdown
Member Author

I did a rebase, plus some initial work on the more detailed interface for the implementation. WIP

@adler-j adler-j mentioned this pull request Sep 11, 2018
20 tasks
@mehrhardt

Copy link
Copy Markdown
Contributor

@kohr-h , maybe this motivates you: I am looking forward to have this in ODL :-)

@kohr-h

kohr-h commented Oct 22, 2018

Copy link
Copy Markdown
Member Author

@kohr-h , maybe this motivates you: I am looking forward to have this in ODL :-)

^^ It does!

@kohr-h
kohr-h force-pushed the issue-209__convolution branch from c88ebff to 7c89f67 Compare March 15, 2019 12:19
@pep8speaks

Copy link
Copy Markdown

Checking updated PR...

Line 847:51: W605 invalid escape sequence '\m'
Line 847:49: W605 invalid escape sequence ','
Line 847:46: W605 invalid escape sequence ','
Line 847:39: W605 invalid escape sequence ','
Line 847:26: W605 invalid escape sequence '\i'
Line 847:12: W605 invalid escape sequence '\s'

Line 1561:80: E501 line too long (88 > 79 characters)
Line 1461:80: E501 line too long (88 > 79 characters)

Line 349:55: W605 invalid escape sequence '\c'
Line 349:52: W605 invalid escape sequence ','
Line 349:44: W605 invalid escape sequence ','
Line 346:36: W605 invalid escape sequence '\c'
Line 346:27: W605 invalid escape sequence ','
Line 345:27: W605 invalid escape sequence '\c'
Line 344:24: W605 invalid escape sequence '\c'
Line 337:21: W605 invalid escape sequence '\c'

@kohr-h

kohr-h commented Mar 15, 2019

Copy link
Copy Markdown
Member Author

Hold your horses, I only rebased!

@adler-j

adler-j commented Mar 15, 2019

Copy link
Copy Markdown
Member

Reviewers right now:

horses

@kohr-h

kohr-h commented Mar 15, 2019

Copy link
Copy Markdown
Member Author

🏃‍♂️

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.

4 participants