@danielsimonjr/mathts-core 0.9.0 → 0.11.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/dist/{chunk-2WW76EEF.js → chunk-PALIR4V6.js} +128 -50
- package/dist/{index-zKEDY9aj.d.ts → index-B4LIOfHN.d.ts} +85 -1
- package/dist/index.d.ts +20 -3
- package/dist/index.js +13 -1
- package/dist/internal.d.ts +715 -9
- package/dist/internal.js +1344 -1
- package/package.json +1 -1
|
@@ -1342,6 +1342,127 @@ function isPath(str) {
|
|
|
1342
1342
|
return str.includes(".");
|
|
1343
1343
|
}
|
|
1344
1344
|
|
|
1345
|
+
// src/error/MathjsError.ts
|
|
1346
|
+
var MathjsError = class _MathjsError extends Error {
|
|
1347
|
+
isMathjsError = true;
|
|
1348
|
+
/**
|
|
1349
|
+
* Create a MathjsError
|
|
1350
|
+
* @param message Error message
|
|
1351
|
+
*/
|
|
1352
|
+
constructor(message) {
|
|
1353
|
+
super(message);
|
|
1354
|
+
this.name = "MathjsError";
|
|
1355
|
+
const errorCtor = Error;
|
|
1356
|
+
if (errorCtor.captureStackTrace) {
|
|
1357
|
+
errorCtor.captureStackTrace(this, _MathjsError);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
// src/factory.ts
|
|
1363
|
+
function factory(name2, dependencies2, create2, meta) {
|
|
1364
|
+
function assertAndCreate(scope) {
|
|
1365
|
+
const deps = pickShallow(scope, dependencies2.map(stripOptionalNotation));
|
|
1366
|
+
assertDependencies(name2, dependencies2, scope);
|
|
1367
|
+
return create2(deps);
|
|
1368
|
+
}
|
|
1369
|
+
assertAndCreate.isFactory = true;
|
|
1370
|
+
assertAndCreate.fn = name2;
|
|
1371
|
+
assertAndCreate.dependencies = dependencies2.slice().sort();
|
|
1372
|
+
if (meta) {
|
|
1373
|
+
assertAndCreate.meta = meta;
|
|
1374
|
+
}
|
|
1375
|
+
return assertAndCreate;
|
|
1376
|
+
}
|
|
1377
|
+
function sortFactories(factories) {
|
|
1378
|
+
const factoriesByName = {};
|
|
1379
|
+
factories.forEach((factory2) => {
|
|
1380
|
+
const name2 = isFactory(factory2) ? factory2.fn : factory2.name;
|
|
1381
|
+
factoriesByName[name2] = factory2;
|
|
1382
|
+
});
|
|
1383
|
+
const checkedForCycles = /* @__PURE__ */ new Set();
|
|
1384
|
+
function checkCycles(fact, visiting, visited) {
|
|
1385
|
+
if (isFactory(fact)) {
|
|
1386
|
+
const factName = fact.fn;
|
|
1387
|
+
if (visiting.has(factName)) {
|
|
1388
|
+
throw new Error(`Circular dependency detected: ${factName}`);
|
|
1389
|
+
}
|
|
1390
|
+
if (visited.has(factName)) {
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
visiting.add(factName);
|
|
1394
|
+
fact.dependencies.forEach((d) => {
|
|
1395
|
+
const depFactory = factoriesByName[d];
|
|
1396
|
+
if (depFactory) {
|
|
1397
|
+
checkCycles(depFactory, visiting, visited);
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
visiting.delete(factName);
|
|
1401
|
+
visited.add(factName);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
factories.forEach((factory2) => {
|
|
1405
|
+
if (isFactory(factory2)) {
|
|
1406
|
+
checkCycles(factory2, /* @__PURE__ */ new Set(), checkedForCycles);
|
|
1407
|
+
}
|
|
1408
|
+
});
|
|
1409
|
+
function containsDependency(factory2, dependency) {
|
|
1410
|
+
if (isFactory(factory2)) {
|
|
1411
|
+
const depName = isFactory(dependency) ? dependency.fn : dependency.name;
|
|
1412
|
+
if (factory2.dependencies.includes(depName)) {
|
|
1413
|
+
return true;
|
|
1414
|
+
}
|
|
1415
|
+
if (factory2.dependencies.some((d) => {
|
|
1416
|
+
const depFactory = factoriesByName[d];
|
|
1417
|
+
return depFactory && containsDependency(depFactory, dependency);
|
|
1418
|
+
})) {
|
|
1419
|
+
return true;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
return false;
|
|
1423
|
+
}
|
|
1424
|
+
const sorted = [];
|
|
1425
|
+
function addFactory(factory2) {
|
|
1426
|
+
let index = 0;
|
|
1427
|
+
while (index < sorted.length && !containsDependency(sorted[index], factory2)) {
|
|
1428
|
+
index++;
|
|
1429
|
+
}
|
|
1430
|
+
sorted.splice(index, 0, factory2);
|
|
1431
|
+
}
|
|
1432
|
+
factories.filter(isFactory).forEach(addFactory);
|
|
1433
|
+
factories.filter((factory2) => !isFactory(factory2)).forEach(addFactory);
|
|
1434
|
+
return sorted;
|
|
1435
|
+
}
|
|
1436
|
+
function create(factories, scope = {}) {
|
|
1437
|
+
sortFactories(factories).forEach((factory2) => {
|
|
1438
|
+
if (isFactory(factory2)) {
|
|
1439
|
+
factory2(scope);
|
|
1440
|
+
}
|
|
1441
|
+
});
|
|
1442
|
+
return scope;
|
|
1443
|
+
}
|
|
1444
|
+
function isFactory(obj) {
|
|
1445
|
+
const f = obj;
|
|
1446
|
+
return typeof obj === "function" && typeof f.fn === "string" && Array.isArray(f.dependencies);
|
|
1447
|
+
}
|
|
1448
|
+
function assertDependencies(name2, dependencies2, scope) {
|
|
1449
|
+
const allDefined = dependencies2.filter((dependency) => !isOptionalDependency(dependency)).every((dependency) => scope[dependency] !== void 0);
|
|
1450
|
+
if (!allDefined) {
|
|
1451
|
+
const missingDependencies = dependencies2.filter(
|
|
1452
|
+
(dependency) => scope[dependency] === void 0
|
|
1453
|
+
);
|
|
1454
|
+
throw new MathjsError(
|
|
1455
|
+
`Cannot create function "${name2}", some dependencies are missing: ${missingDependencies.map((d) => `"${d}"`).join(", ")}.`
|
|
1456
|
+
);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
function isOptionalDependency(dependency) {
|
|
1460
|
+
return dependency[0] === "?";
|
|
1461
|
+
}
|
|
1462
|
+
function stripOptionalNotation(dependency) {
|
|
1463
|
+
return dependency && dependency[0] === "?" ? dependency.slice(1) : dependency;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1345
1466
|
// src/types/fraction.ts
|
|
1346
1467
|
function isFraction2(value) {
|
|
1347
1468
|
return value instanceof Fraction;
|
|
@@ -3199,56 +3320,6 @@ var DimensionMismatchError = class extends Error {
|
|
|
3199
3320
|
}
|
|
3200
3321
|
};
|
|
3201
3322
|
|
|
3202
|
-
// src/error/MathjsError.ts
|
|
3203
|
-
var MathjsError = class _MathjsError extends Error {
|
|
3204
|
-
isMathjsError = true;
|
|
3205
|
-
/**
|
|
3206
|
-
* Create a MathjsError
|
|
3207
|
-
* @param message Error message
|
|
3208
|
-
*/
|
|
3209
|
-
constructor(message) {
|
|
3210
|
-
super(message);
|
|
3211
|
-
this.name = "MathjsError";
|
|
3212
|
-
const errorCtor = Error;
|
|
3213
|
-
if (errorCtor.captureStackTrace) {
|
|
3214
|
-
errorCtor.captureStackTrace(this, _MathjsError);
|
|
3215
|
-
}
|
|
3216
|
-
}
|
|
3217
|
-
};
|
|
3218
|
-
|
|
3219
|
-
// src/factory.ts
|
|
3220
|
-
function factory(name2, dependencies2, create, meta) {
|
|
3221
|
-
function assertAndCreate(scope) {
|
|
3222
|
-
const deps = pickShallow(scope, dependencies2.map(stripOptionalNotation));
|
|
3223
|
-
assertDependencies(name2, dependencies2, scope);
|
|
3224
|
-
return create(deps);
|
|
3225
|
-
}
|
|
3226
|
-
assertAndCreate.isFactory = true;
|
|
3227
|
-
assertAndCreate.fn = name2;
|
|
3228
|
-
assertAndCreate.dependencies = dependencies2.slice().sort();
|
|
3229
|
-
if (meta) {
|
|
3230
|
-
assertAndCreate.meta = meta;
|
|
3231
|
-
}
|
|
3232
|
-
return assertAndCreate;
|
|
3233
|
-
}
|
|
3234
|
-
function assertDependencies(name2, dependencies2, scope) {
|
|
3235
|
-
const allDefined = dependencies2.filter((dependency) => !isOptionalDependency(dependency)).every((dependency) => scope[dependency] !== void 0);
|
|
3236
|
-
if (!allDefined) {
|
|
3237
|
-
const missingDependencies = dependencies2.filter(
|
|
3238
|
-
(dependency) => scope[dependency] === void 0
|
|
3239
|
-
);
|
|
3240
|
-
throw new MathjsError(
|
|
3241
|
-
`Cannot create function "${name2}", some dependencies are missing: ${missingDependencies.map((d) => `"${d}"`).join(", ")}.`
|
|
3242
|
-
);
|
|
3243
|
-
}
|
|
3244
|
-
}
|
|
3245
|
-
function isOptionalDependency(dependency) {
|
|
3246
|
-
return dependency[0] === "?";
|
|
3247
|
-
}
|
|
3248
|
-
function stripOptionalNotation(dependency) {
|
|
3249
|
-
return dependency && dependency[0] === "?" ? dependency.slice(1) : dependency;
|
|
3250
|
-
}
|
|
3251
|
-
|
|
3252
3323
|
// src/types/unit/Unit.ts
|
|
3253
3324
|
function normalizeDegreeSymbols(s) {
|
|
3254
3325
|
return s.replace(/°C/g, "degC").replace(/°F/g, "degF").replace(/°/g, "deg");
|
|
@@ -6335,7 +6406,14 @@ export {
|
|
|
6335
6406
|
set,
|
|
6336
6407
|
pick,
|
|
6337
6408
|
pickShallow,
|
|
6409
|
+
MathjsError,
|
|
6338
6410
|
factory,
|
|
6411
|
+
sortFactories,
|
|
6412
|
+
create,
|
|
6413
|
+
isFactory,
|
|
6414
|
+
assertDependencies,
|
|
6415
|
+
isOptionalDependency,
|
|
6416
|
+
stripOptionalNotation,
|
|
6339
6417
|
isFraction2,
|
|
6340
6418
|
Fraction,
|
|
6341
6419
|
FRACTION_ZERO,
|
|
@@ -8,6 +8,17 @@ interface FactoryFunction<TResult = unknown> {
|
|
|
8
8
|
dependencies: string[];
|
|
9
9
|
meta?: FactoryMeta;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Type for legacy factory objects (old-style factories)
|
|
13
|
+
*/
|
|
14
|
+
interface LegacyFactory {
|
|
15
|
+
type?: string;
|
|
16
|
+
name: string;
|
|
17
|
+
factory: (...args: unknown[]) => unknown;
|
|
18
|
+
math?: boolean;
|
|
19
|
+
dependencies?: string[];
|
|
20
|
+
meta?: FactoryMeta;
|
|
21
|
+
}
|
|
11
22
|
/**
|
|
12
23
|
* Meta information that can be attached to a factory
|
|
13
24
|
*/
|
|
@@ -25,6 +36,79 @@ interface FactoryMeta {
|
|
|
25
36
|
*/
|
|
26
37
|
[key: string]: unknown;
|
|
27
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Type for dependency names, which can be optional (prefixed with '?')
|
|
41
|
+
*/
|
|
42
|
+
type DependencyName = string;
|
|
43
|
+
/**
|
|
44
|
+
* Type for the create callback function
|
|
45
|
+
*/
|
|
46
|
+
type CreateFunction<TDeps extends Record<string, unknown>, TResult> = (dependencies: TDeps) => TResult;
|
|
47
|
+
/**
|
|
48
|
+
* Create a factory function, which can be used to inject dependencies.
|
|
49
|
+
*
|
|
50
|
+
* The created functions are memoized, a consecutive call of the factory
|
|
51
|
+
* with the exact same inputs will return the same function instance.
|
|
52
|
+
* The memoized cache is exposed on `factory.cache` and can be cleared
|
|
53
|
+
* if needed.
|
|
54
|
+
*
|
|
55
|
+
* Example:
|
|
56
|
+
*
|
|
57
|
+
* const name = 'log'
|
|
58
|
+
* const dependencies = ['config', 'typed', 'divideScalar', 'Complex']
|
|
59
|
+
*
|
|
60
|
+
* export const createLog = factory(name, dependencies, ({ typed, config, divideScalar, Complex }) => {
|
|
61
|
+
* // ... create the function log here and return it
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* @param name Name of the function to be created
|
|
65
|
+
* @param dependencies The names of all required dependencies
|
|
66
|
+
* @param create Callback function called with an object with all dependencies
|
|
67
|
+
* @param meta Optional object with meta information that will be attached
|
|
68
|
+
* to the created factory function as property `meta`. For explanation
|
|
69
|
+
* of what meta properties can be specified and what they mean, see
|
|
70
|
+
* docs/core/extension.md.
|
|
71
|
+
* @returns The factory function
|
|
72
|
+
*/
|
|
73
|
+
declare function factory<TDeps extends Record<string, unknown> = Record<string, unknown>, TResult = unknown>(name: string, dependencies: DependencyName[], create: CreateFunction<TDeps, TResult>, meta?: FactoryMeta): FactoryFunction<TResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Sort all factories such that when loading in order, the dependencies are resolved.
|
|
76
|
+
*
|
|
77
|
+
* @param factories Array of factory functions or legacy factories
|
|
78
|
+
* @returns Returns a new array with the sorted factories
|
|
79
|
+
*/
|
|
80
|
+
declare function sortFactories(factories: Array<FactoryFunction | LegacyFactory>): Array<FactoryFunction | LegacyFactory>;
|
|
81
|
+
declare function create(factories: Array<FactoryFunction | LegacyFactory>, scope?: Record<string, unknown>): Record<string, unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* Test whether an object is a factory. This is the case when it has
|
|
84
|
+
* properties name, dependencies, and a function create.
|
|
85
|
+
* @param obj Any value to test
|
|
86
|
+
* @returns true if obj is a factory function
|
|
87
|
+
*/
|
|
88
|
+
declare function isFactory(obj: unknown): obj is FactoryFunction;
|
|
89
|
+
/**
|
|
90
|
+
* Assert that all dependencies of a list with dependencies are available in the provided scope.
|
|
91
|
+
*
|
|
92
|
+
* Will throw an exception when there are dependencies missing.
|
|
93
|
+
*
|
|
94
|
+
* @param name Name for the function to be created. Used to generate a useful error message
|
|
95
|
+
* @param dependencies Array of dependency names
|
|
96
|
+
* @param scope Object containing the available dependencies
|
|
97
|
+
* @throws Error if required dependencies are missing
|
|
98
|
+
*/
|
|
99
|
+
declare function assertDependencies(name: string, dependencies: DependencyName[], scope: Record<string, unknown>): void;
|
|
100
|
+
/**
|
|
101
|
+
* Check if a dependency is optional (starts with '?')
|
|
102
|
+
* @param dependency The dependency name to check
|
|
103
|
+
* @returns true if the dependency is optional
|
|
104
|
+
*/
|
|
105
|
+
declare function isOptionalDependency(dependency: DependencyName): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Remove the optional notation '?' from a dependency name
|
|
108
|
+
* @param dependency The dependency name
|
|
109
|
+
* @returns The dependency name without optional notation
|
|
110
|
+
*/
|
|
111
|
+
declare function stripOptionalNotation(dependency: DependencyName): string;
|
|
28
112
|
|
|
29
113
|
interface BigNumber {
|
|
30
114
|
isBigNumber: boolean;
|
|
@@ -362,4 +446,4 @@ interface UnitConstructor {
|
|
|
362
446
|
/** The core `Unit` class, pre-wired to core's numeric primitives. */
|
|
363
447
|
declare const Unit: UnitConstructor;
|
|
364
448
|
|
|
365
|
-
export {
|
|
449
|
+
export { isDate as $, type UnitDef as A, type BaseUnitDef as B, type Complex as C, type DenseMatrix as D, type UnitFormatOptions as E, type FactoryFunction as F, type UnitJSON as G, type UnitSystem as H, type Index as I, type UnitSystemEntry as J, assertDependencies as K, type LegacyFactory as L, type Matrix as M, type Numeric as N, create as O, type ParseOptions as P, factory as Q, type Range as R, type ScalarBinaryOp as S, type TypeConverters as T, Unit as U, isArray as V, isBigInt as W, isBigNumber as X, isBoolean as Y, isCollection as Z, isComplex as _, type UnitInstance as a, isDenseMatrix as a0, isFactory as a1, isFraction as a2, isFunction as a3, isIndex as a4, isMap as a5, isMatrix as a6, isNull as a7, isNumber as a8, isObject as a9, isOptionalDependency as aa, isRange as ab, isRegExp as ac, isSparseMatrix as ad, isString as ae, isUndefined as af, sortFactories as ag, stripOptionalNotation as ah, typeOf as ai, type UnitConstructor as b, type UnitDependencies as c, type BigNumber as d, type BigNumberConstructor as e, type ComplexConstructor as f, type ComplexValue as g, type ConverterFn as h, isUnit as i, type CreateFunction as j, type CreateUnitDefObject as k, type CreateUnitOptions as l, type DependencyName as m, type FactoryMeta as n, type Fraction as o, type FractionConstructor as p, type FractionValue as q, type IndexDimension as r, type PrefixDef as s, type PrefixTable as t, type ScalarUnaryOp as u, type SparseMatrix as v, type SubtractScalar as w, type Unit$1 as x, type UnitComponent as y, type UnitConfig as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FactoryFunction$1 } from './index-
|
|
2
|
-
export { U as Unit, a as UnitInstance, i as isUnitValue } from './index-
|
|
1
|
+
import { F as FactoryFunction$1 } from './index-B4LIOfHN.js';
|
|
2
|
+
export { U as Unit, a as UnitInstance, i as isUnitValue } from './index-B4LIOfHN.js';
|
|
3
3
|
import { TypedInstance, ReferTo, ReferToSelf, TypedFunction, SignatureFunction } from 'typed-function';
|
|
4
4
|
export { ReferTo, ReferToSelf, SignatureFunction, TypedFunction, TypedInstance, create, default as typed } from 'typed-function';
|
|
5
5
|
|
|
@@ -2538,6 +2538,23 @@ declare function pairwiseDot(a: ArrayLike<number>, b: ArrayLike<number>, start?:
|
|
|
2538
2538
|
* The two ranges are assumed the same length; callers guard that.
|
|
2539
2539
|
*/
|
|
2540
2540
|
declare function scaledDistance(a: ArrayLike<number>, b: ArrayLike<number>): number;
|
|
2541
|
+
/**
|
|
2542
|
+
* Sum of squared deviations from the mean, `Σ(xᵢ − x̄)²` — the **corrected two-pass** form, the
|
|
2543
|
+
* numerator of a numerically stable variance.
|
|
2544
|
+
*
|
|
2545
|
+
* Variance is where large means bite: the deviations `xᵢ − x̄` can be O(1) while the values sit on
|
|
2546
|
+
* a huge pedestal, so any error in `x̄` rides straight into every deviation. Two things fix it:
|
|
2547
|
+
* 1. compute the mean with {@link pairwiseSum}, not a naive running total; and
|
|
2548
|
+
* 2. subtract the residual mean-bias term `(Σd)²/n` — `Σd` is zero in exact arithmetic but not in
|
|
2549
|
+
* floating point, and that leftover is exactly the systematic error a plain `Σd²` carries.
|
|
2550
|
+
*
|
|
2551
|
+
* Measured on 1e9-pedestal data: the plain naive two-pass (what shipped) lands ~1e-7 relative error;
|
|
2552
|
+
* this lands ~1e-16 — better than `np.var`, which uses the uncorrected two-pass (~1e-13).
|
|
2553
|
+
*
|
|
2554
|
+
* Divide the result by `n` (uncorrected), `n − 1` (unbiased/sample), or `n + 1` (biased) for the
|
|
2555
|
+
* corresponding variance. Returns 0 for fewer than two elements.
|
|
2556
|
+
*/
|
|
2557
|
+
declare function sumSquaredDeviations(xs: ArrayLike<number>): number;
|
|
2541
2558
|
/**
|
|
2542
2559
|
* Cumulative sum with **Neumaier compensation** — each prefix total is written to `out[i]` carrying
|
|
2543
2560
|
* the low-order bits a naive running sum throws away.
|
|
@@ -2562,4 +2579,4 @@ declare function neumaierCumsum(xs: ArrayLike<number>, out: {
|
|
|
2562
2579
|
|
|
2563
2580
|
declare const VERSION = "0.1.0";
|
|
2564
2581
|
|
|
2565
|
-
export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, type BackendType, BigNumber, type BigNumberConfig, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, type ConversionDef, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DUAL_UNARY_RULES, DimensionMismatchError, type Dimensions, Dual, type DualUnaryRule, type DualUnaryRuleName, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, type FactoryDependencies, type FactoryFunction, type FactoryImport, Fraction, FunctionRegistry, I, type IBigNumber, type IComplex, type IFraction, type IMatrix, LN10, LN2, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericScalar, type NumericType, PHI, PI, Range, type RangeForEachCallback, type RangeFormatOptions, type RangeJSON, type RangeMapCallback, type RoundingMode, SI_PREFIXES, SQRT1_2, SQRT2, type Scalar, TAU, type TypeDef, TypeRegistry, UNIT_ALIASES, type UnitDef, UnitParseError, VERSION, abs, addScalar, createFactory, createMathTSTyped, createRangeClass, createTypedFunction, dim, divideScalar, equal, fix, getPrefix, getUnitDef, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isNumeric, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, math, mathTyped, multiplyScalar, neumaierCumsum, neumaierSum, norm2, number, pairwiseDot, pairwiseSum, pow, registerNativeTypes, registry, round, scaledDistance, subtractScalar };
|
|
2582
|
+
export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, type BackendType, BigNumber, type BigNumberConfig, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, type ConversionDef, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DUAL_UNARY_RULES, DimensionMismatchError, type Dimensions, Dual, type DualUnaryRule, type DualUnaryRuleName, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, type FactoryDependencies, type FactoryFunction, type FactoryImport, Fraction, FunctionRegistry, I, type IBigNumber, type IComplex, type IFraction, type IMatrix, LN10, LN2, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericScalar, type NumericType, PHI, PI, Range, type RangeForEachCallback, type RangeFormatOptions, type RangeJSON, type RangeMapCallback, type RoundingMode, SI_PREFIXES, SQRT1_2, SQRT2, type Scalar, TAU, type TypeDef, TypeRegistry, UNIT_ALIASES, type UnitDef, UnitParseError, VERSION, abs, addScalar, createFactory, createMathTSTyped, createRangeClass, createTypedFunction, dim, divideScalar, equal, fix, getPrefix, getUnitDef, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isNumeric, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, math, mathTyped, multiplyScalar, neumaierCumsum, neumaierSum, norm2, number, pairwiseDot, pairwiseSum, pow, registerNativeTypes, registry, round, scaledDistance, subtractScalar, sumSquaredDeviations };
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
round,
|
|
45
45
|
sign,
|
|
46
46
|
subtractScalar
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-PALIR4V6.js";
|
|
48
48
|
|
|
49
49
|
// src/types/matrix/Range.ts
|
|
50
50
|
var name = "Range";
|
|
@@ -1297,6 +1297,17 @@ function scaledDistance(a, b) {
|
|
|
1297
1297
|
}
|
|
1298
1298
|
return scale === 0 ? 0 : scale * Math.sqrt(ssq);
|
|
1299
1299
|
}
|
|
1300
|
+
function sumSquaredDeviations(xs) {
|
|
1301
|
+
const n = xs.length;
|
|
1302
|
+
if (n < 2) return 0;
|
|
1303
|
+
const mean = pairwiseSum(xs) / n;
|
|
1304
|
+
const d = new Float64Array(n);
|
|
1305
|
+
for (let i = 0; i < n; i++) d[i] = xs[i] - mean;
|
|
1306
|
+
const sumD = pairwiseSum(d);
|
|
1307
|
+
const sumDD = pairwiseDot(d, d);
|
|
1308
|
+
const corrected = sumDD - sumD * sumD / n;
|
|
1309
|
+
return corrected < 0 ? 0 : corrected;
|
|
1310
|
+
}
|
|
1300
1311
|
function neumaierCumsum(xs, out) {
|
|
1301
1312
|
let sum = 0;
|
|
1302
1313
|
let c = 0;
|
|
@@ -1411,5 +1422,6 @@ export {
|
|
|
1411
1422
|
round,
|
|
1412
1423
|
scaledDistance,
|
|
1413
1424
|
subtractScalar,
|
|
1425
|
+
sumSquaredDeviations,
|
|
1414
1426
|
typed
|
|
1415
1427
|
};
|