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

times — Multiply arrays element-wise (A .* B) with MATLAB-compatible implicit expansion and complex support.

times(A, B) (or A .* B) multiplies corresponding elements of A and B using MATLAB-compatible implicit expansion, so scalars and singleton dimensions broadcast automatically.

Syntax

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

Inputs

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

Returns

NameTypeDescription
CNumericArrayElementwise product result.

Errors

IdentifierWhenMessage
RunMat:times:InvalidArgumentOptional arguments are malformed or unsupported.times: invalid argument
RunMat:times:InvalidInputOperands or prototypes cannot be converted into supported numeric/logical forms.times: invalid input
RunMat:times:SizeMismatchOperands are not broadcast-compatible.times: array sizes are not compatible for broadcasting
RunMat:times:InternalProvider interaction, gather/upload, or internal tensor construction failed.times: internal error
RunMat:times:SparseSizeMismatchSparse operands cannot be implicitly expanded to a compatible result shape.times: sparse operand sizes are not compatible
RunMat:times:SparseUnsupportedOperandSparse arithmetic is requested with an unsupported operand class or residency.times: unsupported sparse arithmetic operand
RunMat:times:SparseDensifyTooLargeA sparse operation would have to materialize a dense or fully populated sparse result beyond the runtime limit.times: sparse arithmetic result is too large to materialize
RunMat:times:SparseInternalSparse arithmetic storage construction or conversion failed unexpectedly.times: sparse arithmetic internal error

How times works

  • Supports real, complex, logical, and character inputs; logical and character data are promoted to double precision before multiplication.
  • 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(ad + bc).
  • Empty dimensions propagate naturally—if either operand has a zero-sized dimension after broadcasting, the result is empty with the broadcasted shape.
  • Integer multiplication preserves the integer class. The other operand must use the same integer class or be scalar double; fractional results round, overflow saturates, and 64-bit integer/scalar-double arithmetic uses the extended-precision compatibility path.
  • Sparse real matrices interoperate with sparse, dense, logical, character, scalar, and complex operands. Sparse-sparse, sparse-scalar, and same-shape dense products preserve real sparse storage; complex products return full complex storage because RunMat does not yet have a complex sparse storage class.
  • In RunMat compatibility mode, the RunMat-only optional 'like' prototype makes the output adopt the residency and complexity characteristics of the prototype. MATLAB-compatible mode rejects this extension before dispatch.

Does RunMat run times 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_mul hook, including for complex-interleaved resident handles. 2. If one operand is a real scalar and the other is a gpuArray, the runtime calls scalar_mul to keep the result on the device. 3. For shape-compatible implicit expansion, RunMat first expands gpuArray operands on device with repmat and then dispatches elem_mul. 4. The fusion planner treats times as a fusible elementwise node, so adjacent elementwise producers/consumers can execute inside a single WGSL kernel or provider-optimised pipeline, avoiding spurious 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. The documentation callouts below flag this fallback behaviour explicitly.

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

Multiply two matrices element-wise

A = [1 2 3; 4 5 6];
B = [7 8 9; 1 2 3];
P = times(A, B)

Expected output:

P =
    7   16   27
    4   10   18

Scale a matrix by a scalar

A = magic(3);
scaled = times(A, 0.5)

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];
m = times(col, row)

Expected output:

m =
    10    20    30
    20    40    60
    30    60    90

Multiply complex inputs element-wise

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

Expected output:

prod =
    4 + 3i   1 + 7i

Multiply character codes by a numeric scalar

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

Expected output:

codes = [130 132 134]

Execute times directly on gpuArray inputs

G1 = gpuArray([1 2 3]);
G2 = gpuArray([4 5 6]);
deviceProd = times(G1, G2);
result = gather(deviceProd)

Expected output:

deviceProd =
  1x3 gpuArray
     4     10     18
result =
     4    10    18

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

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

Expected output:

C =
  1x3 gpuArray
      4     10     18

Using times with coding agents

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

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

FAQ

Does times support MATLAB implicit expansion?⌄

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

What numeric type does times 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.

Can I multiply gpuArrays and 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 times 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: times(A, B, 'like', gpuArray.zeros(1, 1)) keeps the result on the device even if one of the inputs originated on the host.

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 multiplication preserves the integer class, rounds fractional results, and saturates overflow. 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.

Does times preserve sparse matrices?⌄

Sparse-sparse, sparse-scalar, and same-shape dense element-wise products preserve real sparse storage. Products with complex operands return full complex storage until RunMat has a complex sparse representation.

What about string arrays?⌄

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

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

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