Skip to content

Commit 374b802

Browse files
committed
Replace usage of len by shape
1 parent efa127f commit 374b802

5 files changed

Lines changed: 16 additions & 16 deletions

File tree

muscatpy/src/leakage_detection.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub fn compute_snr<'py>(
1515
get_class: &Bound<'py, PyFunction>,
1616
batch_size: usize,
1717
) -> PyResult<Bound<'py, PyArray1<f32>>> {
18-
let mut traces_class = Array1::zeros(traces.len());
19-
for i in 0..traces_class.len() {
18+
let mut traces_class = Array1::zeros(traces.shape()[0]);
19+
for i in 0..traces_class.shape()[0] {
2020
traces_class[i] = get_class
2121
.call((i,), None)
2222
.unwrap()
@@ -64,8 +64,8 @@ pub fn compute_nicv<'py>(
6464
get_class: &Bound<'py, PyFunction>,
6565
batch_size: usize,
6666
) -> PyResult<Bound<'py, PyArray1<f32>>> {
67-
let mut traces_class = Array1::zeros(traces.len());
68-
for i in 0..traces_class.len() {
67+
let mut traces_class = Array1::zeros(traces.shape()[0]);
68+
for i in 0..traces_class.shape()[0] {
6969
traces_class[i] = get_class
7070
.call((i,), None)
7171
.unwrap()

src/leakage_detection.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
/// # Panics
117117
/// - Panics in debug if the length of the trace is different from the size of [`SnrProcessor`].
118118
pub fn process(&mut self, trace: ArrayView1<T>, class: usize) {
119-
debug_assert!(trace.len() == self.size());
119+
debug_assert!(trace.shape()[0] == self.size());
120120
debug_assert!(class < self.num_classes());
121121

122122
self.mean_var.process(trace);
@@ -168,7 +168,7 @@ where
168168

169169
/// Return the number of classes handled.
170170
pub fn num_classes(&self) -> usize {
171-
self.classes_count.len()
171+
self.classes_count.shape()[0]
172172
}
173173

174174
/// Determine if two [`SnrProcessor`] are compatible for addition.
@@ -351,7 +351,7 @@ where
351351
/// # Panics
352352
/// Panics in debug if the length of the trace is different from the size of [`Snr`].
353353
pub fn process(&mut self, trace: ArrayView1<T>, class: usize) {
354-
debug_assert!(trace.len() == self.size());
354+
debug_assert!(trace.shape()[0] == self.size());
355355
debug_assert!(class < self.num_classes());
356356

357357
self.mean_var.process(trace);
@@ -397,7 +397,7 @@ where
397397

398398
/// Returns the number of classes handled.
399399
pub fn num_classes(&self) -> usize {
400-
self.classes_count.len()
400+
self.classes_count.shape()[0]
401401
}
402402

403403
/// Determine if two [`NicvProcessor`] are compatible for addition.
@@ -525,9 +525,9 @@ where
525525
/// * `class` - Indicates to which of the two partitions the given trace belongs.
526526
///
527527
/// # Panics
528-
/// Panics in debug if `trace.len() != self.size()`.
528+
/// Panics in debug if `trace.shape()[0] != self.size()`.
529529
pub fn process(&mut self, trace: ArrayView1<T>, class: bool) {
530-
debug_assert!(trace.len() == self.size());
530+
debug_assert!(trace.shape()[0] == self.size());
531531

532532
if class {
533533
self.mean_var_2.process(trace);

src/preprocessors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ where
218218
cmp,
219219
);
220220

221-
let mut aligned_trace = Array1::zeros([trace.len()]);
221+
let mut aligned_trace = Array1::zeros([trace.shape()[0]]);
222222
let mut k = 0;
223-
for j in 0..trace.len() {
223+
for j in 0..trace.shape()[0] {
224224
let mut count = T::Container::zero();
225225
let mut sum = T::Container::zero();
226226

src/processors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ where
4646
/// # Panics
4747
/// Panics in debug if the length of the trace is different form the size of [`MeanVar`].
4848
pub fn process(&mut self, trace: ArrayView1<T>) {
49-
debug_assert!(trace.len() == self.size());
49+
debug_assert!(trace.shape()[0] == self.size());
5050

51-
for i in 0..self.sum.len() {
51+
for i in 0..self.sum.shape()[0] {
5252
let x = trace[i].into();
5353

5454
self.sum[i] += x;
@@ -74,7 +74,7 @@ where
7474

7575
/// Returns the trace size handled.
7676
pub fn size(&self) -> usize {
77-
self.sum.len()
77+
self.sum.shape()[0]
7878
}
7979

8080
/// Returns the number of traces processed.

src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ where
7070
{
7171
let mut idx_max = 0;
7272

73-
for i in 0..array.len() {
73+
for i in 0..array.shape()[0] {
7474
if compare(&array[i], &array[idx_max]).is_gt() {
7575
idx_max = i;
7676
}

0 commit comments

Comments
 (0)