Skip to content

Commit

Permalink
test of subject and object
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoMfer committed Dec 4, 2023
1 parent d43814c commit f88e0e2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 51 deletions.
17 changes: 9 additions & 8 deletions examples/serialize_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ static ALLOCATOR: jemallocator::Jemalloc = jemallocator::Jemalloc;

fn main() {
let args: Vec<String> = env::args().collect();
if args.len() <= 1 {
panic!("Usage: cargo run --example serialize_bench <number_of_universities>");
if args.len() <= 3 {
panic!("Usage: cargo run --example serialize_bench <rdf_path> <zarr_path> <shard_size>");
}
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::<u64>().unwrap()),
)
.unwrap();

Expand Down
40 changes: 14 additions & 26 deletions src/engine/array.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
use sprs::{CsVec, CsMat, CsMatBase};
use sprs::{CsMat, TriMat};

use crate::storage::ZarrArray;

use super::{EngineResult, EngineStrategy};

impl EngineStrategy<CsVec<u8>> for ZarrArray {
fn get_subject(&self, index: usize) -> EngineResult<CsVec<u8>> {
let selection = CsVec::new(self.rows(), vec![index], vec![1]);
Ok(&self.transpose_view() * &selection)
impl EngineStrategy<CsMat<u8>> for ZarrArray {
fn get_subject(&self, index: usize) -> EngineResult<CsMat<u8>> {
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<CsMat<u8>> {


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);
fn get_predicate(&self, value: u8) -> EngineResult<CsMat<u8>> {

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

View workflow job for this annotation

GitHub Actions / Check (stable)

unused variable: `value`

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

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

unused variable: `value`

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

View workflow job for this annotation

GitHub Actions / Clippy (stable)

unused variable: `value`

Ok(result)
unimplemented!()
}

fn get_object(&self, index: usize) -> EngineResult<CsVec<u8>> {
let selection = CsVec::new(self.cols(), vec![index], vec![1]);
Ok(self * &selection)
fn get_object(&self, index: usize) -> EngineResult<CsMat<u8>> {
let mut matrix = TriMat::new((self.cols(), self.cols()));
matrix.add_triplet(index, index, 1);
let matrix = matrix.to_csc();
Ok(self * &matrix)
}
}
2 changes: 1 addition & 1 deletion src/engine/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<T: ReadableStorageTraits> EngineStrategy<Vec<u8>> for Array<T> {
}
}

fn get_predicate(&self, index: usize) -> EngineResult<Vec<u8>> {
fn get_predicate(&self, index: u8) -> EngineResult<Vec<u8>> {

Check warning on line 26 in src/engine/chunk.rs

View workflow job for this annotation

GitHub Actions / Check (stable)

unused variable: `index`

Check warning on line 26 in src/engine/chunk.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

unused variable: `index`

Check failure on line 26 in src/engine/chunk.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

unused variable: `index`
unimplemented!()
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ pub type EngineResult<T> = Result<T, EngineError>;

pub trait EngineStrategy<T> {
fn get_subject(&self, index: usize) -> EngineResult<T>;
fn get_predicate(&self, index: usize) -> EngineResult<T>;
fn get_predicate(&self, index: u8) -> EngineResult<T>;
fn get_object(&self, index: usize) -> EngineResult<T>;
}
4 changes: 3 additions & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ impl Graph {
Object::GCHQ.get_idx(dictionary),
Predicate::Manufacturer.get_idx(dictionary),
);

ans.to_csc()



}
}
10 changes: 7 additions & 3 deletions tests/get_object_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 )
}


9 changes: 4 additions & 5 deletions tests/get_predicate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use remote_hdt::{
engine::EngineStrategy,
storage::{matrix::MatrixLayout, tabular::TabularLayout, ChunkingStrategy, LocalStorage},

Check warning on line 3 in tests/get_predicate_test.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

unused import: `matrix::MatrixLayout`
};
use sprs::CsVec;

use sprs:: TriMat;

Check warning on line 5 in tests/get_predicate_test.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

unused import: `sprs:: TriMat`
mod common;

#[test]
Expand All @@ -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
)

}
16 changes: 10 additions & 6 deletions tests/get_subject_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}

0 comments on commit f88e0e2

Please sign in to comment.