-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from valentingol/gpudtype
🐛 Solve GPU and different dtypes issues
- Loading branch information
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Test PCA with GPU and different dtypes.""" | ||
|
||
# Copyright (c) 2024 Valentin Goldité. All Rights Reserved. | ||
import pytest_check as check | ||
import torch | ||
|
||
from torch_pca import PCA | ||
|
||
|
||
def test_gpu() -> None: | ||
"""Test with GPU and different dtypes.""" | ||
inputs = torch.load("tests/input_data.pt").to("cuda:0") | ||
for dtype in [torch.float32, torch.float16, torch.float64]: | ||
inputs = inputs.to(dtype) | ||
out1 = PCA(svd_solver="full").fit_transform(inputs) | ||
out2 = PCA(svd_solver="covariance_eigh").fit_transform(inputs) | ||
out3 = PCA(svd_solver="randomized", random_state=0).fit_transform(inputs) | ||
for out in [out1, out2, out3]: | ||
check.equal(str(out.device), "cuda:0") | ||
check.equal(out.dtype, dtype) |