/// Represents d-dimensional vector objects into 1-dimentional
/// unique ids.
Represents d-dimensional vector objects into 1-dimentional
unique ids.
Represents d - dimensional vector objects into 1 - dimentional unique ids .
pub fn vectors_to_ids(
    objects: ArrayView2<usize>,
    mapping: Option<HashMap<Array1<usize>, usize>>,
) -> (Array1<usize>, HashMap<Array1<usize>, usize>) {
    let mut out = Vec::with_capacity(objects.nrows());
    let mut next_id = 0;
    let mut mapping = if let Some(mapping) = mapping {
        if let Some(id) = mapping.values().max() {
            next_id = id + 1;
        }
        mapping
    } else {
        HashMap::new()
    };
    for x in objects.outer_iter() {
        let id = mapping.entry(x.to_owned()).or_insert_with(|| {
            next_id += 1;
            next_id - 1
        });
        out.push(*id);
    }
    (Array::from(out), mapping)
}
pub fn vectors_to_ids ( objects : ArrayView2 < usize > , mapping : Option < HashMap < Array1 < usize > , usize > > , ) -> ( Array1 < usize > , HashMap < Array1 < usize > , usize > ) { let mut out = Vec :: with_capacity ( objects . nrows ( ) ) ; let mut next_id = 0 ; let mut mapping = if let Some ( mapping ) = mapping { if let Some ( id ) = mapping . values ( ) . max ( ) { next_id = id + 1 ; } mapping } else { HashMap :: new ( ) } ; for x in objects . outer_iter ( ) { let id = mapping . entry ( x . to_owned ( ) ) . or_insert_with ( | | { next_id += 1 ; next_id - 1 } ) ; out . push ( * id ) ; } ( Array :: from ( out ) , mapping ) }
Represents d-dimensional vector objects into 1-dimentional
unique ids.
Represents d - dimensional vector objects into 1 - dimentional unique ids .
objects
ArrayView2<usize>
mapping
Option<HashMap<Array1<usize>, usize>>