Skip to content

Commit

Permalink
get_predicate implementation for vec
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoMfer committed Nov 28, 2023
1 parent 981d032 commit d43814c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/engine/array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sprs::CsVec;
use sprs::{CsVec, CsMat, CsMatBase};

Check warning on line 1 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

unused import: `CsMatBase`

Check failure on line 1 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

unused import: `CsMatBase`

Check warning on line 1 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Check (stable)

unused import: `CsMatBase`

use crate::storage::ZarrArray;

Expand All @@ -10,8 +10,25 @@ impl EngineStrategy<CsVec<u8>> for ZarrArray {
Ok(&self.transpose_view() * &selection)
}

fn get_predicate(&self, index: usize) -> EngineResult<CsVec<u8>> {
unimplemented!()
fn get_predicate(&self, index: usize) -> EngineResult<CsMat<u8>> {

Check failure on line 13 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

method `get_predicate` has an incompatible type for trait

Check failure on line 13 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

method `get_predicate` has an incompatible type for trait

Check failure on line 13 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Check (stable)

method `get_predicate` has an incompatible type for trait


let mut rows: Vec<usize> = vec![];
let mut cols: Vec<usize> = vec![];
let mut values: Vec<u8> = vec![];
let iterator = self.into_iter();
for value in iterator {
if *value.0 == index as u8 {
rows.push(value.1.0);
cols.push(value.1.1);
values.push(*value.0);
}

}
//CsMatBase<u8, usize, Vec<usize>, Vec<usize>, Vec<u8>>
let result = CsMat::new(self.shape(),rows, cols, values);

Ok(result)
}

fn get_object(&self, index: usize) -> EngineResult<CsVec<u8>> {
Expand Down
1 change: 1 addition & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl Predicate {
pub fn get_idx(self, dictionary: &Dictionary) -> u8 {
dictionary.get_predicate_idx_unchecked(self.into()) as u8
}

}

impl From<Predicate> for &str {
Expand Down
24 changes: 24 additions & 0 deletions tests/get_predicate_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use remote_hdt::{
engine::EngineStrategy,
storage::{matrix::MatrixLayout, tabular::TabularLayout, ChunkingStrategy, LocalStorage},
};
use sprs::CsVec;

mod common;

#[test]
fn get_predicate_tabular_test() {
let mut storage = LocalStorage::new(TabularLayout);
common::setup(common::TABULAR_ZARR, &mut storage, ChunkingStrategy::Chunk);

let actual = storage
.load_sparse(common::TABULAR_ZARR)
.unwrap()
.get_predicate(common::Predicate::InstanceOf.get_idx(&storage.get_dictionary()) as usize)
.unwrap();

assert_eq!(
actual,
CsVec::new(9, vec![0, 1, 2, 7, 8], vec![2, 4, 5, 7, 8])
)
}

0 comments on commit d43814c

Please sign in to comment.