[英]xt::xexpression is protected within this context
Consider the following code:考虑以下代码:
#include <chrono>
#include <iostream>
#include "xtensor/xadapt.hpp"
#include "xtensor/xarray.hpp"
#include "xtensor/xindex_view.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xview.hpp"
using namespace std;
using namespace std::chrono;
int main() {
high_resolution_clock::time_point t1 = high_resolution_clock::now();
for (int i = 0; i < 1000; i++) {
xt::expression<float> a = xt::zeros<float>({3, 256, 256});
}
high_resolution_clock::time_point t2 = high_resolution_clock::now();
duration<double> time = duration_cast<duration<double>>(t2 - t1);
cout << time.count() << endl;
}
This fails to compile, with the following error: test.cpp:24:66: error: 'xt::xexpression<D>::~xexpression() [with D = float]' is protected within this context
.这无法编译,并出现以下错误:
test.cpp:24:66: error: 'xt::xexpression<D>::~xexpression() [with D = float]' is protected within this context
。 When changing xt::xexpression<float>
(the correct return type) to auto
it compiles and runs.当将
xt::xexpression<float>
(正确的返回类型)更改为auto
它会编译并运行。 If xt::expression
is protected, why can auto
access it?如果
xt::expression
受保护,为什么可以auto
访问它? and is there a way I can specify the type rather than use auto
, without evaluating the xexpression?有没有一种方法可以指定类型而不是使用
auto
而不评估 xexpression? (ie I can't have the type of a
be xt::xarray
, because this forces evaluation). (即我不能有类型
a
是xt::xarray
,因为这种力量的评价)。
Auto
is not resolving to xexpression
, but a child of xexpression
, as Kevin pointed out in the comments.正如凯文在评论中指出的那样,
Auto
不是解析为xexpression
,而是解析为xexpression
的xexpression
。 Changing the type to xt::xbroadcast<xt::xscalar<float>, std::array<long unsigned int, 3> >
will compile without evaluating.将类型更改为
xt::xbroadcast<xt::xscalar<float>, std::array<long unsigned int, 3> >
将编译而不求值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.