|
1 | 1 | import numpy as np |
2 | 2 |
|
| 3 | +def pixel_triplets_from_subpixel_arrays_from( |
| 4 | + pix_indexes_for_sub, # (M_sub, P) |
| 5 | + pix_weights_for_sub, # (M_sub, P) |
| 6 | + slim_index_for_sub, # (M_sub,) |
| 7 | + fft_index_for_masked_pixel, # (N_unmasked,) |
| 8 | + sub_fraction_slim, # (N_unmasked,) |
| 9 | +): |
| 10 | + """ |
| 11 | + Build sparse source→image mapping triplets (rows, cols, vals) |
| 12 | + for a fixed-size interpolation stencil. |
| 13 | +
|
| 14 | + Assumptions: |
| 15 | + - Every subpixel maps to exactly P source pixels |
| 16 | + - All entries in pix_indexes_for_sub are valid |
| 17 | + - No padding / ragged rows needed |
| 18 | + """ |
| 19 | + import jax.numpy as jnp |
| 20 | + |
| 21 | + |
| 22 | + M_sub, P = pix_indexes_for_sub.shape |
| 23 | + |
| 24 | + sub_ids = jnp.repeat(jnp.arange(M_sub, dtype=jnp.int32), P) |
| 25 | + |
| 26 | + cols = pix_indexes_for_sub.reshape(-1).astype(jnp.int32) |
| 27 | + vals = pix_weights_for_sub.reshape(-1).astype(jnp.float64) |
| 28 | + |
| 29 | + slim_rows = slim_index_for_sub[sub_ids].astype(jnp.int32) |
| 30 | + rows = fft_index_for_masked_pixel[slim_rows].astype(jnp.int32) |
| 31 | + |
| 32 | + vals = vals * sub_fraction_slim[slim_rows].astype(jnp.float64) |
| 33 | + return rows, cols, vals |
| 34 | + |
3 | 35 |
|
4 | 36 | def psf_operator_matrix_dense_from( |
5 | 37 | kernel_native: np.ndarray, |
|
0 commit comments