Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diego #7

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 14 additions & 9 deletions src/engine/array.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
use sprs::CsVec;
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<CsVec<u8>> {
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 failure on line 15 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

unused variable: `value`

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

View workflow job for this annotation

GitHub Actions / Check (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`

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 warning on line 15 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Test Suite (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 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`

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

View workflow job for this annotation

GitHub Actions / Check (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`

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 / Check (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`

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 warning on line 15 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Test Suite (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 warning on line 15 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Test Suite (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 warning on line 15 in src/engine/array.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

unused variable: `value`

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 @@
}
}

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 failure on line 26 in src/engine/chunk.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

unused variable: `index`

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

View workflow job for this annotation

GitHub Actions / Check (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`

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 warning on line 26 in src/engine/chunk.rs

View workflow job for this annotation

GitHub Actions / Test Suite (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 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`

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

View workflow job for this annotation

GitHub Actions / Check (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`

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 / Check (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`

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 warning on line 26 in src/engine/chunk.rs

View workflow job for this annotation

GitHub Actions / Test Suite (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 warning on line 26 in src/engine/chunk.rs

View workflow job for this annotation

GitHub Actions / Test Suite (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 warning on line 26 in src/engine/chunk.rs

View workflow job for this annotation

GitHub Actions / Test Suite (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>;
}
5 changes: 4 additions & 1 deletion 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 Expand Up @@ -180,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 )
}


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)
}

Loading