def _predict_fy_samples_cuda(self, attr): n, dx, dy = 5, 3, 2 x, y = np.random.randn(n, dx), np.random.randn(n, dy) kern = Rbf(dx, ARD=True) gp = GPR(x, y, kern) f = getattr(gp, attr) n_test = 5 x_test = np.random.randn(n_test, dx) x_test_torch = TensorType(x_test) gp.cuda() # Numpy input: samples_cuda_np = f(x_test) assert isinstance(samples_cuda_np, np.ndarray) # PyTorch (cpu) input samples_cuda_torch = f(x_test_torch) assert samples_cuda_torch.device == x_test_torch.device # PyTorch (GPU) input samples_cuda_gpu = f(x_test_torch.to("cuda")) assert samples_cuda_gpu.is_cuda
def _predict_fy_cuda(self, attr): """ attr='predict_f' or 'predict_y' """ gp = self._get_model() f = getattr(gp, attr) x_test = np.random.randn(5, gp.input_dimension) x_test_torch = TensorType(x_test) # Test that CUDA works in all cases: gp.cuda() # Numpy input: cuda_np = f(x_test) for result in cuda_np: assert isinstance(result, np.ndarray) # PyTorch (cpu) input cuda_torch = f(x_test_torch) for result in cuda_torch: assert result.device == x_test_torch.device # PyTorch (GPU) input cuda_gpu = f(x_test_torch.to("cuda")) for result in cuda_gpu: assert result.is_cuda