56 template<
typename dtype>
64 if (inSep.compare(
"") == 0)
67 std::ifstream file(inFilename.c_str(), std::ios::in | std::ios::binary);
73 file.seekg(0, file.end);
74 const uint32 fileSize =
static_cast<uint32>(file.tellg());
75 file.seekg(0, file.beg);
77 const auto fileBuffer = std::unique_ptr<char>(
new char[fileSize]);
78 file.read(fileBuffer.get(), fileSize);
80 if (file.bad() || file.fail())
87 NdArray<dtype> returnArray(reinterpret_cast<dtype*>(fileBuffer.get()), fileSize /
sizeof(dtype));
94 if (!(inSep.compare(
" ") == 0 || inSep.compare(
"\t") == 0 || inSep.compare(
"\n") == 0))
99 std::vector<dtype> values;
101 std::ifstream file(inFilename.c_str());
108 std::getline(file, line);
110 std::istringstream iss(line);
116 values.push_back(value);
119 catch (
const std::invalid_argument& ia)
121 std::cout <<
"Warning: fromfile: line " << lineNumber <<
"\n" << ia.what() << std::endl;
125 std::cout <<
"Warning: fromfile: line " << lineNumber << std::endl;
NdArray< dtype > fromfile(const std::string &inFilename, const std::string &inSep="")
Definition: fromFile.hpp:57
Definition: Coordinate.hpp:45
uint32_t uint32
Definition: Types.hpp:41
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:38
Provides simple filesystem functions.
Definition: Filesystem.hpp:40
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:66