forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetMatrixDataType.js
More file actions
51 lines (49 loc) · 1.76 KB
/
getMatrixDataType.js
File metadata and controls
51 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { factory } from '../../utils/factory.js'
import { getArrayDataType } from '../../utils/array.js'
import { typeOf } from '../../utils/is.js'
const name = 'getMatrixDataType'
const dependencies = ['typed']
export const createGetMatrixDataType = /* #__PURE__ */ factory(name, dependencies, ({ typed }) => {
/**
* Find the data type of all elements in a matrix or array,
* for example 'number' if all items are a number and 'Complex' if all values
* are complex numbers.
* If a matrix contains more than one data type, it will return 'mixed'.
*
* Syntax:
*
* math.getMatrixDataType(x)
*
* Examples:
*
* const x = [ [1, 2, 3], [4, 5, 6] ]
* const mixedX = [ [1, true], [2, 3] ]
* const fractionX = [ [math.fraction(1, 3)], [math.fraction(1, 3] ]
* const unitX = [ [math.unit('5cm')], [math.unit('5cm')] ]
* const bigNumberX = [ [math.bignumber(1)], [math.bignumber(0)] ]
* const sparse = math.sparse(x)
* const dense = math.matrix(x)
* math.getMatrixDataType(x) // returns 'number'
* math.getMatrixDataType(sparse) // returns 'number'
* math.getMatrixDataType(dense) // returns 'number'
* math.getMatrixDataType(mixedX) // returns 'mixed'
* math.getMatrixDataType(fractionX) // returns 'Fraction'
* math.getMatrixDataType(unitX) // returns 'Unit'
* math.getMatrixDataType(bigNumberX) // return 'BigNumber'
*
* See also:
* SparseMatrix, DenseMatrix
*
* @param {...Matrix | Array} x The Matrix with values.
*
* @return {string} A string representation of the matrix type
*/
return typed(name, {
Array: function (x) {
return getArrayDataType(x, typeOf)
},
Matrix: function (x) {
return x.getDataType()
}
})
})