RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact
  • License
  • Privacy

Learn

  • Docs
  • Blog
  • Benchmarks
  • RunMat vs MATLAB Online

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.

/
See all docs
Builtin Reference
    • cross
    • ctranspose
    • dot
    • mldivide
    • mpower
    • mrdivide
    • mtimes
    • pagemtimes
    • pagetranspose
    • trace
    • transpose

cross — Compute vector cross products in MATLAB and RunMat.

cross(A, B) computes vector cross products for matching 3-element vectors. MATLAB documents single and double data operands; RunMat mode additionally admits logical and all eight real or complex integer classes through explicit compatibility gates. Output is single when either data operand is single and double otherwise.

Syntax

C = cross(A, B)
C = cross(A, B, dim)

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—Left operand.
BAnyYes—Right operand.
dimNumericScalarYes—Dimension with extent 3.

Returns

NameTypeDescription
CNumericArrayCross product result.

Errors

IdentifierWhenMessage
RunMat:cross:InvalidArgumentArgument count or dimension argument is invalid.cross: invalid argument
RunMat:cross:InvalidInputInputs are unsupported or incompatible for cross product.cross: A and B must be the same size.
RunMat:cross:InternalRuntime cannot materialize cross outputs.cross: internal runtime failure

How cross works

  • Inputs A and B must be the same size.
  • With no dimension argument, cross uses the first dimension whose extent is exactly 3.
  • cross(A, B, dim) requires dim to be a valid array dimension and size(A, dim) == 3.
  • The output has the same shape as the inputs because each input 3-vector produces one output 3-vector.
  • Typed-integer and logical data operands are RunMat-only extensions, independently gated for A and B, and cross a floating evaluation boundary. Output is single when either data operand is single and double otherwise; arithmetic has floating rounding/overflow behavior rather than integer saturation.
  • An ordinary positive integer-valued double dim is documented. Because the public cross reference does not list typed or logical classes for dim, exact all-eight-class typed-integer dimensions and logical dimensions are conservatively classified as separately gated RunMat extensions; resident typed dimensions gather through their owner for exact validation.
  • A native provider hook is used only for same-owner, same-device real floating handles whose result has the required class. Other supported resident values gather independently and eligible real or complex floating results return to the first owner.

Does RunMat run cross on the GPU?

The WGPU provider computes real-valued cross products by gathering the three vector components into temporary device tensors, applying multiply/subtract kernels on-device, and scattering the results back into the output tensor. Providers that do not implement cross fall back to the host reference path.

GPU memory and residency

You usually do not need to call gpuArray explicitly for cross. RunMat uses a class-preserving native hook for eligible same-owner real inputs and otherwise follows a gather -> host compute -> class-preserving re-upload path for supported real and complex floating values.

Examples

Computing the cross product of row vectors

a = [1 0 0];
b = [0 1 0];
c = cross(a, b)

Expected output:

c =
     0     0     1

Computing the cross product of column vectors

u = [1; 0; 0];
v = [0; 1; 0];
w = cross(u, v)

Expected output:

w =
     0
     0
     1

Applying cross row-wise across a matrix

A = [1 0 0; 0 1 0];
B = [0 1 0; 0 0 1];
C = cross(A, B, 2)

Expected output:

C =
     0     0     1
     1     0     0

Evaluating cross on GPU-resident tensors

G1 = gpuArray([1 0 0]);
G2 = gpuArray([0 1 0]);
G = cross(G1, G2);
result = gather(G)

Expected output:

result =
     0     0     1

Using cross with coding agents

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

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

FAQ

Does cross require vectors of length 3?⌄

Yes. The operating dimension must have extent 3, whether the vectors are stored as rows, columns, or slices of a higher-rank tensor.

How is the default dimension chosen?⌄

RunMat follows MATLAB semantics and picks the first dimension whose size is exactly 3.

What happens if I pass dim explicitly?⌄

The dimension must exist and must have length 3; otherwise cross raises a descriptive error.

Can I use complex inputs?⌄

Yes for documented single/double complex inputs. RunMat mode also accepts typed complex integers under the corresponding operand gate, converts both components to double, and applies the standard bilinear formula without conjugation.

Does the result stay on the GPU?⌄

Same-owner, same-device real floating inputs remain resident when a provider's cross hook returns the required class. Other resident inputs gather independently, and eligible real or complex floating results return to the first owner. Typed complex integers work on the host, but the current provider ABI cannot encode typed complex-integer resident buffers.

Related Linalg functions

Ops

ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose

Structure

bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm

Factor

chol · decomposition · eig · eigs · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref · vecnorm

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how cross is executed, line by line, in Rust.

  • View the source for cross 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 cross works
  • Does RunMat run cross on the GPU?
  • GPU memory and residency
  • Examples
  • Computing the cross product of row vectors
  • Computing the cross product of column vectors
  • Applying cross row-wise across a matrix
  • Evaluating cross on GPU-resident tensors
  • Using cross with coding agents
  • FAQ
  • Related Linalg functions
  • Ops
  • Structure
  • Factor
  • Solve
  • Open-source implementation
  • About RunMat