Skip to content

Commit

Permalink
Merge pull request #1016 from YosefLab/michael/tonumpy
Browse files Browse the repository at this point in the history
changes numpy.array() on tensors to .numpy()
  • Loading branch information
adamgayoso authored Apr 6, 2021
2 parents 3e4d2ff + 966dcc4 commit f3a1080
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scvi/external/cellassign/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def predict(self) -> pd.DataFrame:
gamma = outputs["gamma"]
predictions += [gamma.cpu()]
return pd.DataFrame(
np.array(torch.cat(predictions)), columns=self.cell_type_markers.columns
torch.cat(predictions).numpy(), columns=self.cell_type_markers.columns
)

def train(
Expand Down
2 changes: 1 addition & 1 deletion scvi/model/_scanvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def predict(
pred = pred.argmax(dim=1)
y_pred.append(pred.detach().cpu())

y_pred = np.array(torch.cat(y_pred))
y_pred = torch.cat(y_pred).numpy()
if not soft:
predictions = []
for p in y_pred:
Expand Down
4 changes: 2 additions & 2 deletions scvi/model/_totalvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def get_latent_library_size(
else:
library = outputs["library_gene"]
libraries += [library.cpu()]
return np.array(torch.cat(libraries))
return torch.cat(libraries).numpy()

@torch.no_grad()
def get_normalized_expression(
Expand Down Expand Up @@ -1025,7 +1025,7 @@ def get_protein_background_mean(self, adata, indices, batch_size):
for tensors in scdl:
_, inference_outputs, _ = self.module.forward(tensors)
b_mean = inference_outputs["py_"]["rate_back"]
background_mean += [np.array(b_mean.cpu())]
background_mean += [b_mean.cpu().numpy()]
return np.concatenate(background_mean)


Expand Down
8 changes: 4 additions & 4 deletions scvi/model/base/_rnamixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,13 @@ def get_likelihood_parameters(

n_batch = px_rate.size(0) if n_samples == 1 else px_rate.size(1)

px_r = np.array(px_r.cpu())
px_r = px_r.cpu().numpy()
if len(px_r.shape) == 1:
dispersion_list += [np.repeat(px_r[np.newaxis, :], n_batch, axis=0)]
else:
dispersion_list += [px_r]
mean_list += [np.array(px_rate.cpu())]
dropout_list += [np.array(px_dropout.cpu())]
mean_list += [px_rate.cpu().numpy()]
dropout_list += [px_dropout.cpu().numpy()]

dropout = np.concatenate(dropout_list)
means = np.concatenate(mean_list)
Expand Down Expand Up @@ -553,4 +553,4 @@ def get_latent_library_size(
else:
library = torch.distributions.LogNormal(ql_m, ql_v.sqrt()).mean
libraries += [library.cpu()]
return np.array(torch.cat(libraries))
return torch.cat(libraries).numpy()
2 changes: 1 addition & 1 deletion scvi/model/base/_vaemixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ def get_latent_representation(
z = qz_m

latent += [z.cpu()]
return np.array(torch.cat(latent))
return torch.cat(latent).numpy()

0 comments on commit f3a1080

Please sign in to comment.