简体   繁体   English

为什么 xtensor 中的第一个示例无法运行?

[英]why the first example in xtensor can't run?

I install the xtensor by conda我通过 conda 安装 xtensor

conda install -c conda-forge xtensor

and I find the position where the xtensor is installed,我找到了安装 xtensor 的 position,

path_xtensor="/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/"
path_xtl="/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/"    

the first example is given by the xtensor docs , ie第一个示例由xtensor 文档给出,即

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

int main(int argc, char* argv[])
{
    xt::xarray<double> arr1
        {{1.0, 2.0, 3.0},
         {2.0, 5.0, 7.0},
         {2.0, 5.0, 7.0}};

    xt::xarray<double> arr2
        {5.0, 6.0, 7.0};

    xt::xarray<double> res = xt::view(arr1, 1) + arr2;

    std::cout << res << std::endl;

    return 0;
}

I followed that and run the command in linux servers我跟着那个在 linux 服务器上运行命令

g++ -I path_xtensor -I path_xtl x.cpp -o x

but the command cause error, the log is too long, the following is partly:但是命令报错,日志太长,以下是部分内容:

/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:63: error: ‘int xt::xfunction_iterator<F, CT>::deref_impl’ is not a static data member of ‘class xt::xfunction_iterator<F, CT>’  
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:63: error: template definition of non-template ‘int xt::xfunction_iterator<F, CT>::deref_impl’  
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:58: error: ‘index_sequence’ is not a member of ‘std’  
inline auto xfunction_iterator<F, CT...>::deref_impl(std::index_sequence<I...>) const -> reference
^
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:936:29: warning: variadic templates only available with -std=c++11 or -std=gnu++11  
template <class F, class... CT>  
^  
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:937:30: warning: variadic templates only available with -std=c++11 or -std=gnu++11  
template <std::size_t... I>  
^  

...

/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp: In member function ‘void xt::xfunction_stepper<F, CT>::step_leading()’:  
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:1058:14: error: ‘ame a type  
virtual const char what() const noexcept override { return "bad_variant_access"; }  
^  
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:914:38: note: C++11 ‘noexcept’ only available with -std=c++11 or -std=gnu++11  
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:914:25: error: looser throw specifier for ‘virtual const char mpark::bad_variant_access::what() const’  
virtual const char what() const noexcept override { return "bad_variant_access"; }
^  
In file included from /usr/include/c++/5/ios:39:0,  
from /usr/include/c++/5/ostream:38,  
from /usr/include/c++/5/iostream:39,  
from x.cpp:24:  
/usr/include/c++/5/exception:68:25: error: overriding ‘virtual const char std::exception::what() const throw ()’  
virtual const char* what() const _GLIBCXX_USE_NOEXCEPT;  
^  
In file included from /amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant.hpp:13:0,  
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xstrided_view.hpp:20,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xgenerator.hpp:27,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xbuilder.hpp:31,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xmanipulation.hpp:13,  
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xmath.hpp:28,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xcontainer.hpp:25,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xarray.hpp:20,
from x.cpp:25:  
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:917:3: error: expected unqualified-id before ‘[’ token  
[[noreturn]] inline void throw_bad_variant_access() {  
^  
x.cpp:38:1: error: expected ‘}’ at end of input  
}

Thanks in advance for any help/suggestion.在此先感谢您的帮助/建议。

Is the following command the full command line you execute?以下命令是您执行的完整命令行吗?

g++ -I path_xtensor -I path_xtl x.cpp -o x

Then it is missing two helpful options:然后它缺少两个有用的选项:

  • To ensure the compiler is using a modern c++ standard, add an option like -std=c++11 or -std=c++14 or even newer standards, depending what your compiler supports and what you want to use in the remainder of your project.为确保编译器使用现代 c++ 标准,添加一个选项,如-std=c++11-std=c++14或更新的标准,具体取决于您的编译器支持的内容以及您希望在其余部分中使用的内容你的项目。 xtensor requires at least c++11 . xtensor 至少需要c++11
  • To ensure that the compiler will use good CPU optimizations for the binary, add flags that enable general performance optimizations like -O2 and specific hardware optimizations for your current CPU like -march=native , unless you want your resulting binary to be portable to other computers (with a less modern CPU).为确保编译器将对二进制文件使用良好的 CPU 优化,请添加启用一般性能优化的标志,如-O2和针对当前 CPU 的特定硬件优化,如-march=native ,除非你希望生成的二进制文件可移植到其他计算机(使用较不现代的 CPU)。 This can give an huge performance boost with xtensor.这可以为 xtensor 带来巨大的性能提升。

Does that help?这有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM