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

heaviside — Compute the element-wise Heaviside step function.

Y = heaviside(X) returns the Heaviside step function applied element by element. Negative real values map to 0, zero maps to 0.5, and positive values map to 1. Integer, logical, character, and GPU-resident numeric inputs are conservative RunMat extensions and require extension mode.

Syntax

Y = heaviside(X)

Inputs

NameTypeRequiredDefaultDescription
XAnyYes—Real numeric, logical, or character input.

Returns

NameTypeDescription
YNumericArrayElementwise Heaviside step result.

Errors

IdentifierWhenMessage
RunMat:heaviside:InvalidInputInput is not a supported real numeric/logical/character value.heaviside: invalid input
RunMat:heaviside:ProviderFailedProvider unary_heaviside dispatch fails with a non-unsupported error.heaviside: GPU provider unary_heaviside failed
RunMat:heaviside:InternalInternal gather/provider/tensor construction failed.heaviside: internal error

How heaviside works

  • Real scalars, vectors, matrices, and higher-dimensional tensors are evaluated elementwise.
  • Both 0.0 and -0.0 map to 0.5.
  • Inf maps to 1, -Inf maps to 0, and NaN remains NaN.
  • CPU, provider, WGPU, and fusion paths all use the same real scalar mapping.
  • In RunMat extension mode, logical inputs are promoted to doubles, so heaviside(false) returns 0.5 and heaviside(true) returns 1.
  • In RunMat extension mode, character arrays are treated as their numeric code points and return doubles of the same shape.
  • Symbolic scalar inputs return symbolic heaviside(...) expressions.
  • Complex and string inputs are rejected with a stable invalid-input identifier.

GPU memory and residency

heaviside keeps real GPU tensors resident when the active provider exposes unary_heaviside. If that hook is unavailable, RunMat gathers the tensor and evaluates the same scalar mapping on the host.

Examples

Evaluate the step at representative scalar values

values = heaviside([-2 0 3])

Expected output:

values = [0 0.5 1]

Gate a sinusoid using a unit step

t = -1:0.01:1;
x = sin(2*pi*t).*heaviside(t)

Preserve shape for matrix inputs

A = [-1 0; 2 NaN];
Y = heaviside(A)

Expected output:

Y = [0 0.5; 1 NaN]

Evaluating logical step inputs

mask = [false true];
y = heaviside(mask)

Expected output:

y = [0.5 1]

Preserve symbolic expressions

syms x;
y = heaviside(x)

Expected output:

y = heaviside(x)

Evaluating resident step inputs

G = gpuArray([-1 0 1]);
Y = heaviside(G);
host = gather(Y)

Using heaviside with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how heaviside changes the result.

Run a small heaviside example, explain the result, then change one input and compare the output.

FAQ

What value does RunMat use at zero?⌄

RunMat returns 0.5 for both positive and negative zero, matching MATLAB's convention for numeric Heaviside step values.

Does heaviside support complex numbers?⌄

No. RunMat implements the real-valued Heaviside step function. Complex inputs raise RunMat:heaviside:InvalidInput instead of silently choosing a branch.

Does heaviside support symbolic expressions?⌄

Yes. Symbolic scalar inputs remain symbolic and format as heaviside(expr).

Does heaviside preserve NaN values?⌄

Yes. NaN inputs remain NaN on CPU, GPU provider, and fused elementwise paths.

Will heaviside(gpuArray(...)) stay on the GPU?⌄

Yes when the active provider implements unary_heaviside. Providers without that hook fall back to host evaluation for correctness.

Can heaviside participate in fusion?⌄

Yes. The fusion planner emits an elementwise step expression with explicit zero and NaN handling.

Related Math functions

Elementwise

abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · 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

Signal

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

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 heaviside is executed, line by line, in Rust.

  • View the source for heaviside 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 heaviside works
  • GPU memory and residency
  • Examples
  • Evaluate the step at representative scalar values
  • Gate a sinusoid using a unit step
  • Preserve shape for matrix inputs
  • Evaluating logical step inputs
  • Preserve symbolic expressions
  • Evaluating resident step inputs
  • Using heaviside with coding agents
  • FAQ
  • Related Math functions
  • Elementwise
  • Trigonometry
  • Reduction
  • Structure
  • Signal
  • Rounding
  • Factor
  • Solve
  • Optim
  • Ops
  • Symbolic
  • Fft
  • Interpolation
  • Discrete
  • Ode
  • Poly
  • Open-source implementation
  • About RunMat