simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

size.js (1620B)


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