nnlib
GPU-accelerated, C/C++ neural network library.
Functions
read.h File Reference

Header file declaring methods that can be used when reading from files. More...

#include "tensor.h"
#include <string>
#include <vector>

Go to the source code of this file.

Functions

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...
 
sTensor readCSV (const std::string &filepath, const std::string &delim=",", int numThreads=1)
 Read a csv file from a path. More...
 

Detailed Description

Header file declaring methods that can be used when reading from files.

Author
Jan Warchocki
Date
06 March 2022

Function Documentation

◆ fileExists()

bool fileExists ( const std::string &  filepath)

Check if a file exists with the provided filepath.

Parameters
filepathThe filepath of the file to check.
Returns
True if the file exists, false otherwise.

◆ readCSV()

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.

Parameters
filepathThe path to the csv file.
delimThe delimiter to use when splitting data.
numThreadsThe number of threads to use when splitting data.
Returns
Matrix of data that was read from the csv file.

◆ readFile()

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.

Parameters
filepathThe path to the file.
Returns
The lines read from the file.