Strange behavior of self-build toolkit - conflicts with predefined operators???

Hi,

I'm building a toolkit for BFL.
I want to include support for a ColumnVector and a Matrix. These are both
indexable types, and their indices start from one.

For the ColumnVector I inherited from TemplateIndexTypeInfo.

struct VectorTypeInfo : public
TemplateIndexTypeInfo<ColumnVector,int,double,ArrayIndexChecker >, SizeAssignChecker<ColumnVector >,true

I implemented a [] operator and this one is working just fine:

******************************************************************
In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector
Got :cvector
= [3](1,2,3)

In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector[1]
Got :cvector[1]
= 1

In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector[2]
Got :cvector[2]
= 2

In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector[3]
Got :cvector[3]
= 3
******************************************************************

However when I try to change the value of a element of my vector, the index
seems to start from 0 in stead of one:

******************************************************************
In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector
Got :cvector
= [3](1,2,3)

In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector[1]=4.0
Got :cvector[1]=4.0
= true

In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector
Got :cvector
= [3](1,4,3)
******************************************************************

Even when I don't implement any [] operator, the []= operator seems to exist
(with index starting from 0). I however don't find any code/documentation which
suggests the existence of this operator

Anyone a clue what is going on?

Tinne

Strange behavior of self-build toolkit - conflicts with predefin

On Wednesday 18 March 2009 16:16:26 Tinne De Laet wrote:
> Hi,
>
> I'm building a toolkit for BFL.
> I want to include support for a ColumnVector and a Matrix. These are both
> indexable types, and their indices start from one.
>
> For the ColumnVector I inherited from TemplateIndexTypeInfo.
>
> struct VectorTypeInfo : public
> TemplateIndexTypeInfo<ColumnVector,int,double,ArrayIndexChecker >r
>
> >, SizeAssignChecker<ColumnVector >,true
>
> I implemented a [] operator and this one is working just fine:
>
> ******************************************************************
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector
> Got :cvector
> = [3](1,2,3)
>
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector[1]
> Got :cvector[1]
> = 1
>
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector[2]
> Got :cvector[2]
> = 2
>
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector[3]
> Got :cvector[3]
> = 3
> ******************************************************************
>
> However when I try to change the value of a element of my vector, the index
> seems to start from 0 in stead of one:
>
> ******************************************************************
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector
> Got :cvector
> = [3](1,2,3)
>
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector[1]=4.0
> Got :cvector[1]=4.0
> = true
>
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector
> Got :cvector
> = [3](1,4,3)
> ******************************************************************
>
> Even when I don't implement any [] operator, the []= operator seems to
> exist (with index starting from 0). I however don't find any
> code/documentation which suggests the existence of this operator
>
> Anyone a clue what is going on?

The [] operator exists because you inherit from TemplateIndexTypeInfo, which
uses IndexedValueDataSource to represent your cvector object internally.
updatePartCommand of that class creates the command
(detail::AssignIndexCommand) that does the assignment when executed.

That class has in its execute() function a line:
lhs->set()[ ind ] = rhs->value(); //lhs is cvector, ind is the index and rhs
is the double you want to put into the cvector.

Which uses your C++ datatype's operator[] to set the index and assign the
value. So Orocos doesn't really interprete the index, it's your C++ class...

Peter

Strange behavior of self-build toolkit - conflicts with predefin

On Wednesday 18 March 2009 23:35:46 Peter Soetens wrote:
> On Wednesday 18 March 2009 16:16:26 Tinne De Laet wrote:
> > Hi,
> >
> > I'm building a toolkit for BFL.
> > I want to include support for a ColumnVector and a Matrix. These are both
> > indexable types, and their indices start from one.
> >
> > For the ColumnVector I inherited from TemplateIndexTypeInfo.
> >
> > struct VectorTypeInfo : public
> > TemplateIndexTypeInfo<ColumnVector,int,double,ArrayIndexChecker > >to r
> >
> > >, SizeAssignChecker<ColumnVector >,true
> >
> > I implemented a [] operator and this one is working just fine:
> >
> > ******************************************************************
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector
> > Got :cvector
> > = [3](1,2,3)
> >
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector[1]
> > Got :cvector[1]
> > = 1
> >
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector[2]
> > Got :cvector[2]
> > = 2
> >
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector[3]
> > Got :cvector[3]
> > = 3
> > ******************************************************************
> >
> > However when I try to change the value of a element of my vector, the
> > index seems to start from 0 in stead of one:
> >
> > ******************************************************************
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector
> > Got :cvector
> > = [3](1,2,3)
> >
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector[1]=4.0
> > Got :cvector[1]=4.0
> > = true
> >
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector
> > Got :cvector
> > = [3](1,4,3)
> > ******************************************************************
> >
> > Even when I don't implement any [] operator, the []= operator seems to
> > exist (with index starting from 0). I however don't find any
> > code/documentation which suggests the existence of this operator
> >
> > Anyone a clue what is going on?
>
> The [] operator exists because you inherit from TemplateIndexTypeInfo,
> which uses IndexedValueDataSource to represent your cvector object
> internally. updatePartCommand of that class creates the command
> (detail::AssignIndexCommand) that does the assignment when executed.
The operator [] does not exist. The operator []= however still works,
indicating that this function does NOT use the [] operator I implemented. If I
don't implement the operator I get the following result:

*********************************************************
In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector
Got :cvector
= [3](1,2,3)

In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector[1]
Got :cvector[1]
Fatal Semantic error: Cannot apply binary operation ColumnVector [] int.

In Task tester[U]. (Status of last Command : none )
(type 'ls' for context info) :cvector[1]=4.0
Got :cvector[1]=4.0
= true

***************************************************************8

> That class has in its execute() function a line:
> lhs->set()[ ind ] = rhs->value(); //lhs is cvector, ind is the index and
> rhs is the double you want to put into the cvector.
>
> Which uses your C++ datatype's operator[] to set the index and assign the
> value. So Orocos doesn't really interprete the index, it's your C++
> class...
If this function calls MY datatype operator[], why is it's behavior different
from the one I implemented?
When I call cvector[1] I get the FIRST element
When I call cvector[1]=value it changes the value of the SECOND element.
So I believe the last command does not call the operator[] I implemented!

Tinne

Strange behavior of self-build toolkit - conflicts with predefin

On Thursday 19 March 2009 09:10:32 Tinne De Laet wrote:
> On Wednesday 18 March 2009 23:35:46 Peter Soetens wrote:
> > On Wednesday 18 March 2009 16:16:26 Tinne De Laet wrote:
> > > Hi,
> > >
> > > I'm building a toolkit for BFL.
> > > I want to include support for a ColumnVector and a Matrix. These are
> > > both indexable types, and their indices start from one.
> > >
> > > For the ColumnVector I inherited from TemplateIndexTypeInfo.
> > >
> > > struct VectorTypeInfo : public
> > > TemplateIndexTypeInfo<ColumnVector,int,double,ArrayIndexChecker > > >ec to r
> > >
> > > >, SizeAssignChecker<ColumnVector >,true
> > >
> > > I implemented a [] operator and this one is working just fine:
> > >
> > > ******************************************************************
> > > In Task tester[U]. (Status of last Command : none )
> > > (type 'ls' for context info) :cvector
> > > Got :cvector
> > > = [3](1,2,3)
> > >
> > > In Task tester[U]. (Status of last Command : none )
> > > (type 'ls' for context info) :cvector[1]
> > > Got :cvector[1]
> > > = 1
> > >
> > > In Task tester[U]. (Status of last Command : none )
> > > (type 'ls' for context info) :cvector[2]
> > > Got :cvector[2]
> > > = 2
> > >
> > > In Task tester[U]. (Status of last Command : none )
> > > (type 'ls' for context info) :cvector[3]
> > > Got :cvector[3]
> > > = 3
> > > ******************************************************************
> > >
> > > However when I try to change the value of a element of my vector, the
> > > index seems to start from 0 in stead of one:
> > >
> > > ******************************************************************
> > > In Task tester[U]. (Status of last Command : none )
> > > (type 'ls' for context info) :cvector
> > > Got :cvector
> > > = [3](1,2,3)
> > >
> > > In Task tester[U]. (Status of last Command : none )
> > > (type 'ls' for context info) :cvector[1]=4.0
> > > Got :cvector[1]=4.0
> > > = true
> > >
> > > In Task tester[U]. (Status of last Command : none )
> > > (type 'ls' for context info) :cvector
> > > Got :cvector
> > > = [3](1,4,3)
> > > ******************************************************************
> > >
> > > Even when I don't implement any [] operator, the []= operator seems to
> > > exist (with index starting from 0). I however don't find any
> > > code/documentation which suggests the existence of this operator
> > >
> > > Anyone a clue what is going on?
> >
> > The [] operator exists because you inherit from TemplateIndexTypeInfo,
> > which uses IndexedValueDataSource to represent your cvector object
> > internally. updatePartCommand of that class creates the command
> > (detail::AssignIndexCommand) that does the assignment when executed.
>
> The operator [] does not exist. The operator []= however still works,
> indicating that this function does NOT use the [] operator I implemented.
> If I don't implement the operator I get the following result:
>
> *********************************************************
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector
> Got :cvector
> = [3](1,2,3)
>
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector[1]
> Got :cvector[1]
> Fatal Semantic error: Cannot apply binary operation ColumnVector [] int.
>
> In Task tester[U]. (Status of last Command : none )
> (type 'ls' for context info) :cvector[1]=4.0
> Got :cvector[1]=4.0
> = true
>
> ***************************************************************8
>
> > That class has in its execute() function a line:
> > lhs->set()[ ind ] = rhs->value(); //lhs is cvector, ind is the index and
> > rhs is the double you want to put into the cvector.
> >
> > Which uses your C++ datatype's operator[] to set the index and assign the
> > value. So Orocos doesn't really interprete the index, it's your C++
> > class...
>
> If this function calls MY datatype operator[], why is it's behavior
> different from the one I implemented?
> When I call cvector[1] I get the FIRST element
> When I call cvector[1]=value it changes the value of the SECOND element.
> So I believe the last command does not call the operator[] I implemented!

Exactly, I just said " lhs->set()[ ind ] = rhs->value();" is what gets called
during assignment (second case), if your type inherits from
TemplateIndexTypeInfo. This fully depends on your C++ operator[] defined
in/by/for the ColumnVector class (in BFL!). The cvector[1] situation uses
*another* mechanism, which you probably added to the OperatorRegistry using
newBinaryOperator() (and are able to turn on and off). They are independent. So
maybe you didn't realise they are two different functions: one for reading and
one for writing.

Peter

Ruben Smits's picture

Strange behavior of self-build toolkit - conflicts with predefin

On Thursday 19 March 2009 10:24:57 Peter Soetens wrote:
> On Thursday 19 March 2009 09:10:32 Tinne De Laet wrote:
> > On Wednesday 18 March 2009 23:35:46 Peter Soetens wrote:
> > > On Wednesday 18 March 2009 16:16:26 Tinne De Laet wrote:
> > > > Hi,
> > > >
> > > > I'm building a toolkit for BFL.
> > > > I want to include support for a ColumnVector and a Matrix. These are
> > > > both indexable types, and their indices start from one.
> > > >
> > > > For the ColumnVector I inherited from TemplateIndexTypeInfo.
> > > >
> > > > struct VectorTypeInfo : public
> > > > TemplateIndexTypeInfo<ColumnVector,int,double,ArrayIndexChecker > > > >nV ec to r
> > > >
> > > > >, SizeAssignChecker<ColumnVector >,true
> > > >
> > > > I implemented a [] operator and this one is working just fine:
> > > >
> > > > ******************************************************************
> > > > In Task tester[U]. (Status of last Command : none )
> > > > (type 'ls' for context info) :cvector
> > > > Got :cvector
> > > > = [3](1,2,3)
> > > >
> > > > In Task tester[U]. (Status of last Command : none )
> > > > (type 'ls' for context info) :cvector[1]
> > > > Got :cvector[1]
> > > > = 1
> > > >
> > > > In Task tester[U]. (Status of last Command : none )
> > > > (type 'ls' for context info) :cvector[2]
> > > > Got :cvector[2]
> > > > = 2
> > > >
> > > > In Task tester[U]. (Status of last Command : none )
> > > > (type 'ls' for context info) :cvector[3]
> > > > Got :cvector[3]
> > > > = 3
> > > > ******************************************************************
> > > >
> > > > However when I try to change the value of a element of my vector, the
> > > > index seems to start from 0 in stead of one:
> > > >
> > > > ******************************************************************
> > > > In Task tester[U]. (Status of last Command : none )
> > > > (type 'ls' for context info) :cvector
> > > > Got :cvector
> > > > = [3](1,2,3)
> > > >
> > > > In Task tester[U]. (Status of last Command : none )
> > > > (type 'ls' for context info) :cvector[1]=4.0
> > > > Got :cvector[1]=4.0
> > > > = true
> > > >
> > > > In Task tester[U]. (Status of last Command : none )
> > > > (type 'ls' for context info) :cvector
> > > > Got :cvector
> > > > = [3](1,4,3)
> > > > ******************************************************************
> > > >
> > > > Even when I don't implement any [] operator, the []= operator seems
> > > > to exist (with index starting from 0). I however don't find any
> > > > code/documentation which suggests the existence of this operator
> > > >
> > > > Anyone a clue what is going on?
> > >
> > > The [] operator exists because you inherit from TemplateIndexTypeInfo,
> > > which uses IndexedValueDataSource to represent your cvector object
> > > internally. updatePartCommand of that class creates the command
> > > (detail::AssignIndexCommand) that does the assignment when executed.
> >
> > The operator [] does not exist. The operator []= however still works,
> > indicating that this function does NOT use the [] operator I implemented.
> > If I don't implement the operator I get the following result:
> >
> > *********************************************************
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector
> > Got :cvector
> > = [3](1,2,3)
> >
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector[1]
> > Got :cvector[1]
> > Fatal Semantic error: Cannot apply binary operation ColumnVector [] int.
> >
> > In Task tester[U]. (Status of last Command : none )
> > (type 'ls' for context info) :cvector[1]=4.0
> > Got :cvector[1]=4.0
> > = true
> >
> > ***************************************************************8
> >
> > > That class has in its execute() function a line:
> > > lhs->set()[ ind ] = rhs->value(); //lhs is cvector, ind is the index
> > > and rhs is the double you want to put into the cvector.
> > >
> > > Which uses your C++ datatype's operator[] to set the index and assign
> > > the value. So Orocos doesn't really interprete the index, it's your C++
> > > class...
> >
> > If this function calls MY datatype operator[], why is it's behavior
> > different from the one I implemented?
> > When I call cvector[1] I get the FIRST element
> > When I call cvector[1]=value it changes the value of the SECOND element.
> > So I believe the last command does not call the operator[] I implemented!
>
> Exactly, I just said " lhs->set()[ ind ] = rhs->value();" is what gets
> called during assignment (second case), if your type inherits from
> TemplateIndexTypeInfo. This fully depends on your C++ operator[] defined
> in/by/for the ColumnVector class (in BFL!). The cvector[1] situation uses
> *another* mechanism, which you probably added to the OperatorRegistry using
> newBinaryOperator() (and are able to turn on and off). They are
> independent. So maybe you didn't realise they are two different functions:
> one for reading and one for writing.

How come the one for writing is automatically defined by inheriting from
TemplateIndexTypeInfo and the one for reading is not. Sounds like a bug to me
:p

Ruben