size.js (1421B)
1 import { arraySize } from '../../utils/array.js'; 2 import { factory } from '../../utils/factory.js'; 3 import { noMatrix } from '../../utils/noop.js'; 4 var name = 'size'; 5 var dependencies = ['typed', 'config', '?matrix']; 6 export var createSize = /* #__PURE__ */factory(name, dependencies, _ref => { 7 var { 8 typed, 9 config, 10 matrix 11 } = _ref; 12 13 /** 14 * Calculate the size of a matrix or scalar. 15 * 16 * Syntax: 17 * 18 * math.size(x) 19 * 20 * Examples: 21 * 22 * math.size(2.3) // returns [] 23 * math.size('hello world') // returns [11] 24 * 25 * const A = [[1, 2, 3], [4, 5, 6]] 26 * math.size(A) // returns [2, 3] 27 * math.size(math.range(1,6)) // returns [5] 28 * 29 * See also: 30 * 31 * count, resize, squeeze, subset 32 * 33 * @param {boolean | number | Complex | Unit | string | Array | Matrix} x A matrix 34 * @return {Array | Matrix} A vector with size of `x`. 35 */ 36 return typed(name, { 37 Matrix: function Matrix(x) { 38 return x.create(x.size()); 39 }, 40 Array: arraySize, 41 string: function string(x) { 42 return config.matrix === 'Array' ? [x.length] : matrix([x.length]); 43 }, 44 'number | Complex | BigNumber | Unit | boolean | null': function numberComplexBigNumberUnitBooleanNull(x) { 45 // scalar 46 return config.matrix === 'Array' ? [] : matrix ? matrix([]) : noMatrix(); 47 } 48 }); 49 });