deepbox 0.1.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/LICENSE +21 -0
- package/README.md +344 -0
- package/dist/CSRMatrix-CwGwQRea.d.cts +219 -0
- package/dist/CSRMatrix-KzNt6QpS.d.ts +219 -0
- package/dist/Tensor-BQLk1ltW.d.cts +147 -0
- package/dist/Tensor-g8mUClel.d.ts +147 -0
- package/dist/chunk-4S73VUBD.js +677 -0
- package/dist/chunk-4S73VUBD.js.map +1 -0
- package/dist/chunk-5R4S63PF.js +2925 -0
- package/dist/chunk-5R4S63PF.js.map +1 -0
- package/dist/chunk-6AE5FKKQ.cjs +9264 -0
- package/dist/chunk-6AE5FKKQ.cjs.map +1 -0
- package/dist/chunk-AD436M45.js +3854 -0
- package/dist/chunk-AD436M45.js.map +1 -0
- package/dist/chunk-ALS7ETWZ.cjs +4263 -0
- package/dist/chunk-ALS7ETWZ.cjs.map +1 -0
- package/dist/chunk-AU7XHGKJ.js +2092 -0
- package/dist/chunk-AU7XHGKJ.js.map +1 -0
- package/dist/chunk-B5TNKUEY.js +1481 -0
- package/dist/chunk-B5TNKUEY.js.map +1 -0
- package/dist/chunk-BCR7G3A6.js +9136 -0
- package/dist/chunk-BCR7G3A6.js.map +1 -0
- package/dist/chunk-C4PKXY74.cjs +1917 -0
- package/dist/chunk-C4PKXY74.cjs.map +1 -0
- package/dist/chunk-DWZY6PIP.cjs +6400 -0
- package/dist/chunk-DWZY6PIP.cjs.map +1 -0
- package/dist/chunk-E3EU5FZO.cjs +2113 -0
- package/dist/chunk-E3EU5FZO.cjs.map +1 -0
- package/dist/chunk-F3JWBINJ.js +1054 -0
- package/dist/chunk-F3JWBINJ.js.map +1 -0
- package/dist/chunk-FJYLIGJX.js +1940 -0
- package/dist/chunk-FJYLIGJX.js.map +1 -0
- package/dist/chunk-JSCDE774.cjs +729 -0
- package/dist/chunk-JSCDE774.cjs.map +1 -0
- package/dist/chunk-LWECRCW2.cjs +2412 -0
- package/dist/chunk-LWECRCW2.cjs.map +1 -0
- package/dist/chunk-MLBMYKCG.js +6379 -0
- package/dist/chunk-MLBMYKCG.js.map +1 -0
- package/dist/chunk-OX6QXFMV.cjs +3874 -0
- package/dist/chunk-OX6QXFMV.cjs.map +1 -0
- package/dist/chunk-PHV2DKRS.cjs +1072 -0
- package/dist/chunk-PHV2DKRS.cjs.map +1 -0
- package/dist/chunk-PL7TAYKI.js +4056 -0
- package/dist/chunk-PL7TAYKI.js.map +1 -0
- package/dist/chunk-PR647I7R.js +1898 -0
- package/dist/chunk-PR647I7R.js.map +1 -0
- package/dist/chunk-QERHVCHC.cjs +2960 -0
- package/dist/chunk-QERHVCHC.cjs.map +1 -0
- package/dist/chunk-XEG44RF6.cjs +1514 -0
- package/dist/chunk-XEG44RF6.cjs.map +1 -0
- package/dist/chunk-XMWVME2W.js +2377 -0
- package/dist/chunk-XMWVME2W.js.map +1 -0
- package/dist/chunk-ZB75FESB.cjs +1979 -0
- package/dist/chunk-ZB75FESB.cjs.map +1 -0
- package/dist/chunk-ZLW62TJG.cjs +4061 -0
- package/dist/chunk-ZLW62TJG.cjs.map +1 -0
- package/dist/chunk-ZXKBDFP3.js +4235 -0
- package/dist/chunk-ZXKBDFP3.js.map +1 -0
- package/dist/core/index.cjs +204 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/dataframe/index.cjs +22 -0
- package/dist/dataframe/index.cjs.map +1 -0
- package/dist/dataframe/index.d.cts +3 -0
- package/dist/dataframe/index.d.ts +3 -0
- package/dist/dataframe/index.js +5 -0
- package/dist/dataframe/index.js.map +1 -0
- package/dist/datasets/index.cjs +134 -0
- package/dist/datasets/index.cjs.map +1 -0
- package/dist/datasets/index.d.cts +3 -0
- package/dist/datasets/index.d.ts +3 -0
- package/dist/datasets/index.js +5 -0
- package/dist/datasets/index.js.map +1 -0
- package/dist/index-74AB8Cyh.d.cts +1126 -0
- package/dist/index-9oQx1HgV.d.cts +1180 -0
- package/dist/index-BJY2SI4i.d.ts +483 -0
- package/dist/index-BWGhrDlr.d.ts +733 -0
- package/dist/index-B_DK4FKY.d.cts +242 -0
- package/dist/index-BbA2Gxfl.d.ts +456 -0
- package/dist/index-BgHYAoSS.d.cts +837 -0
- package/dist/index-BndMbqsM.d.ts +1439 -0
- package/dist/index-C1mfVYoo.d.ts +2517 -0
- package/dist/index-CCvlwAmL.d.cts +809 -0
- package/dist/index-CDw5CnOU.d.ts +785 -0
- package/dist/index-Cn3SdB0O.d.ts +1126 -0
- package/dist/index-CrqLlS-a.d.ts +776 -0
- package/dist/index-D61yaSMY.d.cts +483 -0
- package/dist/index-D9Loo1_A.d.cts +2517 -0
- package/dist/index-DIT_OO9C.d.cts +785 -0
- package/dist/index-DIp_RrRt.d.ts +242 -0
- package/dist/index-DbultU6X.d.cts +1427 -0
- package/dist/index-DmEg_LCm.d.cts +776 -0
- package/dist/index-DoPWVxPo.d.cts +1439 -0
- package/dist/index-DuCxd-8d.d.ts +837 -0
- package/dist/index-Dx42TZaY.d.ts +809 -0
- package/dist/index-DyZ4QQf5.d.cts +456 -0
- package/dist/index-GFAVyOWO.d.ts +1427 -0
- package/dist/index-WHQLn0e8.d.cts +733 -0
- package/dist/index-ZtI1Iy4L.d.ts +1180 -0
- package/dist/index-eJgeni9c.d.cts +1911 -0
- package/dist/index-tk4lSYod.d.ts +1911 -0
- package/dist/index.cjs +72 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/linalg/index.cjs +86 -0
- package/dist/linalg/index.cjs.map +1 -0
- package/dist/linalg/index.d.cts +3 -0
- package/dist/linalg/index.d.ts +3 -0
- package/dist/linalg/index.js +5 -0
- package/dist/linalg/index.js.map +1 -0
- package/dist/metrics/index.cjs +158 -0
- package/dist/metrics/index.cjs.map +1 -0
- package/dist/metrics/index.d.cts +3 -0
- package/dist/metrics/index.d.ts +3 -0
- package/dist/metrics/index.js +5 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/ml/index.cjs +87 -0
- package/dist/ml/index.cjs.map +1 -0
- package/dist/ml/index.d.cts +3 -0
- package/dist/ml/index.d.ts +3 -0
- package/dist/ml/index.js +6 -0
- package/dist/ml/index.js.map +1 -0
- package/dist/ndarray/index.cjs +501 -0
- package/dist/ndarray/index.cjs.map +1 -0
- package/dist/ndarray/index.d.cts +5 -0
- package/dist/ndarray/index.d.ts +5 -0
- package/dist/ndarray/index.js +4 -0
- package/dist/ndarray/index.js.map +1 -0
- package/dist/nn/index.cjs +142 -0
- package/dist/nn/index.cjs.map +1 -0
- package/dist/nn/index.d.cts +6 -0
- package/dist/nn/index.d.ts +6 -0
- package/dist/nn/index.js +5 -0
- package/dist/nn/index.js.map +1 -0
- package/dist/optim/index.cjs +77 -0
- package/dist/optim/index.cjs.map +1 -0
- package/dist/optim/index.d.cts +4 -0
- package/dist/optim/index.d.ts +4 -0
- package/dist/optim/index.js +4 -0
- package/dist/optim/index.js.map +1 -0
- package/dist/plot/index.cjs +114 -0
- package/dist/plot/index.cjs.map +1 -0
- package/dist/plot/index.d.cts +6 -0
- package/dist/plot/index.d.ts +6 -0
- package/dist/plot/index.js +5 -0
- package/dist/plot/index.js.map +1 -0
- package/dist/preprocess/index.cjs +82 -0
- package/dist/preprocess/index.cjs.map +1 -0
- package/dist/preprocess/index.d.cts +4 -0
- package/dist/preprocess/index.d.ts +4 -0
- package/dist/preprocess/index.js +5 -0
- package/dist/preprocess/index.js.map +1 -0
- package/dist/random/index.cjs +74 -0
- package/dist/random/index.cjs.map +1 -0
- package/dist/random/index.d.cts +3 -0
- package/dist/random/index.d.ts +3 -0
- package/dist/random/index.js +5 -0
- package/dist/random/index.js.map +1 -0
- package/dist/stats/index.cjs +142 -0
- package/dist/stats/index.cjs.map +1 -0
- package/dist/stats/index.d.cts +3 -0
- package/dist/stats/index.d.ts +3 -0
- package/dist/stats/index.js +5 -0
- package/dist/stats/index.js.map +1 -0
- package/dist/tensor-B96jjJLQ.d.cts +205 -0
- package/dist/tensor-B96jjJLQ.d.ts +205 -0
- package/package.json +226 -0
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/core/index.ts
|
|
8
|
+
var core_exports = {};
|
|
9
|
+
__export(core_exports, {
|
|
10
|
+
BroadcastError: () => BroadcastError,
|
|
11
|
+
ConvergenceError: () => ConvergenceError,
|
|
12
|
+
DEVICES: () => DEVICES,
|
|
13
|
+
DTYPES: () => DTYPES,
|
|
14
|
+
DTypeError: () => DTypeError,
|
|
15
|
+
DataValidationError: () => DataValidationError,
|
|
16
|
+
DeepboxError: () => DeepboxError,
|
|
17
|
+
DeviceError: () => DeviceError,
|
|
18
|
+
IndexError: () => IndexError,
|
|
19
|
+
InvalidParameterError: () => InvalidParameterError,
|
|
20
|
+
MemoryError: () => MemoryError,
|
|
21
|
+
NotFittedError: () => NotFittedError,
|
|
22
|
+
NotImplementedError: () => NotImplementedError,
|
|
23
|
+
ShapeError: () => ShapeError,
|
|
24
|
+
asReadonlyArray: () => asReadonlyArray,
|
|
25
|
+
dtypeToTypedArrayCtor: () => dtypeToTypedArrayCtor,
|
|
26
|
+
ensureNumericDType: () => ensureNumericDType,
|
|
27
|
+
getArrayElement: () => getArrayElement,
|
|
28
|
+
getBigIntElement: () => getBigIntElement,
|
|
29
|
+
getConfig: () => getConfig,
|
|
30
|
+
getDevice: () => getDevice,
|
|
31
|
+
getDtype: () => getDtype,
|
|
32
|
+
getElementAsNumber: () => getElementAsNumber,
|
|
33
|
+
getNumericElement: () => getNumericElement,
|
|
34
|
+
getSeed: () => getSeed,
|
|
35
|
+
getShapeDim: () => getShapeDim,
|
|
36
|
+
getStringElement: () => getStringElement,
|
|
37
|
+
isBigInt64Array: () => isBigInt64Array,
|
|
38
|
+
isDType: () => isDType,
|
|
39
|
+
isDevice: () => isDevice,
|
|
40
|
+
isNumericTypedArray: () => isNumericTypedArray,
|
|
41
|
+
isTypedArray: () => isTypedArray,
|
|
42
|
+
normalizeAxes: () => normalizeAxes,
|
|
43
|
+
normalizeAxis: () => normalizeAxis,
|
|
44
|
+
resetConfig: () => resetConfig,
|
|
45
|
+
setConfig: () => setConfig,
|
|
46
|
+
setDevice: () => setDevice,
|
|
47
|
+
setDtype: () => setDtype,
|
|
48
|
+
setSeed: () => setSeed,
|
|
49
|
+
shapeToSize: () => shapeToSize,
|
|
50
|
+
validateArray: () => validateArray,
|
|
51
|
+
validateDevice: () => validateDevice,
|
|
52
|
+
validateDtype: () => validateDtype,
|
|
53
|
+
validateInteger: () => validateInteger,
|
|
54
|
+
validateNonNegative: () => validateNonNegative,
|
|
55
|
+
validateOneOf: () => validateOneOf,
|
|
56
|
+
validatePositive: () => validatePositive,
|
|
57
|
+
validateRange: () => validateRange,
|
|
58
|
+
validateShape: () => validateShape
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// src/core/errors/base.ts
|
|
62
|
+
var DeepboxError = class extends Error {
|
|
63
|
+
name = "DeepboxError";
|
|
64
|
+
cause;
|
|
65
|
+
constructor(message, options) {
|
|
66
|
+
super(message);
|
|
67
|
+
if (options?.cause !== void 0) {
|
|
68
|
+
this.cause = options.cause;
|
|
69
|
+
}
|
|
70
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/core/errors/validation.ts
|
|
75
|
+
var DataValidationError = class extends DeepboxError {
|
|
76
|
+
name = "DataValidationError";
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/core/types/device.ts
|
|
80
|
+
var DEVICES = ["cpu", "webgpu", "wasm"];
|
|
81
|
+
function isDevice(value) {
|
|
82
|
+
if (typeof value !== "string") {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
for (const d of DEVICES) {
|
|
86
|
+
if (d === value) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/core/types/dtype.ts
|
|
94
|
+
var DTYPES = [
|
|
95
|
+
"float32",
|
|
96
|
+
"float64",
|
|
97
|
+
"int32",
|
|
98
|
+
"int64",
|
|
99
|
+
"uint8",
|
|
100
|
+
"bool",
|
|
101
|
+
"string"
|
|
102
|
+
];
|
|
103
|
+
function isDType(value) {
|
|
104
|
+
if (typeof value !== "string") {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
for (const d of DTYPES) {
|
|
108
|
+
if (d === value) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/core/utils/validation.ts
|
|
116
|
+
function shapeToSize(shape, name = "shape") {
|
|
117
|
+
const validated = validateShape(shape, name);
|
|
118
|
+
let size = 1;
|
|
119
|
+
for (const dim of validated) {
|
|
120
|
+
if (dim === 0) return 0;
|
|
121
|
+
if (size > Number.MAX_SAFE_INTEGER / dim) {
|
|
122
|
+
throw new DataValidationError(
|
|
123
|
+
`${name} is too large; total size exceeds ${Number.MAX_SAFE_INTEGER}`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
size *= dim;
|
|
127
|
+
}
|
|
128
|
+
return size;
|
|
129
|
+
}
|
|
130
|
+
function validateShape(shape, name = "shape") {
|
|
131
|
+
if (!Array.isArray(shape)) {
|
|
132
|
+
throw new DataValidationError(`${name} must be an array of integers`);
|
|
133
|
+
}
|
|
134
|
+
const validated = [];
|
|
135
|
+
for (let i = 0; i < shape.length; i++) {
|
|
136
|
+
const dim = shape[i];
|
|
137
|
+
if (typeof dim !== "number" || !Number.isFinite(dim) || !Number.isInteger(dim)) {
|
|
138
|
+
throw new DataValidationError(
|
|
139
|
+
`${name}[${i}] must be a finite integer; received ${String(dim)}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
if (dim < 0) {
|
|
143
|
+
throw new DataValidationError(`${name}[${i}] must be >= 0; received ${dim}`);
|
|
144
|
+
}
|
|
145
|
+
if (!Number.isSafeInteger(dim)) {
|
|
146
|
+
throw new DataValidationError(
|
|
147
|
+
`${name}[${i}] must be a safe integer (<= ${Number.MAX_SAFE_INTEGER}); received ${dim}`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
validated.push(dim);
|
|
151
|
+
}
|
|
152
|
+
return validated;
|
|
153
|
+
}
|
|
154
|
+
function validateDtype(dtype, name = "dtype") {
|
|
155
|
+
if (!isDType(dtype)) {
|
|
156
|
+
throw new DataValidationError(
|
|
157
|
+
`${name} must be one of [${DTYPES.join(", ")}]; received ${String(dtype)}`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return dtype;
|
|
161
|
+
}
|
|
162
|
+
function validateDevice(device, name = "device") {
|
|
163
|
+
if (!isDevice(device)) {
|
|
164
|
+
throw new DataValidationError(
|
|
165
|
+
`${name} must be one of [${DEVICES.join(", ")}]; received ${String(device)}`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return device;
|
|
169
|
+
}
|
|
170
|
+
function validatePositive(value, name) {
|
|
171
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
172
|
+
throw new DataValidationError(`${name} must be a finite number; received ${String(value)}`);
|
|
173
|
+
}
|
|
174
|
+
if (value <= 0) {
|
|
175
|
+
throw new DataValidationError(`${name} must be positive (> 0); received ${value}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function validateNonNegative(value, name) {
|
|
179
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
180
|
+
throw new DataValidationError(`${name} must be a finite number; received ${String(value)}`);
|
|
181
|
+
}
|
|
182
|
+
if (value < 0) {
|
|
183
|
+
throw new DataValidationError(`${name} must be non-negative (>= 0); received ${value}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function validateRange(value, min, max, name) {
|
|
187
|
+
if (typeof min !== "number" || !Number.isFinite(min)) {
|
|
188
|
+
throw new DataValidationError(`${name} min must be a finite number; received ${String(min)}`);
|
|
189
|
+
}
|
|
190
|
+
if (typeof max !== "number" || !Number.isFinite(max)) {
|
|
191
|
+
throw new DataValidationError(`${name} max must be a finite number; received ${String(max)}`);
|
|
192
|
+
}
|
|
193
|
+
if (min > max) {
|
|
194
|
+
throw new DataValidationError(`${name} min must be <= max; received min=${min}, max=${max}`);
|
|
195
|
+
}
|
|
196
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
197
|
+
throw new DataValidationError(`${name} must be a finite number; received ${String(value)}`);
|
|
198
|
+
}
|
|
199
|
+
if (value < min || value > max) {
|
|
200
|
+
throw new DataValidationError(`${name} must be in range [${min}, ${max}]; received ${value}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function validateInteger(value, name) {
|
|
204
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
205
|
+
throw new DataValidationError(`${name} must be a finite number; received ${String(value)}`);
|
|
206
|
+
}
|
|
207
|
+
if (!Number.isInteger(value)) {
|
|
208
|
+
throw new DataValidationError(`${name} must be an integer; received ${value}`);
|
|
209
|
+
}
|
|
210
|
+
if (!Number.isSafeInteger(value)) {
|
|
211
|
+
throw new DataValidationError(
|
|
212
|
+
`${name} must be a safe integer (<= ${Number.MAX_SAFE_INTEGER}); received ${value}`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function validateOneOf(value, options, name) {
|
|
217
|
+
if (typeof value !== "string") {
|
|
218
|
+
throw new DataValidationError(`${name} must be a string; received ${typeof value}`);
|
|
219
|
+
}
|
|
220
|
+
let found = false;
|
|
221
|
+
for (const opt of options) {
|
|
222
|
+
if (opt === value) {
|
|
223
|
+
found = true;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (!found) {
|
|
228
|
+
throw new DataValidationError(
|
|
229
|
+
`${name} must be one of [${options.join(", ")}]; received ${String(value)}`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function validateArray(arr, name) {
|
|
234
|
+
if (!Array.isArray(arr)) {
|
|
235
|
+
throw new DataValidationError(`${name} must be an array; received ${typeof arr}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/core/config/global.ts
|
|
240
|
+
var DEFAULT_CONFIG = {
|
|
241
|
+
defaultDtype: "float32",
|
|
242
|
+
defaultDevice: "cpu",
|
|
243
|
+
seed: null
|
|
244
|
+
};
|
|
245
|
+
var CONFIG_KEYS = ["defaultDtype", "defaultDevice", "seed"];
|
|
246
|
+
var config = { ...DEFAULT_CONFIG };
|
|
247
|
+
function isPlainConfigObject(value) {
|
|
248
|
+
const prototype = Object.getPrototypeOf(value);
|
|
249
|
+
return prototype === Object.prototype || prototype === null;
|
|
250
|
+
}
|
|
251
|
+
function hasOwnConfigKey(source, key) {
|
|
252
|
+
return Object.hasOwn(source, key);
|
|
253
|
+
}
|
|
254
|
+
function normalizeSeed(value, name, allowNull) {
|
|
255
|
+
if (value === null) {
|
|
256
|
+
if (allowNull) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
throw new DataValidationError(`${name} must be a safe integer; received null`);
|
|
260
|
+
}
|
|
261
|
+
if (typeof value !== "number") {
|
|
262
|
+
throw new DataValidationError(`${name} must be a finite number; received ${String(value)}`);
|
|
263
|
+
}
|
|
264
|
+
validateInteger(value, name);
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
function getConfig() {
|
|
268
|
+
return { ...config };
|
|
269
|
+
}
|
|
270
|
+
function setConfig(next) {
|
|
271
|
+
if (next === null || typeof next !== "object" || Array.isArray(next)) {
|
|
272
|
+
throw new DataValidationError(`config must be an object with keys [${CONFIG_KEYS.join(", ")}]`);
|
|
273
|
+
}
|
|
274
|
+
if (!isPlainConfigObject(next)) {
|
|
275
|
+
throw new DataValidationError(
|
|
276
|
+
`config must be a plain object with keys [${CONFIG_KEYS.join(", ")}]`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
const keys = Object.keys(next);
|
|
280
|
+
const unknownKeys = [];
|
|
281
|
+
for (const key of keys) {
|
|
282
|
+
let isKnown = false;
|
|
283
|
+
for (const allowed of CONFIG_KEYS) {
|
|
284
|
+
if (allowed === key) {
|
|
285
|
+
isKnown = true;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (!isKnown) {
|
|
290
|
+
unknownKeys.push(key);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (unknownKeys.length > 0) {
|
|
294
|
+
throw new DataValidationError(
|
|
295
|
+
`config contains unsupported keys: ${unknownKeys.join(", ")}. Allowed keys are [${CONFIG_KEYS.join(
|
|
296
|
+
", "
|
|
297
|
+
)}]`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
const nextDefaultDtype = hasOwnConfigKey(next, "defaultDtype") ? validateDtype(next.defaultDtype, "defaultDtype") : config.defaultDtype;
|
|
301
|
+
const nextDefaultDevice = hasOwnConfigKey(next, "defaultDevice") ? validateDevice(next.defaultDevice, "defaultDevice") : config.defaultDevice;
|
|
302
|
+
const nextSeed = hasOwnConfigKey(next, "seed") ? normalizeSeed(next.seed, "seed", true) : config.seed;
|
|
303
|
+
config = {
|
|
304
|
+
defaultDtype: nextDefaultDtype,
|
|
305
|
+
defaultDevice: nextDefaultDevice,
|
|
306
|
+
seed: nextSeed
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function resetConfig() {
|
|
310
|
+
config = { ...DEFAULT_CONFIG };
|
|
311
|
+
}
|
|
312
|
+
function setSeed(seed) {
|
|
313
|
+
const normalized = normalizeSeed(seed, "seed", false);
|
|
314
|
+
config = { ...config, seed: normalized };
|
|
315
|
+
}
|
|
316
|
+
function getSeed() {
|
|
317
|
+
return config.seed;
|
|
318
|
+
}
|
|
319
|
+
function setDevice(device) {
|
|
320
|
+
const normalized = validateDevice(device, "device");
|
|
321
|
+
config = { ...config, defaultDevice: normalized };
|
|
322
|
+
}
|
|
323
|
+
function getDevice() {
|
|
324
|
+
return config.defaultDevice;
|
|
325
|
+
}
|
|
326
|
+
function setDtype(dtype) {
|
|
327
|
+
const normalized = validateDtype(dtype, "dtype");
|
|
328
|
+
config = { ...config, defaultDtype: normalized };
|
|
329
|
+
}
|
|
330
|
+
function getDtype() {
|
|
331
|
+
return config.defaultDtype;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/core/errors/broadcast.ts
|
|
335
|
+
function cloneShape(shape) {
|
|
336
|
+
return Object.freeze([...shape]);
|
|
337
|
+
}
|
|
338
|
+
var BroadcastError = class extends DeepboxError {
|
|
339
|
+
name = "BroadcastError";
|
|
340
|
+
/** The first shape involved in the broadcast operation */
|
|
341
|
+
shape1;
|
|
342
|
+
/** The second shape involved in the broadcast operation */
|
|
343
|
+
shape2;
|
|
344
|
+
constructor(shape1, shape2, context) {
|
|
345
|
+
const ctx = context ? ` (${context})` : "";
|
|
346
|
+
super(`Shapes [${shape1}] and [${shape2}] cannot be broadcast together${ctx}`);
|
|
347
|
+
this.shape1 = cloneShape(shape1);
|
|
348
|
+
this.shape2 = cloneShape(shape2);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// src/core/errors/convergence.ts
|
|
353
|
+
var ConvergenceError = class extends DeepboxError {
|
|
354
|
+
name = "ConvergenceError";
|
|
355
|
+
/** Number of iterations completed before convergence failure */
|
|
356
|
+
iterations;
|
|
357
|
+
/** Tolerance value used for convergence check */
|
|
358
|
+
tolerance;
|
|
359
|
+
constructor(message, details) {
|
|
360
|
+
super(message);
|
|
361
|
+
if (details?.iterations !== void 0) {
|
|
362
|
+
this.iterations = details.iterations;
|
|
363
|
+
}
|
|
364
|
+
if (details?.tolerance !== void 0) {
|
|
365
|
+
this.tolerance = details.tolerance;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// src/core/errors/device.ts
|
|
371
|
+
var DeviceError = class extends DeepboxError {
|
|
372
|
+
/**
|
|
373
|
+
* Discriminator name for this error type.
|
|
374
|
+
*/
|
|
375
|
+
name = "DeviceError";
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/core/errors/dtype.ts
|
|
379
|
+
var DTypeError = class extends DeepboxError {
|
|
380
|
+
/**
|
|
381
|
+
* Discriminator name for this error type.
|
|
382
|
+
*/
|
|
383
|
+
name = "DTypeError";
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/core/errors/indexError.ts
|
|
387
|
+
var IndexError = class extends DeepboxError {
|
|
388
|
+
name = "IndexError";
|
|
389
|
+
/** The invalid index value */
|
|
390
|
+
index;
|
|
391
|
+
/** The valid range for the index */
|
|
392
|
+
validRange;
|
|
393
|
+
constructor(message, details) {
|
|
394
|
+
super(message);
|
|
395
|
+
if (details?.index !== void 0) {
|
|
396
|
+
this.index = details.index;
|
|
397
|
+
}
|
|
398
|
+
if (details?.validRange !== void 0) {
|
|
399
|
+
this.validRange = details.validRange;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// src/core/errors/invalidParameter.ts
|
|
405
|
+
var InvalidParameterError = class extends DeepboxError {
|
|
406
|
+
name = "InvalidParameterError";
|
|
407
|
+
/** The name of the invalid parameter */
|
|
408
|
+
parameterName;
|
|
409
|
+
/** The invalid value that was provided */
|
|
410
|
+
value;
|
|
411
|
+
constructor(message, parameterName, value) {
|
|
412
|
+
super(message);
|
|
413
|
+
if (parameterName !== void 0) {
|
|
414
|
+
this.parameterName = parameterName;
|
|
415
|
+
}
|
|
416
|
+
if (value !== void 0) {
|
|
417
|
+
this.value = value;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// src/core/errors/memory.ts
|
|
423
|
+
var MemoryError = class extends DeepboxError {
|
|
424
|
+
name = "MemoryError";
|
|
425
|
+
/** The amount of memory requested in bytes */
|
|
426
|
+
requestedBytes;
|
|
427
|
+
/** The amount of memory available in bytes */
|
|
428
|
+
availableBytes;
|
|
429
|
+
constructor(message, details) {
|
|
430
|
+
super(message);
|
|
431
|
+
if (details?.requestedBytes !== void 0) {
|
|
432
|
+
this.requestedBytes = details.requestedBytes;
|
|
433
|
+
}
|
|
434
|
+
if (details?.availableBytes !== void 0) {
|
|
435
|
+
this.availableBytes = details.availableBytes;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// src/core/errors/notFitted.ts
|
|
441
|
+
var NotFittedError = class extends DeepboxError {
|
|
442
|
+
name = "NotFittedError";
|
|
443
|
+
/** The name of the model or estimator that was not fitted */
|
|
444
|
+
modelName;
|
|
445
|
+
constructor(message, modelName) {
|
|
446
|
+
super(message);
|
|
447
|
+
if (modelName !== void 0) {
|
|
448
|
+
this.modelName = modelName;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// src/core/errors/notImplemented.ts
|
|
454
|
+
var NotImplementedError = class extends DeepboxError {
|
|
455
|
+
/**
|
|
456
|
+
* Discriminator name for this error type.
|
|
457
|
+
*/
|
|
458
|
+
name = "NotImplementedError";
|
|
459
|
+
/**
|
|
460
|
+
* Create a new NotImplementedError.
|
|
461
|
+
*
|
|
462
|
+
* @param message - Optional error message.
|
|
463
|
+
*/
|
|
464
|
+
constructor(message = "Not implemented") {
|
|
465
|
+
super(message);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/core/errors/shape.ts
|
|
470
|
+
function cloneShape2(shape) {
|
|
471
|
+
return Object.freeze([...shape]);
|
|
472
|
+
}
|
|
473
|
+
var ShapeError = class _ShapeError extends DeepboxError {
|
|
474
|
+
name = "ShapeError";
|
|
475
|
+
expected;
|
|
476
|
+
received;
|
|
477
|
+
context;
|
|
478
|
+
constructor(message, details = {}) {
|
|
479
|
+
super(message);
|
|
480
|
+
this.expected = details.expected === void 0 ? void 0 : cloneShape2(details.expected);
|
|
481
|
+
this.received = details.received === void 0 ? void 0 : cloneShape2(details.received);
|
|
482
|
+
this.context = details.context;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Create a ShapeError for a shape mismatch.
|
|
486
|
+
*
|
|
487
|
+
* Convenience factory method for the common case of shape mismatches.
|
|
488
|
+
*
|
|
489
|
+
* @param expected - The expected shape
|
|
490
|
+
* @param received - The actual shape that was received
|
|
491
|
+
* @param context - Optional context about where the mismatch occurred
|
|
492
|
+
* @returns A new ShapeError with formatted message and details
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* throw ShapeError.mismatch([3, 4], [3, 5], 'matrix multiplication');
|
|
497
|
+
* // Error: Shape mismatch (matrix multiplication): expected [3,4], received [3,5]
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
static mismatch(expected, received, context) {
|
|
501
|
+
const ctx = context ? ` (${context})` : "";
|
|
502
|
+
const details = {
|
|
503
|
+
expected,
|
|
504
|
+
received,
|
|
505
|
+
...context !== void 0 ? { context } : {}
|
|
506
|
+
};
|
|
507
|
+
return new _ShapeError(
|
|
508
|
+
`Shape mismatch${ctx}: expected [${expected}], received [${received}]`,
|
|
509
|
+
details
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
// src/core/utils/axis.ts
|
|
515
|
+
function normalizeAxis(axis, ndim) {
|
|
516
|
+
if (!Number.isInteger(ndim) || ndim < 0) {
|
|
517
|
+
throw new InvalidParameterError(
|
|
518
|
+
`ndim must be a non-negative integer; received ${ndim}`,
|
|
519
|
+
"ndim",
|
|
520
|
+
ndim
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
let ax;
|
|
524
|
+
if (typeof axis === "string") {
|
|
525
|
+
if (axis === "index" || axis === "rows") {
|
|
526
|
+
ax = 0;
|
|
527
|
+
} else if (axis === "columns") {
|
|
528
|
+
ax = 1;
|
|
529
|
+
} else {
|
|
530
|
+
throw new InvalidParameterError(
|
|
531
|
+
`Invalid axis: '${axis}'. Must be 'index', 'rows', or 'columns'`,
|
|
532
|
+
"axis",
|
|
533
|
+
axis
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
} else {
|
|
537
|
+
if (!Number.isInteger(axis)) {
|
|
538
|
+
throw new InvalidParameterError(`axis must be an integer; received ${axis}`, "axis", axis);
|
|
539
|
+
}
|
|
540
|
+
ax = axis;
|
|
541
|
+
}
|
|
542
|
+
const normalized = ax < 0 ? ndim + ax : ax;
|
|
543
|
+
if (normalized < 0 || normalized >= ndim) {
|
|
544
|
+
throw new InvalidParameterError(`axis ${axis} is out of bounds for ndim=${ndim}`, "axis", axis);
|
|
545
|
+
}
|
|
546
|
+
return normalized;
|
|
547
|
+
}
|
|
548
|
+
function normalizeAxes(axis, ndim) {
|
|
549
|
+
if (!Number.isInteger(ndim) || ndim < 0) {
|
|
550
|
+
throw new InvalidParameterError(
|
|
551
|
+
`ndim must be a non-negative integer; received ${ndim}`,
|
|
552
|
+
"ndim",
|
|
553
|
+
ndim
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
const axes = Array.isArray(axis) ? axis : [axis];
|
|
557
|
+
const seen = /* @__PURE__ */ new Set();
|
|
558
|
+
const normalized = [];
|
|
559
|
+
for (const ax of axes) {
|
|
560
|
+
const norm = normalizeAxis(ax, ndim);
|
|
561
|
+
if (seen.has(norm)) {
|
|
562
|
+
throw new InvalidParameterError("duplicate axis", "axis", axis);
|
|
563
|
+
}
|
|
564
|
+
seen.add(norm);
|
|
565
|
+
normalized.push(norm);
|
|
566
|
+
}
|
|
567
|
+
return normalized;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// src/core/utils/dtypeUtils.ts
|
|
571
|
+
function ensureNumericDType(dtype, context) {
|
|
572
|
+
if (dtype === "string") {
|
|
573
|
+
throw new DTypeError(`${context} does not support string dtype`);
|
|
574
|
+
}
|
|
575
|
+
return dtype;
|
|
576
|
+
}
|
|
577
|
+
function dtypeToTypedArrayCtor(dtype) {
|
|
578
|
+
switch (dtype) {
|
|
579
|
+
case "float32":
|
|
580
|
+
return Float32Array;
|
|
581
|
+
case "float64":
|
|
582
|
+
return Float64Array;
|
|
583
|
+
case "int32":
|
|
584
|
+
return Int32Array;
|
|
585
|
+
case "int64":
|
|
586
|
+
return BigInt64Array;
|
|
587
|
+
case "uint8":
|
|
588
|
+
return Uint8Array;
|
|
589
|
+
case "bool":
|
|
590
|
+
return Uint8Array;
|
|
591
|
+
case "string":
|
|
592
|
+
throw new DTypeError("string dtype is not supported for TypedArray storage");
|
|
593
|
+
default: {
|
|
594
|
+
const _exhaustive = dtype;
|
|
595
|
+
throw new DTypeError(`Unsupported dtype: ${String(_exhaustive)}`);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/core/utils/typedArrayAccess.ts
|
|
601
|
+
var MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
602
|
+
var MIN_SAFE_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
|
|
603
|
+
function getNumericElement(arr, index) {
|
|
604
|
+
const value = arr[index];
|
|
605
|
+
if (value === void 0) {
|
|
606
|
+
throw new IndexError(
|
|
607
|
+
`Index ${index} is out of bounds for typed array of length ${arr.length}`,
|
|
608
|
+
{ index, validRange: [0, arr.length - 1] }
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
return value;
|
|
612
|
+
}
|
|
613
|
+
function getBigIntElement(arr, index) {
|
|
614
|
+
const value = arr[index];
|
|
615
|
+
if (value === void 0) {
|
|
616
|
+
throw new IndexError(
|
|
617
|
+
`Index ${index} is out of bounds for BigInt64Array of length ${arr.length}`,
|
|
618
|
+
{ index, validRange: [0, arr.length - 1] }
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
return value;
|
|
622
|
+
}
|
|
623
|
+
function getElementAsNumber(arr, index) {
|
|
624
|
+
if (arr instanceof BigInt64Array) {
|
|
625
|
+
const value2 = arr[index];
|
|
626
|
+
if (value2 === void 0) {
|
|
627
|
+
throw new IndexError(
|
|
628
|
+
`Index ${index} is out of bounds for BigInt64Array of length ${arr.length}`,
|
|
629
|
+
{ index, validRange: [0, arr.length - 1] }
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
if (value2 > MAX_SAFE_BIGINT || value2 < MIN_SAFE_BIGINT) {
|
|
633
|
+
throw new DataValidationError(
|
|
634
|
+
`BigInt value at index ${index} exceeds safe integer range; received ${value2.toString()}`
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
return Number(value2);
|
|
638
|
+
}
|
|
639
|
+
const value = arr[index];
|
|
640
|
+
if (value === void 0) {
|
|
641
|
+
throw new IndexError(
|
|
642
|
+
`Index ${index} is out of bounds for typed array of length ${arr.length}`,
|
|
643
|
+
{ index, validRange: [0, arr.length - 1] }
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
return value;
|
|
647
|
+
}
|
|
648
|
+
function getShapeDim(shape, index) {
|
|
649
|
+
const value = shape[index];
|
|
650
|
+
return value !== void 0 ? value : 1;
|
|
651
|
+
}
|
|
652
|
+
function getArrayElement(arr, index, defaultValue = 0) {
|
|
653
|
+
const value = arr[index];
|
|
654
|
+
return value !== void 0 ? value : defaultValue;
|
|
655
|
+
}
|
|
656
|
+
function getStringElement(arr, index) {
|
|
657
|
+
const value = arr[index];
|
|
658
|
+
return value !== void 0 ? value : "";
|
|
659
|
+
}
|
|
660
|
+
function asReadonlyArray(arr) {
|
|
661
|
+
return arr;
|
|
662
|
+
}
|
|
663
|
+
function isBigInt64Array(arr) {
|
|
664
|
+
return arr instanceof BigInt64Array;
|
|
665
|
+
}
|
|
666
|
+
function isNumericTypedArray(arr) {
|
|
667
|
+
return !(arr instanceof BigInt64Array);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/core/utils/typeGuards.ts
|
|
671
|
+
function isTypedArray(value) {
|
|
672
|
+
return value instanceof Float32Array || value instanceof Float64Array || value instanceof Int32Array || value instanceof BigInt64Array || value instanceof Uint8Array;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export { BroadcastError, ConvergenceError, DEVICES, DTYPES, DTypeError, DataValidationError, DeepboxError, DeviceError, IndexError, InvalidParameterError, MemoryError, NotFittedError, NotImplementedError, ShapeError, __export, asReadonlyArray, core_exports, dtypeToTypedArrayCtor, ensureNumericDType, getArrayElement, getBigIntElement, getConfig, getDevice, getDtype, getElementAsNumber, getNumericElement, getSeed, getShapeDim, getStringElement, isBigInt64Array, isDType, isDevice, isNumericTypedArray, isTypedArray, normalizeAxes, normalizeAxis, resetConfig, setConfig, setDevice, setDtype, setSeed, shapeToSize, validateArray, validateDevice, validateDtype, validateInteger, validateNonNegative, validateOneOf, validatePositive, validateRange, validateShape };
|
|
676
|
+
//# sourceMappingURL=chunk-4S73VUBD.js.map
|
|
677
|
+
//# sourceMappingURL=chunk-4S73VUBD.js.map
|