conv — Compute one-dimensional linear convolution in MATLAB and RunMat.
conv(a, b) computes one-dimensional linear convolution. It accepts real or complex row and column vectors, scalars, logical values, and all eight fixed-width integer classes. Either single input selects single output; otherwise the output is double. Integer arithmetic crosses an explicit floating-point boundary before multiplication and accumulation.
Syntax
C = conv(A, B)
C = conv(A, B, shape)Inputs
A- Type
Any- Required
- Yes
- Description
- First input vector/scalar.
B- Type
Any- Required
- Yes
- Description
- Second input vector/scalar.
shape- Type
StringScalar- Required
- No
- Default
"full"- Description
- Output shape: full, same, or valid.
Returns
C- Type
NumericArray- Description
- Convolution result.
Errors
RunMat:conv:ShapeInvalid- When
- Third argument is missing or not one of full/same/valid.
- Message
conv: third argument must be the string 'full', 'same', or 'valid'
RunMat:conv:ArgCount- When
- More than three input arguments are provided.
- Message
conv: expected at most three input arguments
RunMat:conv:InvalidInput- When
- An input value is not numeric/logical scalar/vector/tensor compatible.
- Message
conv: unsupported input type
Shape and orientation
The optional shape selector is full (default), same, or valid. Full convolution is a row unless both inputs are columns. Same and valid follow the first input's orientation when it is unambiguous.
Inputs must be vectors or scalars, not genuine matrices or N-D arrays. Empty inputs normally return empty output. conv(u, [], 'valid') returns zeros with the length and orientation of u, preserving the selected floating class and explicit complexity.
Classes and execution
Logical values are promoted to double. An explicitly complex input produces complex output even if every resulting imaginary component is zero. Fixed-width integer inputs produce floating output and therefore use floating rounding and overflow, not integer saturation.
Same-owner, same-device real floating inputs may use the provider's conv1d hook. The result is accepted only with the expected class, shape, device, owner, and a distinct live allocation. Other supported resident inputs gather through their owners; an eligible floating result returns to its owner without changing class or complexity. Host complex integer values are supported, but the current provider ABI cannot encode typed complex-integer resident buffers.
Convolution ends a fusion plan. There are no user-facing GPU tuning knobs; the provider chooses its launch parameters.
Examples
Full convolution of two row vectors
a = [1 2 3];
b = [1 1 1];
c = conv(a, b)Expected output:
c = [1 3 6 5 3]Keep the first input's length
kernel = [1 0 -1];
signal = [3 4 5 6 7];
edge = conv(signal, kernel, 'same')Expected output:
edge = [4 2 2 2 -6]Valid convolution without padding
weights = [1 2 3 4];
window = [1 1 1];
valid = conv(weights, window, 'valid')Expected output:
valid = [6 9]Convolve column vectors
a = (1:3)';
b = [2; 0; -2];
c = conv(a, b)Expected output:
c =
2
4
4
-4
-6Multiply polynomial coefficients
p = [1 3 3 1]; % (x + 1)^3 coefficients
q = [1 -1]; % (x - 1)
coeff = conv(p, q)Expected output:
coeff = [1 2 0 -2 -1]Complex convolution
t = 0:3;
sig = exp(1i * pi/4 * t);
filt = [1 2i];
resp = conv(sig, filt)Expected output:
resp =
1.0000 0.7071 + 2.7071i -1.4142 + 2.4142i -2.7071 + 0.7071i -1.4142 - 1.4142iScale by a scalar
s = [4 5 6];
y = conv(2, s)Expected output:
y = [8 10 12]Use resident inputs
g = gpuArray([1 2 3 4]);
h = gpuArray([1 0 -1]);
edge = conv(g, h, 'same');
result = gather(edge)Using conv with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how conv changes the result.
Run a small conv example, explain the result, then change one input and compare the output.
FAQ
Does conv require row vectors?⌄
No. It accepts rows, columns, and scalars. Use conv2 for matrices; RunMat does not currently provide convn for general N-D convolution. Full orientation follows the both-columns rule, while same and valid normally follow the first input.
What happens when an input is empty?⌄
The result is normally empty. With conv(u, [], 'valid'), RunMat returns zeros with the length and orientation of u and the selected floating class and complexity.
How is same computed?⌄
It selects the central portion of the full convolution with the first input's length.
When should I use valid?⌄
Use it for results whose sliding window fits without zero padding.
Does conv support single precision?⌄
Either single numeric input selects single output; otherwise logical, integer, and double inputs produce double. Integer arithmetic uses floating rounding and overflow rather than saturation.
Will the result stay on the GPU?⌄
A same-owner, same-device real floating pair can use the native provider hook. Other supported resident values gather through their owners, and eligible floating results return to the first owner. Typed complex integer host inputs are supported; resident typed complex integer buffers are not encoded by the current provider ABI.
Can I convolve matrices or N-D arrays?⌄
conv accepts vectors and scalars. Use conv2 for matrices; general N-D convolution through convn is not currently available in RunMat.
How do I use an impulse kernel?⌄
Use a 1 followed by zeros; convolution with a discrete delta retains the input with corresponding padding.
What about circular convolution?⌄
For a circular convolution of length n, multiply fft(a, n) by fft(b, n) elementwise and apply ifft to the product. RunMat does not currently provide cconv.
Are there GPU tuning controls?⌄
No. The provider chooses kernel launch settings.
Related Math functions
Signal
blackman · butter · buttord · cheb2ord · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. Read exactly how conv is executed, line by line, in Rust.
- View the source for conv in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.