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

sign — Return element-wise sign values for real and complex numeric inputs.

y = sign(x) returns the sign of each element of x. Real values map to -1, 0, or 1, while complex values are normalized as x ./ abs(x), matching MATLAB behavior.

Syntax

Y = sign(X)

Inputs

NameTypeRequiredDefaultDescription
XAnyYes—Real or complex numeric input.

Returns

NameTypeDescription
YNumericArrayElementwise sign result.

Errors

IdentifierWhenMessage
RunMat:sign:InvalidInputInput is not a supported numeric/logical/character value.sign: invalid input
RunMat:sign:InternalInternal gather/provider/tensor construction failed.sign: internal error

How sign works

  • Real scalars, vectors, matrices, and higher-dimensional tensors produce -1, 0, or 1 for each element.
  • Complex inputs return x ./ abs(x); zero-valued elements remain exactly 0 + 0i.
  • Logical inputs are promoted to doubles before applying the sign function.
  • Character arrays are treated as their numeric code points and return doubles of the same shape.
  • All eight integer input classes return the same integer class and shape, with each element mapped exactly to -1, 0, or 1 without overflow.
  • NaN inputs propagate (sign(NaN) is NaN), matching MATLAB semantics.
  • Inf and -Inf map to 1 and -1 respectively; complex numbers with infinite parts normalise accordingly.

Does RunMat run sign on the GPU?

Hook available: The sign is evaluated directly on the device with no host transfers, including complex normalization as x ./ abs(x).

Hook missing or unsupported dtype: RunMat gathers the tensor, applies the CPU logic (including complex handling), and continues execution transparently.

GPU memory and residency

sign keeps real and complex-interleaved GPU tensors resident when the active provider exposes unary_sign. Complex gpuArray inputs return complex-interleaved gpuArray outputs.

Examples

Determining the sign of a scalar

result = sign(-42)

Expected output:

result = -1

Applying sign to a vector of mixed values

v = [-3 -0.0 0 2 5];
s = sign(v)

Expected output:

s = [-1 0 0 1 1]

Normalising complex numbers to unit magnitude

z = [3+4i, -1+1i, 0+0i];
u = sign(z)

Expected output:

u = [0.6+0.8i, -0.7071+0.7071i, 0]

Using sign with character data

codes = sign('RunMat')

Expected output:

codes = [1 1 1 1 1 1]

Working with logical masks

mask = [false true false; true false true];
numeric = sign(mask)

Expected output:

numeric = [0 1 0; 1 0 1]

Executing sign on a GPU-resident tensor

G = randn(4096, 4096, 'gpuArray');
S = sign(G)

Handling infinities and NaNs

values = [Inf, -Inf, NaN, 0];
out = sign(values)

Expected output:

out = [1 -1 NaN 0]

Using sign with coding agents

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

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

FAQ

Does sign modify NaN values?⌄

No. NaN inputs remain NaN, matching IEEE behaviour and MATLAB semantics.

How does sign handle complex zeros?⌄

0 + 0i stays 0 + 0i. Other complex values are scaled to lie on the unit circle (x ./ abs(x)).

What happens for infinite complex components?⌄

If either component is infinite, RunMat returns a direction vector with unit magnitude (e.g., 1 + 0i or ±1/√2 ± 1/√2 i), mirroring MATLAB.

Can I call sign on string arrays?⌄

No. sign accepts numeric, logical, or character arrays. Use double(string) followed by sign if needed.

Does sign allocate a new array?⌄

Yes. The builtin returns a fresh array; downstream fusion may combine operations to reduce allocations.

Is GPU execution numerically identical to CPU?⌄

Results match within the provider's precision (single or double). NaN propagation and zero handling remain consistent between CPU and GPU paths.

Will sign participate in fusion?⌄

Yes. The fusion planner can fold sign into neighbouring elementwise kernels, keeping data on the GPU when possible.

How do I keep results on the GPU?⌄

Avoid gather unless host data is required. RunMat keeps the outputs of fused expressions device-resident when beneficial.

Related Math functions

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

  • View the source for sign 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 sign works
  • Does RunMat run sign on the GPU?
  • GPU memory and residency
  • Examples
  • Determining the sign of a scalar
  • Applying sign to a vector of mixed values
  • Normalising complex numbers to unit magnitude
  • Using sign with character data
  • Working with logical masks
  • Executing sign on a GPU-resident tensor
  • Handling infinities and NaNs
  • Using sign 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