2D Evaluator

2D evaluator for the compiled backend.

All component functions live in trspecfit.functions.energy as the single source of truth. Peak functions broadcast naturally with (n_time, 1) params and (1, n_energy) energy. Background functions (Offset, LinBack, Shirley) accept optional or axis-agnostic signatures that work for both 1D and 2D evaluation.

trspecfit.eval_2d.eval_expr_program(program: ExprProgram, traces: ndarray) ndarray[source]

Evaluate an RPN ExprProgram against the trace matrix.

Works for both plan initialization and hot-path evaluation. Each PARAM_REF reads a full (n_time,) row from traces; constants are broadcast to (n_time,) via np.full.

Parameters:
  • program – Compiled RPN instruction array.

  • traces(n_params, n_time) trace matrix (current state).

Returns:

(n_time,) result.

Return type:

ndarray

trspecfit.eval_2d.evaluate_2d(plan: ScheduledPlan2D, theta: ndarray) ndarray[source]

Evaluate the compiled 2D model at optimizer parameters theta.

Parameters:
  • plan – Immutable compiled execution schedule from schedule_2d.

  • theta(n_opt,) optimizer parameter vector. Order must match plan.opt_param_names.

Returns:

(n_time, n_energy) model spectrum.

Return type:

ndarray

Raises:

ValueError – If len(theta) != len(plan.opt_indices).