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
    • colon
    • createArray
    • empty
    • eye
    • false
    • full
    • inf
    • linspace
    • logspace
    • magic
    • meshgrid
    • nan
    • nchoosek
    • ndgrid
    • nonzeros
    • ones
    • peaks
    • perms
    • rand
    • randi
    • randn
    • randperm
    • range
    • sparse
    • spdiags
    • speye
    • spones
    • sprand
    • true
    • zeros

sprand — Create sparse random matrices.

sprand creates sparse double matrices with random values and optional reciprocal-condition control.

Syntax

R = sprand(S)
R = sprand(S, typename)
R = sprand(m, n, density)
R = sprand(m, n, density, typename)
R = sprand(m, n, density, rc)
R = sprand(m, n, density, rc, typename)

Inputs

NameTypeRequiredDefaultDescription
ANumericArrayYes—Full or sparse matrix.
SNumericArrayYes—Full or sparse matrix.
typenameStringScalarNodoubleSparse storage type: double or single.
mSizeArgYes—Number of rows.
nSizeArgYes—Number of columns.
densityNumericScalarYes—Approximate density in [0,1].
rcNumericArrayYes—Reciprocal condition number target or singular-value vector.

Returns

NameTypeDescription
SNumericArraySparse matrix.

Errors

IdentifierWhenMessage
RunMat:sparse:InvalidInputInputs are not a supported sparse construction form.sparse: invalid input
RunMat:sparse:InvalidIndexRow or column subscripts are nonpositive, noninteger, or outside explicit dimensions.sparse: invalid index
RunMat:sparse:InternalSparse matrix materialisation fails internally.sparse: internal error

How sprand works

  • sprand(S) preserves the nonzero pattern and shape of S while replacing stored values with uniform random values.
  • sprand(m, n, density) creates an m x n sparse matrix with approximately round(m*n*density) stored entries.
  • density must be finite and between 0 and 1.
  • sprand(m, n, density, rc) accepts a scalar reciprocal-condition target or a vector of singular values in [0,1]. RunMat starts from the requested singular profile and applies random orthogonal plane rotations to add sparse fill while preserving that profile.
  • A trailing "double" or "single" typename selects the sparse output class.
  • All eight integer classes are documented for the pattern input S. Typed integer dimensions, density, and condition controls are RunMat extensions; dimensions are structural, while numerical controls reject if binary64 conversion would round.
  • Large requested sparse patterns, condition-profile dense intermediates, and excessive plane-rotation work are rejected before allocating or running unbounded work.

GPU memory and residency

sprand runs on the host RNG and produces a host sparse matrix.

Example

Random values on an existing pattern

P = sparse([1; 3], [1; 2], [10; 20], 3, 2);
R = sprand(P);
issparse(R)

Expected output:

ans = 1

Using sprand with coding agents

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

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

FAQ

Does sprand(...,rc) enforce the reciprocal condition number?⌄

Yes. RunMat uses orthogonal row and column plane rotations, which preserve the singular values of the requested scalar reciprocal condition target or vector singular profile. The requested density remains approximate for small or structurally constrained shapes.

Related Array functions

Creation

colon · createArray · empty · eye · false · full · inf · linspace · logspace · magic · meshgrid · nan · nchoosek · ndgrid · nonzeros · ones · peaks · perms · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · true · zeros

Grouping

accumarray · combinations · discretize · findgroups · groupcounts · grp2idx · splitapply

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Shape

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

Indexing

find · ind2sub · sub2ind

Introspection

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

Open-source implementation

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

  • View the source for sprand 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 sprand works
  • GPU memory and residency
  • Example
  • Random values on an existing pattern
  • Using sprand with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Grouping
  • Sorting Sets
  • Shape
  • Indexing
  • Introspection
  • Open-source implementation
  • About RunMat