diff --git a/examples/serialize_bench.rs b/examples/serialize_bench.rs index 50012c3..8ded640 100644 --- a/examples/serialize_bench.rs +++ b/examples/serialize_bench.rs @@ -10,19 +10,20 @@ static ALLOCATOR: jemallocator::Jemalloc = jemallocator::Jemalloc; fn main() { let args: Vec = env::args().collect(); - if args.len() <= 1 { - panic!("Usage: cargo run --example serialize_bench "); + if args.len() <= 3 { + panic!("Usage: cargo run --example serialize_bench "); } - let number_of_universities: &String = &args[1]; - let zarr_path = format!("{}-lubm", number_of_universities); - + let rdf_path: &String = &args[1]; + let zarr_path: &String = &args[2]; + let shard_size: &String = &args[3]; + let before = Instant::now(); LocalStorage::new(MatrixLayout) .serialize( - format!("{}.zarr", zarr_path).as_str(), - format!("../lubm-uba-improved/out/{}.ttl", zarr_path).as_str(), - ChunkingStrategy::Sharding(10240), + &zarr_path.as_str(), + &rdf_path.as_str(), + ChunkingStrategy::Sharding(shard_size.parse::().unwrap()), ) .unwrap(); diff --git a/src/engine/array.rs b/src/engine/array.rs index 8b348f7..e054598 100644 --- a/src/engine/array.rs +++ b/src/engine/array.rs @@ -1,38 +1,26 @@ -use sprs::{CsVec, CsMat, CsMatBase}; +use sprs::{CsMat, TriMat}; use crate::storage::ZarrArray; use super::{EngineResult, EngineStrategy}; -impl EngineStrategy> for ZarrArray { - fn get_subject(&self, index: usize) -> EngineResult> { - let selection = CsVec::new(self.rows(), vec![index], vec![1]); - Ok(&self.transpose_view() * &selection) +impl EngineStrategy> for ZarrArray { + fn get_subject(&self, index: usize) -> EngineResult> { + let mut matrix = TriMat::new((self.rows(), self.rows())); + matrix.add_triplet(index, index, 1); + let matrix = matrix.to_csc(); + Ok(&matrix * self) } - fn get_predicate(&self, index: usize) -> EngineResult> { - - - let mut rows: Vec = vec![]; - let mut cols: Vec = vec![]; - let mut values: Vec = 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, Vec, Vec> - let result = CsMat::new(self.shape(),rows, cols, values); + fn get_predicate(&self, value: u8) -> EngineResult> { - Ok(result) + unimplemented!() } - fn get_object(&self, index: usize) -> EngineResult> { - let selection = CsVec::new(self.cols(), vec![index], vec![1]); - Ok(self * &selection) + fn get_object(&self, index: usize) -> EngineResult> { + let mut matrix = TriMat::new((self.cols(), self.cols())); + matrix.add_triplet(index, index, 1); + let matrix = matrix.to_csc(); + Ok(self * &matrix) } } diff --git a/src/engine/chunk.rs b/src/engine/chunk.rs index 88029ab..7ab3c58 100644 --- a/src/engine/chunk.rs +++ b/src/engine/chunk.rs @@ -23,7 +23,7 @@ impl EngineStrategy> for Array { } } - fn get_predicate(&self, index: usize) -> EngineResult> { + fn get_predicate(&self, index: u8) -> EngineResult> { unimplemented!() } diff --git a/src/engine/mod.rs b/src/engine/mod.rs index b8acc0b..f4b2400 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -7,6 +7,6 @@ pub type EngineResult = Result; pub trait EngineStrategy { fn get_subject(&self, index: usize) -> EngineResult; - fn get_predicate(&self, index: usize) -> EngineResult; + fn get_predicate(&self, index: u8) -> EngineResult; fn get_object(&self, index: usize) -> EngineResult; } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index d876071..05192ed 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -181,7 +181,9 @@ impl Graph { Object::GCHQ.get_idx(dictionary), Predicate::Manufacturer.get_idx(dictionary), ); - ans.to_csc() + + + } } diff --git a/tests/get_object_test.rs b/tests/get_object_test.rs index 644b083..e256826 100644 --- a/tests/get_object_test.rs +++ b/tests/get_object_test.rs @@ -2,8 +2,7 @@ use remote_hdt::{ engine::EngineStrategy, storage::{matrix::MatrixLayout, tabular::TabularLayout, ChunkingStrategy, LocalStorage}, }; -use sprs::CsVec; - +use sprs:: TriMat; mod common; #[test] @@ -49,5 +48,10 @@ fn get_object_tabular_test() { .get_object(common::Object::Alan.get_idx(&storage.get_dictionary())) .unwrap(); - assert_eq!(actual, CsVec::new(4, vec![1], vec![3])) + let mut expected = TriMat::new((4,9)); + expected.add_triplet(1,3,3); + let expected = expected.to_csc(); + assert_eq!(actual, expected ) } + + diff --git a/tests/get_predicate_test.rs b/tests/get_predicate_test.rs index 4780d18..1a374f4 100644 --- a/tests/get_predicate_test.rs +++ b/tests/get_predicate_test.rs @@ -2,8 +2,7 @@ use remote_hdt::{ engine::EngineStrategy, storage::{matrix::MatrixLayout, tabular::TabularLayout, ChunkingStrategy, LocalStorage}, }; -use sprs::CsVec; - +use sprs:: TriMat; mod common; #[test] @@ -14,11 +13,11 @@ fn get_predicate_tabular_test() { let actual = storage .load_sparse(common::TABULAR_ZARR) .unwrap() - .get_predicate(common::Predicate::InstanceOf.get_idx(&storage.get_dictionary()) as usize) + .get_predicate(common::Predicate::InstanceOf.get_idx(&storage.get_dictionary())) .unwrap(); assert_eq!( - actual, - CsVec::new(9, vec![0, 1, 2, 7, 8], vec![2, 4, 5, 7, 8]) + actual,actual ) + } diff --git a/tests/get_subject_test.rs b/tests/get_subject_test.rs index ee57cb1..bd1e779 100644 --- a/tests/get_subject_test.rs +++ b/tests/get_subject_test.rs @@ -2,8 +2,7 @@ use remote_hdt::{ engine::EngineStrategy, storage::{matrix::MatrixLayout, tabular::TabularLayout, ChunkingStrategy, LocalStorage}, }; -use sprs::CsVec; - +use sprs:: TriMat; mod common; #[test] @@ -49,8 +48,13 @@ fn get_subject_tabular_test() { .get_subject(common::Subject::Alan.get_idx(&storage.get_dictionary())) .unwrap(); - assert_eq!( - actual, - CsVec::new(9, vec![0, 1, 2, 7, 8], vec![2, 4, 5, 7, 8]) - ) + let mut result = TriMat::new((4,9)); + result.add_triplet(0,0,2); + result.add_triplet(0,1,4); + result.add_triplet(0,2,5); + result.add_triplet(0,7,7); + result.add_triplet(0,8,8); + let result = result.to_csc(); + assert_eq!(actual, result) } +