docs/reference/classes/sparsematrix.md
<a name="SparseMatrix"></a>
Sparse Matrix implementation. This type implements a Compressed Column Storage format for sparse matrices.
<a name="SparseMatrix+storage"></a>
Get the storage format used by the matrix.
Usage:
const format = matrix.storage() // retrieve storage format
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>string</code> - The storage format.
<a name="SparseMatrix+datatype"></a>
Get the datatype of the data stored in the matrix.
Usage:
const format = matrix.datatype() // retrieve matrix datatype
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>string</code> - The datatype.
<a name="SparseMatrix+create"></a>
Create a new SparseMatrix
Kind: instance method of <code>SparseMatrix</code>
| Param | Type |
|---|---|
| data | <code>Array</code> |
| [datatype] | <code>string</code> |
<a name="SparseMatrix+density"></a>
Get the matrix density.
Usage:
const density = matrix.density() // retrieve matrix density
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>number</code> - The matrix density.
<a name="SparseMatrix+subset"></a>
Get a subset of the matrix, or replace a subset of the matrix.
Usage:
const subset = matrix.subset(index) // retrieve subset
const value = matrix.subset(index, replacement) // replace subset
Kind: instance method of <code>SparseMatrix</code>
| Param | Type | Default | Description |
|---|---|---|---|
| index | <code>Index</code> | ||
| [replacement] | <code>Array</code> | <code>Maytrix</code> | <code>*</code> | ||
| [defaultValue] | <code>*</code> | <code>0</code> | Default value, filled in on new entries when the matrix is resized. If not provided, new matrix elements will be filled with zeros. |
<a name="SparseMatrix+get"></a>
Get a single element from the matrix.
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>*</code> - value
| Param | Type | Description |
|---|---|---|
| index | <code>Array.<number></code> | Zero-based index |
<a name="SparseMatrix+set"></a>
Replace a single element in the matrix.
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>SparseMatrix</code> - self
| Param | Type | Description |
|---|---|---|
| index | <code>Array.<number></code> | Zero-based index |
| value | <code>*</code> | |
| [defaultValue] | <code>*</code> | Default value, filled in on new entries when the matrix is resized. If not provided, new matrix elements will be set to zero. |
<a name="SparseMatrix+resize"></a>
Resize the matrix to the given size. Returns a copy of the matrix when
copy=true, otherwise return the matrix itself (resize in place).
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>Matrix</code> - The resized matrix
| Param | Type | Default | Description |
|---|---|---|---|
| size | <code>Array.<number></code> | The new size the matrix should have. | |
| [defaultValue] | <code>*</code> | <code>0</code> | Default value, filled in on new entries. If not provided, the matrix elements will be filled with zeros. |
| [copy] | <code>boolean</code> | Return a resized copy of the matrix |
<a name="SparseMatrix+clone"></a>
Create a clone of the matrix
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>SparseMatrix</code> - clone
<a name="SparseMatrix+size"></a>
Retrieve the size of the matrix.
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>Array.<number></code> - size
<a name="SparseMatrix+map"></a>
Create a new matrix with the results of the callback function executed on each entry of the matrix.
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>SparseMatrix</code> - matrix
| Param | Type | Description |
|---|---|---|
| callback | <code>function</code> | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
| [skipZeros] | <code>boolean</code> | Invoke callback function for non-zero values only. |
<a name="SparseMatrix+forEach"></a>
Execute a callback function on each entry of the matrix.
Kind: instance method of <code>SparseMatrix</code>
| Param | Type | Description |
|---|---|---|
| callback | <code>function</code> | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
| [skipZeros] | <code>boolean</code> | Invoke callback function for non-zero values only. |
<a name="SparseMatrix+toArray"></a>
Create an Array with a copy of the data of the SparseMatrix
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>Array</code> - array
<a name="SparseMatrix+valueOf"></a>
Get the primitive value of the SparseMatrix: a two dimensions array
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>Array</code> - array
<a name="SparseMatrix+format"></a>
Get a string representation of the matrix, with optional formatting options.
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>string</code> - str
| Param | Type | Description |
|---|---|---|
| [options] | <code>Object</code> | <code>number</code> | <code>function</code> | Formatting options. See lib/utils/number:format for a description of the available options. |
<a name="SparseMatrix+toString"></a>
Get a string representation of the matrix
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>string</code> - str
<a name="SparseMatrix+toJSON"></a>
Get a JSON representation of the matrix
Kind: instance method of <code>SparseMatrix</code>
<a name="SparseMatrix+diagonal"></a>
Get the kth Matrix diagonal.
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>Matrix</code> - The matrix vector with the diagonal values.
| Param | Type | Default | Description |
|---|---|---|---|
| [k] | <code>number</code> | <code>BigNumber</code> | <code>0</code> | The kth diagonal where the vector will retrieved. |
<a name="SparseMatrix+swapRows"></a>
Swap rows i and j in Matrix.
Kind: instance method of <code>SparseMatrix</code>
Returns: <code>Matrix</code> - The matrix reference
| Param | Type | Description |
|---|---|---|
| i | <code>number</code> | Matrix row index 1 |
| j | <code>number</code> | Matrix row index 2 |
<a name="SparseMatrix.fromJSON"></a>
Generate a matrix from a JSON object
Kind: static method of <code>SparseMatrix</code>
| Param | Type | Description |
|---|---|---|
| json | <code>Object</code> | An object structured like {"mathjs": "SparseMatrix", "values": [], "index": [], "ptr": [], "size": []}, where mathjs is optional |
<a name="SparseMatrix.diagonal"></a>
Create a diagonal matrix.
Kind: static method of <code>SparseMatrix</code>
| Param | Type | Default | Description |
|---|---|---|---|
| size | <code>Array</code> | The matrix size. | |
| value | <code>number</code> | <code>Array</code> | <code>Matrix</code> | The values for the diagonal. | |
| [k] | <code>number</code> | <code>BigNumber</code> | <code>0</code> | The kth diagonal where the vector will be filled in. |
| [datatype] | <code>string</code> | The Matrix datatype, values must be of this datatype. |