Closed OneRaynyDay closed 6 years ago
These using declarations (strides_type
, backstrides_type
and their inner counterpart) do not make sense for all kinds of expression, so they should not be defined in the xshared_expression
.
@JohanMabille Should we remove these inner counterparts from the code then? I can make a PR for it.
If that does not break other tests, that can be a quick (but incomplete) fix.
If we want the shared expression to work with any kind of expressions, it's a bit more complicated; we should have something like:
using shape_type = typename E::shape_type;
using strides_type = std::conditional_t<has_strides<E>::value, typename E::strides_type, get_strides_t<shape_type>>;
using back_strides = std::conditional<has_backstrides<E>::value_type, typename E::backstrides_type, strides_type>;
using inner_shape_type = std::conditional_t<has_inner_shape<E>, typename E::inner_shape_type, shape_typr>;
// Similar for inner_strides_type and inner_backstrides_type
Where some of the has_XXX
are already defined somewhere in xtensor, the others need to be defined.
Besides, and that's totally independent from the previous oint, the type returned in XTENSOR_FORWARD_METHOD
should be decltype(auto)
instead of auto
.
Here is what happens if we remove the declarations:
(cling) ❯ g++ -std=c++17 -I/Users/ray_zhang/anaconda3/envs/cling/include hmm.cpp
In file included from hmm.cpp:2:
In file included from /Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xarray.hpp:19:
In file included from /Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xcontainer.hpp:23:
In file included from /Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xmath.hpp:23:
In file included from /Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xaccumulator.hpp:17:
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:409:32: error: no member named 'strides' in
'xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &,
const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long,
4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>'
XTENSOR_FORWARD_METHOD(strides);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:324:39: note: expanded from macro 'XTENSOR_FORWARD_METHOD'
-> decltype(std::declval<E>().name()) \
~~~~~~~~~~~~~~~~~ ^
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:503:16: note: in instantiation of template class
'xt::xshared_expression<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
>' requested here
return xshared_expression<E>(std::make_shared<E>(expr));
^
hmm.cpp:11:27: note: in instantiation of function template specialization 'xt::make_xshared<xt::xfunction<xt::detail::plus<double>,
double, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major,
xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &, const
xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4,
std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &> >' requested here
auto expression = xt::make_xshared(std::move(expr));
^
hmm.cpp:20:5: note: in instantiation of function template specialization 'make_shared<xt::xfunction<xt::detail::plus<double>, double,
const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long,
4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &> >' requested here
make_shared(arr1+arr2); // fails
^
In file included from hmm.cpp:2:
In file included from /Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xarray.hpp:19:
In file included from /Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xcontainer.hpp:23:
In file included from /Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xmath.hpp:23:
In file included from /Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xaccumulator.hpp:17:
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:411:32: error: no member named 'data' in
'xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &,
const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long,
4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>'
XTENSOR_FORWARD_METHOD(data);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:324:39: note: expanded from macro 'XTENSOR_FORWARD_METHOD'
-> decltype(std::declval<E>().name()) \
~~~~~~~~~~~~~~~~~ ^
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:413:32: error: no member named 'data_offset' in
'xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &,
const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long,
4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>'
XTENSOR_FORWARD_METHOD(data_offset);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:324:39: note: expanded from macro 'XTENSOR_FORWARD_METHOD'
-> decltype(std::declval<E>().name()) \
~~~~~~~~~~~~~~~~~ ^
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:415:32: error: no member named 'storage' in
'xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &,
const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long,
4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>'
XTENSOR_FORWARD_METHOD(storage);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:324:39: note: expanded from macro 'XTENSOR_FORWARD_METHOD'
-> decltype(std::declval<E>().name()) \
~~~~~~~~~~~~~~~~~ ^
In file included from hmm.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:470:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view:169:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__string:56:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:643:
/Library/Developer/CommandLineTools/usr/include/c++/v1/memory:2057:9: error: no matching constructor for initialization of
'xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &,
const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long,
4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>'
: __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/memory:2159:9: note: in instantiation of function template specialization
'std::__1::__compressed_pair_elem<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>,
1, false>::__compressed_pair_elem<xt::xexpression<xt::xfunction<xt::detail::plus<double>, double, const
xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4,
std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &> > &, 0>' requested here
_Base2(__pc, _VSTD::move(__second_args),
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/memory:3572:16: note: in instantiation of function template specialization
'std::__1::__compressed_pair<std::__1::allocator<xt::xfunction<xt::detail::plus<double>, double, const
xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4,
std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &> >, xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
>::__compressed_pair<std::__1::allocator<xt::xfunction<xt::detail::plus<double>, double, const
xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4,
std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &> > &, xt::xexpression<xt::xfunction<xt::detail::plus<double>, double, const
xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4,
std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &> > &>' requested here
: __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/memory:4230:26: note: in instantiation of function template specialization
'std::__1::__shared_ptr_emplace<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>,
std::__1::allocator<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
> >::__shared_ptr_emplace<xt::xexpression<xt::xfunction<xt::detail::plus<double>, double, const
xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4,
std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &> > &>' requested here
::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/memory:4600:29: note: in instantiation of function template specialization
'std::__1::shared_ptr<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
>::make_shared<xt::xexpression<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
> &>' requested here
return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
^
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xexpression.hpp:503:43: note: in instantiation of function template specialization
'std::__1::make_shared<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>,
xt::xexpression<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
> &>' requested here
return xshared_expression<E>(std::make_shared<E>(expr));
^
hmm.cpp:20:5: note: in instantiation of function template specialization 'make_shared<xt::xfunction<xt::detail::plus<double>, double,
const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long,
4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &> >' requested here
make_shared(arr1+arr2); // fails
^
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xfunction.hpp:557:9: note: candidate constructor not viable: no known conversion
from 'xt::xexpression<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
>' to 'const xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>'
for 1st argument
xfunction(const xfunction&) = default;
^
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xfunction.hpp:560:9: note: candidate constructor not viable: no known conversion
from 'xt::xexpression<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
>' to 'xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &,
const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long,
4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>' for 1st argument
xfunction(xfunction&&) = default;
^
/Users/ray_zhang/anaconda3/envs/cling/include/xtensor/xfunction.hpp:553:9: note: candidate template ignored: requirement
'!std::is_base_of<std::decay_t<xexpression<xfunction<plus<double>, double, const xarray_container<uvector<double, allocator<double>
>, xt::layout_type::row_major, svector<unsigned long, 4, allocator<unsigned long>, true>, xtensor_expression_tag> &, const
xarray_container<uvector<double, allocator<double> >, xt::layout_type::row_major, svector<unsigned long, 4, allocator<unsigned
long>, true>, xtensor_expression_tag> &> > &>, self_type>::value' was not satisfied [with Func =
xt::xexpression<xt::xfunction<xt::detail::plus<double>, double, const xt::xarray_container<xt::uvector<double,
std::__1::allocator<double> >, xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>,
xt::xtensor_expression_tag> &, const xt::xarray_container<xt::uvector<double, std::__1::allocator<double> >,
xt::layout_type::row_major, xt::svector<unsigned long, 4, std::__1::allocator<unsigned long>, true>, xt::xtensor_expression_tag> &>
> &, CTA = <>]
xfunction(Func&& f, CTA&&... e) noexcept;
^
5 errors generated.
Thanks guys for fixing this up!
Reproducing from a cpp file:
The error seems to be that
xshared_expression
requires astrides_type
, and generalxfunctions
do not have this attribute: