RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

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
    • assert
    • error
    • rethrow
    • runtests
    • warning

assert — Throw an error when a condition is false, matching MATLAB and RunMat assert semantics.

assert(cond, ...) throws when a logical or logically convertible condition is false and has no public output. A real numeric condition is true only when it is nonempty and every element is nonzero; NaN cannot convert to logical. Optional text supplies a formatted message and a qualified error identifier.

Syntax

assert(condition)
assert(condition, message)
assert(condition, message, A...)
assert(condition, message_id, message)
assert(condition, message_id, message, A...)

Inputs

condition
Type
Any
Required
Yes
Description
Logical or logically convertible condition that must evaluate to true.
message
Type
StringScalar
Required
Yes
Default
"Assertion failed."
Description
Failure message text.
message
Type
StringScalar
Required
Yes
Default
"Assertion failed."
Description
Failure message template text.
A
Type
Any
Required
Variadic
Description
Formatting values for the message template.
message_id
Type
StringScalar
Required
Yes
Default
"RunMat:assertion:failed"
Description
Message identifier.
NameTypeRequiredDefaultDescription
conditionAnyYes—Logical or logically convertible condition that must evaluate to true.
messageStringScalarYes"Assertion failed."Failure message text.
messageStringScalarYes"Assertion failed."Failure message template text.
AAnyVariadic—Formatting values for the message template.
message_idStringScalarYes"RunMat:assertion:failed"Message identifier.

Errors

RunMat:assertion:failed
When
Condition evaluates to false and no custom identifier/message override is provided.
Message
Assertion failed.
RunMat:assertion:invalidCondition
When
First argument is not logical or convertible to a logical condition.
Message
assert: first input must be logical or convertible to logical.
RunMat:assertion:invalidInput
When
Message identifier/message text or formatting payload is invalid.
Message
assert: invalid input argument
IdentifierWhenMessage
RunMat:assertion:failedCondition evaluates to false and no custom identifier/message override is provided.Assertion failed.
RunMat:assertion:invalidConditionFirst argument is not logical or convertible to a logical condition.assert: first input must be logical or convertible to logical.
RunMat:assertion:invalidInputMessage identifier/message text or formatting payload is invalid.assert: invalid input argument
RunMat:minrhsNo condition argument is provided.Not enough input arguments.
RunMat:assertion:TooManyOutputsOne or more public outputs are requested from assert.assert: too many output arguments

Behavior

The documented condition is logical or convertible to logical. Logical, character, and real numeric conditions pass only when nonempty and every element is nonzero. All eight integer classes are tested directly from authoritative storage. NaN cannot convert to logical, and complex conditions are a mode-gated RunMat extension.

assert(cond) raises RunMat:assertion:failed with message Assertion failed. when cond is false.

assert(cond, msg, A...) formats msg with sprintf-compatible conversions. Each documented A is a character vector, string scalar, or numeric scalar; integer scalar values remain exact through decimal, unsigned, hexadecimal, and string formatting.

assert(cond, errID, msg, A...) requires colon-separated identifier fields that each begin with a letter and otherwise contain letters, digits, or underscores. Automatic RunMat: qualification of an unqualified identifier is a mode-gated RunMat extension.

Arguments are validated strictly: identifiers and message templates must be string scalars or character vectors, replacement arrays reject, and malformed format strings raise RunMat:assertion:invalidInput.

The public gpuArray form executes on the client. Resident conditions and scalar numeric replacements gather through typed storage; no assertion kernel runs on the GPU.

GPU and residency

assert is a control-flow builtin. Public documentation accepts gpuArray input but states that execution does not run on the GPU. RunMat therefore gathers resident logical, real numeric, and scalar formatting values through authoritative typed storage before host evaluation; all eight integer classes remain exact, and no provider assertion kernel is launched.

Examples

Checking that all elements are nonzero

A = [1 2 3];
assert(all(A))

Verifying array bounds during development

signal = 1:20;
idx = 12;
assert(idx >= 1 && idx <= numel(signal), ...
       "Index %d is outside [1, %d].", idx, numel(signal))

Attaching a custom identifier for tooling

M = magic(3);
assert(det(M) ~= 0, "runmat:demo:singularMatrix", ...
       "Matrix must be nonsingular (determinant is zero).")

Guarding GPU computations without manual gathering

G = gpuArray(rand(1024, 1));
assert(all(G > 0), "All entries must be positive.")

Converting NaN checks into assertion failures

samples = [1.0 2.5 3.7 4.2];
avg = mean(samples);
assert(~isnan(avg), "Average must be finite.")

Ensuring structure fields exist before use

cfg = struct("timeout", 30, "rate", 60);
assert(isfield(cfg, "rate"), ...
       "runmat:config:missingField", ...
       "Configuration missing required field '%s'.", "rate")

Detecting invalid enumeration values early

mode = "linear";
valid = ["nearest", "linear", "spline"];
assert(any(mode == valid), ...
       "Invalid interpolation mode '%s'.", mode)

Validating dimensions before expensive work

A = rand(3, 4);
B = rand(4, 5);
assert(size(A, 2) == size(B, 1), ...
       "runmat:demo:dimensionMismatch", ...
       "Inner dimensions must agree (size(A,2)=%d, size(B,1)=%d).", ...
       size(A, 2), size(B, 1))

Catching an assertion failure by identifier

assert(false, 'runmat:demo:assertFailed', 'Rejected value %d.', 7)

Using assert with coding agents

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

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

FAQ

What types can I pass as the condition?⌄

Logical arrays, character arrays, and real numeric arrays are accepted when convertible to a logical condition. Strings, cells, structs, and other unsupported values reject. Complex conditions are available only in RunMat compatibility mode.

How are NaN values treated?⌄

NaN cannot be converted to logical, so a real condition containing NaN raises the invalid-condition diagnostic rather than an ordinary assertion failure.

Do empty arrays pass the assertion?⌄

No. A condition is true only when its result is nonempty and all elements are nonzero, so empty logical, character, or real numeric conditions fail the assertion.

Can I omit the namespace in the message identifier?⌄

Only in RunMat compatibility mode. The documented form requires colon-separated component and mnemonic fields; RunMat mode can prefix an unqualified identifier with RunMat:.

What happens if my format string is malformed?⌄

The builtin raises RunMat:assertion:invalidInput describing the formatting issue.

Does assert run on the GPU?⌄

No. GPU tensors are gathered automatically and evaluated on the CPU to preserve MATLAB semantics.

Can I use strings for messages and identifiers?⌄

Yes. Both character vectors and string scalars are accepted for identifiers and message templates.

What value does assert return when the condition is true?⌄

assert has no public output. RunMat uses an internal control-flow sentinel only to complete runtime dispatch.

How do I disable assertions in production code?⌄

Wrap the condition in an if statement controlled by your own flag; MATLAB (and RunMat) always evaluates assert.

How do I distinguish assertion failures from other errors?⌄

Provide a custom identifier (for example runmat:module:assertFailed) and catch it in a try/catch block.

Related Diagnostics functions

error · rethrow · runtests · warning

Source you can read

Every RunMat function's source is public. Read exactly how assert is executed, line by line, in Rust.

  • View the source for assert in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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
  • Errors
  • Behavior
  • GPU and residency
  • Examples
  • Checking that all elements are nonzero
  • Verifying array bounds during development
  • Attaching a custom identifier for tooling
  • Guarding GPU computations without manual gathering
  • Converting NaN checks into assertion failures
  • Ensuring structure fields exist before use
  • Detecting invalid enumeration values early
  • Validating dimensions before expensive work
  • Catching an assertion failure by identifier
  • Using assert with coding agents
  • FAQ
  • Related Diagnostics functions
  • Source you can read
  • About RunMat