flatten.js (1286B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.createFlatten = void 0; 7 8 var _object = require("../../utils/object.js"); 9 10 var _array = require("../../utils/array.js"); 11 12 var _factory = require("../../utils/factory.js"); 13 14 var name = 'flatten'; 15 var dependencies = ['typed', 'matrix']; 16 var createFlatten = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { 17 var typed = _ref.typed, 18 matrix = _ref.matrix; 19 20 /** 21 * Flatten a multi dimensional matrix into a single dimensional matrix. 22 * It is guaranteed to always return a clone of the argument. 23 * 24 * Syntax: 25 * 26 * math.flatten(x) 27 * 28 * Examples: 29 * 30 * math.flatten([[1,2], [3,4]]) // returns [1, 2, 3, 4] 31 * 32 * See also: 33 * 34 * concat, resize, size, squeeze 35 * 36 * @param {Matrix | Array} x Matrix to be flattened 37 * @return {Matrix | Array} Returns the flattened matrix 38 */ 39 return typed(name, { 40 Array: function Array(x) { 41 return (0, _array.flatten)((0, _object.clone)(x)); 42 }, 43 Matrix: function Matrix(x) { 44 var flat = (0, _array.flatten)((0, _object.clone)(x.toArray())); // TODO: return the same matrix type as x 45 46 return matrix(flat); 47 } 48 }); 49 }); 50 exports.createFlatten = createFlatten;