Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where 'exog' was not moved to GPU memory when using cuda #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyPLNmodels/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ def _format_model_param(
exog = _format_data(exog)
if add_const is True:
if exog is None:
exog = torch.ones(endog.shape[0], 1)
exog = torch.ones(endog.shape[0], 1, device=DEVICE)
else:
if _has_null_variance(exog) is False:
exog = torch.concat(
(exog, torch.ones(endog.shape[0]).unsqueeze(1)), dim=1
(exog, torch.ones(endog.shape[0], device=DEVICE).unsqueeze(1)), dim=1
)
if offsets is None:
if offsets_formula == "logsum":
Expand Down
6 changes: 3 additions & 3 deletions pyPLNmodels/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def viz(self, *, ax=None, colors=None, show_cov: bool = False):
if self._get_max_components() < 2:
raise RuntimeError("Can't perform visualization for dim < 2.")
pca = self.sk_PCA(n_components=2)
proj_variables = pca.transform(self.latent_variables)
proj_variables = pca.transform(self.latent_variables.cpu())
x = proj_variables[:, 0]
y = proj_variables[:, 1]
sns.scatterplot(x=x, y=y, hue=colors, ax=ax)
Expand Down Expand Up @@ -503,7 +503,7 @@ def scatter_pca_matrix(self, n_components=None, color=None):
f"You ask more components ({n_components}) than variables ({self.dim})"
)
pca = self.sk_PCA(n_components=n_components)
proj_variables = pca.transform(self.latent_variables)
proj_variables = pca.transform(self.latent_variables.cpu())
components = torch.from_numpy(pca.components_)

labels = {
Expand Down Expand Up @@ -563,7 +563,7 @@ def plot_pca_correlation_graph(self, variables_names, indices_of_variables=None)

n_components = 2
pca = self.sk_PCA(n_components=n_components)
variables = self.latent_variables
variables = self.latent_variables.cpu()
proj_variables = pca.transform(variables)
## the package is not correctly printing the variance ratio
figure, correlation_matrix = plot_pca_correlation_graph(
Expand Down