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

Discrete convolution #1230

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Conversation

kohr-h
Copy link
Member

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

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
Copy link
Member Author

kohr-h commented Nov 22, 2017

@pep8speaks check this

@adler-j
Copy link
Member

adler-j commented Nov 22, 2017

Review ready?

@kohr-h
Copy link
Member Author

kohr-h commented Nov 23, 2017

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

@kohr-h
Copy link
Member Author

kohr-h commented Nov 23, 2017

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.

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.

Some comments except for the auto weighting stuff


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

def __init__(self, domain, kernel, range=None, axis=None, impl='fft',
Copy link
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?

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
Member

Choose a reason for hiding this comment

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

why this choice?

operator.
Default: ``'forward'``
cache_kernel_ft : bool, optional
If ``True``, store the Fourier transform of the kernel for
Copy link
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"?

[ -1., -3., -5.]]
)

Convolution in selected axes can be done either with broadcasting
Copy link
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.

kernel = ker_space.element(kernel)

if ran is None:
if str(impl).lower() == 'fft':
Copy link
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.

self.__fft_impl = None
elif self.impl == 'fft':
self.__real_impl = None
self.__fft_impl = 'pyfftw' if PYFFTW_AVAILABLE else 'numpy'
Copy link
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

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
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.

flags=['FFTW_ESTIMATE'],
threads=multiprocessing.cpu_count())
plan_x(x_prep, x_ft)
plan_x = None # can be gc'ed
Copy link
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
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?


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
Member

Choose a reason for hiding this comment

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

notes where?

@adler-j
Copy link
Member

adler-j commented Feb 3, 2018

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

@kohr-h
Copy link
Member Author

kohr-h commented Feb 3, 2018

@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.

@adler-j
Copy link
Member

adler-j commented Jun 28, 2018

Well hello! How are we doing today?

@kohr-h
Copy link
Member Author

kohr-h commented Jun 28, 2018

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
Contributor

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

@kohr-h
Copy link
Member Author

kohr-h commented Oct 22, 2018

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

^^ It does!

@pep8speaks
Copy link

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
Copy link
Member Author

kohr-h commented Mar 15, 2019

Hold your horses, I only rebased!

@adler-j
Copy link
Member

adler-j commented Mar 15, 2019

Reviewers right now:

horses

@kohr-h
Copy link
Member Author

kohr-h commented Mar 15, 2019

🏃‍♂️

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