Skip to content

Commit

Permalink
retro compat
Browse files Browse the repository at this point in the history
  • Loading branch information
kali committed Jan 2, 2024
1 parent 41fa13c commit 4a14cc1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions onnx-opl/src/ml/category_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ pub struct ReverseLookup {
fallback_value: i32,
}

#[allow(clippy::manual_hash_one)]
impl ReverseLookup {
pub fn new(keys: Arc<Tensor>, fallback_value: i32) -> TractResult<ReverseLookup> {
unsafe fn new_t<T: Datum + Hash>(keys: &Tensor) -> HashMap<u64, SmallVec<[i32; 1]>> {
let keys = keys.as_slice_unchecked::<T>();
let mut hashmap = HashMap::<u64, SmallVec<[i32; 1]>>::default();
for (ix, k) in keys.iter().enumerate() {
let u = hashmap.hasher().hash_one(k);
let mut hasher = hashmap.hasher().build_hasher();
k.hash(&mut hasher);
let u = hasher.finish();
hashmap.entry(u).or_default().push(ix as i32);
}
hashmap
Expand All @@ -118,8 +121,9 @@ impl ReverseLookup {

unsafe fn search_t<T: Datum + Hash>(&self, needle: &T) -> Option<i32> {
let keys = self.keys.as_slice_unchecked::<T>();

let u = self.index.hasher().hash_one(needle);
let mut hasher = self.index.hasher().build_hasher();
needle.hash(&mut hasher);
let u = hasher.finish();
if let Some(candidates) = self.index.get(&u) {
for candidate in candidates {
if &keys[*candidate as usize] == needle {
Expand Down

0 comments on commit 4a14cc1

Please sign in to comment.