Skip to content

Commit 28f3062

Browse files
author
Ian
committed
added optimized subsetting methods, Version Bump
1 parent 2ab878b commit 28f3062

5 files changed

Lines changed: 487 additions & 74 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "anndata-memory"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
edition = "2021"
55
readme = "README.md"
66
repository = "https://github.com/SingleRust/Anndata-Memory"

src/ad/helpers.rs

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use polars::{
1919
series::Series,
2020
};
2121

22-
use crate::base::DeepClone;
2322
use crate::base::RwSlot;
23+
use crate::{base::DeepClone, utils::subset_dyn_csc_matrix, utils::subset_dyn_csr_matrix};
2424

2525
impl DeepClone for ArrayData {
2626
fn deep_clone(&self) -> Self {
@@ -58,10 +58,32 @@ impl IMArrayElement {
5858
let mut write_guard = self.0.write_inner();
5959
let d = write_guard.deref_mut();
6060

61-
// Perform the selection operation directly on d
62-
*d = d.select(s);
61+
// Replace the data with a placeholder to take ownership
62+
let placeholder = ArrayData::Array(DynArray::from(Array2::<f64>::zeros((0, 0))));
63+
let data = std::mem::replace(d, placeholder);
64+
65+
// Process the data by consuming it
66+
let result = match data {
67+
ArrayData::Array(arr) => Ok(ArrayData::Array(arr).select(s)),
68+
ArrayData::DataFrame(df) => Ok(ArrayData::DataFrame(df).select(s)),
69+
ArrayData::CsrNonCanonical(csr) => Ok(ArrayData::CsrNonCanonical(csr).select(s)),
70+
ArrayData::CsrMatrix(dyn_csr) => {
71+
subset_dyn_csr_matrix(dyn_csr, s).map(ArrayData::CsrMatrix)
72+
}
73+
ArrayData::CscMatrix(dyn_csc) => {
74+
subset_dyn_csc_matrix(dyn_csc, s).map(ArrayData::CscMatrix)
75+
}
76+
};
6377

64-
Ok(())
78+
match result {
79+
Ok(processed) => {
80+
*d = processed;
81+
Ok(())
82+
}
83+
Err(e) => {
84+
Err(e)
85+
}
86+
}
6587
}
6688

6789
pub fn convert_matrix_format(&self) -> anyhow::Result<()> {
@@ -132,44 +154,6 @@ impl IMArrayElement {
132154
pub fn deep_clone_content(&self) -> anyhow::Result<ArrayData> {
133155
Ok(self.0.read_inner().clone())
134156
}
135-
136-
// pub fn change_matrix_type<T>(&self) -> anyhow::Result<()> {
137-
// let mut write_guard = self.0.write_inner();
138-
// let d = write_guard.deref_mut();
139-
//
140-
// // Create a placeholder that we can swap with - use an empty dense array as it's likely the smallest
141-
// let ddata: Array2<f64> = Array2::zeros((0, 0));
142-
// let placeholder = ArrayData::Array(DynArray::from(ddata));
143-
//
144-
// // Take ownership using replace
145-
// let matrix_data = std::mem::replace(d, placeholder);
146-
//
147-
// let converted_matrix = match matrix_data {
148-
// ArrayData::Array(dyn_array) => todo!(),
149-
// ArrayData::CsrMatrix(dyn_csr_matrix) => {
150-
// let csr_matrix: CsrMatrix<T> = match dyn_csr_matrix {
151-
// DynCsrMatrix::I8(csr_matrix) => csr_matrix.try_into()?,
152-
// DynCsrMatrix::I16(csr_matrix) => todo!(),
153-
// DynCsrMatrix::I32(csr_matrix) => todo!(),
154-
// DynCsrMatrix::I64(csr_matrix) => todo!(),
155-
// DynCsrMatrix::U8(csr_matrix) => todo!(),
156-
// DynCsrMatrix::U16(csr_matrix) => todo!(),
157-
// DynCsrMatrix::U32(csr_matrix) => todo!(),
158-
// DynCsrMatrix::U64(csr_matrix) => todo!(),
159-
// DynCsrMatrix::F32(csr_matrix) => todo!(),
160-
// DynCsrMatrix::F64(csr_matrix) => todo!(),
161-
// DynCsrMatrix::Bool(csr_matrix) => todo!(),
162-
// DynCsrMatrix::String(csr_matrix) => todo!(),
163-
// };
164-
// ArrayData::from(csr_matrix)
165-
// }
166-
// ArrayData::CsrNonCanonical(dyn_csr_non_canonical) => todo!(),
167-
// ArrayData::CscMatrix(dyn_csc_matrix) => todo!(),
168-
// ArrayData::DataFrame(data_frame) => todo!(),
169-
// };
170-
// * d = converted_matrix;
171-
// Ok(())
172-
// }
173157
}
174158

175159
impl DeepClone for IMArrayElement {

0 commit comments

Comments
 (0)