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(instructions: ndarray, traces: ndarray) ndarray[source]
Evaluate a compiled RPN program against the trace matrix.
Works for both plan initialization and hot-path evaluation. Each PARAM_REF pushes a view of its
(n_time,)trace row and constants stay scalar; every operator allocates a fresh array, so the views are never written to. Callers must not mutate the result in place (it may alias a traces row).- Parameters:
instructions – Compiled RPN instruction array (one program’s slice of the packed
expr_instructions).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 matchplan.opt_param_names.
- Returns:
(n_time, n_energy)model spectrum.- Return type:
ndarray
- Raises:
ValueError – If
len(theta) != len(plan.opt_indices).
- trspecfit.eval_2d.resolve_param_traces(traces: ndarray, resolution_kinds: ndarray, resolution_indices: ndarray, dyn_group_target_row: ndarray, dyn_group_base_row: ndarray, dyn_group_indptr: ndarray, dyn_sub_func_id: ndarray, dyn_sub_n_params: ndarray, dyn_sub_param_rows: ndarray, dyn_sub_time_axes: ndarray, dyn_sub_masks: ndarray, expr_target_rows: ndarray, expr_instructions: ndarray, expr_indptr: ndarray, conv_target_rows: ndarray, conv_func_ids: ndarray, conv_param_indptr: ndarray, conv_param_rows: ndarray, conv_operator: ConvOperator | None) None[source]
Resolve dynamics, expressions, and convolutions into traces in place.
Dynamics groups, expressions, and resolved-trace convolutions are interleaved in topological order so that downstream consumers see the fully resolved trace (base + dynamics + expressions + IRF). A dynamics group evaluates all substeps (e.g. two expFun in a bi-exponential) and sums them: target = base + sum(traces). Expression-valued dynamics params are resolved before the group that consumes them.
Shared between the hot path (
evaluate_2d) and compile-time trace initialization inschedule_2d.