21#include <boost/python/list.hpp>
22#include <boost/python/numpy.hpp>
23#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
24#include <boost/python/tuple.hpp>
27namespace np = boost::python::numpy;
38 auto& first_row = *table.
begin();
39 auto& first_value = boost::get<std::vector<T>>(first_row[idx]);
40 auto size = first_value.size();
43 for (
auto& row : table) {
49 return py::make_tuple(size);
56 auto& first_row = *table.
begin();
57 auto& first_value = boost::get<std::string>(first_row[idx]);
58 auto size = first_value.size();
61 for (
auto& row : table) {
62 if (size != boost::get<std::string>(row[idx]).size()) {
76 auto& first_row = *table.
begin();
77 auto& first_value = boost::get<Euclid::NdArray::NdArray<T>>(first_row[idx]);
78 auto shape = first_value.shape();
81 for (
auto& row : table) {
89 for (
auto d : shape) {
92 return py::tuple(pyshape);
100 auto& name = descr.name;
104 if (type ==
typeid(int32_t)) {
105 return py::make_tuple(name,
"i4");
106 }
else if (type ==
typeid(int64_t)) {
107 return py::make_tuple(name,
"i8");
108 }
else if (type ==
typeid(
float)) {
109 return py::make_tuple(name,
"f4");
110 }
else if (type ==
typeid(
double)) {
111 return py::make_tuple(name,
"f8");
113 return py::make_tuple(name,
"S" +
std::to_string(getStringShape(table, idx)));
115 return py::make_tuple(name,
"i4", getVectorShape<int32_t>(table, idx));
117 return py::make_tuple(name,
"i8", getVectorShape<int64_t>(table, idx));
119 return py::make_tuple(name,
"f4", getVectorShape<float>(table, idx));
121 return py::make_tuple(name,
"f8", getVectorShape<double>(table, idx));
123 return py::make_tuple(name,
"i4", getNdArrayShape<int32_t>(table, idx));
125 return py::make_tuple(name,
"i8", getNdArrayShape<int64_t>(table, idx));
127 return py::make_tuple(name,
"f4", getNdArrayShape<float>(table, idx));
129 return py::make_tuple(name,
"f8", getNdArrayShape<double>(table, idx));
140 auto& v = boost::get<std::vector<T>>(cell);
148 auto& v = boost::get<std::string>(cell);
157 auto& v = boost::get<Euclid::NdArray::NdArray<T>>(cell);
176 const void* data_ptr;
178 if (type ==
typeid(int32_t)) {
179 data_size =
sizeof(int32_t);
180 data_ptr = &boost::get<int32_t>(cell);
181 }
else if (type ==
typeid(int64_t)) {
182 data_size =
sizeof(int64_t);
183 data_ptr = &boost::get<int64_t>(cell);
184 }
else if (type ==
typeid(
float)) {
185 data_size =
sizeof(float);
186 data_ptr = &boost::get<float>(cell);
187 }
else if (type ==
typeid(
double)) {
188 data_size =
sizeof(double);
189 data_ptr = &boost::get<double>(cell);
191 std::tie(data_size, data_ptr) = getStringCellData(cell);
193 std::tie(data_size, data_ptr) = getVectorCellData<int32_t>(cell);
195 std::tie(data_size, data_ptr) = getVectorCellData<int64_t>(cell);
197 std::tie(data_size, data_ptr) = getVectorCellData<float>(cell);
199 std::tie(data_size, data_ptr) = getVectorCellData<double>(cell);
201 std::tie(data_size, data_ptr) = getNdArrayCellData<int32_t>(cell);
203 std::tie(data_size, data_ptr) = getNdArrayCellData<int64_t>(cell);
205 std::tie(data_size, data_ptr) = getNdArrayCellData<float>(cell);
207 std::tie(data_size, data_ptr) = getNdArrayCellData<double>(cell);
220 size_t ncols = colinfo->size();
221 size_t nrows = table.
size();
226 for (
size_t i = 0; i < ncols; ++i) {
227 auto coldesc = colinfo->getDescription(i);
228 cols.append(numpyType(table, i));
232 np::dtype dtype(cols);
235 auto array = np::zeros(py::make_tuple(table.
size()), dtype);
238 char* nd_ptr = array.get_data();
239 for (
size_t i = 0; i < nrows; ++i) {
240 const auto& row = table[i];
241 for (
size_t j = 0; j < ncols; ++j) {
242 nd_ptr += copyCell(nd_ptr, colinfo->getDescription(j), row[j]);
Contains the description of a specific column of a Table.
boost::variant< bool, int32_t, int64_t, float, double, std::string, std::vector< bool >, std::vector< int32_t >, std::vector< int64_t >, std::vector< float >, std::vector< double >, NdArray::NdArray< int32_t >, NdArray::NdArray< int64_t >, NdArray::NdArray< float >, NdArray::NdArray< double > > cell_type
The possible cell types.
std::size_t size() const
Returns the number of rows in the table.
const_iterator begin() const
Returns a const iterator to the first row.
std::shared_ptr< ColumnInfo > getColumnInfo() const
Returns a ColumnInfo object describing the columns of the table.
boost::python::numpy::ndarray table2numpy(const Euclid::Table::Table &table)