52 template<
typename dtype>
61 std::ifstream file(inFilename.c_str(), std::ios::in | std::ios::binary);
67 file.seekg(0, std::ifstream::end);
68 const uint32 fileSize =
static_cast<uint32>(file.tellg());
69 file.seekg(0, std::ifstream::beg);
71 std::vector<char> fileBuffer;
72 fileBuffer.reserve(fileSize);
73 file.read(fileBuffer.data(), fileSize);
75 if (file.bad() || file.fail())
82 NdArray<dtype> returnArray(
reinterpret_cast<dtype*
>(fileBuffer.data()), fileSize /
sizeof(dtype));
97 template<
typename dtype>
102 std::ifstream file(inFilename.c_str());
108 std::vector<dtype> values;
113 std::getline(file, line, inSep);
115 std::istringstream iss(line);
121 values.push_back(value);
124 catch (
const std::invalid_argument& ia)
126 std::cout <<
"Warning: fromfile: line " << lineNumber <<
'\n' << ia.what() << std::endl;
130 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)
Definition: fromfile.hpp:53
std::uint32_t uint32
Definition: Types.hpp:40