Re: [eigen] Tensor Module: TensorBase, derived() not accessible?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


An instance of TensorBase can either represent an actual tensor or a tensor _expression_. In the first case, you can access the coefficient, but in the second case you can't since expressions must first be evaluated. That makes using TensorBase a little tricky and dangerous, which is why it's private.

To write generic code you can instead wrap your tensor or tensor _expression_ inside a TensorRef. A TensorRef will evaluate the _expression_ it encapsulates if needed to allow you to safely read or update the underlying coefficients. For example, you could write:
Tensor<float, 1> T1(10);
Tensor<float, 1> T2(10);
TensorRef<Tensor<float, 1> > ref1(T1);
TensorRef<Tensor<float, 1> > ref2(T1.slice(foo, bar));
TensorRef<Tensor<float, 1> > ref3(T1 + T2);

ref1 and ref2 will both allow you to update the coefficient of T1, ref3 will be read only.

There are a few more examples in the tests unsupported/test/cxx11_tensor_ref.cpp



On Thu, Oct 8, 2015 at 9:25 AM, Gabriel <gnuetzi@xxxxxxxxx> wrote:
I am trying to write a general function for a tensor

as used for eigen i did this like so:


template< typename Derived >
void modifiyData(const TensorBase<Derived, WriteAccessors> & m){

    std::cout << m.derived().dimensions();

}


Unfortunately, this does not compile since derived() is  protected in

TensorBase<Derived, WriteAccessors>

Could somebody enlighten me, how to write a general template function accepting a tensor?
Or is this not yet supported?



Thanks  a lot for your help!



BR Gabriel






Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/