PY-92

Trace a Wrong Figure to Its First Divergence

  • Medium
  • Visual Diagnosis
  • Python

Task

Write trace_figure_divergence(source_values, plot_data, rendered_coordinates, transform_values, render_coordinates).

Convert the first three inputs to independent NumPy float64 arrays. They must be finite and have the same non-empty shape. Call transform_values(source_copy) to compute the expected plot data, then call render_coordinates(expected_plot_copy) to compute the expected rendered coordinates. Each helper result must also be finite and retain the source shape. Do not change any input or pass an input array directly to a helper.

Compare arrays with np.isclose(..., rtol=1e-9, atol=1e-12). Inspect values in flat row-major order:

  1. If supplied plot_data first differs from the expected plot data, the first divergence stage is "plot data".
  2. Otherwise, if supplied rendered_coordinates differs from the expected rendered coordinates, the stage is "rendered coordinates".
  3. If both match, there is no divergence.

Return a dictionary with exactly these keys:

status, first_divergence, plot_data, rendered_coordinates,
numerical_match, visual_match

status is "ok" when no mismatch exists and "repaired" otherwise. A divergence is a dictionary containing stage, index, expected, and observed; index is the full tuple returned by np.unravel_index. Return the newly computed expected arrays as the repaired plot_data and rendered_coordinates. The two match flags describe those returned arrays, so both must be True after a successful computation.

Example

The first divergence is at (1,) in "plot data", where 4.0 was expected and 99.0 was observed. The returned arrays contain [2, 4, 6] and [20, 40, 60].

Your implementation

You may import NumPy as np. Do not print or ask for input.