Skip to content

Commit

Permalink
fix invalid mask and overflow in transform_data
Browse files Browse the repository at this point in the history
  • Loading branch information
jirigav committed Sep 16, 2023
1 parent 8399861 commit 64b7dbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,25 @@ pub(crate) fn transform_data(data: Vec<Vec<u8>>) -> Data {
let block_size = data[0].len() * 8;
for blocks in data.chunks(128) {
let mut ints = vec![0_u128; block_size];
let mut v = 1;
for block in blocks {

for (e, block) in blocks.iter().enumerate() {
for (i, int) in ints.iter_mut().enumerate().take(block_size) {
if bit_value_in_block(i, block) {
*int += v;
*int += 1_u128 << e;
}
}
v *= 2;
}
result.push(ints);
}
let mask: u128;
if data.len() % 128 == 0{
mask = u128::MAX;
} else {
mask = 2_u128.pow((data.len() % 128) as u32) - 1;
}
Data {
data: result,
mask: 2_u128.pow((data.len() % 128) as u32) - 1,
mask,
num_of_blocks: data.len(),
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ fn hist_result(
}

fn run_bottomup(args: Args) {
let s = Instant::now();
let (training_data, validation_data_option, testing_data_option) = prepare_data(
&args.data_source,
args.block_size,
args.halving,
args.validation_and_testing_split,
);
println!("data loaded in: {:?}", s.elapsed());


let start = Instant::now();
let final_patterns = bottomup(&training_data, validation_data_option.as_ref(), &args);
Expand Down

0 comments on commit 64b7dbc

Please sign in to comment.