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

speye — Create sparse identity matrices.

speye returns a host-resident sparse matrix with ones on the main diagonal and unstored zeros elsewhere.

Syntax

S = speye()
S = speye(n)
S = speye(n, typename)
S = speye(m, n)
S = speye(m, n, typename)
S = speye(sz)
S = speye(sz, typename)

Inputs

NameTypeRequiredDefaultDescription
ANumericArrayYes—Full or sparse matrix to convert.
sizeNumericArrayYes—Square size or two-element size vector.
typenameStringScalarYes—Sparse storage type: double, single, or logical.
mSizeArgYes—Number of rows.
nSizeArgYes—Number of columns.

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 speye works

  • speye() returns a sparse 1 x 1 identity matrix.
  • speye(n) returns an n x n sparse identity matrix.
  • speye(m, n) and speye([m n]) return an m x n sparse matrix with min(m,n) stored diagonal ones.
  • Negative dimensions are treated as zero, matching MATLAB sparse allocation behavior.
  • The optional typename selects double, single, or logical sparse storage.
  • Scalar, two-element-vector, and two-argument dimensions accept single, double, and all eight integer classes and are decoded without conversion through double.

GPU memory and residency

speye produces a host sparse matrix because RunMat does not currently expose native sparse GPU handles.

Example

Rectangular sparse identity

S = speye(2, 4);
full(S)

Expected output:

ans = [1 0 0 0; 0 1 0 0]

Using speye with coding agents

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

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

FAQ

Does speye allocate a dense matrix?⌄

No. It constructs RunMat's compressed sparse column representation directly.

Can speye create native sparse GPU matrices?⌄

Not yet. RunMat sparse matrices are host-resident until the acceleration API exposes sparse storage.

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 · spones · sprand · 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 speye is executed, line by line, in Rust.

  • View the source for speye 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 speye works
  • GPU memory and residency
  • Example
  • Rectangular sparse identity
  • Using speye with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Grouping
  • Sorting Sets
  • Shape
  • Indexing
  • Introspection
  • Open-source implementation
  • About RunMat