UNPKG

1.75 kBJavaScriptView Raw
1'use strict'
2
3function factory (type, config, load, typed) {
4 const getArrayDataType = load(require('../../type/matrix/utils/getArrayDataType'))
5 /**
6 * Find the data type of all elements in a matrix or array,
7 * for example 'number' if all items are a number and 'Complex' if all values
8 * are complex numbers.
9 * If a matrix contains more than one data type, it will return 'mixed'.
10 *
11 * Syntax:
12 *
13 * math.getMatrixDataType(x)
14 *
15 * Examples:
16 *
17 * const x = [ [1, 2, 3], [4, 5, 6] ]
18 * const mixedX = [ [1, true], [2, 3] ]
19 * const fractionX = [ [math.fraction(1, 3)], [math.fraction(1, 3] ]
20 * const unitX = [ [math.unit('5cm')], [math.unit('5cm')] ]
21 * const bigNumberX = [ [math.bignumber(1)], [math.bignumber(0)] ]
22 * const sparse = math.sparse(x)
23 * const dense = math.matrix(x)
24 * math.getMatrixDataType(x) // returns 'number'
25 * math.getMatrixDataType(sparse) // returns 'number'
26 * math.getMatrixDataType(dense) // returns 'number'
27 * math.getMatrixDataType(mixedX) // returns 'mixed'
28 * math.getMatrixDataType(fractionX) // returns 'Fraction'
29 * math.getMatrixDataType(unitX) // returns 'Unit'
30 * math.getMatrixDataType(bigNumberX) // return 'BigNumber'
31 *
32 * See also:
33 * SparseMatrix, DenseMatrix
34 *
35 * @param {...Matrix | Array} x The Matrix with values.
36 *
37 * @return {string} A string representation of the matrix type
38 */
39 const getMatrixDataType = typed('getMatrixDataType', {
40 'Array': function (x) {
41 return getArrayDataType(x)
42 },
43 'Matrix': function (x) {
44 return x.getDataType()
45 }
46 })
47 return getMatrixDataType
48}
49
50exports.name = 'getMatrixDataType'
51exports.factory = factory