RunMat
GitHub

eq — Element-wise equality comparison for scalars, arrays, strings, and gpuArray inputs.

eq(A, B) (or the infix A == B) performs an element-wise equality comparison. The result is a logical scalar when the broadcasted shape contains one element, or a logical array otherwise.

How eq works in RunMat

  • Numeric, logical, and character inputs are compared element-wise using MATLAB's implicit expansion rules.
  • Complex numbers are equal only when both their real and imaginary parts match.
  • Character arrays compare by Unicode code point; you can mix them with numeric arrays ('A' == 65) or strings.
  • String scalars and string arrays compare lexically; implicit expansion works across the string dimensions.
  • Handle objects compare by identity rather than by structural equality.
  • Mixed numeric/string inputs raise MATLAB-compatible type errors.

How eq runs on the GPU

When both operands are gpuArray values and the active acceleration provider implements the elem_eq hook, RunMat executes the comparison entirely on the device and returns a gpuArray logical result. If the provider does not expose this hook, the runtime gathers the inputs to host memory automatically and performs the CPU comparison instead of failing.

GPU memory and residency

You usually do **not** need to call gpuArray explicitly. RunMat's native auto-offload planner keeps intermediate results on the GPU when fused expressions benefit from device execution. Explicit gpuArray and gather calls remain available for compatibility with MATLAB code that manages residency manually.

Examples

Check If Two Scalars Are Equal

flag = eq(42, 42)

Expected output:

flag =
     1

Compare Two Vectors Element-Wise

A = [1 2 3 4];
B = [1 0 3 5];
mask = eq(A, B)

Expected output:

mask =
  1×4 logical array
     1     0     1     0

Apply Equality With Implicit Expansion

M = [1 2 3; 4 5 6];
sel = eq(M, 2)

Expected output:

sel =
  2×3 logical array
     0     1     0
     0     0     0

Compare Character Data To Numeric Codes

letters = ['A' 'B' 'C'];
isA = eq(letters, 65)

Expected output:

isA =
  1×3 logical array
     1     0     0

Compare String Arrays To A Scalar String

names = ["alice" "bob" "alice"];
matches = eq(names, "alice")

Expected output:

matches =
  1×3 logical array
     1     0     1

Run eq Directly On gpuArray Inputs

G1 = gpuArray([1 2 3]);
G2 = gpuArray([1 0 3]);
deviceResult = eq(G1, G2)
hostResult = gather(deviceResult)

Expected output:

deviceResult =
  1  0  1
hostResult =
  1  0  1

FAQ

Does eq return logical values?

Yes. Scalars return true or false. Arrays return logical arrays, and gpuArray inputs return gpuArray logical outputs.

How are NaN values treated?

NaN == NaN evaluates to false, matching MATLAB's behaviour.

Can I compare complex numbers with eq?

Yes. Both the real and imaginary parts must match for the comparison to return true.

Are character vectors treated as numbers or text?

Both: they compare numerically (character code) against numeric inputs, and textually when compared to strings or other character arrays.

What happens when I mix numeric and string inputs?

RunMat raises a MATLAB-compatible error describing the unsupported type combination.

Do handle objects compare by value?

No. Handles compare by identity: two handles are equal only when they reference the same underlying object.

Does implicit expansion apply to string arrays?

Yes. String arrays support MATLAB-style implicit expansion, so you can compare against scalar strings without manual replication.

Can I chain eq inside fused GPU expressions?

Yes. The builtin registers element-wise fusion metadata so the planner can fuse comparisons with surrounding GPU-friendly operations.

These functions work well alongside eq. Each page has runnable examples you can try in the browser.

ge, gt, isequal, le, lt, ne

Open-source implementation

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

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat — free, no sign-up

Start running MATLAB code immediately in your browser.