Joseph Summerhays
Joseph Summerhays

Reputation: 121

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. When changing xt::xexpression<float> (the correct return type) to auto it compiles and runs. If xt::expression is protected, why can auto access it? and is there a way I can specify the type rather than use auto, without evaluating the xexpression? (i.e. I can't have the type of a be xt::xarray, because this forces evaluation).

Upvotes: 0

Views: 102

Answers (1)

Joseph Summerhays
Joseph Summerhays

Reputation: 121

Auto is not resolving to xexpression, but a child of xexpression, as Kevin pointed out in the comments. Changing the type to xt::xbroadcast<xt::xscalar<float>, std::array<long unsigned int, 3> > will compile without evaluating.

Upvotes: 2

Related Questions