RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • blackman
    • butter
    • buttord
    • cheb2ord
    • conv
    • 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

conv — Compute one-dimensional linear convolution in MATLAB and RunMat.

conv(a, b) computes the one-dimensional linear convolution of vectors a and b. MATLAB documents all eight integer classes, logical, single, double, and complex inputs; any single input selects single output and every other combination returns double.

Syntax

C = conv(A, B)
C = conv(A, B, shape)

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—First input vector/scalar.
BAnyYes—Second input vector/scalar.
shapeStringScalarNo"full"Output shape: "full", "same", or "valid".

Returns

NameTypeDescription
CNumericArrayConvolution result.

Errors

IdentifierWhenMessage
RunMat:conv:ShapeInvalidThird argument is missing or not one of full/same/valid.conv: third argument must be the string 'full', 'same', or 'valid'
RunMat:conv:ArgCountMore than three input arguments are provided.conv: expected at most three input arguments
RunMat:conv:InvalidInputAn input value is not numeric/logical scalar/vector/tensor compatible.conv: unsupported input type
RunMat:conv:ConversionInput conversion from logical/gpu tensor into host numeric domain fails.conv: input conversion failed
RunMat:conv:GatherFailedGPU input cannot be gathered for host fallback normalization.conv: failed to gather GPU input
RunMat:conv:BuildOutputOutput tensor allocation fails.conv: failed to build tensor
RunMat:conv:BuildComplexOutputOutput complex tensor allocation fails.conv: failed to build complex tensor

How conv works

  • Accepts real or complex row/column vectors from all documented numeric and logical classes. Integer inputs cross an explicit floating boundary and never produce integer output.
  • In the compatibility target, full output is a row unless both inputs are columns; 'same' and 'valid' retain the orientation of the first input.
  • Supports the three MATLAB shape modes: 'full' (default), 'same', and 'valid'.
  • Empty inputs normally return empty output. MATLAB's documented 'valid' exception for an empty second vector returns a zero vector with the first input's length, orientation, class, and complexity.
  • Logical inputs are promoted to double precision before the convolution.
  • Explicitly complex input produces complex output even when every resulting imaginary component is zero.
  • The public GPU-array surface is supported. A native hook is used only for same-owner, same-device real floating handles whose result has the required class; other supported resident values use class-preserving gather/restore fallback.

Examples

Computing the 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]

Keeping the same length as the first input

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 zero padding

weights = [1 2 3 4];
window = [1 1 1];
valid = conv(weights, window, 'valid')

Expected output:

valid = [6 9]

Convolving column vectors

a = (1:3)';
b = [2; 0; -2];
c = conv(a, b)

Expected output:

c =
     2
     4
     4
     -4
     -6

Multiplying polynomials using convolution

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-valued 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.4142i

Scaling a signal by a scalar

s = [4 5 6];
y = conv(2, s)

Expected output:

y = [8 10 12]

Using gpuArray inputs with automatic host fallback

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. conv accepts row vectors, column vectors, and scalars. Genuine matrices and higher-dimensional arrays are rejected; use conv2 or convn for those inputs. The result preserves the orientation of the first input when that orientation is unambiguous.

What happens when one of the inputs is empty?⌄

The result is normally empty. For conv(u, [], 'valid'), MATLAB documents a special case: RunMat returns zeros with the same length and orientation as u, while preserving the selected floating class and explicit complexity.

How is 'same' computed?⌄

'same' returns the central portion of the full convolution whose length matches the first input. Internally RunMat performs a full convolution and slices the appropriate window.

When should I use 'valid'?⌄

Use 'valid' when you only want results that do not rely on zero padding. This is common when sliding windows should fit completely inside the input without extending past the boundaries.

Does conv support single precision?⌄

When either numeric input is single, the output is single. Otherwise integer, logical, and double inputs produce double output. Integer multiplication and accumulation therefore have floating overflow/rounding semantics rather than integer saturation.

Will the result stay on the GPU?⌄

Same-owner, same-device real floating inputs remain resident when a provider's conv1d hook returns the required class. Other resident inputs gather through their own providers and eligible floating results return to the first owner. Typed complex integers work on the host, but the current provider ABI cannot encode typed complex-integer resident buffers.

Can I convolve matrices or higher-dimensional arrays?⌄

MATLAB requires vectors. RunMat rejects genuine matrix inputs; use conv2 or convn for multidimensional convolution.

How do I convolve with an impulse (delta) kernel?⌄

Include a 1 followed by zeros in your kernel. The input will be preserved (with appropriate padding) because convolution with a delta function is an identity operation.

What about circular convolution?⌄

Use cconv for circular convolution, or compute the FFT manually and multiply in the frequency domain before performing an inverse FFT.

Are there GPU-specific tuning knobs?⌄

Not yet. Current providers choose kernel launch parameters automatically; user-facing tuning switches will arrive alongside future backend updates.

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 · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · swapbytes · times · typecast · uint16 · uint32 · uint8

Trigonometry

acos · acosh · asin · asinh · atan · atan2 · 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

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · decomposition · eig · eigs · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref · vecnorm

Optim

coneprog · fminbnd · fminunc · fsolve · fzero · integral · linprog · lsqcurvefit · lsqnonlin · optimoptions · optimset · quad · secondordercone

Ops

cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose

Symbolic

digits · int · limit · piecewise · sym · syms · vpa

Fft

fft · fft2 · fftn · fftshift · ifft · ifft2 · ifftn · ifftshift

Interpolation

griddedInterpolant · interp1 · interp1q · interp2 · pchip · ppval · spline

Discrete

lcm · primes

Ode

ode15s · ode23 · ode45

Poly

polyder · polyfit · polyint · polyval · roots

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. 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 an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How conv works
  • Examples
  • Computing the full convolution of two row vectors
  • Keeping the same length as the first input
  • Valid convolution without zero padding
  • Convolving column vectors
  • Multiplying polynomials using convolution
  • Complex-valued convolution
  • Scaling a signal by a scalar
  • Using gpuArray inputs with automatic host fallback
  • Using conv with coding agents
  • FAQ
  • Related Math functions
  • Signal
  • Elementwise
  • Trigonometry
  • Reduction
  • Structure
  • Rounding
  • Factor
  • Solve
  • Optim
  • Ops
  • Symbolic
  • Fft
  • Interpolation
  • Discrete
  • Ode
  • Poly
  • Open-source implementation
  • About RunMat