Skip to content

Commit

Permalink
Adding some example
Browse files Browse the repository at this point in the history
  • Loading branch information
beroy committed Oct 11, 2023
1 parent ca78562 commit a6cd2aa
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsoma/IntIndexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def map_locations(keys: np.ndarray[np.int64, Any]) -> clib.IntIndexer:
)
compute_concurrency = 5
if context._tiledb_ctx:
compute_concurrency = context._tiledb_ctx.config()[
compute_concurrency = int(int(context._tiledb_ctx.config()))/2[
"sm.compute_concurrency_level"
]
thread_counts = int(compute_concurrency)
Expand Down
24 changes: 12 additions & 12 deletions apis/python/src/tiledbsoma/_fast_csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class _CSRAccumulatorFinalResult(NamedTuple):
Contains a sparse CSR consituent elements
"""

data: npt.NDArray[np.number] # type: ignore[type-arg]
indptr: npt.NDArray[np.integer] # type: ignore[type-arg]
indices: npt.NDArray[np.integer] # type: ignore[type-arg]
data: npt.NDArray[np.number] # type: ignore
indptr: npt.NDArray[np.integer] # type: ignore
indices: npt.NDArray[np.integer] # type: ignore
shape: Tuple[int, int]


Expand Down Expand Up @@ -187,11 +187,11 @@ def _accum_row_length(
@numba.jit(nopython=True, nogil=True) # type: ignore[attr-defined]
def _copy_chunk_range(
row_ind_chunk: npt.NDArray[np.signedinteger], # ignore-type
col_ind_chunk: npt.NDArray[np.signedinteger],
data_chunk: npt.NDArray[np.number],
data: npt.NDArray[np.number],
indices: npt.NDArray[np.signedinteger],
indptr: npt.NDArray[np.signedinteger],
col_ind_chunk: npt.NDArray[np.signedinteger], # type: ignore
data_chunk: npt.NDArray[np.number], # type: ignore
data: npt.NDArray[np.number], # type: ignore
indices: npt.NDArray[np.signedinteger], # type: ignore
indptr: npt.NDArray[np.signedinteger], # type: ignore
row_rng_mask: int,
row_rng_val: int,
) -> None:
Expand All @@ -208,9 +208,9 @@ def _copy_chunk_range(
@numba.jit(nopython=True, nogil=True) # type: ignore[attr-defined]
def _copy_chunklist_range(
chunk_list: numba.typed.List,
data: npt.NDArray[np.number], # type: ignore[attr-defined]
indices: npt.NDArray[np.signedinteger], # type: ignore[attr-defined]
indptr: npt.NDArray[np.signedinteger], # type: ignore[attr-defined]
data: npt.NDArray[np.number], # type: ignore
indices: npt.NDArray[np.signedinteger], # type: ignore
indptr: npt.NDArray[np.signedinteger], # type: ignore
row_rng_mask_bits: int,
job: int,
):
Expand Down Expand Up @@ -284,7 +284,7 @@ def _read_csr(
acc = _CSRAccumulator(
obs_joinids=obs_joinids, var_joinids=var_joinids, pool=pool
)
for tbl in somacore._eager_iter.EagerIterator(
for tbl in somacore.query._eager_iter.EagerIterator(
matrix.read((obs_joinids, var_joinids)).tables(),
pool=pool,
):
Expand Down
22 changes: 22 additions & 0 deletions libtiledbsoma/src/reindexer/examples/ann_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import cellxgene_census
import tiledbsoma as soma
from time import perf_counter

soma._query.ExperimentAxisQuery.USE_FAST_INDEXER = False

census_S3_latest = dict(census_version="latest")
census_local_copy = dict(uri="/Users/brobatmili/projects/census_data/")

def main():
t1 = perf_counter()
with cellxgene_census.open_soma(**census_S3_latest, context=soma.SOMATileDBContext(use_optimized_reindexing=True)) as census:
with census["census_data"]["homo_sapiens"].axis_query(
measurement_name="RNA", obs_query=soma.AxisQuery(
value_filter="""tissue_general == 'eye'""")

) as query:
query.to_anndata(X_name="raw")
t2 = perf_counter()
print(f"End to end time {t2 - t1}")

main()
14 changes: 14 additions & 0 deletions libtiledbsoma/src/reindexer/examples/test_indexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tiledbsoma.IntIndexer import IntIndexer
import numpy as np

# 1d array to list
keys = np.array([-1, 1, 2, 3, 4, 5])
look_ups = np.array([-1, 1, 2, 3, 4, 5, -1, 1, 2, 3, 4, 5, -1, 1, 2, 3, 4, 5, -1, 1, 2, 3, 4, 5])

def main():
indexer = IntIndexer.map_locations(keys)
results = indexer.lookup(look_ups)
print(f"Lookup results {results}")

if __name__ == "__main__":
main()
14 changes: 14 additions & 0 deletions libtiledbsoma/src/reindexer/test_indexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tiledbsoma.IntIndexer import IntIndexer
import numpy as np

# 1d array to list
keys = np.array([-1, 1, 2, 3, 4, 5])
look_ups = np.array([-1, 1, 2, 3, 4, 5, -1, 1, 2, 3, 4, 5, -1, 1, 2, 3, 4, 5, -1, 1, 2, 3, 4, 5])

def main():
indexer = IntIndexer.map_locations(keys)
results = indexer.lookup(look_ups)
print(f"Lookup results {results}")

if __name__ == "__main__":
main()

0 comments on commit a6cd2aa

Please sign in to comment.