Writing Eigen::Vector typekit plugins

Hello,

I would like to write a typekit for some of the Eigen types (Vector only for
now). Following the documentation, I was able so far to add the types with
some ctors. I was inspired by this example:

http://svn.mech.kuleuven.be/repos/orocos/trunk/kul-ros-pkg/iTaSC/src/eig...

I would like to have some hints how to implement missing functionalities.
What are currently missing in my typekit are the following operations:

// **********************************************
// 1. Accessors
// **********************************************

Example: my_first_eigen_vector[1] = my_second_eigen_vector[3];

For the accessors, altough I don't see how we can distinguish between a
"dot" member and an index, I guess the good way is the SequenceTypeInfo way.
However, I saw this in the code:


                if ( id_indx ) {
                    try {
                        if ( item->isAssignable() )
                                return
internal::newFunctorDataSource(&get_container_item<T>,
internal::GenerateDataSource()(item.get(), id_indx.get() ) );
                            else
                                return
internal::newFunctorDataSource(&get_container_item_copy<T>,
internal::GenerateDataSource()(item.get(), id_indx.get() ) );
                    } catch(...) {}
                }


Is it real-time safe since it uses the newFunctorDataSource method? Does
that mean that reading a accessing an array member isn't real-time?

// **********************************************
// 2. Binary operators
// **********************************************

result = my_first_eigen_vector + my_second_eigen_vector;

This seems to be done with the "newBinaryOperator". Since most operators are
already implemented in Eigen, can I just do something like this:

oreg->add( newBinaryOperator( "*", std::multiplies<Eigen::VectorXd>() ) );

?

// **********************************************
// 3. Misc. members
// **********************************************
my_size = eigen_vector.size();

Since the newDotOperator method has disapeared, I guess the good way to do
is the SequenceTypeInfo way, i.e. overloading "getMember" ?

Thank you,

Philippe

Writing Eigen::Vector typekit plugins

On Thu, May 19, 2011 at 5:01 PM, Philippe Hamelin
<philippe [dot] hamelin [..] ...> wrote:
> Hello,
> I would like to write a typekit for some of the Eigen types (Vector only for
> now). Following the documentation, I was able so far to add the types with
> some ctors. I was inspired by this example:
> http://svn.mech.kuleuven.be/repos/orocos/trunk/kul-ros-pkg/iTaSC/src/eig...

This is RTT 1.x code.

> I would like to have some hints how to implement missing functionalities.
> What are currently missing in my typekit are the following operations:
> // **********************************************
> // 1. Accessors
> // **********************************************
> Example: my_first_eigen_vector[1] = my_second_eigen_vector[3];
> For the accessors, altough I don't see how we can distinguish between a
> "dot" member and an index, I guess the good way is the SequenceTypeInfo way.
> However, I saw this in the code:
> &#10;&gt;                 if ( id_indx ) {&#10;&gt;                     try {&#10;&gt;                         if ( item-&gt;isAssignable() )&#10;&gt;                                 return&#10;&gt; internal::newFunctorDataSource(&amp;get_container_item&lt;T&gt;,&#10;&gt; internal::GenerateDataSource()(item.get(), id_indx.get() ) );&#10;&gt;                             else&#10;&gt;                                 return&#10;&gt; internal::newFunctorDataSource(&amp;get_container_item_copy&lt;T&gt;,&#10;&gt; internal::GenerateDataSource()(item.get(), id_indx.get() ) );&#10;&gt;                     } catch(...) {}&#10;&gt;                 }&#10;&gt;
> Is it real-time safe since it uses the newFunctorDataSource method? Does
> that mean that reading a accessing an array member isn't real-time?

Not at all. The scripts are first parsed completely and then executed.
It's during this parsing step that this function is executed. So it's
a factory function returning real-time data sources.

> // **********************************************
> // 2. Binary operators
> // **********************************************
> result = my_first_eigen_vector + my_second_eigen_vector;
> This seems to be done with the "newBinaryOperator". Since most operators are
> already implemented in Eigen, can I just do something like this:
> oreg->add( newBinaryOperator( "*", std::multiplies<Eigen::VectorXd>() ) );

I didn't check the syntax, but yes that's the way.

> ?
> // **********************************************
> // 3. Misc. members
> // **********************************************
> my_size = eigen_vector.size();
> Since the newDotOperator method has disapeared, I guess the good way to do
> is the SequenceTypeInfo way, i.e. overloading "getMember" ?

You can't have functions anymore on structs, only 'members'.

Also look at the BFL typekit for inspiration, which has gone through
much of the trouble
for getting similar functionality as you desire for Eigen. Especially
indexing in matrices
is a bit hard. You have to return a reference to an internal row, and
then index that again.
The row type needs to be known to the type system as a sequence. We
don't have an operator[a, b].

You should work if possible with 'ReferenceDataSource' such that no
copies are made
and the original data is manipulated.

Peter
--
Orocos-Users mailing list
Orocos-Users [..] ...
http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users