@nirs4all/methods 1.3.3 → 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);
@@ -4657,6 +4657,29 @@ export declare class QResiduals extends NativeProcedure implements Procedure {
4657
4657
  constructor(params?: QResidualsParams);
4658
4658
  run(X: Matrix, y?: Matrix | Float64Array | ArrayLike<number>, inputs?: FitInputs): Record<string, ProcedureOutput>;
4659
4659
  }
4660
+ /** Parameters of RaggedSummary; unset values take the native defaults. */
4661
+ export interface RaggedSummaryParams {
4662
+ /** Required. */
4663
+ offsets?: number[];
4664
+ /** Default []. */
4665
+ presence?: number[];
4666
+ /** Default []. */
4667
+ time_coordinates?: number[];
4668
+ /** Default "reject". */
4669
+ missing_policy?: "reject" | "zero_with_indicator";
4670
+ }
4671
+ /** Native `utilities.ragged_summary` (generic). */
4672
+ export declare class RaggedSummary extends NativeProcedure implements Procedure {
4673
+ readonly methodId = "utilities.ragged_summary";
4674
+ readonly paramTypes: {
4675
+ readonly offsets: "int_array";
4676
+ readonly presence: "int_array";
4677
+ readonly time_coordinates: "double_array";
4678
+ readonly missing_policy: "enum";
4679
+ };
4680
+ constructor(params?: RaggedSummaryParams);
4681
+ run(X: Matrix, y?: Matrix | Float64Array | ArrayLike<number>, inputs?: FitInputs): Record<string, ProcedureOutput>;
4682
+ }
4660
4683
  /** Parameters of SignalTypeDetector; unset values take the native defaults. */
4661
4684
  export interface SignalTypeDetectorParams {
4662
4685
  /** Default 0.7. */
@@ -3785,6 +3785,24 @@ export class QResiduals extends NativeProcedure {
3785
3785
  }
3786
3786
  }
3787
3787
  NativeMethod.register("utilities.q_residuals", QResiduals);
3788
+ /** Native `utilities.ragged_summary` (generic). */
3789
+ export class RaggedSummary extends NativeProcedure {
3790
+ methodId = "utilities.ragged_summary";
3791
+ paramTypes = {
3792
+ offsets: "int_array",
3793
+ presence: "int_array",
3794
+ time_coordinates: "double_array",
3795
+ missing_policy: "enum",
3796
+ };
3797
+ constructor(params = {}) {
3798
+ super();
3799
+ this.params = { ...params };
3800
+ }
3801
+ run(X, y, inputs = {}) {
3802
+ return this.runOutputs(X, y, inputs);
3803
+ }
3804
+ }
3805
+ NativeMethod.register("utilities.ragged_summary", RaggedSummary);
3788
3806
  /** Native `utilities.signal_type_detector` (generic). */
3789
3807
  export class SignalTypeDetector extends NativeProcedure {
3790
3808
  methodId = "utilities.signal_type_detector";
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";