RunMat
GitHub

nan — Create arrays filled with IEEE NaN values using MATLAB-compatible size, class, and like forms.

nan(...) creates NaN-filled arrays across scalar, vector, matrix, and N-D size signatures, with MATLAB-compatible class and 'like' option behavior.

Syntax

A = nan(2, 3)

How nan works

  • nan() returns the scalar NaN.
  • nan(n) returns an n x n double array filled with NaN.
  • nan(m, n, ...) returns a dense double array with the requested dimensions.
  • nan(sz) accepts a size vector and returns an array with prod(sz) NaN elements.
  • nan(A) returns a NaN array with the same size as A.
  • nan(___, 'single') returns a single-precision numeric array.
  • nan(___, 'like', prototype) matches numeric precision and device residency for supported prototype arrays.

Does RunMat run nan on the GPU?

Provider-backed nan construction uses constant-fill hooks, so fully resident GPU pipelines can create NaN arrays without first materializing a host tensor when provider support is available.

GPU memory and residency

When a GPU prototype is supplied, RunMat preserves residency by allocating the output through the active acceleration provider. If the provider cannot fill on device, RunMat falls back to a host NaN tensor and uploads it.

Examples

Creating a 2x3 matrix of NaN values

A = nan(2, 3)

Expected output:

A = [NaN NaN NaN; NaN NaN NaN]

Creating a single-precision NaN array

A = nan(4, 1, 'single')

Expected output:

A = [NaN; NaN; NaN; NaN]

Creating a GPU-resident NaN array like a prototype

G = gpuArray(rand(2,2));
A = nan(2, 2, 'like', G)

Expected output:

A = [NaN NaN; NaN NaN]

Using nan with coding agents

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

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

FAQ

How is nan different from NaN?

Both bare identifiers resolve to the scalar IEEE NaN constant. The callable form nan(...) constructs NaN-filled arrays.

Does nan(n) create a row vector?

No. MATLAB compatibility requires nan(n) to create an n x n matrix. Use nan(1, n) or nan(n, 1) for vectors.

Can nan create GPU arrays?

Yes. With a GPU prototype, nan(..., 'like', G) asks the active acceleration provider to allocate a NaN-filled GPU tensor.

Creation

colon · eye · false · fill · inf · linspace · logspace · magic · meshgrid · ones · peaks · rand · randi · randn · randperm · range · true · zeros

Sorting Sets

argsort · intersect · ismember · issorted · setdiff · sort · sortrows · union · unique

Shape

cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · squeeze · tril · triu · vertcat

Indexing

find · ind2sub · sub2ind

Introspection

isempty · ismatrix · isscalar · isvector · length · ndims · numel · size

Open-source implementation

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

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.