@nirs4all/methods 1.3.4 → 1.3.5

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/context.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // SPDX-License-Identifier: CECILL-2.1
2
2
  import { checkStatus, getModule } from "./ffi.js";
3
+ import { N4mError, Status } from "./types.js";
3
4
  /** RAII wrapper around n4m_context_t. */
4
5
  export class Context {
5
6
  _ptr;
@@ -10,6 +11,8 @@ export class Context {
10
11
  static create() {
11
12
  const m = getModule();
12
13
  const out = m._malloc(4);
14
+ if (out === 0)
15
+ throw new N4mError(Status.ERR_OUT_OF_MEMORY, "context allocation failed");
13
16
  try {
14
17
  const status = m.ccall("n4m_context_create", "number", ["number"], [out]);
15
18
  checkStatus(status);
package/dist/ffi.js CHANGED
@@ -69,12 +69,36 @@ export function makeMatrixView(data, rows, cols, dtype = 1 /* N4M_DTYPE_F64 */)
69
69
  throw new Error(`matrix data length ${data.length} != rows*cols (${expected})`);
70
70
  }
71
71
  const bytes = Math.max(1, data.length) * 8;
72
+ if (!Number.isSafeInteger(bytes) || bytes > 0x7fffffff) {
73
+ throw new RangeError("matrix exceeds WASM allocation limit");
74
+ }
72
75
  const dataPtr = m._malloc(bytes);
76
+ if (dataPtr === 0)
77
+ throw new N4mError(Status.ERR_OUT_OF_MEMORY, "matrix allocation failed");
73
78
  if (data.length > 0) {
74
79
  m.HEAPF64.set(data, dataPtr / 8);
75
80
  }
76
- const viewPtr = m._malloc(MATRIX_VIEW_SIZE);
77
- const status = m.ccall("n4m_matrix_view_init_rowmajor", "number", ["number", "number", "i64", "i64", "number"], [viewPtr, dataPtr, BigInt(rows), BigInt(cols), dtype]);
81
+ let viewPtr;
82
+ try {
83
+ viewPtr = m._malloc(MATRIX_VIEW_SIZE);
84
+ }
85
+ catch (error) {
86
+ m._free(dataPtr);
87
+ throw error;
88
+ }
89
+ if (viewPtr === 0) {
90
+ m._free(dataPtr);
91
+ throw new N4mError(Status.ERR_OUT_OF_MEMORY, "matrix view allocation failed");
92
+ }
93
+ let status;
94
+ try {
95
+ status = m.ccall("n4m_matrix_view_init_rowmajor", "number", ["number", "number", "i64", "i64", "number"], [viewPtr, dataPtr, BigInt(rows), BigInt(cols), dtype]);
96
+ }
97
+ catch (error) {
98
+ m._free(viewPtr);
99
+ m._free(dataPtr);
100
+ throw error;
101
+ }
78
102
  if (status !== Status.OK) {
79
103
  m._free(dataPtr);
80
104
  m._free(viewPtr);
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { SpectralEncoder, type SpectralEncodingOptions } from "./spectralEncodin
2
2
  export { Optimizer, type OptimizerOptions, type OptimizerTrial, type BatchResult, type OptimizerTrialRecord, type SearchAxis, type SearchConstraint, type TrialValue } from "./optimization.js";
3
3
  export { loadModule, getModule, makeMatrixView, readArrayView } from "./ffi.js";
4
4
  export { Context } from "./context.js";
5
+ export { preflightPca, preflightRepeatability, preflightSummary, preflightNearestNeighbors, preflightLocalContrast, type PreflightPcaResult, type PreflightRepeatabilityResult, type PreflightNeighborResult, type PreflightLocalContrastResult } from "./preflightDiagnostics.js";
5
6
  export { Config } from "./config.js";
6
7
  export { Model, fitPls, predictPls, fitModel, predictModel, fitAom, fitAomChain, fitPop, fitAomRidge, fitAomStack, computeSplit, computeSplitIndices, type PlsModel, type FittedModel, type AomModel, type AomChainDescriptor, type AomChainModel, type PopModel, type AomRidgeOptions, type AomStackOptions, type SplitKind, type SplitOptions, type SplitIndices } from "./model.js";
7
8
  export { ppCreate, ppFit, ppTransform, ppGetState, ppSetState, ppDestroy, type PpOperator, } from "./preprocessing.js";
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ export { SpectralEncoder } from "./spectralEncoding.js";
14
14
  export { Optimizer } from "./optimization.js";
15
15
  export { loadModule, getModule, makeMatrixView, readArrayView } from "./ffi.js";
16
16
  export { Context } from "./context.js";
17
+ export { preflightPca, preflightRepeatability, preflightSummary, preflightNearestNeighbors, preflightLocalContrast } from "./preflightDiagnostics.js";
17
18
  export { Config } from "./config.js";
18
19
  export { Model, fitPls, predictPls, fitModel, predictModel, fitAom, fitAomChain, fitPop, fitAomRidge, fitAomStack, computeSplit, computeSplitIndices } from "./model.js";
19
20
  export { ppCreate, ppFit, ppTransform, ppGetState, ppSetState, ppDestroy, } from "./preprocessing.js";