11.08., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

...
 
Commits (2)
......@@ -6,6 +6,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/numpy.h>
#include <functional>
......@@ -103,7 +104,7 @@ namespace elsa
template <typename data_t>
struct DataContainerHints : public ClassHints<elsa::DataContainer<data_t>> {
constexpr static std::tuple ignoreMethods = {
constexpr static std::array ignoreMethods = {
"operator()", "begin", "cbegin", "end", "cend", "rbegin", "crbegin", "rend", "crend"};
template <typename type_, typename... options>
......@@ -115,45 +116,32 @@ namespace elsa
template <typename type_, typename... options>
static void exposeBufferInfo(py::class_<type_, options...>& c)
{
c.def(py::init([](py::buffer b) {
py::buffer_info info = b.request();
if (info.format != py::format_descriptor<data_t>::format())
throw std::invalid_argument("Incompatible scalar types");
elsa::IndexVector_t coeffsPerDim(info.ndim);
ssize_t minStride = info.strides[0];
for (std::size_t i = 0; i < static_cast<std::size_t>(info.ndim); i++) {
if (info.strides[i] < minStride)
minStride = info.strides[i];
coeffsPerDim[static_cast<elsa::index_t>(i)] =
static_cast<elsa::index_t>(info.shape[i]);
}
if (static_cast<std::size_t>(minStride) / sizeof(data_t) != 1)
throw std::invalid_argument("Cannot convert strided buffer to DataContainer");
auto map = Eigen::Map<Eigen::Matrix<data_t, Eigen::Dynamic, 1>>(
static_cast<data_t*>(info.ptr), coeffsPerDim.prod());
elsa::VolumeDescriptor dd{coeffsPerDim};
return std::make_unique<elsa::DataContainer<data_t>>(dd, map);
})).def_buffer([](elsa::DataContainer<data_t>& m) {
std::vector<ssize_t> dims, strides;
auto coeffsPerDim = m.getDataDescriptor().getNumberOfCoefficientsPerDimension();
ssize_t combined = 1;
for (int i = 0; i < coeffsPerDim.size(); i++) {
dims.push_back(coeffsPerDim[i]);
strides.push_back(combined * static_cast<ssize_t>(sizeof(data_t)));
combined *= coeffsPerDim[i];
}
return py::buffer_info(
&m[0], sizeof(data_t), py::format_descriptor<data_t>::format(),
m.getDataDescriptor().getNumberOfDimensions(), coeffsPerDim, strides);
});
c.def(
py::init([](py::array_t<data_t, py::array::f_style | py::array::forcecast> array) {
elsa::IndexVector_t coeffsPerDim(array.ndim());
for (index_t i = 0; i < coeffsPerDim.size(); i++)
coeffsPerDim[i] = array.shape(static_cast<ssize_t>(i));
auto map = Eigen::Map<const Eigen::Matrix<data_t, Eigen::Dynamic, 1>>(
array.data(), coeffsPerDim.prod());
elsa::VolumeDescriptor dd{coeffsPerDim};
return std::make_unique<elsa::DataContainer<data_t>>(dd, map);
}))
.def_buffer([](elsa::DataContainer<data_t>& m) {
std::vector<ssize_t> strides;
auto coeffsPerDim = m.getDataDescriptor().getNumberOfCoefficientsPerDimension();
ssize_t combined = 1;
for (int i = 0; i < coeffsPerDim.size(); i++) {
strides.push_back(combined * static_cast<ssize_t>(sizeof(data_t)));
combined *= coeffsPerDim[i];
}
return py::buffer_info(
&m[0], sizeof(data_t), py::format_descriptor<data_t>::format(),
m.getDataDescriptor().getNumberOfDimensions(), coeffsPerDim, strides);
});
}
};
......@@ -169,7 +157,7 @@ namespace elsa
template <typename data_t>
struct DataContainerComplexHints : public ClassHints<elsa::DataContainer<data_t>> {
constexpr static std::tuple ignoreMethods = {
constexpr static std::array ignoreMethods = {
"operator()", "begin", "cbegin", "end", "cend", "rbegin", "crbegin", "rend", "crend"};
template <typename type_, typename... options>
......
......@@ -17,7 +17,7 @@ namespace elsa
namespace py = pybind11;
struct EDFHints : public ClassHints<EDF> {
constexpr static std::tuple ignoreMethods = {"read"};
constexpr static std::array ignoreMethods = {"read"};
template <typename type_, typename... options>
static void addCustomMethods(py::class_<type_, options...>& c)
......@@ -35,7 +35,7 @@ namespace elsa
};
struct MHDHints : public ClassHints<MHD> {
constexpr static std::tuple ignoreMethods = {"read"};
constexpr static std::array ignoreMethods = {"read"};
template <typename type_, typename... options>
static void addCustomMethods(py::class_<type_, options...>& c)
......
......@@ -621,18 +621,16 @@ public:
if (varDecl->getNameAsString() == "ignoreMethods") {
auto constructExpr =
dyn_cast<CXXConstructExpr>(varDecl->getInit()->IgnoreImplicit());
if (constructExpr) {
for (auto arg : constructExpr->arguments()) {
while (!dyn_cast<StringLiteral>(arg)) {
if (dyn_cast<Expr>(*arg->child_begin())) {
arg = dyn_cast<Expr>(*arg->child_begin());
} else {
break;
}
}
auto initListExpr = dyn_cast<InitListExpr>(
dyn_cast<InitListExpr>(varDecl->getInit())->getInit(0)->IgnoreImplicit());
llvm::outs() << initListExpr->getNumInits() << "\n";
initListExpr->getInit(0)->dump();
if (initListExpr) {
for (auto arg : initListExpr->inits()) {
arg = arg->IgnoreImplicit();
if (!dyn_cast<StringLiteral>(arg))
assert(false
......