UNPKG

1.86 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createSparse = void 0;
7
8var _factory = require("../../../utils/factory");
9
10var name = 'sparse';
11var dependencies = ['typed', 'SparseMatrix'];
12var createSparse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
13 var typed = _ref.typed,
14 SparseMatrix = _ref.SparseMatrix;
15
16 /**
17 * Create a Sparse Matrix. The function creates a new `math.Matrix` object from
18 * an `Array`. A Matrix has utility functions to manipulate the data in the
19 * matrix, like getting the size and getting or setting values in the matrix.
20 *
21 * Syntax:
22 *
23 * math.sparse() // creates an empty sparse matrix.
24 * math.sparse(data) // creates a sparse matrix with initial data.
25 * math.sparse(data, 'number') // creates a sparse matrix with initial data, number datatype.
26 *
27 * Examples:
28 *
29 * let m = math.sparse([[1, 2], [3, 4]])
30 * m.size() // Array [2, 2]
31 * m.resize([3, 2], 5)
32 * m.valueOf() // Array [[1, 2], [3, 4], [5, 5]]
33 * m.get([1, 0]) // number 3
34 *
35 * See also:
36 *
37 * bignumber, boolean, complex, index, number, string, unit, matrix
38 *
39 * @param {Array | Matrix} [data] A two dimensional array
40 *
41 * @return {Matrix} The created matrix
42 */
43 return typed(name, {
44 '': function _() {
45 return new SparseMatrix([]);
46 },
47 string: function string(datatype) {
48 return new SparseMatrix([], datatype);
49 },
50 'Array | Matrix': function ArrayMatrix(data) {
51 return new SparseMatrix(data);
52 },
53 'Array | Matrix, string': function ArrayMatrixString(data, datatype) {
54 return new SparseMatrix(data, datatype);
55 }
56 });
57});
58exports.createSparse = createSparse;
\No newline at end of file