torchquad
torchquad copied to clipboard
Using keyword arguments in `calculate_result` fails
trafficstars
Issue
Problem Description
When using keyword arguments in Simpson().calculate_result() function, fails with IndexError: tuple index out of range. The issue seems to come from expand_func_values_and_squeeze_integral only checking args and not kwargs, so when specifying keyword arguments, args is reduced to (self,) and leads to the previous error
Expected Behavior
Should run properly as when not specifying keywords.
What Needs to be Done
Change expand_func_values_and_squeeze_integral to handle a both only keyword arguments and a mixture of positional and keyword arguments
How Can It Be Tested or Reproduced
Here is a minimal example failing using torchquad v0.4.0
import torch
from torchquad import Simpson
N = 101
integration_domain = torch.tensor([[0.,1.]])
y = torch.randn(N)
x = torch.linspace(integration_domain[0,0], integration_domain[0,1], N)
integrator = Simpson()
integrator.calculate_result(
function_values=y,
dim=1,
n_per_dim=N,
hs=torch.diff(x)[:0],
integration_domain=integration_domain,
)
# fails with IndexError: tuple index out of range