SparseMatrix #
Sparse Matrix implementation. This type implements a Compressed Column Storage format for sparse matrices.
- 实例
- .storage() ⇒
string - .datatype() ⇒
string - .create(data, [datatype])
- .density() ⇒
number - .subset(index, [replacement], [defaultValue])
- .get(index) ⇒
\* - .set(index, value, [defaultValue]) ⇒
[SparseMatrix](#SparseMatrix) - .resize(size, [defaultValue], [copy]) ⇒
Matrix - .clone() ⇒
[SparseMatrix](#SparseMatrix) - .size() ⇒
Array.<number> - .map(callback, [skipZeros]) ⇒
[SparseMatrix](#SparseMatrix) - .forEach(callback, [skipZeros])
- .toArray() ⇒
Array - .valueOf() ⇒
Array - .format([options]) ⇒
string - .toString() ⇒
string - .toJSON() ⇒
Object - .diagonal([k]) ⇒
Matrix - .swapRows(i, j) ⇒
Matrix
- .storage() ⇒
- 静态
- .fromJSON(json) ⇒
[SparseMatrix](#SparseMatrix) - .diagonal(size, value, [k], [datatype]) ⇒
[SparseMatrix](#SparseMatrix)
- .fromJSON(json) ⇒
sparseMatrix.storage() ⇒ string #
获取矩阵使用的存储格式。
用法
const format = matrix.storage() // retrieve storage format
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: string - The storage format.
sparseMatrix.datatype() ⇒ string #
获取矩阵中存储的数据的类型。
用法
const format = matrix.datatype() // retrieve matrix datatype
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: string - The datatype.
sparseMatrix.create(data, [datatype]) #
创建一个新的 SparseMatrix
Kind: instance method of [SparseMatrix](#SparseMatrix)
| 参数 | Type |
|---|---|
| data | Array |
| [datatype] | string |
sparseMatrix.density() ⇒ number #
获取矩阵的密度。
用法
const density = matrix.density() // retrieve matrix density
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: number - The matrix density.
sparseMatrix.subset(index, [replacement], [defaultValue]) #
获取矩阵的子集,或替换矩阵的子集。
用法
const subset = matrix.subset(index) // retrieve subset
const value = matrix.subset(index, replacement) // replace subset
Kind: instance method of [SparseMatrix](#SparseMatrix)
| 参数 | Type | Default | Description |
|---|---|---|---|
| index | Index |
||
| [replacement] | Array | Maytrix | \* |
||
| [defaultValue] | \* |
0 |
默认值,当矩阵被调整大小时,用于填充新条目。如果未提供,新矩阵元素将用零填充。 |
sparseMatrix.get(index) ⇒ \* #
从矩阵中获取单个元素。
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: \* - value
| 参数 | Type | Description |
|---|---|---|
| index | Array.<number> |
Zero-based index |
sparseMatrix.set(index, value, [defaultValue]) ⇒ [SparseMatrix](#SparseMatrix) #
替换矩阵中的单个元素。
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: [SparseMatrix](#SparseMatrix) - self
| 参数 | Type | Description |
|---|---|---|
| index | Array.<number> |
Zero-based index |
| value | \* |
|
| [defaultValue] | \* |
默认值,当矩阵被调整大小时,用于填充新条目。如果未提供,新矩阵元素将用零填充。 |
sparseMatrix.resize(size, [defaultValue], [copy]) ⇒ Matrix #
将矩阵调整为给定大小。当 copy=true 时,返回矩阵的副本,否则返回矩阵本身(原地调整大小)。
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: Matrix - The resized matrix
| 参数 | Type | Default | Description |
|---|---|---|---|
| size | Array.<number> |
矩阵应具有的新大小。 | |
| [defaultValue] | \* |
0 |
用于填充新条目的默认值。如果未提供,矩阵元素将用零填充。 |
| [copy] | boolean |
返回一个调整大小后的矩阵副本 |
sparseMatrix.clone() ⇒ [SparseMatrix](#SparseMatrix) #
创建矩阵的克隆
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: [SparseMatrix](#SparseMatrix) - clone
sparseMatrix.size() ⇒ Array.<number> #
检索矩阵的大小。
Kind: instance method of [SparseMatrix](#SparseMatrix)
返回: Array.<number> - 大小
sparseMatrix.map(callback, [skipZeros]) ⇒ [SparseMatrix](#SparseMatrix) #
创建一个新矩阵,其中包含在矩阵的每个条目上执行回调函数的结果。
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: [SparseMatrix](#SparseMatrix) - matrix
| 参数 | Type | Description |
|---|---|---|
| 回调函数 | function |
回调函数以三个参数调用:元素的值、元素的索引以及正在遍历的 Matrix。 |
| [skipZeros] | boolean |
仅对非零值调用回调函数。 |
sparseMatrix.forEach(callback, [skipZeros]) #
在矩阵的每个条目上执行回调函数。
Kind: instance method of [SparseMatrix](#SparseMatrix)
| 参数 | Type | Description |
|---|---|---|
| 回调函数 | function |
回调函数以三个参数调用:元素的值、元素的索引以及正在遍历的 Matrix。 |
| [skipZeros] | boolean |
仅对非零值调用回调函数。 |
sparseMatrix.toArray() ⇒ Array #
创建一个包含 SparseMatrix 数据副本的 Array
Kind: instance method of [SparseMatrix](#SparseMatrix)
返回: Array - 数组
sparseMatrix.valueOf() ⇒ Array #
获取 SparseMatrix 的原始值:一个二维数组
Kind: instance method of [SparseMatrix](#SparseMatrix)
返回: Array - 数组
sparseMatrix.format([options]) ⇒ string #
获取矩阵的字符串表示形式,带可选的格式化选项。
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: string - str
| 参数 | Type | Description |
|---|---|---|
| [options] | Object | number | function |
格式化选项。有关可用选项的说明,请参阅 lib/utils/number:format。 |
sparseMatrix.toString() ⇒ string #
获取矩阵的字符串表示形式
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: string - str
sparseMatrix.toJSON() ⇒ Object #
获取矩阵的 JSON 表示形式
Kind: instance method of [SparseMatrix](#SparseMatrix)
sparseMatrix.diagonal([k]) ⇒ Matrix #
获取第 k 个 Matrix 对角线。
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: Matrix - 包含对角线值的矩阵向量。
| 参数 | Type | Default | Description |
|---|---|---|---|
| [k] | number | BigNumber |
0 |
将从中检索向量的第 k 个对角线。 |
sparseMatrix.swapRows(i, j) ⇒ Matrix #
在 Matrix 中交换行 i 和 j。
Kind: instance method of [SparseMatrix](#SparseMatrix)
Returns: Matrix - The matrix reference
| 参数 | Type | Description |
|---|---|---|
| i | number |
Matrix row index 1 |
| j | number |
Matrix row index 2 |
SparseMatrix.fromJSON(json) ⇒ [SparseMatrix](#SparseMatrix) #
从 JSON 对象生成矩阵
Kind: static method of [SparseMatrix](#SparseMatrix)
| 参数 | Type | Description |
|---|---|---|
| json | Object |
一个结构类似于 {"mathjs": "SparseMatrix", "values": [], "index": [], "ptr": [], "size": []} 的对象,其中 mathjs 是可选的 |
SparseMatrix.diagonal(size, value, [k], [datatype]) ⇒ [SparseMatrix](#SparseMatrix) #
创建一个对角矩阵。
Kind: static method of [SparseMatrix](#SparseMatrix)
| 参数 | Type | Default | Description |
|---|---|---|---|
| size | Array |
矩阵大小。 | |
| value | number | Array | Matrix |
对角线的值。 | |
| [k] | number | BigNumber |
0 |
将填充向量的第 k 个对角线。 |
| [datatype] | string |
矩阵数据类型,值必须是此数据类型。 |