@danielsimonjr/mathts-core
v0.22.0
Published
Core types, utilities, and configuration for MathTS
Readme
@danielsimonjr/mathts-core
Core types, utilities, and configuration for MathTS.
Installation
npm install @danielsimonjr/mathts-coreUsage
import { DEFAULT_CONFIG, isNumber, isMatrix } from '@danielsimonjr/mathts-core';
import { DenseMatrix } from '@danielsimonjr/mathts-matrix';
// Factory default configuration (MathTSConfig)
const config = { ...DEFAULT_CONFIG, preferredBackend: 'wasm' };
// Type guards
console.log(isNumber(42)); // true
console.log(
isMatrix([
[1, 2],
[3, 4],
])
); // false — nested arrays are not matrices
const m = DenseMatrix.fromArray([
[1, 2],
[3, 4],
]);
console.log(isMatrix(m)); // trueAPI
Types
BackendType- Available backends:'js' | 'wasm' | 'gpu'NumericType- Numeric precision typesMathTSConfig- Configuration interface
SI dimension vectors
toSiDimensionVector returns exact Fraction exponents [L, M, T, I, Θ, N, J]; use
vec.map((f) => f.toNumber()) when you need plain numbers (there is no
toSiDimensionNumbers helper). fromSiDimensionVector accepts SiDimensionExponent
(number | Fraction) and produces the length-10 Unit exponent array.
Functions
createSeededRng(seed)/SeededRng— forkable Mulberry32 stream (next,nextInt,normal,fork); number seeds matchmulberry32, strings are FNV-1a UTF-8 (not cryptographically secure)const rng = createSeededRng(42); rng.next(); // 0.6011037519201636 rng.fork('a').next(); // 0.668102843221277 createSeededRng('a').seed; // -468965076mulberry32(seed)— seeded Mulberry32 PRNG returning U[0, 1) samples (not cryptographically secure)boxMuller(u1, u2)— Box–Muller pair of N(0, 1) samples from two uniformsrowMajorStrides(shape)— row-major stride vector for a dense tensor shapeDEFAULT_CONFIG- Default configuration objectisNumber(value)- Type guard for numbersisComplex(value)- Type guard for complex numbersisMatrix(value)- Type guard for matrix-like objects (rows,cols,get,type)
License
MIT
