gputools
gputools copied to clipboard
Convolve without preserving the size ("valid" convolution)
Hi,
Thanks for building this great package.
Convolve seems to produce same output size as input size commonly referred as "same" convolution. Is there a way to perform convolution "valid" convolution where output size is shrinked?
hi,
convolve does not support "valid" convolution out of the box, but it should be easy to define it yourself:
import numpy as np
from gputools.convolve import convolve
def convolve_valid(x,h, **kwargs):
y = convolve(x, h, **kwargs)
# extract valid region
valid_slices = tuple(slice(s//2, -(s-s//2) if s>1 else None) for s in h.shape)
return y[valid_slices]
x = np.random.rand(128,128)
h = np.random.rand(3,11)
res = convolve_validx,h)
Hope that helps!