Skip to content

Commit fe50245

Browse files
committed
Add total number of elements
1 parent 906f9e9 commit fe50245

File tree

6 files changed

+15
-4
lines changed

6 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
- Add byte size
6+
- Add total number of elements
67

78
## [0.1.1] - 2025-09-12
89

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ just run-float
5555

5656
- Limit showing unique values to 10 values
5757
- If there are more than 10 values, show the smallest 10 and the highest 10
58-
- Total Elements
5958
- Mean, Standard Deviation, Median
6059
- Different output formats: text, json, ...
6160

src/analyze.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ pub struct NpyAnalysis {
1616
#[derive(Debug)]
1717
pub enum ValueStats {
1818
F64 {
19+
count: usize,
1920
unique_values: Vec<f64>,
2021
min: f64,
2122
max: f64,
2223
},
2324
I64 {
25+
count: usize,
2426
unique_values: Vec<i64>,
2527
min: i64,
2628
max: i64,
@@ -48,6 +50,7 @@ pub fn analyze_npy(file_path: &str) -> Result<NpyAnalysis, Box<dyn std::error::E
4850
if data.is_empty() {
4951
None
5052
} else {
53+
let count = data.len();
5154
let mut unique_numbers: Vec<_> = HashSet::<OrderedFloat<f64>>::from_iter(
5255
data.into_iter().map(OrderedFloat),
5356
)
@@ -57,6 +60,7 @@ pub fn analyze_npy(file_path: &str) -> Result<NpyAnalysis, Box<dyn std::error::E
5760

5861
match (unique_numbers.first(), unique_numbers.last()) {
5962
(Some(first), Some(last)) => Some(ValueStats::F64 {
63+
count,
6064
min: first.0,
6165
max: last.0,
6266
unique_values: unique_numbers.into_iter().map(|n| n.0).collect(),
@@ -72,11 +76,13 @@ pub fn analyze_npy(file_path: &str) -> Result<NpyAnalysis, Box<dyn std::error::E
7276
if data.is_empty() {
7377
None
7478
} else {
79+
let count = data.len();
7580
let mut unique_numbers: Vec<_> =
7681
HashSet::<i64>::from_iter(data).into_iter().collect();
7782
unique_numbers.sort_unstable();
7883

7984
Some(ValueStats::I64 {
85+
count,
8086
min: *unique_numbers
8187
.first()
8288
.expect("unique_numbers should not be empty due to is_empty check"),

src/present.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,33 @@ pub fn present_analysis(file_path: &str, analysis: &NpyAnalysis) {
1717

1818
match &analysis.stats {
1919
Some(ValueStats::F64 {
20+
count,
2021
unique_values,
2122
min,
2223
max,
2324
}) => {
24-
print_stats(unique_values, min, max);
25+
print_stats(count, unique_values, min, max);
2526
}
2627
Some(ValueStats::I64 {
28+
count,
2729
unique_values,
2830
min,
2931
max,
3032
}) => {
31-
print_stats(unique_values, min, max);
33+
print_stats(count, unique_values, min, max);
3234
}
3335
None => {
3436
println!("Unsupported dtype for unique value calculation");
3537
}
3638
}
3739
}
3840

39-
fn print_stats<T, U>(unique_values: &U, min: &T, max: &T)
41+
fn print_stats<T, U>(count: &usize, unique_values: &U, min: &T, max: &T)
4042
where
4143
T: std::fmt::Debug + std::fmt::Display,
4244
U: std::fmt::Debug + std::ops::Deref<Target = [T]>,
4345
{
46+
println!("Number of values: {count}");
4447
println!("Number of unique values: {}", unique_values.len());
4548
println!("Unique values: {unique_values:?}");
4649
println!("Min value: {min}");

tests/snapshots/cli__cli_run_float.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Shape: [2, 3]
99
Type: Float8
1010
Bytes: 176 B
1111
----------------------------------------
12+
Number of values: 6
1213
Number of unique values: 6
1314
Unique values: [1.1, 3.3, 4.2, 8.4, 12.6, 22.5]
1415
Min value: 1.1

tests/snapshots/cli__cli_run_int.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Shape: [2, 3]
99
Type: Int8
1010
Bytes: 176 B
1111
----------------------------------------
12+
Number of values: 6
1213
Number of unique values: 6
1314
Unique values: [1, 3, 4, 8, 12, 22]
1415
Min value: 1

0 commit comments

Comments
 (0)