Added fast C based direct CSV-to-matrix functionality with options #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@josevalim, this function is very fast: I compared it's execution time with that of Pandas'
read_csv
for the MNIST test dataset (test.csv
) (source) and Pandas took2.5492329597473145
seconds while Tensorflex'sload_csv_as_matrix/2
took1.711494
seconds.Usage is simple, and gives the user the option of passing in if header is not present (defaults to header being present), and also the ability of choosing the delimiter (defaults to
','
). I have added two sample CSV files in the test folder around which I will write tests soon, but for now I am using here to showcase the usage. Also, thetest.csv
file I use in the example code below belongs to the MNIST Kaggle CSV data (source), which contains 28000 rows and 784 columns. It is comma delimited and also contains a header. From that, I created a custom file without the header present which I will refer to astest_without_header.csv
in the examples below. I have not put the file on Github since it is relatively large in size.Code usage:
On a visual inspection of the very large
test.csv
file, one can see that the values in these particular positions are correct. Now I will show usage for the same file but without header:Next for the sample CSV files sample2.csv and sample1.csv, I'll show that the function does the job. Here, it is also reasonable to use the
Tensorflex.matrix_to_lists/1
function for the matrix because the data is not high dimensional. It is not advisable to do that for the above mentioned MNIST files:Also incorrect usage will
raise
: