Skip to content

Commit

Permalink
Resolve warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
khb7840 committed Apr 22, 2024
1 parent 2bd033f commit 64c843e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 263 deletions.
12 changes: 6 additions & 6 deletions src/geometry/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl GeometricHash {
GeometricHash::PDBTrRosetta(hash) => hash.reverse_hash_default(),
GeometricHash::TertiaryInteraction(hash) => hash.reverse_hash_default(),
// append new hash type here
_ => panic!("Invalid hash type"),
// _ => panic!("Invalid hash type"),
}
}

Expand All @@ -271,7 +271,7 @@ impl GeometricHash {
GeometricHash::PDBTrRosetta(hash) => hash.reverse_hash(nbin_dist, nbin_angle),
GeometricHash::TertiaryInteraction(hash) => hash.reverse_hash(nbin_dist, nbin_angle),
// append new hash type here
_ => panic!("Invalid hash type"),
// _ => panic!("Invalid hash type"),
}
}

Expand All @@ -287,7 +287,7 @@ impl GeometricHash {
GeometricHash::PDBTrRosetta(hash) => hash.hash_type(),
GeometricHash::TertiaryInteraction(hash) => hash.hash_type(),
// append new hash type here
_ => panic!("Invalid hash type"),
// _ => panic!("Invalid hash type"),
}
}

Expand Down Expand Up @@ -378,7 +378,7 @@ impl GeometricHash {
GeometricHash::PDBTrRosetta(hash) => hash.as_u64(),
GeometricHash::TertiaryInteraction(hash) => hash.as_u64(),
// append new hash type here
_ => panic!("Invalid hash type"),
// _ => panic!("Invalid hash type"),
}
}

Expand Down Expand Up @@ -471,7 +471,7 @@ impl fmt::Debug for GeometricHash {
write!(f, "TertiaryInteraction({:?})", hash)
},
// append new hash type here
_ => panic!("Invalid hash type"),
// _ => panic!("Invalid hash type"),
}
}
}
Expand Down Expand Up @@ -507,7 +507,7 @@ impl fmt::Display for GeometricHash {
write!(f, "TertiaryInteraction\t{:?}", hash)
},
// append new hash type here
_ => panic!("Invalid hash type"),
// _ => panic!("Invalid hash type"),
}
}
}
127 changes: 2 additions & 125 deletions src/index/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
// Author: Hyunbin Kim ([email protected])
// Copyright © 2023 Hyunbin Kim, All rights reserved

use rayon::iter::ParallelIterator;
use rayon::prelude::*;
// external crates
use rustc_hash::{FxHashMap};
use rustc_hash::FxHashMap;
use dashmap::DashMap;


//
use std::sync::{Arc};
use std::sync::Arc;
use std::cell::UnsafeCell;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;

// Measure time


use crate::HashableSync;

const DEFAULT_NUM_THREADS: usize = 4;
Expand Down Expand Up @@ -368,121 +363,3 @@ pub fn convert_sorted_pairs_to_offset_and_values_vec<V: HashableSync, K:Hashable
vec.shrink_to_fit();
(offset_list, vec)
}

#[cfg(test)]
mod tests {
use super::*;

fn create_test_data(num_key: usize, num_value: usize) -> Vec<Vec<usize>> {
let mut data = Vec::new();
for i in 0..num_key {
let mut inner = Vec::new();
for j in 0..num_value {
inner.push(i * num_value + j);
}
data.push(inner);
}
println!("Created test data with {} keys and {} values", num_key, num_value);
println!("data.len(): {}", data.len());
data
}
}

// pub struct HugeAllocation {
// pub allocation: UnsafeCell<Vec<usize>>,
// }

// unsafe impl Sync for HugeAllocation {}

// pub fn run(num_threads: usize, ext_data: Arc<Vec<Vec<usize>>>) -> Arc<HugeAllocation> {
// println!("Creating {} threads", num_threads);
// // Iterate through ext_data and get the total size
// let total_size = Arc::new(AtomicUsize::new(0));
// let ext_data_index = Arc::new(AtomicUsize::new(0));
// // Spawn threads to find out the size to allocate
// let start = Instant::now();
// let mut handles = vec![];
// for i in 0..num_threads {
// let ext_data = ext_data.clone();
// let total_size = total_size.clone();
// let ext_data_index = ext_data_index.clone();
// let handle = thread::spawn(move || {
// // While there is data to check the size, keep checking
// while ext_data_index.load(Ordering::Relaxed) < ext_data.len() {
// let ext_data_index = ext_data_index.fetch_add(1, Ordering::Relaxed);
// if ext_data_index >= ext_data.len() {
// break;
// }
// let ext_data_inner = &ext_data[ext_data_index];
// total_size.fetch_add(ext_data_inner.len(), Ordering::Relaxed);
// }
// });
// handles.push(handle);
// }
// for handle in handles {
// handle.join().unwrap();
// }
// let estimation_time = start.elapsed();
// println!("Estimation time: {:?}", estimation_time);
// println!(
// "Allocating {} gigabytes",
// total_size.clone().load(Ordering::Relaxed) as f32 * 8.0 / 1024.0 / 1024.0 / 1024.0
// );

// // Allocate the memory
// let start = Instant::now();
// let data = Arc::new(HugeAllocation {
// allocation: UnsafeCell::new(vec![0; total_size.load(Ordering::Relaxed)]),
// });
// let allocation_time = start.elapsed();
// println!("Allocation time: {:?}", allocation_time);
// // Spawn threads to copy the data
// let start = Instant::now();
// let mut handles = vec![];
// let mut ext_data_index = Arc::new(AtomicUsize::new(0));

// let expected_num_value = ext_data[0].len();
// let size_per_value = total_size.load(Ordering::Relaxed) / expected_num_value;
// let offset_vec = (0..expected_num_value).map(
// |x| AtomicUsize::new(x * size_per_value)
// ).collect::<Vec<AtomicUsize>>();
// let offset_vec = Arc::new(offset_vec);

// for i in 0..num_threads {
// let data_clone = Arc::clone(&data);
// let ext_data = ext_data.clone();
// let ext_data_index = ext_data_index.clone();
// let offset_vec = offset_vec.clone();
// let handle = thread::spawn(move || {
// while ext_data_index.load(Ordering::Relaxed) < ext_data.len() {
// let ext_data_index = ext_data_index.fetch_add(1, Ordering::Relaxed);
// if ext_data_index >= ext_data.len() {
// break;
// }
// let ext_data_inner = &ext_data[ext_data_index];
// // let offset_in_allocation = offset_in_allocation.fetch_add(ext_data_inner.len(), Ordering::Relaxed);
// let data = data_clone.allocation.get();
// for j in 0..ext_data_inner.len() {
// // Get offset from offsets map for value of j
// let val = ext_data_inner[j];
// let offset_in_allocation = offset_vec[val].fetch_add(1, Ordering::Relaxed);
// unsafe {
// (*data)[offset_in_allocation] = ext_data_index;
// }
// }
// }
// });
// handles.push(handle);
// }
// for handle in handles {
// handle.join().unwrap();
// }
// let computation_time = start.elapsed();
// println!("Filling time: {:?}", computation_time);

// for i in 0..10 {
// println!("{:?}", offset_vec[i].load(Ordering::Relaxed));
// }

// return data;
// }
2 changes: 1 addition & 1 deletion src/structure/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod pdb;
#[derive(Debug)]
pub enum StructureFileFormat {
PDB,
PDB_GZ,
PDBGZ,
CIF,
FCZ,
MMTF,
Expand Down
6 changes: 2 additions & 4 deletions src/utils/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ pub fn compare_target_answer_set<T: Eq + PartialEq + Hash>(target: &HashSet<T>,
pub fn measure_up_to_k_fp<T: Eq + PartialEq + Hash>(target: &Vec<T>, answer: &HashSet<T>, all: &HashSet<T>, k: f64) -> Metrics {
// Iter until k false positives are found
let mut true_pos = 0.0;
let mut true_neg = 0.0;
let mut false_pos = 0.0;
let mut false_neg = 0.0;
// Iterate over target
for t in target {
if answer.contains(t) {
Expand All @@ -89,8 +87,8 @@ pub fn measure_up_to_k_fp<T: Eq + PartialEq + Hash>(target: &Vec<T>, answer: &Ha
}
}
// False negatives
false_neg = answer.len() as f64 - true_pos;
let false_neg = answer.len() as f64 - true_pos;
// True negatives
true_neg = all.len() as f64 - (true_pos + false_pos + false_neg);
let true_neg = all.len() as f64 - (true_pos + false_pos + false_neg);
Metrics::new(true_pos, true_neg, false_pos, false_neg)
}
46 changes: 23 additions & 23 deletions tests/common/loader.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
pub fn load_homeobox_toy() -> Vec<String> {
vec![
"data/homeobox/1akha-.pdb".to_string(),
"data/homeobox/1b72a-.pdb".to_string(),
"data/homeobox/1b72b-.pdb".to_string(),
"data/homeobox/1ba5--.pdb".to_string(),
]
}
// pub fn load_homeobox_toy() -> Vec<String> {
// vec![
// "data/homeobox/1akha-.pdb".to_string(),
// "data/homeobox/1b72a-.pdb".to_string(),
// "data/homeobox/1b72b-.pdb".to_string(),
// "data/homeobox/1ba5--.pdb".to_string(),
// ]
// }

pub fn load_yeast_proteome() -> Vec<String> {
// Load all pdbs in data/yeast
let mut pdb_paths = Vec::new();
let paths = std::fs::read_dir("data/yeast").expect("Unable to read yeast proteome");
for path in paths {
let path = path.expect("Unable to read path");
let path = path.path();
let path = path.to_str().expect("Unable to convert path to string");
// If the path is a pdb file, add it to the list
if path.ends_with(".pdb") {
pdb_paths.push(path.to_string());
}
}
pdb_paths
}
// pub fn load_yeast_proteome() -> Vec<String> {
// // Load all pdbs in data/yeast
// let mut pdb_paths = Vec::new();
// let paths = std::fs::read_dir("data/yeast").expect("Unable to read yeast proteome");
// for path in paths {
// let path = path.expect("Unable to read path");
// let path = path.path();
// let path = path.to_str().expect("Unable to convert path to string");
// // If the path is a pdb file, add it to the list
// if path.ends_with(".pdb") {
// pdb_paths.push(path.to_string());
// }
// }
// pdb_paths
// }

pub fn load_path(dir: &str) -> Vec<String> {
// Load all pdbs in given path
Expand Down
1 change: 0 additions & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* Common functions for testing */

pub mod loader;
pub mod processor;
92 changes: 0 additions & 92 deletions tests/common/processor.rs

This file was deleted.

11 changes: 0 additions & 11 deletions tests/toydata_test.rs

This file was deleted.

0 comments on commit 64c843e

Please sign in to comment.