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

rdivide — Divide arrays element-wise with MATLAB-compatible implicit expansion, including complex and GPU-backed inputs.

rdivide(A, B) (or A ./ B) divides corresponding elements of A and B using MATLAB-compatible implicit expansion, so scalars and singleton dimensions broadcast automatically.

Syntax

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

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—Dividend operand.
BAnyYes—Divisor operand.
likeStringScalarYes—Literal string "like".
prototypeLikePrototypeYes—Output class/device prototype.

Returns

NameTypeDescription
CNumericArrayElementwise quotient result.

Errors

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

How rdivide works

  • Supports real, complex, logical, and character inputs; logical and character data are promoted to double precision before division.
  • Implicit expansion works across any dimension, provided the non-singleton extents match. Size mismatches raise the standard MATLAB-compatible error.
  • Complex operands follow the analytic rule (a + ib) ./ (c + id) = ((ac + bd) + i(bc - ad)) / (c^2 + d^2), matching MATLAB's behaviour for infinities and NaNs.
  • Empty dimensions propagate naturally—if the broadcasted shape contains a zero extent, the result is empty with that shape.
  • Integer division preserves the integer class. The other operand must use the same integer class or be scalar double; quotients round to the nearest integer with half ties away from zero, overflow saturates, and 64-bit integer/scalar-double arithmetic uses the extended-precision compatibility path.
  • In RunMat compatibility mode, the RunMat-only optional 'like' prototype adopts the prototype's residency and complexity. MATLAB-compatible mode rejects this extension before dispatch; complex gpuArray prototypes are not yet supported.

Does RunMat run rdivide on the GPU?

When a gpuArray provider is active:

1. If both operands are gpuArrays with identical shapes, RunMat dispatches to the provider's elem_div hook so the entire computation stays on device memory, including for complex-interleaved resident handles. 2. If one operand is a real scalar and the other is a gpuArray, the runtime calls scalar_div (tensor ./ scalar) or scalar_rdiv (scalar ./ tensor) accordingly. 3. For shape-compatible implicit expansion, RunMat first expands gpuArray operands on device with repmat and then dispatches elem_div. 4. The fusion planner treats rdivide as a fusible elementwise node, so adjacent elementwise producers or consumers can execute inside a single WGSL kernel or provider-optimised pipeline, reducing host↔device transfers. 5. Unsupported shapes or operand kinds gather transparently to host memory, compute the result with full MATLAB semantics, and return a host tensor. When you request 'like' with a complex prototype, RunMat gathers to the host, performs the conversion, and returns a complex host value so downstream code still sees MATLAB-compatible types.

GPU memory and residency

RunMat's auto-offload planner keeps tensors on the GPU whenever fused expressions benefit from device execution. Explicit gpuArray / gather calls are still supported for MATLAB code that manages residency manually. When the active provider lacks the kernels needed for a particular call (for example, implicit expansion between gpuArrays of different shapes), RunMat gathers back to the host, computes the MATLAB-accurate result, and resumes execution seamlessly.

Examples

Divide two matrices element-wise

A = [8 12 18; 2 10 18];
B = [2 3 6; 2 5 9];
Q = rdivide(A, B)

Expected output:

Q =
    4     4     3
    1     2     2

Divide a matrix by a scalar

A = magic(3);
scaled = rdivide(A, 2)

Expected output:

scaled =
    4.5    0.5    3.5
    1.5    5.0    9.0
    8.0    6.5    2.0

Use implicit expansion between a column and row vector

col = (1:3)';
row = [10 20 30];
ratio = rdivide(col, row)

Expected output:

ratio =
    0.1    0.05    0.0333
    0.2    0.10    0.0667
    0.3    0.15    0.1000

Divide complex inputs element-wise

z1 = [1+2i, 3-4i];
z2 = [2-1i, -1+1i];
quot = rdivide(z1, z2)

Expected output:

quot =
    0.0 + 1.0i   -3.5 + 0.5i

Divide character codes by a numeric scalar

letters = 'ABC';
codes = rdivide(letters, 2)

Expected output:

codes = [32.5 33 33.5]

Execute rdivide directly on gpuArray inputs

G1 = gpuArray([10 20 30]);
G2 = gpuArray([2 5 10]);
deviceQuot = rdivide(G1, G2);
result = gather(deviceQuot)

Expected output:

deviceQuot =
  1x3 gpuArray
     5     4     3
result =
     5     4     3

Keep the result on the GPU with a 'like' prototype

proto = gpuArray.zeros(1, 1);
A = [1 2 3];
B = [2 4 6];
C = rdivide(A, B, 'like', proto);  % stays on the GPU for downstream work

Expected output:

C =
  1x3 gpuArray
      0.5    0.5    0.5

Using rdivide with coding agents

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

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

FAQ

Does rdivide support MATLAB implicit expansion?⌄

Yes. Any singleton dimensions expand automatically. If a dimension has incompatible non-singleton extents, rdivide raises the standard size-mismatch error.

What numeric type does rdivide return?⌄

Ordinary real inputs produce double and complex inputs produce complex double. Integer arithmetic preserves the integer class under MATLAB's same-class-or-scalar-double rules. Logical and character inputs are promoted to double.

How does rdivide handle division by zero?⌄

RunMat follows IEEE rules: finite ./ 0 produces signed infinity, while 0 ./ 0 yields NaN. Complex results follow MATLAB's analytic continuation rules.

Can I divide gpuArrays by host scalars?⌄

Yes. RunMat keeps the computation on the GPU when the scalar is numeric. For other host operand types, the runtime gathers the gpuArray and computes on the CPU.

Does rdivide preserve gpuArray residency after a fallback?⌄

When a fallback occurs (for example, implicit expansion that the provider does not implement), the current result remains on the host. Subsequent operations may move it back to the GPU when auto-offload decides it is profitable.

How can I force the result to stay on the GPU?⌄

Provide a 'like' prototype: rdivide(A, B, 'like', gpuArray.zeros(1, 1)) keeps the result on the device even if one of the inputs originated on the host. Complex prototypes are honoured on the host today; supply a real gpuArray prototype when you need the result to remain device-resident.

How are empty arrays handled?⌄

Empty dimensions propagate. If either operand has an extent of zero in the broadcasted shape, the result is empty with the broadcasted dimensions.

Are integer inputs supported?⌄

Yes. Integer quotients preserve the integer class, round to the nearest integer with half ties away from zero, and saturate. Inputs must use the same integer class or pair one integer operand with scalar double.

Can I mix complex and real operands?⌄

Absolutely. The result is complex, with broadcasting rules identical to MATLAB.

What about string arrays?⌄

String arrays are not numeric and therefore raise an error when passed to rdivide.

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

  • View the source for rdivide 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 rdivide works
  • Does RunMat run rdivide on the GPU?
  • GPU memory and residency
  • Examples
  • Divide two matrices element-wise
  • Divide a matrix by a scalar
  • Use implicit expansion between a column and row vector
  • Divide complex inputs element-wise
  • Divide character codes by a numeric scalar
  • Execute rdivide directly on gpuArray inputs
  • Keep the result on the GPU with a 'like' prototype
  • Using rdivide 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