Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.

Commit 09f54d5

Browse files
csv: added slice type to CSV
1 parent b1862be commit 09f54d5

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

include/parsers/csv.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ typedef struct {
5353
char delim;
5454
} CSV;
5555

56+
typedef struct {
57+
size_t lower;
58+
size_t upper; // non inclusive
59+
} Slice;
60+
5661
/*
5762
Initialize the CSV reader/parser
5863
@@ -80,4 +85,10 @@ Returns a new Mat with only the selected cols
8085
*/
8186
Mat *csv_get_mat(CSV *csv, int *rows, size_t c_size);
8287

88+
/*
89+
Returns a new Mat with only the selected cols using Slice type
90+
*/
91+
92+
Mat *csv_get_mat_slice(CSV *csv, Slice slice);
93+
8394
#endif

src/parsers/csv.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,17 @@ Mat *csv_get_mat(CSV *csv, int *cols, size_t c_size) {
8888

8989
return new_mat;
9090
}
91+
92+
Mat *csv_get_mat_slice(CSV *csv, Slice slice) {
93+
size_t n_cols = slice.upper - slice.lower;
94+
Mat *new_mat = mat_create(csv->values->rows, n_cols);
95+
96+
size_t new_mat_col = 0;
97+
for (size_t i = 0; i < n_cols; i++) {
98+
for (size_t r = 0; r < csv->values->rows; r++) {
99+
mat_set(new_mat, r, new_mat_col, mat_get(csv->values, r, slice.lower + i));
100+
}
101+
new_mat_col++;
102+
}
103+
return new_mat;
104+
}

0 commit comments

Comments
 (0)