[mlpack] Issue using FastCSV

Ryan Curtin ryan at ratml.org
Fri Apr 2 22:14:12 EDT 2021


On Fri, Apr 02, 2021 at 03:35:23PM +0530, Gopi Manohar Tatiraju wrote:
> Hello,
> 
> I am exploring some csv parsers. Link
> <https://github.com/ben-strasser/fast-cpp-csv-parser>
> I went through the basic example:
> 
> # include "csv.h"
> > int main(){
> >   io::CSVReader<3> in("ram.csv");
> >   in.read_header(io::ignore_extra_column, "vendor", "size", "speed");
> >   std::string vendor; int size; double speed;
> >   while(in.read_row(vendor, size, speed)){
> >     // do stuff with the data
> >   }
> > }
> 
> 
> Here you can see that the variables we pass into the function read_row get
> assigned the values of the corresponding columns, but what if I have 20 or
> 25 columns, declaring so many variables won't make sense. There should be
> some C++ syntax to handle cases like this. What is the concept called?
> 
> What if I don't know how many columns are there in my CSV file or what if
> there are 100 columns, we should use a vector or an array. Agreed. But...I
> don't want to pass 3 variables in the while loop(vendor, size, speed) but
> what I want is, pass a single vector or an array and I can unpack the
> vector to get those values.
> 
> Any help would be appreciated.

Hey Gopi,

I think maybe you've progressed past this point, but if you are still
struggling with it you might try checking on that repository.

(Wait, I see that you opened
https://github.com/ben-strasser/fast-cpp-csv-parser/issues/119.)

In your example, the template parameter must be set at compile-time, so
to me it seems strange that the fast-csv designer would have chosen to
make the number of columns a template parameter.

In my view, if there is no workaround that rules this out---we can have
arbitrarily-sized CSVs (even thousands of columns!) and we don't want to
force the compiler to instantiate `CSVReader<>` for every single number
of columns we might encounter...

Hope that helps!

Ryan

-- 
Ryan Curtin    | "I was misinformed."
ryan at ratml.org |   - Rick Blaine


More information about the mlpack mailing list