forked from rikigigi/analisi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readlog_numpy.cpp
29 lines (21 loc) · 1.02 KB
/
readlog_numpy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "readlog_numpy.h"
#include "buffer_utils.h"
template <class TFLOAT>
ReadLog_numpy<TFLOAT>::ReadLog_numpy(pybind11::buffer data, std::vector<std::string> headers) : headers{headers}
{
pybind11::buffer_info info_data{data.request()};
if (info_data.ndim != 2) {
throw std::runtime_error("Wrong number of dimensions of the log array (must be 2)");
}
if (info_data.format != pybind11::format_descriptor<TFLOAT>::format())
throw std::runtime_error("Format of log array is wrong (should be some kind of float, try to change it if it does not work)");
if (!has_no_stride<TFLOAT>(info_data))
throw std::runtime_error("Unsupported stride in log array");
if (info_data.shape[1] != headers.size())
throw std::runtime_error("Number of headers is not equal to the number of columns");
ntimestep=info_data.shape[0];
ncols=info_data.shape[1];
data_=static_cast<TFLOAT *> (info_data.ptr);
}
template class ReadLog_numpy<double>;
template class ReadLog_numpy<long double>;