nnlib
GPU-accelerated, C/C++ neural network library.
|
Source file defining methods that can be used when reading from files. More...
#include "read.h"
#include "printing.h"
#include <cmath>
#include <fstream>
#include <iostream>
#include <thread>
#include <utility>
Functions | |
std::vector< std::string > | split (const std::string &str, const std::string &delim) |
Splits a string given the delimiter. More... | |
bool | fileExists (const std::string &filepath) |
Check if a file exists with the provided filepath. More... | |
std::vector< std::string > | readFile (const std::string &filepath) |
Read file from a filepath. More... | |
void | threadCSVJob (const std::vector< std::string > &lines, const std::string &delim, Tensor &result, int id, int numThreads) |
A method that is executed by every thread during readCSV(). More... | |
sTensor | readCSV (const std::string &filepath, const std::string &delim, int numThreads) |
Read a csv file from a path. More... | |
Source file defining methods that can be used when reading from files.
bool fileExists | ( | const std::string & | filepath | ) |
Check if a file exists with the provided filepath.
filepath | The filepath of the file to check. |
sTensor readCSV | ( | const std::string & | filepath, |
const std::string & | delim = "," , |
||
int | numThreads = 1 |
||
) |
Read a csv file from a path.
The method will first read all lines from the file and then divide the lines over numThreads
threads to split them into values. The values are then written into a matrix that is then returned.
filepath | The path to the csv file. |
delim | The delimiter to use when splitting data. |
numThreads | The number of threads to use when splitting data. |
std::vector<std::string> readFile | ( | const std::string & | filepath | ) |
Read file from a filepath.
Will attempt to read file with the provided filepath or in the parent directory of the filepath.
The method can only read text files and will not work on binary files.
filepath | The path to the file. |
std::vector<std::string> split | ( | const std::string & | str, |
const std::string & | delim | ||
) |
Splits a string given the delimiter.
str | The string to split. |
delim | The delimiter to split on. |
str
by delim
. void threadCSVJob | ( | const std::vector< std::string > & | lines, |
const std::string & | delim, | ||
Tensor & | result, | ||
int | id, | ||
int | numThreads | ||
) |
A method that is executed by every thread during readCSV().
Each thread takes some part of the lines of the file, splits them by the delimiter, converts the values to float and saves those values into a result matrix.
lines | The lines as read from the file. |
delim | The delimiter to use when splitting lines. |
result | A result matrix where the threads should store the results. |
id | The id of the thread. |
numThreads | The total number of threads launched. |