mathjs 13.0.2 → 13.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +26 -1
- 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/core/create.js +12 -9
- package/lib/cjs/core/function/import.js +1 -1
- package/lib/cjs/core/function/typed.js +3 -4
- package/lib/cjs/entry/dependenciesAny/dependenciesFlatten.generated.js +0 -2
- package/lib/cjs/entry/dependenciesAny/dependenciesSqueeze.generated.js +0 -2
- package/lib/cjs/entry/impureFunctionsAny.generated.js +2 -2
- package/lib/cjs/entry/pureFunctionsAny.generated.js +6 -8
- package/lib/cjs/entry/typeChecks.js +18 -0
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +2 -2
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/hypot.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/diff.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/fft.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/ifft.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/kron.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/map.js +3 -3
- package/lib/cjs/expression/embeddedDocs/function/special/zeta.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/statistics/quantileSeq.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/trigonometry/acoth.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/trigonometry/acsch.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/utils/clone.js +1 -1
- package/lib/cjs/expression/function/evaluate.js +5 -0
- package/lib/cjs/expression/node/FunctionNode.js +1 -1
- package/lib/cjs/expression/transform/filter.transform.js +2 -2
- package/lib/cjs/expression/transform/map.transform.js +104 -37
- package/lib/cjs/expression/transform/utils/dimToZeroBase.js +23 -0
- package/lib/cjs/expression/transform/utils/lastDimToZeroBase.js +3 -4
- package/lib/cjs/function/arithmetic/hypot.js +3 -3
- package/lib/cjs/function/matrix/apply.js +1 -1
- package/lib/cjs/function/matrix/fft.js +3 -3
- package/lib/cjs/function/matrix/filter.js +2 -2
- package/lib/cjs/function/matrix/flatten.js +5 -6
- package/lib/cjs/function/matrix/ifft.js +2 -2
- package/lib/cjs/function/matrix/kron.js +4 -4
- package/lib/cjs/function/matrix/map.js +109 -18
- package/lib/cjs/function/matrix/size.js +7 -7
- package/lib/cjs/function/matrix/squeeze.js +3 -4
- package/lib/cjs/function/probability/random.js +1 -1
- package/lib/cjs/function/probability/randomInt.js +1 -1
- package/lib/cjs/function/statistics/cumsum.js +2 -2
- package/lib/cjs/function/trigonometry/acoth.js +2 -2
- package/lib/cjs/function/trigonometry/acsch.js +2 -2
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/matrix/DenseMatrix.js +3 -28
- package/lib/cjs/type/matrix/SparseMatrix.js +5 -8
- package/lib/cjs/type/unit/Unit.js +57 -114
- package/lib/cjs/utils/array.js +27 -0
- package/lib/cjs/utils/collection.js +1 -1
- package/lib/cjs/utils/function.js +0 -14
- package/lib/cjs/utils/is.js +27 -0
- package/lib/cjs/utils/map.js +2 -20
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/create.js +9 -6
- package/lib/esm/core/function/import.js +1 -1
- package/lib/esm/core/function/typed.js +2 -3
- package/lib/esm/entry/dependenciesAny/dependenciesFlatten.generated.js +0 -2
- package/lib/esm/entry/dependenciesAny/dependenciesSqueeze.generated.js +0 -2
- package/lib/esm/entry/impureFunctionsAny.generated.js +3 -3
- package/lib/esm/entry/pureFunctionsAny.generated.js +7 -9
- package/lib/esm/entry/typeChecks.js +1 -1
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +2 -2
- package/lib/esm/expression/embeddedDocs/function/arithmetic/hypot.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/diff.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/fft.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/ifft.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/kron.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/map.js +3 -3
- package/lib/esm/expression/embeddedDocs/function/special/zeta.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/statistics/quantileSeq.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/trigonometry/acoth.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/trigonometry/acsch.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/utils/clone.js +1 -1
- package/lib/esm/expression/function/compile.js +1 -1
- package/lib/esm/expression/function/evaluate.js +8 -3
- package/lib/esm/expression/node/FunctionNode.js +1 -1
- package/lib/esm/expression/parse.js +2 -2
- package/lib/esm/expression/transform/filter.transform.js +4 -4
- package/lib/esm/expression/transform/forEach.transform.js +4 -4
- package/lib/esm/expression/transform/map.transform.js +104 -37
- package/lib/esm/expression/transform/print.transform.js +2 -2
- package/lib/esm/expression/transform/utils/dimToZeroBase.js +16 -0
- package/lib/esm/expression/transform/utils/lastDimToZeroBase.js +4 -6
- package/lib/esm/function/algebra/decomposition/slu.js +1 -1
- package/lib/esm/function/algebra/derivative.js +15 -15
- package/lib/esm/function/algebra/lyap.js +4 -4
- package/lib/esm/function/algebra/simplify/util.js +3 -3
- package/lib/esm/function/algebra/simplifyConstant.js +9 -9
- package/lib/esm/function/algebra/solver/lsolve.js +3 -3
- package/lib/esm/function/algebra/solver/lsolveAll.js +3 -3
- package/lib/esm/function/algebra/solver/lusolve.js +5 -5
- package/lib/esm/function/algebra/solver/usolve.js +3 -3
- package/lib/esm/function/algebra/solver/usolveAll.js +3 -3
- package/lib/esm/function/algebra/sylvester.js +7 -7
- package/lib/esm/function/arithmetic/addScalar.js +4 -4
- package/lib/esm/function/arithmetic/ceil.js +6 -6
- package/lib/esm/function/arithmetic/divide.js +5 -5
- package/lib/esm/function/arithmetic/divideScalar.js +5 -5
- package/lib/esm/function/arithmetic/fix.js +5 -5
- package/lib/esm/function/arithmetic/floor.js +6 -6
- package/lib/esm/function/arithmetic/hypot.js +3 -3
- package/lib/esm/function/arithmetic/mod.js +3 -3
- package/lib/esm/function/arithmetic/multiply.js +7 -7
- package/lib/esm/function/arithmetic/multiplyScalar.js +4 -4
- package/lib/esm/function/arithmetic/norm.js +2 -2
- package/lib/esm/function/arithmetic/pow.js +6 -6
- package/lib/esm/function/arithmetic/round.js +7 -7
- package/lib/esm/function/arithmetic/subtractScalar.js +4 -4
- package/lib/esm/function/arithmetic/xgcd.js +1 -1
- package/lib/esm/function/combinatorics/bellNumbers.js +1 -1
- package/lib/esm/function/combinatorics/catalan.js +1 -1
- package/lib/esm/function/combinatorics/composition.js +1 -1
- package/lib/esm/function/combinatorics/stirlingS2.js +1 -1
- package/lib/esm/function/geometry/distance.js +4 -4
- package/lib/esm/function/geometry/intersect.js +2 -2
- package/lib/esm/function/logical/and.js +2 -2
- package/lib/esm/function/logical/or.js +2 -2
- package/lib/esm/function/logical/xor.js +2 -2
- package/lib/esm/function/matrix/apply.js +2 -2
- package/lib/esm/function/matrix/column.js +1 -1
- package/lib/esm/function/matrix/concat.js +1 -1
- package/lib/esm/function/matrix/count.js +1 -1
- package/lib/esm/function/matrix/cross.js +3 -3
- package/lib/esm/function/matrix/diag.js +10 -10
- package/lib/esm/function/matrix/diff.js +2 -2
- package/lib/esm/function/matrix/eigs.js +3 -3
- package/lib/esm/function/matrix/fft.js +3 -3
- package/lib/esm/function/matrix/filter.js +4 -4
- package/lib/esm/function/matrix/flatten.js +5 -6
- package/lib/esm/function/matrix/forEach.js +4 -4
- package/lib/esm/function/matrix/identity.js +6 -6
- package/lib/esm/function/matrix/ifft.js +3 -3
- package/lib/esm/function/matrix/inv.js +1 -1
- package/lib/esm/function/matrix/kron.js +7 -7
- package/lib/esm/function/matrix/map.js +110 -19
- package/lib/esm/function/matrix/matrixFromFunction.js +6 -6
- package/lib/esm/function/matrix/ones.js +2 -2
- package/lib/esm/function/matrix/partitionSelect.js +2 -2
- package/lib/esm/function/matrix/pinv.js +1 -1
- package/lib/esm/function/matrix/range.js +10 -10
- package/lib/esm/function/matrix/reshape.js +2 -2
- package/lib/esm/function/matrix/rotate.js +4 -4
- package/lib/esm/function/matrix/rotationMatrix.js +6 -6
- package/lib/esm/function/matrix/row.js +1 -1
- package/lib/esm/function/matrix/size.js +8 -8
- package/lib/esm/function/matrix/sort.js +4 -4
- package/lib/esm/function/matrix/sqrtm.js +1 -1
- package/lib/esm/function/matrix/squeeze.js +3 -4
- package/lib/esm/function/matrix/subset.js +2 -2
- package/lib/esm/function/matrix/zeros.js +2 -2
- package/lib/esm/function/probability/combinations.js +1 -1
- package/lib/esm/function/probability/combinationsWithRep.js +2 -2
- package/lib/esm/function/probability/kldivergence.js +4 -4
- package/lib/esm/function/probability/multinomial.js +1 -1
- package/lib/esm/function/probability/permutations.js +2 -2
- package/lib/esm/function/probability/pickRandom.js +6 -6
- package/lib/esm/function/probability/random.js +1 -1
- package/lib/esm/function/probability/randomInt.js +1 -1
- package/lib/esm/function/relational/compare.js +6 -6
- package/lib/esm/function/relational/deepEqual.js +1 -1
- package/lib/esm/function/relational/equal.js +1 -1
- package/lib/esm/function/relational/equalScalar.js +7 -7
- package/lib/esm/function/relational/equalText.js +1 -1
- package/lib/esm/function/relational/larger.js +3 -3
- package/lib/esm/function/relational/largerEq.js +4 -4
- package/lib/esm/function/relational/smaller.js +3 -3
- package/lib/esm/function/relational/smallerEq.js +3 -3
- package/lib/esm/function/relational/unequal.js +1 -1
- package/lib/esm/function/set/setCartesian.js +1 -1
- package/lib/esm/function/set/setDifference.js +1 -1
- package/lib/esm/function/set/setDistinct.js +1 -1
- package/lib/esm/function/set/setIntersect.js +1 -1
- package/lib/esm/function/set/setIsSubset.js +1 -1
- package/lib/esm/function/set/setMultiplicity.js +1 -1
- package/lib/esm/function/set/setPowerset.js +1 -1
- package/lib/esm/function/set/setSize.js +2 -2
- package/lib/esm/function/set/setSymDifference.js +1 -1
- package/lib/esm/function/set/setUnion.js +1 -1
- package/lib/esm/function/signal/freqz.js +6 -6
- package/lib/esm/function/statistics/corr.js +2 -2
- package/lib/esm/function/statistics/cumsum.js +3 -3
- package/lib/esm/function/statistics/max.js +1 -1
- package/lib/esm/function/statistics/median.js +3 -3
- package/lib/esm/function/statistics/min.js +1 -1
- package/lib/esm/function/statistics/prod.js +1 -1
- package/lib/esm/function/statistics/variance.js +2 -2
- package/lib/esm/function/string/bin.js +2 -2
- package/lib/esm/function/string/hex.js +2 -2
- package/lib/esm/function/string/oct.js +2 -2
- package/lib/esm/function/trigonometry/acoth.js +2 -2
- package/lib/esm/function/trigonometry/acsch.js +2 -2
- package/lib/esm/type/bigint.js +1 -1
- package/lib/esm/type/complex/function/complex.js +2 -2
- package/lib/esm/type/fraction/function/fraction.js +1 -1
- package/lib/esm/type/matrix/DenseMatrix.js +13 -38
- package/lib/esm/type/matrix/SparseMatrix.js +5 -8
- package/lib/esm/type/matrix/function/index.js +1 -1
- package/lib/esm/type/matrix/function/matrix.js +1 -1
- package/lib/esm/type/matrix/function/sparse.js +2 -2
- package/lib/esm/type/number.js +1 -1
- package/lib/esm/type/unit/Unit.js +57 -114
- package/lib/esm/type/unit/function/createUnit.js +3 -3
- package/lib/esm/type/unit/function/splitUnit.js +1 -1
- package/lib/esm/type/unit/function/unit.js +2 -2
- package/lib/esm/utils/array.js +26 -0
- package/lib/esm/utils/collection.js +1 -1
- package/lib/esm/utils/function.js +0 -13
- package/lib/esm/utils/is.js +24 -0
- package/lib/esm/utils/map.js +2 -19
- package/lib/esm/version.js +1 -1
- package/package.json +19 -19
- package/types/index.d.ts +108 -25
@@ -54,7 +54,7 @@ export var createFraction = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
54
54
|
string: function string(x) {
|
55
55
|
return new Fraction(x);
|
56
56
|
},
|
57
|
-
'number, number': function
|
57
|
+
'number, number': function number_number(numerator, denominator) {
|
58
58
|
return new Fraction(numerator, denominator);
|
59
59
|
},
|
60
60
|
null: function _null(x) {
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { isArray, isBigNumber, isCollection, isIndex, isMatrix, isNumber, isString, typeOf } from '../../utils/is.js';
|
2
|
-
import { arraySize, getArrayDataType, processSizesWildcard, reshape, resize, unsqueeze, validate, validateIndex, broadcastTo } from '../../utils/array.js';
|
2
|
+
import { arraySize, getArrayDataType, processSizesWildcard, reshape, resize, unsqueeze, validate, validateIndex, broadcastTo, get } from '../../utils/array.js';
|
3
3
|
import { format } from '../../utils/string.js';
|
4
4
|
import { isInteger } from '../../utils/number.js';
|
5
5
|
import { clone, deepStrictEqual } from '../../utils/object.js';
|
6
6
|
import { DimensionError } from '../../error/DimensionError.js';
|
7
7
|
import { factory } from '../../utils/factory.js';
|
8
|
-
import {
|
8
|
+
import { applyCallback } from '../../utils/applyCallback.js';
|
9
9
|
var name = 'DenseMatrix';
|
10
10
|
var dependencies = ['Matrix'];
|
11
11
|
export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _ref => {
|
@@ -166,24 +166,7 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
166
166
|
* @return {*} value
|
167
167
|
*/
|
168
168
|
DenseMatrix.prototype.get = function (index) {
|
169
|
-
|
170
|
-
throw new TypeError('Array expected');
|
171
|
-
}
|
172
|
-
if (index.length !== this._size.length) {
|
173
|
-
throw new DimensionError(index.length, this._size.length);
|
174
|
-
}
|
175
|
-
|
176
|
-
// check index
|
177
|
-
for (var x = 0; x < index.length; x++) {
|
178
|
-
validateIndex(index[x], this._size[x]);
|
179
|
-
}
|
180
|
-
var data = this._data;
|
181
|
-
for (var i = 0, ii = index.length; i < ii; i++) {
|
182
|
-
var indexI = index[i];
|
183
|
-
validateIndex(indexI, data.length);
|
184
|
-
data = data[indexI];
|
185
|
-
}
|
186
|
-
return data;
|
169
|
+
return get(this._data, index);
|
187
170
|
};
|
188
171
|
|
189
172
|
/**
|
@@ -546,28 +529,20 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
546
529
|
DenseMatrix.prototype.map = function (callback) {
|
547
530
|
// matrix instance
|
548
531
|
var me = this;
|
549
|
-
var
|
550
|
-
var recurse = function recurse(value, index) {
|
532
|
+
var _recurse = function recurse(value, index) {
|
551
533
|
if (isArray(value)) {
|
552
534
|
return value.map(function (child, i) {
|
553
|
-
return
|
535
|
+
return _recurse(child, index.concat(i));
|
554
536
|
});
|
555
537
|
} else {
|
556
538
|
// invoke the callback function with the right number of arguments
|
557
|
-
|
558
|
-
return callback(value);
|
559
|
-
} else if (args === 2) {
|
560
|
-
return callback(value, index);
|
561
|
-
} else {
|
562
|
-
// 3 or -1
|
563
|
-
return callback(value, index, me);
|
564
|
-
}
|
539
|
+
return applyCallback(callback, value, index, me, 'map');
|
565
540
|
}
|
566
541
|
};
|
567
542
|
|
568
543
|
// determine the new datatype when the original matrix has datatype defined
|
569
544
|
// TODO: should be done in matrix constructor instead
|
570
|
-
var data =
|
545
|
+
var data = _recurse(this._data, []);
|
571
546
|
var datatype = this._datatype !== undefined ? getArrayDataType(data, typeOf) : undefined;
|
572
547
|
return new DenseMatrix(data, datatype);
|
573
548
|
};
|
@@ -582,16 +557,16 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
582
557
|
DenseMatrix.prototype.forEach = function (callback) {
|
583
558
|
// matrix instance
|
584
559
|
var me = this;
|
585
|
-
var
|
560
|
+
var _recurse2 = function recurse(value, index) {
|
586
561
|
if (isArray(value)) {
|
587
562
|
value.forEach(function (child, i) {
|
588
|
-
|
563
|
+
_recurse2(child, index.concat(i));
|
589
564
|
});
|
590
565
|
} else {
|
591
566
|
callback(value, index, me);
|
592
567
|
}
|
593
568
|
};
|
594
|
-
|
569
|
+
_recurse2(this._data, []);
|
595
570
|
};
|
596
571
|
|
597
572
|
/**
|
@@ -599,10 +574,10 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
599
574
|
* @return {Iterable<{ value, index: number[] }>}
|
600
575
|
*/
|
601
576
|
DenseMatrix.prototype[Symbol.iterator] = function* () {
|
602
|
-
var
|
577
|
+
var _recurse3 = function* recurse(value, index) {
|
603
578
|
if (isArray(value)) {
|
604
579
|
for (var i = 0; i < value.length; i++) {
|
605
|
-
yield*
|
580
|
+
yield* _recurse3(value[i], index.concat(i));
|
606
581
|
}
|
607
582
|
} else {
|
608
583
|
yield {
|
@@ -611,7 +586,7 @@ export var createDenseMatrixClass = /* #__PURE__ */factory(name, dependencies, _
|
|
611
586
|
};
|
612
587
|
}
|
613
588
|
};
|
614
|
-
yield*
|
589
|
+
yield* _recurse3(this._data, []);
|
615
590
|
};
|
616
591
|
|
617
592
|
/**
|
@@ -5,7 +5,7 @@ import { clone, deepStrictEqual } from '../../utils/object.js';
|
|
5
5
|
import { arraySize, getArrayDataType, processSizesWildcard, unsqueeze, validateIndex } from '../../utils/array.js';
|
6
6
|
import { factory } from '../../utils/factory.js';
|
7
7
|
import { DimensionError } from '../../error/DimensionError.js';
|
8
|
-
import {
|
8
|
+
import { applyCallback } from '../../utils/applyCallback.js';
|
9
9
|
var name = 'SparseMatrix';
|
10
10
|
var dependencies = ['typed', 'equalScalar', 'Matrix'];
|
11
11
|
export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies, _ref => {
|
@@ -873,12 +873,9 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
|
|
873
873
|
var rows = this._size[0];
|
874
874
|
var columns = this._size[1];
|
875
875
|
// invoke callback
|
876
|
-
var args = maxArgumentCount(callback);
|
877
876
|
var invoke = function invoke(v, i, j) {
|
878
877
|
// invoke callback
|
879
|
-
|
880
|
-
if (args === 2) return callback(v, [i, j]);
|
881
|
-
return callback(v, [i, j], me);
|
878
|
+
return applyCallback(callback, v, [i, j], me, 'map');
|
882
879
|
};
|
883
880
|
// invoke _map
|
884
881
|
return _map(this, 0, rows - 1, 0, columns - 1, invoke, skipZeros);
|
@@ -908,11 +905,11 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
|
|
908
905
|
// invoke callback
|
909
906
|
var invoke = function invoke(v, x, y) {
|
910
907
|
// invoke callback
|
911
|
-
|
908
|
+
var value = callback(v, x, y);
|
912
909
|
// check value != 0
|
913
|
-
if (!eq(
|
910
|
+
if (!eq(value, zero)) {
|
914
911
|
// store value
|
915
|
-
values.push(
|
912
|
+
values.push(value);
|
916
913
|
// index
|
917
914
|
index.push(x);
|
918
915
|
}
|
@@ -43,7 +43,7 @@ export var createIndex = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
43
43
|
* @return {Index} Returns the created index
|
44
44
|
*/
|
45
45
|
return typed(name, {
|
46
|
-
'...number | string | BigNumber | Range | Array | Matrix': function
|
46
|
+
'...number | string | BigNumber | Range | Array | Matrix': function number__string__BigNumber__Range__Array__Matrix(args) {
|
47
47
|
var ranges = args.map(function (arg) {
|
48
48
|
if (isBigNumber(arg)) {
|
49
49
|
return arg.toNumber(); // convert BigNumber to Number
|
@@ -48,7 +48,7 @@ export var createMatrix = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
48
48
|
string: function string(format) {
|
49
49
|
return _create([], format);
|
50
50
|
},
|
51
|
-
'string, string': function
|
51
|
+
'string, string': function string_string(format, datatype) {
|
52
52
|
return _create([], format, datatype);
|
53
53
|
},
|
54
54
|
Array: function Array(data) {
|
@@ -46,10 +46,10 @@ export var createSparse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
46
46
|
string: function string(datatype) {
|
47
47
|
return new SparseMatrix([], datatype);
|
48
48
|
},
|
49
|
-
'Array | Matrix': function
|
49
|
+
'Array | Matrix': function Array__Matrix(data) {
|
50
50
|
return new SparseMatrix(data);
|
51
51
|
},
|
52
|
-
'Array | Matrix, string': function
|
52
|
+
'Array | Matrix, string': function Array__Matrix_string(data, datatype) {
|
53
53
|
return new SparseMatrix(data, datatype);
|
54
54
|
}
|
55
55
|
});
|
package/lib/esm/type/number.js
CHANGED
@@ -132,7 +132,7 @@ export var createNumber = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
132
132
|
null: function _null(x) {
|
133
133
|
return 0;
|
134
134
|
},
|
135
|
-
'Unit, string | Unit': function
|
135
|
+
'Unit, string | Unit': function Unit_string__Unit(unit, valuelessUnit) {
|
136
136
|
return unit.toNumber(valuelessUnit);
|
137
137
|
},
|
138
138
|
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
@@ -426,7 +426,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
426
426
|
* Return the type of the value of this unit
|
427
427
|
*
|
428
428
|
* @memberof Unit
|
429
|
-
* @
|
429
|
+
* @return {string} type of the value of the unit
|
430
430
|
*/
|
431
431
|
Unit.prototype.valueType = function () {
|
432
432
|
return typeOf(this.value);
|
@@ -436,6 +436,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
436
436
|
* Return whether the unit is derived (such as m/s, or cm^2, but not N)
|
437
437
|
* @memberof Unit
|
438
438
|
* @return {boolean} True if the unit is derived
|
439
|
+
* @private
|
439
440
|
*/
|
440
441
|
Unit.prototype._isDerived = function () {
|
441
442
|
if (this.units.length === 0) {
|
@@ -548,7 +549,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
548
549
|
* check if this unit has given base unit
|
549
550
|
* If this unit is a derived unit, this will ALWAYS return false, since by definition base units are not derived.
|
550
551
|
* @memberof Unit
|
551
|
-
* @param {
|
552
|
+
* @param {BASE_UNIT | string | undefined} base
|
552
553
|
*/
|
553
554
|
Unit.prototype.hasBase = function (base) {
|
554
555
|
if (typeof base === 'string') {
|
@@ -2316,34 +2317,34 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
2316
2317
|
name: 'minim',
|
2317
2318
|
base: BASE_UNITS.VOLUME,
|
2318
2319
|
prefixes: PREFIXES.NONE,
|
2319
|
-
value: 0.
|
2320
|
+
value: 0.000000061611519921875,
|
2320
2321
|
offset: 0
|
2321
2322
|
},
|
2322
|
-
//
|
2323
|
+
// 1/61440 gallons
|
2323
2324
|
fluiddram: {
|
2324
2325
|
name: 'fluiddram',
|
2325
2326
|
base: BASE_UNITS.VOLUME,
|
2326
2327
|
prefixes: PREFIXES.NONE,
|
2327
|
-
value: 0.
|
2328
|
+
value: 0.0000036966911953125,
|
2328
2329
|
offset: 0
|
2329
2330
|
},
|
2330
|
-
//
|
2331
|
+
// 1/1024 gallons
|
2331
2332
|
fluidounce: {
|
2332
2333
|
name: 'fluidounce',
|
2333
2334
|
base: BASE_UNITS.VOLUME,
|
2334
2335
|
prefixes: PREFIXES.NONE,
|
2335
|
-
value: 0.
|
2336
|
+
value: 0.0000295735295625,
|
2336
2337
|
offset: 0
|
2337
2338
|
},
|
2338
|
-
//
|
2339
|
+
// 1/128 gallons
|
2339
2340
|
gill: {
|
2340
2341
|
name: 'gill',
|
2341
2342
|
base: BASE_UNITS.VOLUME,
|
2342
2343
|
prefixes: PREFIXES.NONE,
|
2343
|
-
value: 0.
|
2344
|
+
value: 0.00011829411825,
|
2344
2345
|
offset: 0
|
2345
2346
|
},
|
2346
|
-
//
|
2347
|
+
// 1/32 gallons
|
2347
2348
|
cc: {
|
2348
2349
|
name: 'cc',
|
2349
2350
|
base: BASE_UNITS.VOLUME,
|
@@ -2356,133 +2357,58 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
2356
2357
|
name: 'cup',
|
2357
2358
|
base: BASE_UNITS.VOLUME,
|
2358
2359
|
prefixes: PREFIXES.NONE,
|
2359
|
-
value: 0.
|
2360
|
+
value: 0.0002365882365,
|
2360
2361
|
offset: 0
|
2361
2362
|
},
|
2362
|
-
//
|
2363
|
+
// 1/16 gallons
|
2363
2364
|
pint: {
|
2364
2365
|
name: 'pint',
|
2365
2366
|
base: BASE_UNITS.VOLUME,
|
2366
2367
|
prefixes: PREFIXES.NONE,
|
2367
|
-
value: 0.
|
2368
|
+
value: 0.000473176473,
|
2368
2369
|
offset: 0
|
2369
2370
|
},
|
2370
|
-
//
|
2371
|
+
// 1/8 gallons
|
2371
2372
|
quart: {
|
2372
2373
|
name: 'quart',
|
2373
2374
|
base: BASE_UNITS.VOLUME,
|
2374
2375
|
prefixes: PREFIXES.NONE,
|
2375
|
-
value: 0.
|
2376
|
+
value: 0.000946352946,
|
2376
2377
|
offset: 0
|
2377
2378
|
},
|
2378
|
-
//
|
2379
|
+
// 1/4 gallons
|
2379
2380
|
gallon: {
|
2380
2381
|
name: 'gallon',
|
2381
2382
|
base: BASE_UNITS.VOLUME,
|
2382
2383
|
prefixes: PREFIXES.NONE,
|
2383
|
-
value: 0.
|
2384
|
+
value: 0.003785411784,
|
2384
2385
|
offset: 0
|
2385
2386
|
},
|
2386
|
-
// 3.
|
2387
|
+
// 3.785411784 L
|
2387
2388
|
beerbarrel: {
|
2388
2389
|
name: 'beerbarrel',
|
2389
2390
|
base: BASE_UNITS.VOLUME,
|
2390
2391
|
prefixes: PREFIXES.NONE,
|
2391
|
-
value: 0.
|
2392
|
+
value: 0.117347765304,
|
2392
2393
|
offset: 0
|
2393
2394
|
},
|
2394
|
-
//
|
2395
|
+
// 31 gallons
|
2395
2396
|
oilbarrel: {
|
2396
2397
|
name: 'oilbarrel',
|
2397
2398
|
base: BASE_UNITS.VOLUME,
|
2398
2399
|
prefixes: PREFIXES.NONE,
|
2399
|
-
value: 0.
|
2400
|
+
value: 0.158987294928,
|
2400
2401
|
offset: 0
|
2401
2402
|
},
|
2402
|
-
//
|
2403
|
+
// 42 gallons
|
2403
2404
|
hogshead: {
|
2404
2405
|
name: 'hogshead',
|
2405
2406
|
base: BASE_UNITS.VOLUME,
|
2406
2407
|
prefixes: PREFIXES.NONE,
|
2407
|
-
value: 0.
|
2408
|
+
value: 0.238480942392,
|
2408
2409
|
offset: 0
|
2409
2410
|
},
|
2410
|
-
//
|
2411
|
-
|
2412
|
-
// {name: 'min', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00000006161152, offset: 0}, // 0.06161152 mL // min is already in use as minute
|
2413
|
-
fldr: {
|
2414
|
-
name: 'fldr',
|
2415
|
-
base: BASE_UNITS.VOLUME,
|
2416
|
-
prefixes: PREFIXES.NONE,
|
2417
|
-
value: 0.0000036966911,
|
2418
|
-
offset: 0
|
2419
|
-
},
|
2420
|
-
// 3.696691 mL
|
2421
|
-
floz: {
|
2422
|
-
name: 'floz',
|
2423
|
-
base: BASE_UNITS.VOLUME,
|
2424
|
-
prefixes: PREFIXES.NONE,
|
2425
|
-
value: 0.00002957353,
|
2426
|
-
offset: 0
|
2427
|
-
},
|
2428
|
-
// 29.57353 mL
|
2429
|
-
gi: {
|
2430
|
-
name: 'gi',
|
2431
|
-
base: BASE_UNITS.VOLUME,
|
2432
|
-
prefixes: PREFIXES.NONE,
|
2433
|
-
value: 0.0001182941,
|
2434
|
-
offset: 0
|
2435
|
-
},
|
2436
|
-
// 118.2941 mL
|
2437
|
-
cp: {
|
2438
|
-
name: 'cp',
|
2439
|
-
base: BASE_UNITS.VOLUME,
|
2440
|
-
prefixes: PREFIXES.NONE,
|
2441
|
-
value: 0.0002365882,
|
2442
|
-
offset: 0
|
2443
|
-
},
|
2444
|
-
// 236.5882 mL
|
2445
|
-
pt: {
|
2446
|
-
name: 'pt',
|
2447
|
-
base: BASE_UNITS.VOLUME,
|
2448
|
-
prefixes: PREFIXES.NONE,
|
2449
|
-
value: 0.0004731765,
|
2450
|
-
offset: 0
|
2451
|
-
},
|
2452
|
-
// 473.1765 mL
|
2453
|
-
qt: {
|
2454
|
-
name: 'qt',
|
2455
|
-
base: BASE_UNITS.VOLUME,
|
2456
|
-
prefixes: PREFIXES.NONE,
|
2457
|
-
value: 0.0009463529,
|
2458
|
-
offset: 0
|
2459
|
-
},
|
2460
|
-
// 946.3529 mL
|
2461
|
-
gal: {
|
2462
|
-
name: 'gal',
|
2463
|
-
base: BASE_UNITS.VOLUME,
|
2464
|
-
prefixes: PREFIXES.NONE,
|
2465
|
-
value: 0.003785412,
|
2466
|
-
offset: 0
|
2467
|
-
},
|
2468
|
-
// 3.785412 L
|
2469
|
-
bbl: {
|
2470
|
-
name: 'bbl',
|
2471
|
-
base: BASE_UNITS.VOLUME,
|
2472
|
-
prefixes: PREFIXES.NONE,
|
2473
|
-
value: 0.1173478,
|
2474
|
-
offset: 0
|
2475
|
-
},
|
2476
|
-
// 117.3478 L
|
2477
|
-
obl: {
|
2478
|
-
name: 'obl',
|
2479
|
-
base: BASE_UNITS.VOLUME,
|
2480
|
-
prefixes: PREFIXES.NONE,
|
2481
|
-
value: 0.1589873,
|
2482
|
-
offset: 0
|
2483
|
-
},
|
2484
|
-
// 158.9873 L
|
2485
|
-
// {name: 'hogshead', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.2384810, offset: 0}, // 238.4810 L // TODO: hh?
|
2411
|
+
// 63 gallons
|
2486
2412
|
|
2487
2413
|
// Mass
|
2488
2414
|
g: {
|
@@ -3286,14 +3212,23 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
3286
3212
|
teaspoons: 'teaspoon',
|
3287
3213
|
tablespoons: 'tablespoon',
|
3288
3214
|
minims: 'minim',
|
3215
|
+
fldr: 'fluiddram',
|
3289
3216
|
fluiddrams: 'fluiddram',
|
3217
|
+
floz: 'fluidounce',
|
3290
3218
|
fluidounces: 'fluidounce',
|
3219
|
+
gi: 'gill',
|
3291
3220
|
gills: 'gill',
|
3221
|
+
cp: 'cup',
|
3292
3222
|
cups: 'cup',
|
3223
|
+
pt: 'pint',
|
3293
3224
|
pints: 'pint',
|
3225
|
+
qt: 'quart',
|
3294
3226
|
quarts: 'quart',
|
3227
|
+
gal: 'gallon',
|
3295
3228
|
gallons: 'gallon',
|
3229
|
+
bbl: 'beerbarrel',
|
3296
3230
|
beerbarrels: 'beerbarrel',
|
3231
|
+
obl: 'oilbarrel',
|
3297
3232
|
oilbarrels: 'oilbarrel',
|
3298
3233
|
hogsheads: 'hogshead',
|
3299
3234
|
gtts: 'gtt',
|
@@ -3566,6 +3501,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
3566
3501
|
|
3567
3502
|
/**
|
3568
3503
|
* Set a unit system for formatting derived units.
|
3504
|
+
* @memberof Unit
|
3569
3505
|
* @param {string} [name] The name of the unit system.
|
3570
3506
|
*/
|
3571
3507
|
Unit.setUnitSystem = function (name) {
|
@@ -3578,6 +3514,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
3578
3514
|
|
3579
3515
|
/**
|
3580
3516
|
* Return the current unit system.
|
3517
|
+
* @memberof Unit
|
3581
3518
|
* @return {string} The current unit system.
|
3582
3519
|
*/
|
3583
3520
|
Unit.getUnitSystem = function () {
|
@@ -3667,7 +3604,9 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
3667
3604
|
/**
|
3668
3605
|
* Checks if a character is a valid latin letter (upper or lower case).
|
3669
3606
|
* Note that this function can be overridden, for example to allow support of other alphabets.
|
3607
|
+
* @memberof Unit
|
3670
3608
|
* @param {string} c Tested character
|
3609
|
+
* @return {boolean} true if the character is a latin letter
|
3671
3610
|
*/
|
3672
3611
|
Unit.isValidAlpha = function isValidAlpha(c) {
|
3673
3612
|
return /^[a-zA-Z]$/.test(c);
|
@@ -3687,20 +3626,24 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
3687
3626
|
/**
|
3688
3627
|
* Wrapper around createUnitSingle.
|
3689
3628
|
* Example:
|
3690
|
-
* createUnit({
|
3691
|
-
*
|
3692
|
-
*
|
3693
|
-
*
|
3694
|
-
*
|
3695
|
-
*
|
3696
|
-
*
|
3697
|
-
*
|
3698
|
-
*
|
3699
|
-
*
|
3700
|
-
*
|
3701
|
-
*
|
3629
|
+
* createUnit( {
|
3630
|
+
* foo: {
|
3631
|
+
* prefixes: 'long',
|
3632
|
+
* baseName: 'essence-of-foo'
|
3633
|
+
* },
|
3634
|
+
* bar: '40 foo',
|
3635
|
+
* baz: {
|
3636
|
+
* definition: '1 bar/hour',
|
3637
|
+
* prefixes: 'long'
|
3638
|
+
* }
|
3639
|
+
* },
|
3640
|
+
* {
|
3641
|
+
* override: true
|
3642
|
+
* })
|
3643
|
+
* @memberof Unit
|
3702
3644
|
* @param {object} obj Object map. Each key becomes a unit which is defined by its value.
|
3703
3645
|
* @param {object} options
|
3646
|
+
* @return {Unit} the last created unit
|
3704
3647
|
*/
|
3705
3648
|
Unit.createUnit = function (obj, options) {
|
3706
3649
|
if (typeof obj !== 'object') {
|
@@ -3735,13 +3678,13 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
3735
3678
|
* Create a user-defined unit and register it with the Unit type.
|
3736
3679
|
* Example:
|
3737
3680
|
* createUnitSingle('knot', '0.514444444 m/s')
|
3738
|
-
* createUnitSingle('acre', new Unit(43560, 'ft^2'))
|
3739
3681
|
*
|
3682
|
+
* @memberof Unit
|
3740
3683
|
* @param {string} name The name of the new unit. Must be unique. Example: 'knot'
|
3741
|
-
* @param {string
|
3684
|
+
* @param {string | Unit | object} definition Definition of the unit in terms
|
3742
3685
|
* of existing units. For example, '0.514444444 m / s'. Can be a Unit, a string,
|
3743
3686
|
* or an Object. If an Object, may have the following properties:
|
3744
|
-
* - definition {string|Unit} The definition of this unit.
|
3687
|
+
* - definition {string | Unit} The definition of this unit.
|
3745
3688
|
* - prefixes {string} "none", "short", "long", "binary_short", or "binary_long".
|
3746
3689
|
* The default is "none".
|
3747
3690
|
* - aliases {Array} Array of strings. Example: ['knots', 'kt', 'kts']
|
@@ -50,7 +50,7 @@ export var createCreateUnit = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
50
50
|
*/
|
51
51
|
return typed(name, {
|
52
52
|
// General function signature. First parameter is an object where each property is the definition of a new unit. The object keys are the unit names and the values are the definitions. The values can be objects, strings, or Units. If a property is an empty object or an empty string, a new base unit is created. The second parameter is the options.
|
53
|
-
'Object, Object': function
|
53
|
+
'Object, Object': function Object_Object(obj, options) {
|
54
54
|
return Unit.createUnit(obj, options);
|
55
55
|
},
|
56
56
|
// Same as above but without the options.
|
@@ -58,13 +58,13 @@ export var createCreateUnit = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
58
58
|
return Unit.createUnit(obj, {});
|
59
59
|
},
|
60
60
|
// Shortcut method for creating one unit.
|
61
|
-
'string, Unit | string | Object, Object': function
|
61
|
+
'string, Unit | string | Object, Object': function string_Unit__string__Object_Object(name, def, options) {
|
62
62
|
var obj = {};
|
63
63
|
obj[name] = def;
|
64
64
|
return Unit.createUnit(obj, options);
|
65
65
|
},
|
66
66
|
// Same as above but without the options.
|
67
|
-
'string, Unit | string | Object': function
|
67
|
+
'string, Unit | string | Object': function string_Unit__string__Object(name, def) {
|
68
68
|
var obj = {};
|
69
69
|
obj[name] = def;
|
70
70
|
return Unit.createUnit(obj, {});
|
@@ -25,7 +25,7 @@ export var createSplitUnit = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
25
25
|
* @return {Array} An array of units.
|
26
26
|
*/
|
27
27
|
return typed(name, {
|
28
|
-
'Unit, Array': function
|
28
|
+
'Unit, Array': function Unit_Array(unit, parts) {
|
29
29
|
return unit.splitUnit(parts);
|
30
30
|
}
|
31
31
|
});
|
@@ -48,10 +48,10 @@ export var createUnitFunction = /* #__PURE__ */factory(name, dependencies, _ref
|
|
48
48
|
allowNoUnits: true
|
49
49
|
}); // a unit with value, like '5cm'
|
50
50
|
},
|
51
|
-
'number | BigNumber | Fraction | Complex, string | Unit': function
|
51
|
+
'number | BigNumber | Fraction | Complex, string | Unit': function number__BigNumber__Fraction__Complex_string__Unit(value, unit) {
|
52
52
|
return new Unit(value, unit);
|
53
53
|
},
|
54
|
-
'number | BigNumber | Fraction': function
|
54
|
+
'number | BigNumber | Fraction': function number__BigNumber__Fraction(value) {
|
55
55
|
// dimensionless
|
56
56
|
return new Unit(value);
|
57
57
|
},
|
package/lib/esm/utils/array.js
CHANGED
@@ -780,6 +780,32 @@ export function stretch(arrayToStretch, sizeToStretch, dimToStretch) {
|
|
780
780
|
return concat(...Array(sizeToStretch).fill(arrayToStretch), dimToStretch);
|
781
781
|
}
|
782
782
|
|
783
|
+
/**
|
784
|
+
* Retrieves a single element from an array given an index.
|
785
|
+
*
|
786
|
+
* @param {Array} array - The array from which to retrieve the value.
|
787
|
+
* @param {Array<number>} idx - An array of indices specifying the position of the desired element in each dimension.
|
788
|
+
* @returns {*} - The value at the specified position in the array.
|
789
|
+
*
|
790
|
+
* @example
|
791
|
+
* const arr = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
|
792
|
+
* const index = [1, 0, 1];
|
793
|
+
* console.log(getValue(arr, index)); // 6
|
794
|
+
*/
|
795
|
+
export function get(array, index) {
|
796
|
+
if (!Array.isArray(array)) {
|
797
|
+
throw new Error('Array expected');
|
798
|
+
}
|
799
|
+
var size = arraySize(array);
|
800
|
+
if (index.length !== size.length) {
|
801
|
+
throw new DimensionError(index.length, size.length);
|
802
|
+
}
|
803
|
+
for (var x = 0; x < index.length; x++) {
|
804
|
+
validateIndex(index[x], size[x]);
|
805
|
+
}
|
806
|
+
return index.reduce((acc, curr) => acc[curr], array);
|
807
|
+
}
|
808
|
+
|
783
809
|
/**
|
784
810
|
* Deep clones a multidimensional array
|
785
811
|
* @param {Array} array
|
@@ -78,7 +78,7 @@ export function reduce(mat, dim, callback) {
|
|
78
78
|
throw new IndexError(dim, size.length);
|
79
79
|
}
|
80
80
|
if (isMatrix(mat)) {
|
81
|
-
return mat.create(_reduce(mat.valueOf(), dim, callback));
|
81
|
+
return mat.create(_reduce(mat.valueOf(), dim, callback), mat.datatype());
|
82
82
|
} else {
|
83
83
|
return _reduce(mat, dim, callback);
|
84
84
|
}
|
@@ -83,17 +83,4 @@ export function memoizeCompare(fn, isEqual) {
|
|
83
83
|
};
|
84
84
|
memoize.cache = [];
|
85
85
|
return memoize;
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* Find the maximum number of arguments expected by a typed function.
|
90
|
-
* @param {function} fn A typed function
|
91
|
-
* @return {number} Returns the maximum number of expected arguments.
|
92
|
-
* Returns -1 when no signatures where found on the function.
|
93
|
-
*/
|
94
|
-
export function maxArgumentCount(fn) {
|
95
|
-
return Object.keys(fn.signatures || {}).reduce(function (args, signature) {
|
96
|
-
var count = (signature.match(/,/g) || []).length + 1;
|
97
|
-
return Math.max(args, count);
|
98
|
-
}, -1);
|
99
86
|
}
|