xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.37k stars 400 forks source link

can't get xtensor include files to compile without errors in jupyter notebook #1685

Open cagBRT opened 5 years ago

cagBRT commented 5 years ago

Can someone tell me what I am doing wrong?

I am trying to run this code in a jupyter notebook:

#include <iostream>
#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xview.hpp"

And I am getting these errors:

`In file included from input_line_8:2: In file included from ./xtensor/xarray.hpp:19: In file included from ./xtensor/xcontainer.hpp:23: In file included from ./xtensor/xmath.hpp:25: In file included from ./xtensor/xaccumulator.hpp:17: ./xtensor/xexpression.hpp:505:9: error: no member named 'constify_t' in namespace 'xtl' XTENSOR_FORWARD_CONST_METHOD(shape) ^~~~~~~~~~~ ./xtensor/xexpression.hpp:355:39: note: expanded from macro 'XTENSOR_FORWARD_CONST_METHOD' -> decltype(std::declval<xtl::constify_t>().name()...


./xtensor/xexpression.hpp:505:9: error: 'E' does not refer to a value
./xtensor/xexpression.hpp:355:50: note: expanded from macro 'XTENSOR_FORWARD_CONST_METHOD'
        -> decltype(std::declval<xtl::constify_t<E>>().name()...
                                                 ^
./xtensor/xexpression.hpp:451:21: note: declared here
    template <class E>
                    ^
./xtensor/xexpression.hpp:502:20: error: use of undeclared identifier 'm_ptr'
            return m_ptr->operator()(args...);
                   ^
./xtensor/xexpression.hpp:650:11: error: member initializer 'm_ptr' does not name a non-static data member or base class
        : m_ptr(ptr)
          ^~~~~~~~~~
./xtensor/xexpression.hpp:661:16: error: use of undeclared identifier 'm_ptr'
        return m_ptr.use_count();
               ^
In file included from input_line_8:2:
In file included from ./xtensor/xarray.hpp:19:
In file included from ./xtensor/xcontainer.hpp:23:
In file included from ./xtensor/xmath.hpp:25:
./xtensor/xaccumulator.hpp:285:56: error: expected template parameter
              XTL_REQUIRES(is_evaluation_strategy<EVS>)>
                                                       ^
In file included from input_line_8:2:
In file included from ./xtensor/xarray.hpp:19:
In file included from ./xtensor/xcontainer.hpp:23:
In file included from ./xtensor/xmath.hpp:26:
./xtensor/xoperation.hpp:101:24: error: no member named 'select' in namespace 'xtl'; did you mean 'xt_simd::select'?
                return xtl::select(cond, v1, v2);
                       ^~~~~~~~~~~
                       xt_simd::select
./xtensor/xtensor_simd.hpp:160:14: note: 'xt_simd::select' declared here
    inline T select(bool cond, const T& t1, const T& t2)
             ^
In file included from input_line_8:2:
In file included from ./xtensor/xarray.hpp:19:
In file included from ./xtensor/xcontainer.hpp:23:
In file included from ./xtensor/xmath.hpp:27:
In file included from ./xtensor/xreducer.hpp:28:
./xtensor/xbuilder.hpp:219:88: error: expected template parameter
  ...<class R, class E, class U, class X, XTL_REQUIRES(std::is_integral<X>)>
                                                                           ^
./xtensor/xbuilder.hpp:232:103: error: expected template parameter
  ...E, class U, class X, XTL_REQUIRES(xtl::negation<std::is_integral<X>>)>
                                                                          ^
./xtensor/xbuilder.hpp:233:21: error: redefinition of 'arange_assign_to'
        inline void arange_assign_to(xexpression<E>& e, U start, X step...
                    ^
./xtensor/xbuilder.hpp:220:21: note: previous definition is here
        inline void arange_assign_to(xexpression<E>& e, U start, X step...
                    ^
./xtensor/xbuilder.hpp:299:88: error: expected template parameter
  ...<class T, class S = T, XTL_REQUIRES(xtl::negation<both_integer<T, S>>)>
                                                                           ^
./xtensor/xbuilder.hpp:306:73: error: expected template parameter
        template <class T, class S = T, XTL_REQUIRES(both_integer<T, S>)>
                                                                        ^
./xtensor/xbuilder.hpp:307:52: error: redefinition of default argument
        inline auto arange_impl(T start, T stop, S step = 1) noexcept
                                                   ^      ~
./xtensor/xbuilder.hpp:300:52: note: previous definition is here
        inline auto arange_impl(T start, T stop, S step = 1) noexcept
                                                   ^      ~
./xtensor/xbuilder.hpp:484:32: error: no template named 'promote_type_t' in namespace 'xtl'; did you mean
      'promote_shape_t'?
            using value_type = xtl::promote_type_t<typename std::decay_t...
                               ^~~~~~~~~~~~~~~~~~~
                               promote_shape_t
./xtensor/xshape.hpp:444:5: note: 'promote_shape_t' declared here
    using promote_shape_t = typename promote_shape<S...>::type;
    ^
In file included from input_line_8:2:
In file included from ./xtensor/xarray.hpp:19:
In file included from ./xtensor/xcontainer.hpp:23:
In file included from ./xtensor/xmath.hpp:27:
In file included from ./xtensor/xreducer.hpp:28:
./xtensor/xbuilder.hpp:543:32: error: no template named 'promote_type_t' in namespace 'xtl'; did you mean
      'promote_shape_t'?
            using value_type = xtl::promote_type_t<typename std::decay_t...
                               ^~~~~~~~~~~~~~~~~~~
                               promote_shape_t
./xtensor/xshape.hpp:444:5: note: 'promote_shape_t' declared here
    using promote_shape_t = typename promote_shape<S...>::type;
    ^
In file included from input_line_8:2:
In file included from ./xtensor/xarray.hpp:19:
In file included from ./xtensor/xcontainer.hpp:23:
In file included from ./xtensor/xmath.hpp:27:
./xtensor/xreducer.hpp:39:85: error: expected template parameter
  ...XTL_REQUIRES(is_evaluation_strategy<AX>..., is_evaluation_strategy<X>)>
                                                                           ^
./xtensor/xreducer.hpp:228:96: error: expected template parameter
  ...E::value_type, typename R::value_type>)>
                                            ^
./xtensor/xreducer.hpp:246:111: error: expected template parameter
  ...E::value_type, typename R::value_type>>)>
                                             ^
./xtensor/xreducer.hpp:247:17: error: redefinition of 'copy_to_reduced'
    inline void copy_to_reduced(F& f, const E& e, R& result)
                ^
./xtensor/xreducer.hpp:229:17: note: previous definition is here
    inline void copy_to_reduced(F&, const E& e, R& result)
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]`
SylvainCorlay commented 5 years ago

Do you have xtl installed?

cagBRT commented 5 years ago

Thank you for the prompt reply!

I checked ,,, it is installed

SylvainCorlay commented 5 years ago

How did you install xeus-cling, and xtensor?

cagBRT commented 5 years ago

I followed these directions: https://github.com/QuantStack/xeus-cling

conda create -n cling conda activate cling # Or source activate cling for conda < 4.6 conda install xeus-cling -c conda-forge

And I followed these directions from here: https://github.com/QuantStack/xtensor

conda install -c conda-forge xtensor

I am following this tutorial : https://hub.gke.mybinder.org/user/quantstack-xeus-cling-j9y4f82k/notebooks/notebooks/xcpp.ipynb#

everything worked until I got to xtensor

SylvainCorlay commented 5 years ago

Okay, that seems correct. If you could post the result of conda list it would be great.

Also, note that C++14 is required for xtensor (the C++11 kernel will not work.)

cagBRT commented 5 years ago

Thank you again for the very fast reply! I may have the wrong c++ version - I will make sure I have c++14 .

The result of conda list is shown below.

Name Version Build Channel

ca-certificates 2019.6.16 hecc5488_0 conda-forge clang_variant 1.0 cling_6.14.06 conda-forge clangdev 5.0.0 h412da45_1004 conda-forge cling 0.5 h5c9b4e4_1005 conda-forge cppzmq 4.3.0 h770b8ee_1001 conda-forge icu 58.2 h0a44026_1000 conda-forge libcxx 8.0.0 4 conda-forge libcxxabi 8.0.0 4 conda-forge libiconv 1.15 h01d97ff_1005 conda-forge libsodium 1.0.17 h01d97ff_0 conda-forge libxml2 2.9.9 hd80cff7_1 conda-forge nlohmann_json 3.6.1 h6de7cb9_0 conda-forge openssl 1.1.1c h01d97ff_0 conda-forge xeus 0.20.0 h770b8ee_1 conda-forge xeus-cling 0.6.0 h2dec4b4_1 conda-forge xtensor 0.20.8 h770b8ee_0 conda-forge xtl 0.6.5 h770b8ee_0 conda-forge xz 5.2.4 h1de35cc_1001 conda-forge zeromq 4.3.2 h6de7cb9_1 conda-forge zlib 1.2.11 h1de35cc_1004 conda-forge

SylvainCorlay commented 5 years ago

I may have the wrong c++ version - I will make sure I have c++14 .

It is just the type of kernel that you use...

cagBRT commented 5 years ago

The jupyter notebook says c++14

j2innet commented 5 years ago

i face the same problem

i also added

pragma cling add_include_path("\~/miniconda3/envs/xtensor/include")

pragma cling add_library_path("\~/miniconda3/envs/xtensor/lib")

but no luck.

please advice.

thanks.

===

SOLVED

it works after i changed to

pragma cling add_include_path("/home/user/miniconda3/envs/xtensor/include")

pragma cling add_library_path("/home/user/miniconda3/envs/xtensor/lib")

and restart the notebook.

remember to do this too

conda install xtensor-blas -c conda-forge

thanks.

SylvainCorlay commented 5 years ago

I am confused at how this fixes the issue (which we are not reproducing so far)

hhle88 commented 4 years ago

Okay, that seems correct. If you could post the result of conda list it would be great.

Also, note that C++14 is required for xtensor (the C++11 kernel will not work.)

Many thanks, @SylvainCorlay! It done well with my case. I am not very sure that my problem is same as the question. I was stuck on compiling my C++ program included "xtensor" after installing it correctly by conda. Follow your instruction, I used "g++" to compile the code and select option "-std=gnu++14" instead of "-std=gnu++11". Tada, solved!