56 template<
typename dtype>
69 std::ifstream file(inFilename.c_str(), std::ios::in | std::ios::binary);
75 file.seekg(0, std::ifstream::end);
76 const uint32 fileSize =
static_cast<uint32>(file.tellg());
77 file.seekg(0, std::ifstream::beg);
79 std::vector<char> fileBuffer;
80 fileBuffer.reserve(fileSize);
81 file.read(fileBuffer.data(), fileSize);
83 if (file.bad() || file.fail())
90 NdArray<dtype> returnArray(
reinterpret_cast<dtype*
>(fileBuffer.data()), fileSize /
sizeof(dtype));
96 if (!(inSep ==
" " || inSep ==
"\t" || inSep ==
"\n"))
101 std::vector<dtype> values;
103 std::ifstream file(inFilename.c_str());
110 std::getline(file, line);
112 std::istringstream iss(line);
118 values.push_back(value);
121 catch (
const std::invalid_argument& ia)
123 std::cout <<
"Warning: fromfile: line " << lineNumber <<
"\n" << ia.what() << std::endl;
127 std::cout <<
"Warning: fromfile: line " << lineNumber << std::endl;
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
Provides simple filesystem functions.
Definition: Filesystem.hpp:40
Definition: Coordinate.hpp:45
NdArray< dtype > fromfile(const std::string &inFilename, const std::string &inSep="")
Definition: fromfile.hpp:57
std::uint32_t uint32
Definition: Types.hpp:40