-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cairo
34 lines (32 loc) · 1.14 KB
/
test.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
let mut unique_elements = (*t.data).unique();
let mut new_shape: Array<usize> = array![unique_elements.len()];
// TODO: investigate why calling merge before the next 2 loops
// cause the program to crash with error:
// #73054: One of the arguments does not satisfy the requirements of the libfunc.
if (sorted) {
unique_elements = merge(unique_elements);
// unique_elements = unique_elements;
}
let mut unique_elements_span = unique_elements.span();
let mut data_cpy = *(t.data);
loop {
match unique_elements_span.pop_front() {
Option::Some(value) => {
let occurences = data_cpy.occurrences_of(*value);
count.append(occurences.into());
let idx_in_data = data_cpy.index_of(*value).unwrap();
indices.append(idx_in_data.into());
},
Option::None => { break; }
}
};
unique_elements_span = unique_elements.span();
loop {
match data_cpy.pop_front() {
Option::Some(value) => {
let idx_in_uniques = unique_elements_span.index_of(*value).unwrap();
inverse_indices.append(idx_in_uniques.into());
},
Option::None => { break; }
}
};