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

ldivide — Compute element-wise left division in MATLAB and RunMat.

ldivide(A, B) (or A .\ B) divides each element of B by the corresponding element of A. Broadcasting, complex handling, and output-shape behavior follow MATLAB semantics.

Syntax

C = ldivide(A, B)
C = ldivide(A, B, "like", prototype)

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—Left divisor operand.
BAnyYes—Right dividend operand.
likeStringScalarYes—Literal string "like".
prototypeLikePrototypeYes—Output class/device prototype.

Returns

NameTypeDescription
CNumericArrayElementwise left quotient result.

Errors

IdentifierWhenMessage
RunMat:ldivide:InvalidArgumentOptional arguments are malformed or unsupported.ldivide: invalid argument
RunMat:ldivide:InvalidInputOperands or prototypes cannot be converted into supported numeric/logical forms.ldivide: invalid input
RunMat:ldivide:SizeMismatchOperands are not broadcast-compatible.ldivide: array sizes are not compatible for broadcasting
RunMat:ldivide:InternalProvider interaction, gather/upload, or internal tensor construction failed.ldivide: internal error

How ldivide works

  • Supports real, complex, logical, and character inputs; logical and character data are promoted to double precision before division.
  • Implicit expansion follows MATLAB rules: singleton dimensions expand automatically, while mismatched non-singleton extents raise MATLAB-compatible size errors.
  • Complex operands use the analytic continuation B ./ A, propagating NaN and Inf exactly as MATLAB does.
  • Empty shapes propagate cleanly—if the broadcasted output has a zero dimension, the result is empty with the expected shape.
  • All eight integer classes are supported. Integer operands must share a class, or the other operand must be scalar double; the result preserves the integer class, rounds to nearest with half ties away from zero, and saturates on overflow. Complex integer arithmetic is rejected.
  • The optional 'like' prototype makes the result adopt the residency (host or GPU) and numeric flavour of the prototype. This form is a RunMat extension and is rejected while strict compatibility mode disables extensions.

Does RunMat run ldivide on the GPU?

RunMat first validates integer admission and operand metadata, then uses the exact common owner’s elem_div(B, A) path for compatible resident floating-point or same-class integer pairs, including provider-supported implicit expansion. A resident tensor with a host double scalar uses scalar_div or scalar_rdiv for floating data; an exactly representable integral scalar paired with resident integer data is uploaded in that integer class and evaluated through elem_div. Every provider result is checked for shape, owner, device, storage, class, precision, and non-aliasing. Unsupported or mixed cases gather automatically, execute on the host, and restore the class-preserving result to the original provider; explicit residency must be preserved. The fusion planner can still fuse supported floating elementwise expressions.

GPU memory and residency

You usually do not need to call gpuArray manually. RunMat’s auto-offload planner keeps tensors on the GPU whenever provider kernels cover the operation. When a provider fallback happens, the runtime gathers automatically, computes the class-preserving answer, and restores it to the original provider. Explicit gpuArray inputs must remain resident; the optional 'like' form is a separately gated RunMat extension.

Examples

Left-dividing a vector by a scalar

A = 2;
B = [4 6 8];
Q = ldivide(A, B)

Expected output:

Q = [2 3 4]

Broadcasting between column divisors and row numerators

A = (1:3)';         % column of divisors
B = [10 20 40];     % row of numerators
M = ldivide(A, B);  % implicit expansion

Expected output:

M =
   10.0000   20.0000   40.0000
    5.0000   10.0000   20.0000
    3.3333    6.6667   13.3333

Element-wise left division of complex values

A = [1+2i, 3-4i];
B = [2-1i, -1+1i];
Z = ldivide(A, B)

Expected output:

Z =
   0.0000 - 1.0000i   -0.2800 - 0.0400i

Dividing character codes by a scalar

A = 'ABC';
B = 2;
codes = ldivide(A, B)

Expected output:

codes = [0.0308 0.0303 0.0301]

Computing reciprocals with ldivide

A = [1 2 4 8];
B = 1;
R = ldivide(A, B);   % equivalent to 1 ./ A

Expected output:

R = [1 0.5 0.25 0.125]

Keeping results on the GPU with 'like'

proto = gpuArray.zeros(1, 1);
A = gpuArray([2 4 8 16]);
B = gpuArray([4 8 16 32]);
deviceResult = ldivide(A, B, 'like', proto);
hostCheck = gather(deviceResult)

Expected output:

deviceResult =
  1x4 gpuArray
    2  2  2  2
hostCheck = [2 2 2 2]

Using ldivide with coding agents

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

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

FAQ

Does ldivide support MATLAB implicit expansion?⌄

Yes. Singleton dimensions expand automatically; otherwise incompatible shapes raise MATLAB-style errors.

What numeric type does ldivide return?⌄

Floating inputs preserve their supported floating flavour, mixed or complex inputs return the corresponding complex result, and logical and character inputs promote before division. Typed-integer division preserves the integer class under the documented same-class/scalar-double rules.

How does ldivide handle division by zero?⌄

finite ./ 0 yields signed infinities, and 0 ./ 0 becomes NaN, matching MATLAB and IEEE-754 behaviour.

Can I divide gpuArrays by host scalars?⌄

Yes. Numeric scalars stay on device through scalar_div/scalar_rdiv. Non-numeric host scalars trigger a gather-then-divide fallback.

Does ldivide preserve gpuArray residency after a fallback?⌄

Yes. Unsupported provider cases gather automatically, compute with MATLAB-compatible semantics, and restore the class-preserving result to the original provider. Explicit gpuArray inputs must produce resident output or the call errors; automatic residency may return to host only when safe class preservation on the provider is unavailable.

How do I keep the result on the GPU?⌄

Provide a real gpuArray prototype: ldivide(A, B, 'like', gpuArray.zeros(1,1)). The runtime re-uploads the host result when necessary.

How are empty arrays handled?⌄

Empty operands propagate cleanly—the output shape is the broadcasted shape, and the data vector is empty.

Are integers and logicals supported?⌄

Yes. Logical inputs promote before division. Typed integers preserve their integer class, use nearest rounding with half ties away from zero, and saturate; incompatible integer classes and complex integer arithmetic are rejected.

Can I mix real and complex operands?⌄

Absolutely. Mixed cases return complex doubles with full MATLAB semantics.

Related Math functions

Elementwise

abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · 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 ldivide is executed, line by line, in Rust.

  • View the source for ldivide 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 ldivide works
  • Does RunMat run ldivide on the GPU?
  • GPU memory and residency
  • Examples
  • Left-dividing a vector by a scalar
  • Broadcasting between column divisors and row numerators
  • Element-wise left division of complex values
  • Dividing character codes by a scalar
  • Computing reciprocals with ldivide
  • Keeping results on the GPU with 'like'
  • Using ldivide 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