Home

nmatrix

NMatrix, also styled as nmatrix, is a matrix and multi-dimensional array library for the Ruby programming language. It is a key component of the SciRuby project, created to provide high-performance numerical data structures and operations for scientific computing in Ruby. The library offers dense and sparse representations and aims to combine Ruby’s usability with efficient, lower-level implementations.

NMatrix provides multi-dimensional arrays with customizable data types, including common numeric types such as floating-point and

Implementation and backends are centered on a native Ruby C extension, which enables performance improvements over

In practice, NMatrix is used as a core building block for numerical computing in Ruby, providing a

integer
scalars,
as
well
as
boolean
and
complex
numbers.
It
supports
a
range
of
shapes
and
supports
indexing,
slicing,
and
various
element-wise
and
aggregate
operations.
In
addition
to
basic
arithmetic,
the
library
exposes
a
collection
of
linear
algebra
and
numerical
methods,
depending
on
the
active
backend
and
available
dependencies.
Sparse
matrices
are
supported
to
help
with
memory
efficiency
in
problems
with
large,
mostly
empty
matrices.
pure
Ruby
code.
The
backend
abstraction
allows
NMatrix
to
leverage
optimized
numerical
libraries
when
they
are
available,
and
to
interoperate
with
other
components
in
the
Ruby
scientific
stack.
The
design
emphasizes
compatibility
with
Ruby’s
object
model
and
with
the
broader
SciRuby
ecosystem.
familiar
array-like
API
while
supporting
more
advanced
linear
algebra
and
scientific
workflows.
It
is
commonly
paired
with
other
SciRuby
gems
for
data
analysis,
visualization,
and
statistical
computing.
See
also
SciRuby
and
NArray
for
related
Ruby
numerical
libraries.