question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Numpy convolve mode 'valid'

See original GitHub issue

Feature request

I’ve been working with model simulations and there’s the need for np.convolve(a, k, mode='valid').

I wish to have support for this for use with @jit/@njit decorators.

I have this example implementation from one of the discussions about using Numba for such situation, but I’d rather not have to resort to it in projects which require valid mode.

def numba_convolve_mode_valid_as_loop(arr, kernel):
        m = arr.size
        n = kernel.size
        out_size = m - n + 1
        out = np.empty(out_size, dtype=np.complex128)
        kernel = np.flip(kernel)  # wrong results otherwise
        for i in range(out_size):
            out[i] = np.dot(arr[i:i + n], kernel)
        return out

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jeertmanscommented, Nov 6, 2021

Hello @danilo-bc, are you still working on this ? Otherwise, I would gladly give it a try!

1reaction
gmarkallcommented, Sep 17, 2021

Labelling as “good second issue” as most of the parts needed for the implementation are already present, but need connecting together. Se e.g. https://github.com/numba/numba/blob/master/numba/np/arraymath.py#L4230-L4251.

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.convolve — NumPy v1.24 Manual
Mode 'valid' returns output of length max(M, N) - min(M, N) + 1 . The convolution product is only given for points where...
Read more >
Understanding NumPy's Convolve - python - Stack Overflow
An array in numpy is a signal. The convolution of two signals is defined as the integral of the first signal, reversed, sweeping...
Read more >
np.convolve: How to Use Numpy convolve() Method
The np.convolve() is a built-in numpy library method that returns discrete, linear convolution of two one-dimensional vectors. The numpy ...
Read more >
What is the numpy.convolve() method in Python? - Educative.io
Overview. In Python, we use the numpy.convolve() method to calculate the combination of two one-dimensional vectors discretely and linearly.
Read more >
Numpy Convolve For Different Modes in Python
In this article, we will discuss the Numpy convolve function in Python. The convolution operator is a mathematical operator primarily used ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found