SparseMatrix
in package
implements
Iterator
A sparse matrix implementation based on an associative array of associative arrays.
A SparseMatrix is mostly a wrapper around an array of arrays, but it keeps track of some extra information such as the true matrix dimensions, and the number of non-zero entries. It also provides a convenience method for partitioning the matrix rows into two new sparse matrices.
Tags
Interfaces, Classes, Traits and Enums
- Iterator
Table of Contents
- $data : array<string|int, mixed>
- The actual matrix data, an associative array mapping row indices to associative arrays mapping column indices to their values.
- $m : int
- The number of rows, regardless of whether or not some are empty.
- $n : int
- The number of columns, regardless of whether or not some are empty.
- $nonzero : int
- The number of non-zero entries.
- __construct() : mixed
- Initializes a new sparse matrix with specific dimensions.
- columns() : number
- Accessor method which the number of columns in the matrix
- current() : array<string|int, mixed>
- Returns the current iterated over row
- key() : int
- Returns the index of the current row
- next() : array<string|int, mixed>
- Returns the next row to be iterated over
- nonzero() : number
- Accessor method which the number of nonzero entries in the matrix
- partition() : array<string|int, mixed>
- Given two sets of row indices, returns two new sparse matrices consisting of the corresponding rows.
- rewind() : mixed
- Resets the iterator
- rows() : number
- Accessor method which the number of rows in the matrix
- setRow() : mixed
- Sets a particular row of data, keeping track of any new non-zero entries.
- valid() : bool
- Whether the current key position is not null
Properties
$data
The actual matrix data, an associative array mapping row indices to associative arrays mapping column indices to their values.
public
array<string|int, mixed>
$data
$m
The number of rows, regardless of whether or not some are empty.
public
int
$m
$n
The number of columns, regardless of whether or not some are empty.
public
int
$n
$nonzero
The number of non-zero entries.
public
int
$nonzero
= 0
Methods
__construct()
Initializes a new sparse matrix with specific dimensions.
public
__construct(int $m, int $n) : mixed
Parameters
- $m : int
-
number of rows
- $n : int
-
number of columns
Return values
mixed —columns()
Accessor method which the number of columns in the matrix
public
columns() : number
Return values
number —of columns
current()
Returns the current iterated over row
public
current() : array<string|int, mixed>
Return values
array<string|int, mixed> —current row
key()
Returns the index of the current row
public
key() : int
Return values
int —index of row
next()
Returns the next row to be iterated over
public
next() : array<string|int, mixed>
Return values
array<string|int, mixed> —next row
nonzero()
Accessor method which the number of nonzero entries in the matrix
public
nonzero() : number
Return values
number —of nonzero entries
partition()
Given two sets of row indices, returns two new sparse matrices consisting of the corresponding rows.
public
partition(array<string|int, mixed> $a_indices, array<string|int, mixed> $b_indices) : array<string|int, mixed>
Parameters
- $a_indices : array<string|int, mixed>
-
row indices for first new sparse matrix
- $b_indices : array<string|int, mixed>
-
row indices for second new sparse matrix
Return values
array<string|int, mixed> —array with two entries corresponding to the first and second new matrices
rewind()
Resets the iterator
public
rewind() : mixed
Return values
mixed —rows()
Accessor method which the number of rows in the matrix
public
rows() : number
Return values
number —of rows
setRow()
Sets a particular row of data, keeping track of any new non-zero entries.
public
setRow(int $i, array<string|int, mixed> $row) : mixed
Parameters
- $i : int
-
row index
- $row : array<string|int, mixed>
-
associative array mapping column indices to values
Return values
mixed —valid()
Whether the current key position is not null
public
valid() : bool
Return values
bool —whether it is null or not