mathjs 11.9.1 → 11.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +10 -0
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -2
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesIndexClass.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesIndexTransform.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesQuantileSeq.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesQuantileSeqTransform.generated.js +28 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSubset.generated.js +4 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSubsetTransform.generated.js +4 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesZeta.generated.js +46 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +14 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesQuantileSeq.generated.js +2 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesZeta.generated.js +42 -0
- package/lib/cjs/entry/dependenciesNumber.generated.js +7 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +52 -40
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -0
- package/lib/cjs/entry/pureFunctionsAny.generated.js +159 -136
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +19 -1
- package/lib/cjs/expression/embeddedDocs/construction/index.js +1 -1
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/lib/cjs/expression/embeddedDocs/function/special/zeta.js +15 -0
- package/lib/cjs/expression/node/utils/assign.js +7 -2
- package/lib/cjs/expression/transform/index.transform.js +9 -6
- package/lib/cjs/expression/transform/quantileSeq.transform.js +50 -0
- package/lib/cjs/expression/transform/subset.transform.js +7 -3
- package/lib/cjs/factoriesAny.js +14 -0
- package/lib/cjs/factoriesNumber.js +7 -0
- package/lib/cjs/function/matrix/concat.js +2 -29
- package/lib/cjs/function/matrix/subset.js +86 -24
- package/lib/cjs/function/special/zeta.js +169 -0
- package/lib/cjs/function/statistics/quantileSeq.js +39 -17
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/matrix/DenseMatrix.js +19 -9
- package/lib/cjs/type/matrix/MatrixIndex.js +38 -6
- package/lib/cjs/type/matrix/function/index.js +6 -4
- package/lib/cjs/type/matrix/utils/broadcast.js +8 -14
- package/lib/cjs/utils/array.js +253 -19
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesIndexClass.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesIndexTransform.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesQuantileSeq.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesQuantileSeqTransform.generated.js +20 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSubset.generated.js +4 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSubsetTransform.generated.js +4 -0
- package/lib/esm/entry/dependenciesAny/dependenciesZeta.generated.js +38 -0
- package/lib/esm/entry/dependenciesAny.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesQuantileSeq.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesZeta.generated.js +34 -0
- package/lib/esm/entry/dependenciesNumber.generated.js +1 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +53 -41
- package/lib/esm/entry/impureFunctionsNumber.generated.js +2 -1
- package/lib/esm/entry/pureFunctionsAny.generated.js +140 -118
- package/lib/esm/entry/pureFunctionsNumber.generated.js +18 -1
- package/lib/esm/expression/embeddedDocs/construction/index.js +1 -1
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/lib/esm/expression/embeddedDocs/function/special/zeta.js +8 -0
- package/lib/esm/expression/node/utils/assign.js +7 -2
- package/lib/esm/expression/transform/index.transform.js +9 -6
- package/lib/esm/expression/transform/quantileSeq.transform.js +41 -0
- package/lib/esm/expression/transform/subset.transform.js +7 -3
- package/lib/esm/factoriesAny.js +2 -0
- package/lib/esm/factoriesNumber.js +1 -1
- package/lib/esm/function/matrix/concat.js +3 -30
- package/lib/esm/function/matrix/subset.js +85 -25
- package/lib/esm/function/special/zeta.js +146 -0
- package/lib/esm/function/statistics/quantileSeq.js +30 -16
- package/lib/esm/type/matrix/DenseMatrix.js +20 -10
- package/lib/esm/type/matrix/MatrixIndex.js +39 -7
- package/lib/esm/type/matrix/function/index.js +6 -4
- package/lib/esm/type/matrix/utils/broadcast.js +8 -14
- package/lib/esm/utils/array.js +241 -20
- package/lib/esm/version.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +16 -0
|
@@ -9,9 +9,10 @@ var _object = require("../../utils/object.js");
|
|
|
9
9
|
var _number = require("../../utils/number.js");
|
|
10
10
|
var _factory = require("../../utils/factory.js");
|
|
11
11
|
var name = 'Index';
|
|
12
|
-
var dependencies = ['ImmutableDenseMatrix'];
|
|
12
|
+
var dependencies = ['ImmutableDenseMatrix', 'getMatrixDataType'];
|
|
13
13
|
var createIndexClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
|
14
|
-
var ImmutableDenseMatrix = _ref.ImmutableDenseMatrix
|
|
14
|
+
var ImmutableDenseMatrix = _ref.ImmutableDenseMatrix,
|
|
15
|
+
getMatrixDataType = _ref.getMatrixDataType;
|
|
15
16
|
/**
|
|
16
17
|
* Create an index. An Index can store ranges and sets for multiple dimensions.
|
|
17
18
|
* Matrix.get, Matrix.set, and math.subset accept an Index as input.
|
|
@@ -24,7 +25,9 @@ var createIndexClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
|
24
25
|
* A string (containing a name of an object property)
|
|
25
26
|
* An instance of Range
|
|
26
27
|
* An Array with the Set values
|
|
28
|
+
* An Array with Booleans
|
|
27
29
|
* A Matrix with the Set values
|
|
30
|
+
* A Matrix with Booleans
|
|
28
31
|
*
|
|
29
32
|
* The parameters start, end, and step must be integer numbers.
|
|
30
33
|
*
|
|
@@ -37,20 +40,31 @@ var createIndexClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
|
37
40
|
throw new SyntaxError('Constructor must be called with the new operator');
|
|
38
41
|
}
|
|
39
42
|
this._dimensions = [];
|
|
43
|
+
this._sourceSize = [];
|
|
40
44
|
this._isScalar = true;
|
|
41
45
|
for (var i = 0, ii = arguments.length; i < ii; i++) {
|
|
42
46
|
var arg = arguments[i];
|
|
47
|
+
var argIsArray = (0, _is.isArray)(arg);
|
|
48
|
+
var argIsMatrix = (0, _is.isMatrix)(arg);
|
|
49
|
+
var sourceSize = null;
|
|
43
50
|
if ((0, _is.isRange)(arg)) {
|
|
44
51
|
this._dimensions.push(arg);
|
|
45
52
|
this._isScalar = false;
|
|
46
|
-
} else if (
|
|
53
|
+
} else if (argIsArray || argIsMatrix) {
|
|
47
54
|
// create matrix
|
|
48
|
-
var m =
|
|
55
|
+
var m = void 0;
|
|
56
|
+
if (getMatrixDataType(arg) === 'boolean') {
|
|
57
|
+
if (argIsArray) m = _createImmutableMatrix(_booleansArrayToNumbersForIndex(arg).valueOf());
|
|
58
|
+
if (argIsMatrix) m = _createImmutableMatrix(_booleansArrayToNumbersForIndex(arg._data).valueOf());
|
|
59
|
+
sourceSize = arg.valueOf().length;
|
|
60
|
+
} else {
|
|
61
|
+
m = _createImmutableMatrix(arg.valueOf());
|
|
62
|
+
}
|
|
49
63
|
this._dimensions.push(m);
|
|
50
64
|
// size
|
|
51
65
|
var size = m.size();
|
|
52
66
|
// scalar
|
|
53
|
-
if (size.length !== 1 || size[0] !== 1) {
|
|
67
|
+
if (size.length !== 1 || size[0] !== 1 || sourceSize !== null) {
|
|
54
68
|
this._isScalar = false;
|
|
55
69
|
}
|
|
56
70
|
} else if (typeof arg === 'number') {
|
|
@@ -61,6 +75,7 @@ var createIndexClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
|
61
75
|
} else {
|
|
62
76
|
throw new TypeError('Dimension must be an Array, Matrix, number, string, or Range');
|
|
63
77
|
}
|
|
78
|
+
this._sourceSize.push(sourceSize);
|
|
64
79
|
// TODO: implement support for wildcard '*'
|
|
65
80
|
}
|
|
66
81
|
}
|
|
@@ -90,6 +105,7 @@ var createIndexClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
|
90
105
|
var index = new Index();
|
|
91
106
|
index._dimensions = (0, _object.clone)(this._dimensions);
|
|
92
107
|
index._isScalar = this._isScalar;
|
|
108
|
+
index._sourceSize = this._sourceSize;
|
|
93
109
|
return index;
|
|
94
110
|
};
|
|
95
111
|
|
|
@@ -268,4 +284,20 @@ var createIndexClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
|
268
284
|
}, {
|
|
269
285
|
isClass: true
|
|
270
286
|
});
|
|
271
|
-
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Receives an array of booleans and returns an array of Numbers for Index
|
|
290
|
+
* @param {Array} booleanArrayIndex An array of booleans
|
|
291
|
+
* @return {Array} A set of numbers ready for index
|
|
292
|
+
*/
|
|
293
|
+
exports.createIndexClass = createIndexClass;
|
|
294
|
+
function _booleansArrayToNumbersForIndex(booleanArrayIndex) {
|
|
295
|
+
// gets an array of booleans and returns an array of numbers
|
|
296
|
+
var indexOfNumbers = [];
|
|
297
|
+
booleanArrayIndex.forEach(function (bool, idx) {
|
|
298
|
+
if (bool) {
|
|
299
|
+
indexOfNumbers.push(idx);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
return indexOfNumbers;
|
|
303
|
+
}
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createIndex = void 0;
|
|
7
|
-
var _factory = require("../../../utils/factory.js");
|
|
8
7
|
var _is = require("../../../utils/is.js");
|
|
8
|
+
var _factory = require("../../../utils/factory.js");
|
|
9
9
|
var name = 'index';
|
|
10
10
|
var dependencies = ['typed', 'Index'];
|
|
11
11
|
var createIndex = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
|
@@ -25,17 +25,19 @@ var createIndex = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
|
25
25
|
* - A number
|
|
26
26
|
* - A string for getting/setting an object property
|
|
27
27
|
* - An instance of `Range`
|
|
28
|
-
* - A one-dimensional Array or a Matrix with numbers
|
|
28
|
+
* - A one-dimensional Array or a Matrix with numbers or booleans
|
|
29
29
|
*
|
|
30
30
|
* Indexes must be zero-based, integer numbers.
|
|
31
31
|
*
|
|
32
32
|
* Examples:
|
|
33
33
|
*
|
|
34
34
|
* const b = [1, 2, 3, 4, 5]
|
|
35
|
-
* math.subset(b, math.index([1, 2, 3]))
|
|
35
|
+
* math.subset(b, math.index([1, 2, 3])) // returns [2, 3, 4]
|
|
36
|
+
* math.subset(b, math.index([false, true, true, true, false])) // returns [2, 3, 4]
|
|
36
37
|
*
|
|
37
38
|
* const a = math.matrix([[1, 2], [3, 4]])
|
|
38
39
|
* a.subset(math.index(0, 1)) // returns 2
|
|
40
|
+
* a.subset(math.index(0, [false, true])) // returns 2
|
|
39
41
|
*
|
|
40
42
|
* See also:
|
|
41
43
|
*
|
|
@@ -49,7 +51,7 @@ var createIndex = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
|
49
51
|
var ranges = args.map(function (arg) {
|
|
50
52
|
if ((0, _is.isBigNumber)(arg)) {
|
|
51
53
|
return arg.toNumber(); // convert BigNumber to Number
|
|
52
|
-
} else if (
|
|
54
|
+
} else if ((0, _is.isArray)(arg) || (0, _is.isMatrix)(arg)) {
|
|
53
55
|
return arg.map(function (elem) {
|
|
54
56
|
// convert BigNumber to Number
|
|
55
57
|
return (0, _is.isBigNumber)(elem) ? elem.toNumber() : elem;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createBroadcast = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _array = require("../../../utils/array.js");
|
|
9
10
|
var _factory = require("../../../utils/factory.js");
|
|
10
11
|
var name = 'broadcast';
|
|
11
12
|
var dependancies = ['concat'];
|
|
@@ -40,10 +41,8 @@ var createBroadcast = /* #__PURE__ */(0, _factory.factory)(name, dependancies, f
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
// check if the broadcasting rules applyes for both matrices
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
_checkRules(sizeB, sizeMax, _dim);
|
|
46
|
-
}
|
|
44
|
+
(0, _array.checkBroadcastingRules)(sizeA, sizeMax);
|
|
45
|
+
(0, _array.checkBroadcastingRules)(sizeB, sizeMax);
|
|
47
46
|
|
|
48
47
|
// reshape A or B if needed to make them ready for concat
|
|
49
48
|
var AA = A.clone();
|
|
@@ -55,12 +54,12 @@ var createBroadcast = /* #__PURE__ */(0, _factory.factory)(name, dependancies, f
|
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
// stretches the matrices on each dimension to make them the same size
|
|
58
|
-
for (var
|
|
59
|
-
if (AA._size[
|
|
60
|
-
AA = _stretch(AA, sizeMax[
|
|
57
|
+
for (var _dim = 0; _dim < N; _dim++) {
|
|
58
|
+
if (AA._size[_dim] < sizeMax[_dim]) {
|
|
59
|
+
AA = _stretch(AA, sizeMax[_dim], _dim);
|
|
61
60
|
}
|
|
62
|
-
if (BB._size[
|
|
63
|
-
BB = _stretch(BB, sizeMax[
|
|
61
|
+
if (BB._size[_dim] < sizeMax[_dim]) {
|
|
62
|
+
BB = _stretch(BB, sizeMax[_dim], _dim);
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
|
|
@@ -75,10 +74,5 @@ var createBroadcast = /* #__PURE__ */(0, _factory.factory)(name, dependancies, f
|
|
|
75
74
|
// stretches a matrix up to a certain size in a certain dimension
|
|
76
75
|
return concat.apply(void 0, (0, _toConsumableArray2["default"])(Array(sizeToStretch).fill(arrayToStretch)).concat([dimToStretch]));
|
|
77
76
|
}
|
|
78
|
-
function _checkRules(shape, sizeMax, dim) {
|
|
79
|
-
if (shape[dim] < sizeMax[dim] & shape[dim] > 1) {
|
|
80
|
-
throw new Error("shape missmatch: missmatch is found in arg with shape (".concat(shape, ") not possible to broadcast dimension ").concat(dim, " with size ").concat(shape[dim], " to size ").concat(sizeMax[dim]));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
77
|
});
|
|
84
78
|
exports.createBroadcast = createBroadcast;
|
package/lib/cjs/utils/array.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.arraySize = arraySize;
|
|
8
|
+
exports.broadcastArrays = broadcastArrays;
|
|
9
|
+
exports.broadcastSizes = broadcastSizes;
|
|
10
|
+
exports.broadcastTo = broadcastTo;
|
|
11
|
+
exports.checkBroadcastingRules = checkBroadcastingRules;
|
|
12
|
+
exports.clone = clone;
|
|
13
|
+
exports.concat = concat;
|
|
7
14
|
exports.contains = contains;
|
|
8
15
|
exports.filter = filter;
|
|
9
16
|
exports.filterRegExp = filterRegExp;
|
|
@@ -13,6 +20,7 @@ exports.generalize = generalize;
|
|
|
13
20
|
exports.getArrayDataType = getArrayDataType;
|
|
14
21
|
exports.identify = identify;
|
|
15
22
|
exports.initial = initial;
|
|
23
|
+
exports.isEmptyIndex = isEmptyIndex;
|
|
16
24
|
exports.join = join;
|
|
17
25
|
exports.last = last;
|
|
18
26
|
exports.map = map;
|
|
@@ -20,14 +28,19 @@ exports.processSizesWildcard = processSizesWildcard;
|
|
|
20
28
|
exports.reshape = reshape;
|
|
21
29
|
exports.resize = resize;
|
|
22
30
|
exports.squeeze = squeeze;
|
|
31
|
+
exports.stretch = stretch;
|
|
23
32
|
exports.unsqueeze = unsqueeze;
|
|
24
33
|
exports.validate = validate;
|
|
25
34
|
exports.validateIndex = validateIndex;
|
|
35
|
+
exports.validateIndexSourceSize = validateIndexSourceSize;
|
|
36
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
37
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
26
38
|
var _number = require("./number.js");
|
|
27
39
|
var _is = require("./is.js");
|
|
28
40
|
var _string = require("./string.js");
|
|
29
41
|
var _DimensionError = require("../error/DimensionError.js");
|
|
30
42
|
var _IndexError = require("../error/IndexError.js");
|
|
43
|
+
var _object = require("./object.js");
|
|
31
44
|
/**
|
|
32
45
|
* Calculate the size of a multi dimensional array.
|
|
33
46
|
* This function checks the size of the first entry, it does not validate
|
|
@@ -99,6 +112,23 @@ function validate(array, size) {
|
|
|
99
112
|
}
|
|
100
113
|
}
|
|
101
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Validate whether the source of the index matches the size of the Array
|
|
117
|
+
* @param {Array | Matrix} array Array to be validated
|
|
118
|
+
* @param {Index} index Index with the source information to validate
|
|
119
|
+
* @throws DimensionError
|
|
120
|
+
*/
|
|
121
|
+
function validateIndexSourceSize(value, index) {
|
|
122
|
+
var valueSize = value.isMatrix ? value._size : arraySize(value);
|
|
123
|
+
var sourceSize = index._sourceSize;
|
|
124
|
+
// checks if the source size is not null and matches the valueSize
|
|
125
|
+
sourceSize.forEach(function (sourceDim, i) {
|
|
126
|
+
if (sourceDim !== null && sourceDim !== valueSize[i]) {
|
|
127
|
+
throw new _DimensionError.DimensionError(sourceDim, valueSize[i]);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
102
132
|
/**
|
|
103
133
|
* Test whether index is an integer number with index >= 0 and index < length
|
|
104
134
|
* when length is provided
|
|
@@ -106,18 +136,44 @@ function validate(array, size) {
|
|
|
106
136
|
* @param {number} [length] Length of the array
|
|
107
137
|
*/
|
|
108
138
|
function validateIndex(index, length) {
|
|
109
|
-
if (
|
|
110
|
-
|
|
139
|
+
if (index !== undefined) {
|
|
140
|
+
if (!(0, _is.isNumber)(index) || !(0, _number.isInteger)(index)) {
|
|
141
|
+
throw new TypeError('Index must be an integer (value: ' + index + ')');
|
|
142
|
+
}
|
|
143
|
+
if (index < 0 || typeof length === 'number' && index >= length) {
|
|
144
|
+
throw new _IndexError.IndexError(index, length);
|
|
145
|
+
}
|
|
111
146
|
}
|
|
112
|
-
|
|
113
|
-
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Test if and index has empty values
|
|
151
|
+
* @param {number} index Zero-based index
|
|
152
|
+
*/
|
|
153
|
+
function isEmptyIndex(index) {
|
|
154
|
+
for (var i = 0; i < index._dimensions.length; ++i) {
|
|
155
|
+
var dimension = index._dimensions[i];
|
|
156
|
+
if (dimension._data && (0, _is.isArray)(dimension._data)) {
|
|
157
|
+
if (dimension._size[0] === 0) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
} else if (dimension.isRange) {
|
|
161
|
+
if (dimension.start === dimension.end) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
} else if ((0, _is.isString)(dimension)) {
|
|
165
|
+
if (dimension.length === 0) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
114
169
|
}
|
|
170
|
+
return false;
|
|
115
171
|
}
|
|
116
172
|
|
|
117
173
|
/**
|
|
118
174
|
* Resize a multi dimensional array. The resized array is returned.
|
|
119
|
-
* @param {Array} array Array to be resized
|
|
120
|
-
* @param {
|
|
175
|
+
* @param {Array | number} array Array to be resized
|
|
176
|
+
* @param {number[]} size Array with the size of each dimension
|
|
121
177
|
* @param {*} [defaultValue=0] Value to be filled in in new entries,
|
|
122
178
|
* zero by default. Specify for example `null`,
|
|
123
179
|
* to clearly see entries that are not explicitly
|
|
@@ -125,10 +181,8 @@ function validateIndex(index, length) {
|
|
|
125
181
|
* @return {Array} array The resized array
|
|
126
182
|
*/
|
|
127
183
|
function resize(array, size, defaultValue) {
|
|
128
|
-
// TODO: add support for scalars, having size=[] ?
|
|
129
|
-
|
|
130
184
|
// check the type of the arguments
|
|
131
|
-
if (!Array.isArray(
|
|
185
|
+
if (!Array.isArray(size)) {
|
|
132
186
|
throw new TypeError('Array expected');
|
|
133
187
|
}
|
|
134
188
|
if (size.length === 0) {
|
|
@@ -142,6 +196,11 @@ function resize(array, size, defaultValue) {
|
|
|
142
196
|
}
|
|
143
197
|
});
|
|
144
198
|
|
|
199
|
+
// convert number to an array
|
|
200
|
+
if ((0, _is.isNumber)(array) || (0, _is.isBigNumber)(array)) {
|
|
201
|
+
array = [array];
|
|
202
|
+
}
|
|
203
|
+
|
|
145
204
|
// recursively resize the array
|
|
146
205
|
var _defaultValue = defaultValue !== undefined ? defaultValue : 0;
|
|
147
206
|
_resize(array, size, 0, _defaultValue);
|
|
@@ -210,7 +269,7 @@ function _resize(array, size, dim, defaultValue) {
|
|
|
210
269
|
/**
|
|
211
270
|
* Re-shape a multi dimensional array to fit the specified dimensions
|
|
212
271
|
* @param {Array} array Array to be reshaped
|
|
213
|
-
* @param {
|
|
272
|
+
* @param {number[]} sizes List of sizes for each dimension
|
|
214
273
|
* @returns {Array} Array whose data has been formatted to fit the
|
|
215
274
|
* specified dimensions
|
|
216
275
|
*
|
|
@@ -243,10 +302,10 @@ function reshape(array, sizes) {
|
|
|
243
302
|
|
|
244
303
|
/**
|
|
245
304
|
* Replaces the wildcard -1 in the sizes array.
|
|
246
|
-
* @param {
|
|
305
|
+
* @param {number[]} sizes List of sizes for each dimension. At most on wildcard.
|
|
247
306
|
* @param {number} currentLength Number of elements in the array.
|
|
248
307
|
* @throws {Error} If more than one wildcard or unable to replace it.
|
|
249
|
-
* @returns {
|
|
308
|
+
* @returns {number[]} The sizes array with wildcard replaced.
|
|
250
309
|
*/
|
|
251
310
|
function processSizesWildcard(sizes, currentLength) {
|
|
252
311
|
var newLength = product(sizes);
|
|
@@ -271,7 +330,7 @@ function processSizesWildcard(sizes, currentLength) {
|
|
|
271
330
|
|
|
272
331
|
/**
|
|
273
332
|
* Computes the product of all array elements.
|
|
274
|
-
* @param {
|
|
333
|
+
* @param {number[]} array Array of factors
|
|
275
334
|
* @returns {number} Product of all elements
|
|
276
335
|
*/
|
|
277
336
|
function product(array) {
|
|
@@ -283,7 +342,7 @@ function product(array) {
|
|
|
283
342
|
/**
|
|
284
343
|
* Iteratively re-shape a multi dimensional array to fit the specified dimensions
|
|
285
344
|
* @param {Array} array Array to be reshaped
|
|
286
|
-
* @param {
|
|
345
|
+
* @param {number[]} sizes List of sizes for each dimension
|
|
287
346
|
* @returns {Array} Array whose data has been formatted to fit the
|
|
288
347
|
* specified dimensions
|
|
289
348
|
*/
|
|
@@ -556,18 +615,18 @@ function getArrayDataType(array, typeOf) {
|
|
|
556
615
|
|
|
557
616
|
for (var i = 0; i < array.length; i++) {
|
|
558
617
|
var item = array[i];
|
|
559
|
-
var
|
|
618
|
+
var _isArray = Array.isArray(item);
|
|
560
619
|
|
|
561
620
|
// Saving the target matrix row size
|
|
562
|
-
if (i === 0 &&
|
|
621
|
+
if (i === 0 && _isArray) {
|
|
563
622
|
length = item.length;
|
|
564
623
|
}
|
|
565
624
|
|
|
566
625
|
// If the current item is an array but the length does not equal the targetVectorSize
|
|
567
|
-
if (
|
|
626
|
+
if (_isArray && item.length !== length) {
|
|
568
627
|
return undefined;
|
|
569
628
|
}
|
|
570
|
-
var itemType =
|
|
629
|
+
var itemType = _isArray ? getArrayDataType(item, typeOf) // recurse into a nested array
|
|
571
630
|
: typeOf(item);
|
|
572
631
|
if (type === undefined) {
|
|
573
632
|
type = itemType; // first item
|
|
@@ -582,7 +641,7 @@ function getArrayDataType(array, typeOf) {
|
|
|
582
641
|
|
|
583
642
|
/**
|
|
584
643
|
* Return the last item from an array
|
|
585
|
-
* @param array
|
|
644
|
+
* @param {array}
|
|
586
645
|
* @returns {*}
|
|
587
646
|
*/
|
|
588
647
|
function last(array) {
|
|
@@ -591,6 +650,8 @@ function last(array) {
|
|
|
591
650
|
|
|
592
651
|
/**
|
|
593
652
|
* Get all but the last element of array.
|
|
653
|
+
* @param {array}
|
|
654
|
+
* @returns {*}
|
|
594
655
|
*/
|
|
595
656
|
function initial(array) {
|
|
596
657
|
return array.slice(0, array.length - 1);
|
|
@@ -604,4 +665,177 @@ function initial(array) {
|
|
|
604
665
|
*/
|
|
605
666
|
function contains(array, item) {
|
|
606
667
|
return array.indexOf(item) !== -1;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Recursively concatenate two matrices.
|
|
672
|
+
* The contents of the matrices is not cloned.
|
|
673
|
+
* @param {Array} a Multi dimensional array
|
|
674
|
+
* @param {Array} b Multi dimensional array
|
|
675
|
+
* @param {number} concatDim The dimension on which to concatenate (zero-based)
|
|
676
|
+
* @param {number} dim The current dim (zero-based)
|
|
677
|
+
* @return {Array} c The concatenated matrix
|
|
678
|
+
* @private
|
|
679
|
+
*/
|
|
680
|
+
function concatRecursive(a, b, concatDim, dim) {
|
|
681
|
+
if (dim < concatDim) {
|
|
682
|
+
// recurse into next dimension
|
|
683
|
+
if (a.length !== b.length) {
|
|
684
|
+
throw new _DimensionError.DimensionError(a.length, b.length);
|
|
685
|
+
}
|
|
686
|
+
var c = [];
|
|
687
|
+
for (var i = 0; i < a.length; i++) {
|
|
688
|
+
c[i] = concatRecursive(a[i], b[i], concatDim, dim + 1);
|
|
689
|
+
}
|
|
690
|
+
return c;
|
|
691
|
+
} else {
|
|
692
|
+
// concatenate this dimension
|
|
693
|
+
return a.concat(b);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Concatenates many arrays in the specified direction
|
|
699
|
+
* @param {...Array} arrays All the arrays to concatenate
|
|
700
|
+
* @param {number} concatDim The dimension on which to concatenate (zero-based)
|
|
701
|
+
* @returns
|
|
702
|
+
*/
|
|
703
|
+
function concat() {
|
|
704
|
+
var arrays = Array.prototype.slice.call(arguments, 0, -1);
|
|
705
|
+
var concatDim = Array.prototype.slice.call(arguments, -1);
|
|
706
|
+
if (arrays.length === 1) {
|
|
707
|
+
return arrays[0];
|
|
708
|
+
}
|
|
709
|
+
if (arrays.length > 1) {
|
|
710
|
+
return arrays.slice(1).reduce(function (A, B) {
|
|
711
|
+
return concatRecursive(A, B, concatDim, 0);
|
|
712
|
+
}, arrays[0]);
|
|
713
|
+
} else {
|
|
714
|
+
throw new Error('Wrong number of arguments in function concat');
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Receives two or more sizes and get's the broadcasted size for both.
|
|
720
|
+
* @param {...number[]} sizes Sizes to broadcast together
|
|
721
|
+
* @returns
|
|
722
|
+
*/
|
|
723
|
+
function broadcastSizes() {
|
|
724
|
+
for (var _len = arguments.length, sizes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
725
|
+
sizes[_key] = arguments[_key];
|
|
726
|
+
}
|
|
727
|
+
var dimensions = sizes.map(function (s) {
|
|
728
|
+
return s.length;
|
|
729
|
+
});
|
|
730
|
+
var N = Math.max.apply(Math, (0, _toConsumableArray2["default"])(dimensions));
|
|
731
|
+
var sizeMax = new Array(N).fill(null);
|
|
732
|
+
// check for every size
|
|
733
|
+
for (var i = 0; i < sizes.length; i++) {
|
|
734
|
+
var size = sizes[i];
|
|
735
|
+
var dim = dimensions[i];
|
|
736
|
+
for (var j = 0; j < dim; j++) {
|
|
737
|
+
var n = N - dim + j;
|
|
738
|
+
if (size[j] > sizeMax[n]) {
|
|
739
|
+
sizeMax[n] = size[j];
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
for (var _i = 0; _i < sizes.length; _i++) {
|
|
744
|
+
checkBroadcastingRules(sizes[_i], sizeMax);
|
|
745
|
+
}
|
|
746
|
+
return sizeMax;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Checks if it's possible to broadcast a size to another size
|
|
751
|
+
* @param {number[]} size The size of the array to check
|
|
752
|
+
* @param {number[]} toSize The size of the array to validate if it can be broadcasted to
|
|
753
|
+
*/
|
|
754
|
+
function checkBroadcastingRules(size, toSize) {
|
|
755
|
+
var N = toSize.length;
|
|
756
|
+
var dim = size.length;
|
|
757
|
+
for (var j = 0; j < dim; j++) {
|
|
758
|
+
var n = N - dim + j;
|
|
759
|
+
if (size[j] < toSize[n] && size[j] > 1 || size[j] > toSize[n]) {
|
|
760
|
+
throw new Error("shape missmatch: missmatch is found in arg with shape (".concat(size, ") not possible to broadcast dimension ").concat(dim, " with size ").concat(size[j], " to size ").concat(toSize[n]));
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Broadcasts a single array to a certain size
|
|
767
|
+
* @param {array} array Array to be broadcasted
|
|
768
|
+
* @param {number[]} toSize Size to broadcast the array
|
|
769
|
+
* @returns The broadcasted array
|
|
770
|
+
*/
|
|
771
|
+
function broadcastTo(array, toSize) {
|
|
772
|
+
var Asize = arraySize(array);
|
|
773
|
+
if ((0, _object.deepStrictEqual)(Asize, toSize)) {
|
|
774
|
+
return array;
|
|
775
|
+
}
|
|
776
|
+
checkBroadcastingRules(Asize, toSize);
|
|
777
|
+
var broadcastedSize = broadcastSizes(Asize, toSize);
|
|
778
|
+
var N = broadcastedSize.length;
|
|
779
|
+
var paddedSize = [].concat((0, _toConsumableArray2["default"])(Array(N - Asize.length).fill(1)), (0, _toConsumableArray2["default"])(Asize));
|
|
780
|
+
var A = clone(array);
|
|
781
|
+
// reshape A if needed to make it ready for concat
|
|
782
|
+
if (Asize.length < N) {
|
|
783
|
+
A = reshape(A, paddedSize);
|
|
784
|
+
Asize = arraySize(A);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// stretches the array on each dimension to make it the same size as index
|
|
788
|
+
for (var dim = 0; dim < N; dim++) {
|
|
789
|
+
if (Asize[dim] < broadcastedSize[dim]) {
|
|
790
|
+
A = stretch(A, broadcastedSize[dim], dim);
|
|
791
|
+
Asize = arraySize(A);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return A;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Broadcasts arrays and returns the broadcasted arrays in an array
|
|
799
|
+
* @param {...Array | any} arrays
|
|
800
|
+
* @returns
|
|
801
|
+
*/
|
|
802
|
+
function broadcastArrays() {
|
|
803
|
+
for (var _len2 = arguments.length, arrays = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
804
|
+
arrays[_key2] = arguments[_key2];
|
|
805
|
+
}
|
|
806
|
+
if (arrays.length === 0) {
|
|
807
|
+
throw new Error('Insuficient number of argumnets in function broadcastArrays');
|
|
808
|
+
}
|
|
809
|
+
if (arrays.length === 1) {
|
|
810
|
+
return arrays[0];
|
|
811
|
+
}
|
|
812
|
+
var sizes = arrays.map(function (array) {
|
|
813
|
+
return arraySize(array);
|
|
814
|
+
});
|
|
815
|
+
var broadcastedSize = broadcastSizes.apply(void 0, (0, _toConsumableArray2["default"])(sizes));
|
|
816
|
+
var broadcastedArrays = [];
|
|
817
|
+
arrays.forEach(function (array) {
|
|
818
|
+
broadcastedArrays.push(broadcastTo(array, broadcastedSize));
|
|
819
|
+
});
|
|
820
|
+
return broadcastedArrays;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* stretches a matrix up to a certain size in a certain dimension
|
|
825
|
+
* @param {Array} arrayToStretch
|
|
826
|
+
* @param {number[]} sizeToStretch
|
|
827
|
+
* @param {number} dimToStretch
|
|
828
|
+
* @returns
|
|
829
|
+
*/
|
|
830
|
+
function stretch(arrayToStretch, sizeToStretch, dimToStretch) {
|
|
831
|
+
return concat.apply(void 0, (0, _toConsumableArray2["default"])(Array(sizeToStretch).fill(arrayToStretch)).concat([dimToStretch]));
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Deep clones a multidimensional array
|
|
836
|
+
* @param {Array} array
|
|
837
|
+
* @returns cloned array
|
|
838
|
+
*/
|
|
839
|
+
function clone(array) {
|
|
840
|
+
return (0, _extends2["default"])([], array);
|
|
607
841
|
}
|
package/lib/cjs/version.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.version = void 0;
|
|
7
|
-
var version = '11.
|
|
7
|
+
var version = '11.10.0';
|
|
8
8
|
// Note: This file is automatically generated when building math.js.
|
|
9
9
|
// Changes made in this file will be overwritten.
|
|
10
10
|
exports.version = version;
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* DON'T MAKE CHANGES HERE
|
|
4
4
|
*/
|
|
5
5
|
import { ImmutableDenseMatrixDependencies } from './dependenciesImmutableDenseMatrixClass.generated.js';
|
|
6
|
+
import { getMatrixDataTypeDependencies } from './dependenciesGetMatrixDataType.generated.js';
|
|
6
7
|
import { createIndexClass } from '../../factoriesAny.js';
|
|
7
8
|
export var IndexDependencies = {
|
|
8
9
|
ImmutableDenseMatrixDependencies,
|
|
10
|
+
getMatrixDataTypeDependencies,
|
|
9
11
|
createIndexClass
|
|
10
12
|
};
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* DON'T MAKE CHANGES HERE
|
|
4
4
|
*/
|
|
5
5
|
import { IndexDependencies } from './dependenciesIndexClass.generated.js';
|
|
6
|
+
import { getMatrixDataTypeDependencies } from './dependenciesGetMatrixDataType.generated.js';
|
|
6
7
|
import { createIndexTransform } from '../../factoriesAny.js';
|
|
7
8
|
export var indexTransformDependencies = {
|
|
8
9
|
IndexDependencies,
|
|
10
|
+
getMatrixDataTypeDependencies,
|
|
9
11
|
createIndexTransform
|
|
10
12
|
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { addDependencies } from './dependenciesAdd.generated.js';
|
|
6
6
|
import { compareDependencies } from './dependenciesCompare.generated.js';
|
|
7
|
+
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
|
7
8
|
import { multiplyDependencies } from './dependenciesMultiply.generated.js';
|
|
8
9
|
import { partitionSelectDependencies } from './dependenciesPartitionSelect.generated.js';
|
|
9
10
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
@@ -11,6 +12,7 @@ import { createQuantileSeq } from '../../factoriesAny.js';
|
|
|
11
12
|
export var quantileSeqDependencies = {
|
|
12
13
|
addDependencies,
|
|
13
14
|
compareDependencies,
|
|
15
|
+
isIntegerDependencies,
|
|
14
16
|
multiplyDependencies,
|
|
15
17
|
partitionSelectDependencies,
|
|
16
18
|
typedDependencies,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED
|
|
3
|
+
* DON'T MAKE CHANGES HERE
|
|
4
|
+
*/
|
|
5
|
+
import { addDependencies } from './dependenciesAdd.generated.js';
|
|
6
|
+
import { compareDependencies } from './dependenciesCompare.generated.js';
|
|
7
|
+
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
|
8
|
+
import { multiplyDependencies } from './dependenciesMultiply.generated.js';
|
|
9
|
+
import { partitionSelectDependencies } from './dependenciesPartitionSelect.generated.js';
|
|
10
|
+
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
11
|
+
import { createQuantileSeqTransform } from '../../factoriesAny.js';
|
|
12
|
+
export var quantileSeqTransformDependencies = {
|
|
13
|
+
addDependencies,
|
|
14
|
+
compareDependencies,
|
|
15
|
+
isIntegerDependencies,
|
|
16
|
+
multiplyDependencies,
|
|
17
|
+
partitionSelectDependencies,
|
|
18
|
+
typedDependencies,
|
|
19
|
+
createQuantileSeqTransform
|
|
20
|
+
};
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
* THIS FILE IS AUTO-GENERATED
|
|
3
3
|
* DON'T MAKE CHANGES HERE
|
|
4
4
|
*/
|
|
5
|
+
import { addDependencies } from './dependenciesAdd.generated.js';
|
|
5
6
|
import { matrixDependencies } from './dependenciesMatrix.generated.js';
|
|
6
7
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
8
|
+
import { zerosDependencies } from './dependenciesZeros.generated.js';
|
|
7
9
|
import { createSubset } from '../../factoriesAny.js';
|
|
8
10
|
export var subsetDependencies = {
|
|
11
|
+
addDependencies,
|
|
9
12
|
matrixDependencies,
|
|
10
13
|
typedDependencies,
|
|
14
|
+
zerosDependencies,
|
|
11
15
|
createSubset
|
|
12
16
|
};
|