1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createGetMatrixDataType = void 0;
|
7 |
|
8 | var _factory = require("../../utils/factory.js");
|
9 |
|
10 | var _array = require("../../utils/array.js");
|
11 |
|
12 | var _is = require("../../utils/is.js");
|
13 |
|
14 | var name = 'getMatrixDataType';
|
15 | var dependencies = ['typed'];
|
16 | var createGetMatrixDataType = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
17 | var typed = _ref.typed;
|
18 |
|
19 | /**
|
20 | * Find the data type of all elements in a matrix or array,
|
21 | * for example 'number' if all items are a number and 'Complex' if all values
|
22 | * are complex numbers.
|
23 | * If a matrix contains more than one data type, it will return 'mixed'.
|
24 | *
|
25 | * Syntax:
|
26 | *
|
27 | * math.getMatrixDataType(x)
|
28 | *
|
29 | * Examples:
|
30 | *
|
31 | * const x = [ [1, 2, 3], [4, 5, 6] ]
|
32 | * const mixedX = [ [1, true], [2, 3] ]
|
33 | * const fractionX = [ [math.fraction(1, 3)], [math.fraction(1, 3] ]
|
34 | * const unitX = [ [math.unit('5cm')], [math.unit('5cm')] ]
|
35 | * const bigNumberX = [ [math.bignumber(1)], [math.bignumber(0)] ]
|
36 | * const sparse = math.sparse(x)
|
37 | * const dense = math.matrix(x)
|
38 | * math.getMatrixDataType(x) // returns 'number'
|
39 | * math.getMatrixDataType(sparse) // returns 'number'
|
40 | * math.getMatrixDataType(dense) // returns 'number'
|
41 | * math.getMatrixDataType(mixedX) // returns 'mixed'
|
42 | * math.getMatrixDataType(fractionX) // returns 'Fraction'
|
43 | * math.getMatrixDataType(unitX) // returns 'Unit'
|
44 | * math.getMatrixDataType(bigNumberX) // return 'BigNumber'
|
45 | *
|
46 | * See also:
|
47 | * SparseMatrix, DenseMatrix
|
48 | *
|
49 | * @param {...Matrix | Array} x The Matrix with values.
|
50 | *
|
51 | * @return {string} A string representation of the matrix type
|
52 | */
|
53 | return typed(name, {
|
54 | Array: function Array(x) {
|
55 | return (0, _array.getArrayDataType)(x, _is.typeOf);
|
56 | },
|
57 | Matrix: function Matrix(x) {
|
58 | return x.getDataType();
|
59 | }
|
60 | });
|
61 | });
|
62 | exports.createGetMatrixDataType = createGetMatrixDataType; |
\ | No newline at end of file |