cornellius-gp / gpytorch

A highly efficient implementation of Gaussian Processes in PyTorch
MIT License
3.54k stars 557 forks source link

[Bug] `IndexKernel` with empty input #2530

Open AdrianSosic opened 3 months ago

AdrianSosic commented 3 months ago

🐛 Bug

The IndexKernel seems broken for the case when the input is empty. I stumbled upon this issue when working with botorch (see corresponding bug report here).

To reproduce

Code snippet to reproduce

import torch
from gpytorch.kernels import IndexKernel

k = IndexKernel(num_tasks=2)
t = torch.tensor([])
k(t, t)

Stack trace/error message

ZeroDivisionError: integer division or modulo by zero

Expected Behavior

The output should simply be tensor([], size=(0, 0)), just like you would get it for other kernels. For example, the following snippet works without problems:

import torch
from gpytorch.kernels import MaternKernel

k = MaternKernel()
t = torch.tensor([])
k(t, t)

System information

Please complete the following information: