Skip to content

Commit

Permalink
Update dataToFormat implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape committed Aug 12, 2018
1 parent 9fcba0f commit acd9244
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 3 additions & 10 deletions include/z5/multiarray/xtensor_access.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,13 @@ namespace multiarray {
}


template<typename T, typename ARRAY_IN, typename ARRAY_OUT>
template<typename T, typename ARRAY_IN>
void convertArrayToFormat(const Dataset & ds,
const xt::xexpression<ARRAY_IN> & inExpression,
xt::xexpression<ARRAY_OUT> & outExpression) {
std::vector<char> & out) {
const auto & in = inExpression.derived_cast();
auto & out = outExpression.derived_cast();

std::vector<char> tmp;
types::ShapeType shape(in.shape().begin(), in.shape().end());
ds.dataToFormat(&in(0), tmp, shape);

out.resize({(int64_t) tmp.size()});
// TODO use xadapt instead
std::copy(tmp.begin(), tmp.end(), out.begin());
ds.dataToFormat(&in(0), out, shape);
}

template<typename T, typename ARRAY_IN, typename ARRAY_OUT>
Expand Down
9 changes: 7 additions & 2 deletions src/python/lib/dataset.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ namespace z5 {
template<class T>
inline xt::pytensor<char, 1> convertPyArrayToFormat(const Dataset & ds,
const xt::pyarray<T> & in) {
xt::pytensor<char, 1> out = xt::zeros<char>({1});
multiarray::convertArrayToFormat<T>(ds, in, out);
std::vector<char> tmp;
multiarray::convertArrayToFormat<T>(ds, in, tmp);
typedef xt::pytensor<char, 1>::shape_type ShapeType;
const ShapeType outShape = {static_cast<int64_t>(tmp.size())};
xt::pytensor<char, 1> out = xt::zeros<char>(outShape);
// TODO can we use xt::adapt here instead of std::copy?
std::copy(tmp.begin(), tmp.end(), out.begin());
return out;
}

Expand Down

0 comments on commit acd9244

Please sign in to comment.