Round values to the specified precision.
(
values: Float[np.ndarray, "row col"],
precisions: Int[np.ndarray, " col"],
)
| 8 | |
| 9 | |
| 10 | def round_values( |
| 11 | values: Float[np.ndarray, "row col"], |
| 12 | precisions: Int[np.ndarray, " col"], |
| 13 | ) -> Float[np.ndarray, "row col"]: |
| 14 | """Round values to the specified precision.""" |
| 15 | quantized = np.zeros_like(values) |
| 16 | r, _ = values.shape |
| 17 | precisions = repeat(precisions, "c -> r c", r=r) |
| 18 | for precision in np.unique(precisions): |
| 19 | mask = precisions == precision |
| 20 | quantized[mask] = np.round(values[mask], precision) |
| 21 | return quantized |
| 22 | |
| 23 | |
| 24 | def compute_ranks_for_column( |