xlnstorch.viz.make_error_grid#
- xlnstorch.viz.make_error_grid(op, ideal_op=None, *, f=None, b=None, x_range=(-1.0, 1.0), y_range=None, steps=201, device='cpu', absolute=True, decimal_prec=50)#
Generate a uniformly-sampled grid of differences between an xlnstorch operation op and an exact reference computed with Decimal.
Set decimal_prec high enough that Decimal is effectively exact over the chosen ranges (50 digits is usually plenty up to ~1e15).
- Parameters:
op (Callable) – The xlnstorch operation to benchmark, e.g., torch.mul.
ideal_op (Callable, optional) – A reference function that computes the exact result using Decimal. If not provided, a default mapping from op to an ideal function is used if available.
f (float, optional) – The f parameter for the LNSTensor constructor.
b (float, optional) – The b parameter for the LNSTensor constructor.
x_range (Tuple[float, float], optional) – The range of x values to sample, defaulting to (-1.0, 1.0).
y_range (Tuple[float, float], optional) – The range of y values to sample for binary operations. If None, only a unary operation is performed.
steps (int, optional) – The number of steps to sample in each dimension. Default is 201.
device (torch.device or str, optional) – The device on which to create the input tensors (default is “cpu”).
absolute (bool, optional) – If True, return the absolute error; otherwise, return signed error. Default is True.
decimal_prec (int, optional) – The precision for Decimal operations. This should be set high enough to ensure that Decimal calculations are effectively exact over the specified ranges. Default is 50 digits.
- Returns:
A tuple containing: - xs: A tensor of x values sampled from the specified range. - ys: A tensor of y values sampled from the specified range (if binary operation). If y_range is None, only xs and err are returned. - err: A tensor of errors, where each element is the absolute or signed difference between the computed value and the exact value.
- Return type:
Tuple[torch.Tensor, torch.Tensor, torch.Tensor] or Tuple[torch.Tensor, torch.Tensor]