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

sqrt — Compute principal square roots element-wise with MATLAB-compatible real and complex behavior.

Y = sqrt(X) computes the principal square root of each element in X, preserving single precision for documented single inputs and promoting negative real values to the corresponding complex floating class.

Syntax

Y = sqrt(X)

Inputs

NameTypeRequiredDefaultDescription
XAnyYes—Numeric, logical, char, or complex input.

Returns

NameTypeDescription
YNumericArrayElementwise square-root result.

Errors

IdentifierWhenMessage
RunMat:sqrt:InvalidInputInput cannot be interpreted as numeric, logical, char, or complex data.sqrt: invalid input
RunMat:sqrt:InternalInternal tensor construction or provider interaction failed.sqrt: internal error

How sqrt works

  • sqrt(X) applies the operation element-wise with MATLAB broadcasting rules.
  • Typed integer values are a RunMat-only extension. They enter double square-root arithmetic only when every authoritative value is exactly representable, so wide integers that would round are rejected.
  • RunMat currently converts logical values to doubles (true → 1.0, false → 0.0) before the square root is taken.
  • RunMat currently interprets character arrays as numeric code points and returns dense double tensors.
  • Negative real inputs yield purely imaginary outputs: sqrt([-1 4]) returns [0 + 1i, 2].
  • Complex inputs follow MATLAB's definition and stay on the principal branch of the complex square root, ensuring continuity across the negative real axis.
  • Zeros (including -0) remain zero in the output; infinities and NaNs propagate according to IEEE arithmetic.

Does RunMat run sqrt on the GPU?

RunMat Accelerate keeps tensors on the GPU when the active provider implements both unary_sqrt and reduce_min, allowing the runtime to prove that every element is non-negative before launching the kernel. When the dataset contains negative values (and therefore requires complex promotion) or when either hook is missing, RunMat gathers the data to the host, computes the MATLAB-compatible result, and updates residency metadata so subsequent operations see the correct value.

GPU memory and residency

You typically do not need to call gpuArray manually. The acceleration planner and fusion engine keep tensors on the GPU when profitable. If your data contains negative values, RunMat automatically gathers the tensor, produces the complex result on the host, and keeps residency metadata in sync. You can still use gpuArray/gather to mirror MathWorks MATLAB workflows.

Examples

Taking the square root of a positive scalar

y = sqrt(9)

Expected output:

y = 3

Square roots of a matrix

A = [1 4 9; 16 25 36];
R = sqrt(A)

Expected output:

R = [1 2 3; 4 5 6]

Square roots of negative inputs produce complex results

values = [-1 -4 9];
roots = sqrt(values)

Expected output:

roots = [0.0000 + 1.0000i, 0.0000 + 2.0000i, 3.0000 + 0.0000i]

Element-wise square root on GPU data

G = gpuArray([0 1; 4 9]);
out = sqrt(G);
result = gather(out)

Expected output:

result = [0 1; 2 3]

Square root of complex numbers

z = [3 + 4i, -1 + 2i];
w = sqrt(z)

Expected output:

w = [2 + 1i, 0.7862 + 1.2720i]

Square root of character codes

C = 'AB';
numericRoots = sqrt(C)

Expected output:

numericRoots = [8.0623 8.2462]

Using sqrt with coding agents

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

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

FAQ

Does sqrt return complex results for negative inputs?⌄

Yes. Negative real numbers produce purely imaginary outputs that match MATLAB. Mixed-sign tensors automatically promote to complex tensors.

How are logical inputs handled?⌄

RunMat currently converts logical arrays to doubles before applying the square root, so sqrt([true false]) returns [1 0].

Can the GPU handle negative inputs?⌄

Providers currently operate on real buffers. When negative values are present, RunMat gathers the tensor to the host to compute the correct complex result before continuing execution.

Does sqrt preserve the input shape?⌄

Yes. The output has the same shape as the input, with element-wise results.

How are NaNs and infinities treated?⌄

They follow IEEE rules: sqrt(NaN) is NaN, sqrt(Inf) is Inf, and sqrt(-Inf) is 0 + Inf·i.

What about complex inputs with small imaginary parts?⌄

The implementation uses the principal square root branch and rounds very small real or imaginary components to zero to avoid -0 artefacts.

Will future providers support complex tensors directly?⌄

Yes. The current design promotes to host computation when complex results are needed. Future providers may expose complex buffers, and the builtin will automatically benefit from those hooks.

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

  • View the source for sqrt 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 sqrt works
  • Does RunMat run sqrt on the GPU?
  • GPU memory and residency
  • Examples
  • Taking the square root of a positive scalar
  • Square roots of a matrix
  • Square roots of negative inputs produce complex results
  • Element-wise square root on GPU data
  • Square root of complex numbers
  • Square root of character codes
  • Using sqrt 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