UserFunction yet...
Renato Fernandes Cantão
cantao at ime.unicamp.br
Tue Sep 3 19:45:23 UTC 2002
Hello Guys!
Ok, I think I've got the point with UserFunction. So, I tried to write
my stuff in a way that I could return just references to something being
calculated, so the expression template machinery could take care of it,
as pointed out by Richard and Stephen.
The underlying structure I'm working with is
Array< 1, Array< 2, Vector< 2 > > >
It's a long list of 2D points stored in a 2D Array (it really makes
sense to me :). I'm trying something:
struct SmallOperation
{
// makes some operation on Vector<2>
inline
const Vector< 2 >& operator()( const Vector< 2 >& in ) const
{
return in / norm( in );
}
};
struct BigOperation
{
// here I want to be able to address each Vector<2> using
// the above SmallOperation
inline Array< 2, Vector< 2 > > // no reference here yet...
operator()( const Array< 2, Vector< 2 > >& in ) const
{
return UserFunction< SmallOperation >()( in );
}
};
In the MAIN program...
UserFunction< BigOperation > F;
Array< 1, Array< 2, Vector< 2 > > > V( 10 );
for( int ii = 0; ii < 10; ii++ )
{
V( ii ).initialize( 3, 3 );
V( ii ) = Vector< 2 >( 1.0, 2.0 ); // stupid initial value
}
cout << V << endl;
cout << F( V ) << endl;
What I expected to happen is: F will be applied to each V element
(Array<2,...>), calling BigOperation::operator( ... ), that calls
SmallOperation::operator( ... ).
But, it simply does not compile, complaining it's impossible to convert
Array<2, Vector<2>, UserFunctionEngine<...> >
to
Array<2, Vector<2>, Brick>
Strangely, if I change BigOperation::operator( ... ) to
inline Array< 2, Vector< 2 > >
operator()( const Array< 2, Vector< 2 > >& in ) const
{
Array< 2, Vector< 2 > > out( in.domain() );
out = F( in );
return out;
}
everything works fine, BUT, I still have to make a copy...
The question is:
1. Some constructor is missing?
2. There is some obscure traits class that fix it all?
3. It's really impossible inside Pooma's expression engine?
Thanks a lot, Cantao!
--
'''
(o o)
+--------------oOOO--(_)----------------------+
| Renato F. Cantao! |
| Depto. de Matematica Aplicada |
| IMECC - UNICAMP |
| Sala 215 - Predio da Pos-graduacao - Lado B |
+--------------------------OOOo---------------+
|__|__|
|| ||
ooO Ooo Linux User #207462
More information about the pooma-dev
mailing list