Skip to content

fix issue with torch/numpy indexing#267

Merged
Koncopd merged 6 commits intotheislab:masterfrom
maarten-devries:master
Dec 2, 2025
Merged

fix issue with torch/numpy indexing#267
Koncopd merged 6 commits intotheislab:masterfrom
maarten-devries:master

Conversation

@maarten-devries
Copy link
Copy Markdown
Contributor

@maarten-devries maarten-devries commented Mar 24, 2025

I am personally not able to run scPoli unless I use this workaround.

@Koncopd
Copy link
Copy Markdown
Member

Koncopd commented Mar 26, 2025

Could you elaborate please on the problem you have?

@jggatter
Copy link
Copy Markdown

jggatter commented May 6, 2025

I was running Maarten's code, but not his fork, and encountered the issue. Please see here for details scipy/scipy#22935.

@jggatter
Copy link
Copy Markdown

jggatter commented May 8, 2025

I should further explain that torch.Tensors are not currently supported by scipy for indexing sparse matrices, as seen in the scipy PR. However,I don't really expect the scipy PR to be accepted (at least as is).

An alternative solution in this PR would be to use np.arange to get numpy indices, then convert the indices to a tensor for indexing c. I suppose a numpy array indexer can be passed as seen in this PR and PyTorch likely converts it.

@Koncopd
Copy link
Copy Markdown
Member

Koncopd commented May 8, 2025

Is this a recent change? Because it was working without any problems.

@jggatter
Copy link
Copy Markdown

jggatter commented May 8, 2025

According to the blame, the scpoli_model.py module and get_latent function seem not to have any changes in 2 years (get_latent around Dec 2023 I think). Since then there have been many scipy and pytorch releases. Much of the validation logic for checking indices in scipy was introduced 7-11 months ago it appears. Notably that "compatible boolean index" check, which has some weird logic that causes the failure.

I would comment on the scipy PR with your thoughts if possible. Otherwise, it would be great if this PR or an alternative fix could be made here. 🙏

@maarten-devries
Copy link
Copy Markdown
Contributor Author

Following up here; we have been using this fix without problem for a while; perhaps you would be able to merge it? We are currently always installing scArches from a forked version.

@maarten-devries
Copy link
Copy Markdown
Contributor Author

#279 seems like a similar issue

Comment thread scarches/models/scpoli/scpoli_model.py Outdated
@@ -351,12 +349,15 @@ def get_latent(
indices = torch.arange(x.shape[0])
Copy link
Copy Markdown
Member

@Koncopd Koncopd Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is better to just do this originally with numpy here instead of converting to numpy later

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maarten-devries does this make sense to you?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Koncopd yes, good catch. I believe my latest commit addresses this.

@maarten-devries
Copy link
Copy Markdown
Contributor Author

My latest commit is to avoid a warning when converting to tensor

@Koncopd Koncopd merged commit b5ae098 into theislab:master Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants