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

Use correct shape for obsm/varm layers in anndata export #216

Merged

Conversation

aaronwolen
Copy link
Member

@aaronwolen aaronwolen commented Sep 12, 2024

Overview

This addresses a bug in the ExperimentAxisQuery anndata exporter that is specific to obsm/varm arrays.

Details

Currently, the number of columns needed for the resulting numpy array is taken from the SparseNDArray's shape property, which provides the maximum capacity of the underlying TileDB array, rather than the occupied capacity. This results in the exporter allocating a far larger numpy ndarray than necessary when obsm/varm layers are included in the output.

This issue is specific to obsm/varm arrays because, unlike X/obsp/varp, and as described here, their second dimension doesn't map to the obs or var axis and can include an arbitrary number of columns.

Solution

With this PR the correct number of columns needed for the resulting numpy array is computed using the number of unique values present in the COO-formatted arrow table's "soma_dim_1" column, which is already in-memory and doesn't require any additional TileDB queries.

This solution is a temporary workaround, as SparseNDArray.shape's behavior will change in an upcoming release of TileDB-SOMA (see here for status).

Note: The TileDB-SOMA SparseNDArray class does provide a used_shape property that returns the occupied capacity of the underlying TileDB array that could be used, however, this is specific to the TileDB implementation and is not part of the SOMA API specification.

[sc-51048].

Copy link
Member

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

🚢

@johnkerl johnkerl merged commit 30764e6 into main Sep 12, 2024
7 checks passed
@johnkerl johnkerl deleted the aaronwolen/sc-54878/excessive-memory-allocation-from-anndata branch September 12, 2024 18:49
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.

2 participants