Skip to content

Commit

Permalink
update to fix? scaled=0 situation
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Oct 11, 2024
1 parent ffa9683 commit 5f70fcc
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/core/src/sketch/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ use crate::Error;

pub fn max_hash_for_scaled(scaled: u64) -> u64 {
match scaled {
0 => 0,
0 => 0, // scaled == 0 indicates this is a num minhash
1 => u64::MAX,
_ => (u64::MAX as f64 / scaled as f64) as u64,
}
}

pub fn scaled_for_max_hash(max_hash: u64) -> u64 {
match max_hash {
0 => 0,
0 => 0, // scaled == 0 indicates this is a num minhash
_ => (u64::MAX as f64 / max_hash as f64) as u64,
}
}
Expand Down Expand Up @@ -723,8 +723,12 @@ impl KmerMinHash {

// create a downsampled copy of self
pub fn downsample_max_hash(self, max_hash: u64) -> Result<KmerMinHash, Error> {
let scaled = scaled_for_max_hash(max_hash);
self.downsample_scaled(scaled)
if self.max_hash == 0 {
Ok(self)

Check warning on line 727 in src/core/src/sketch/minhash.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/sketch/minhash.rs#L727

Added line #L727 was not covered by tests
} else {
let scaled = scaled_for_max_hash(max_hash);
self.downsample_scaled(scaled)
}
}

pub fn sum_abunds(&self) -> u64 {
Expand Down Expand Up @@ -770,8 +774,8 @@ impl KmerMinHash {

// create a downsampled copy of self
pub fn downsample_scaled(self, scaled: u64) -> Result<KmerMinHash, Error> {
// @CTB shouldn't we check that new scaled > old scaled?
if self.scaled() == scaled {
// @CTB: check that new scaled > old scaled
if self.scaled() == scaled || self.scaled() == 0 {
Ok(self)
} else {
let mut new_mh = KmerMinHash::new(
Expand Down Expand Up @@ -1536,14 +1540,18 @@ impl KmerMinHashBTree {

// create a downsampled copy of self
pub fn downsample_max_hash(self, max_hash: u64) -> Result<KmerMinHashBTree, Error> {
let scaled = scaled_for_max_hash(max_hash);
self.downsample_scaled(scaled)
if self.max_hash == 0 {
Ok(self)

Check warning on line 1544 in src/core/src/sketch/minhash.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/sketch/minhash.rs#L1542-L1544

Added lines #L1542 - L1544 were not covered by tests
} else {
let scaled = scaled_for_max_hash(max_hash);
self.downsample_scaled(scaled)

Check warning on line 1547 in src/core/src/sketch/minhash.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/sketch/minhash.rs#L1547

Added line #L1547 was not covered by tests
}
}

// create a downsampled copy of self
pub fn downsample_scaled(self, scaled: u64) -> Result<KmerMinHashBTree, Error> {
// @CTB shouldn't we check that new scaled > old scaled?
if self.scaled() == scaled {
// @CTB TODO: check that new scaled > old scaled
if self.scaled() == scaled || self.scaled() == 0 {
Ok(self)
} else {
let mut new_mh = KmerMinHashBTree::new(
Expand Down

0 comments on commit 5f70fcc

Please sign in to comment.