Re: [eigen] Tensor Module: Index mapping support (PATCH)

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


I used SFINAE for the new template function to be choosen correctly.
( needed some is_base_of meta, which I dont know if this is good)

but as far as I understood is the standart indices type -> array<Index,NumIndices>
(I checked the compiler fully optimizes out the additional conversion: http://pastebin.com/n1pnbAUf

You are correct. array<Index, NumIndices> (or it's child DSizes) is the type we use for indexing the dynamically sized tensors. For statically sized ones, we use the Sizes<Indices...> type. 
 
I only added this to the Tensor class, not the TensorBase,
I thought before adapting also the other stuff, it would be good if you would look over it and check if that "try" is of any use :-)
I am not new to Eigen, but not aware of all the little nitty gritty details :-)

Please have a look at the patch and the added test : cxx11_tensor_customIndex.cpp

Is that appropriate? Should the conversion (with SFINAE) also be applied to all other stuff in TensorBase
like reduce , stride .... etc...
some functions are already tempalted on a generic IndexType or Dimension ... ?
 
The TensorMap and TensorFixedSize classes would benefit from your support for custom indices. For most of the operations (striding, ...) that can be performed on tensors the parameters are fully templated. This makes it possible to use either Sizes<> when their values are fully known at compile time or DSizes<> when they are not, or even a TensorIndexList when they are only partially known at compile time. This helps the compiler generate more efficient code. In theory, this means that you can use any custom type that supports the following: array_size<type>, array_get<Index, type>, and the [] operator.
 
Have a look at the comment on line 433 in Tensor.h , is this overload needed?

I don't understand why but this overload was needed to make a compiler happy (I forgot which one though). I should have put a comment to document this better.
 

Thanks!

BR Gabriel








On 10/08/2015 07:49 PM, Benoit Steiner wrote:
It is currently not possible to use custom index types to extract coefficients from a tensor. If you want to add the functionality I'll be happy to review a patch/pull request.

On Thu, Oct 8, 2015 at 6:52 AM, Gabriel <gnuetzi@xxxxxxxxx> wrote:
If the user of the tensor component in eigen
uses its own indices lets say

Eigen::Array<int,3> idx(1,2,3);

this is currently not possible:

Eigen::Tensor<double,3> t(4,4,4)
t( idx ) =  5;


We could implement this maybe with the following wrappers
(here for the resize function and CXX11 support of course as example):

                template<typename IndexType>
            void resize( const IndexType & dimensions ){

                resize(dimensions, std::make_index_sequence<NTensorIndices>{} );

            }

            template<typename IndexType, std::size_t... Is>
            void resize(const IndexType & dimensions, std::index_sequence<Is...> )
            {
                m_tensor.resize( dimensions(Is)... );
            }



Or is this already provided in the tensor module such that one can use own index types ?


Thanks a lot :-)

BR Gabriel








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