From 64b7dbc49b26981709aafc494d3fbaf258cc3bd6 Mon Sep 17 00:00:00 2001 From: jirigav Date: Sat, 16 Sep 2023 20:37:45 +0200 Subject: [PATCH] fix invalid mask and overflow in transform_data --- src/common.rs | 15 ++++++++++----- src/main.rs | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/common.rs b/src/common.rs index 0492178..6eb8dcc 100644 --- a/src/common.rs +++ b/src/common.rs @@ -138,20 +138,25 @@ pub(crate) fn transform_data(data: Vec>) -> 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(), } } diff --git a/src/main.rs b/src/main.rs index 4abb77a..c412cb3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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);