Dear Volker,
thanks for your help. I tried your first suggestion and it works!
About the design: My intuition suggests that an array _is_ a (trivial) arra=
y=20
expression. That is probably why I couldn't find the solution by myself. I=
=20
just expected the problem to be somewhere else.
=46rom my point of view, a type casting operator=3D would be logical. IMHO,=
the=20
code you suggested looks a bit clumsy, considering it implements just a=20
simple array cast. However, there might be reasons against it, as you said.
Previously, I have also tried
x =3D blitz::cast( y, float() );
(to no avail, of course) but now I start to realize that this is probably n=
ot=20
the way the blitz::cast function was meant to be used.
Thanks,
Johannes.
On Saturday 05 January 2008 16:39:16 you wrote:
> There are only two operator=3D for blitz::Array, which
>
> a) Copy Array of the same type, or
> b) assign the result of an expression.
>
> So you can use b) via
>
> blitz::Array< float, 2 > x;
> blitz::Array< int, 2 > y;
> x =3D y(blitz::tensor::i, blitz::tensor::j);
>
> or
>
> blitz::Array< float, 2 > x;
> blitz::Array< int, 2 > y;
> blitz::firstIndex i; blitz::secondIndex j;
> x =3D y(i,j);
>
> Arguably the type conversion operator=3D is missing. On the other hand,
> making the type conversion more explicit might save you from
> accidentally losing precision.
>
> Volker
>
> On Fri, 2008-01-04 at 18:41 +0100, Johannes Ball=C3=A9 wrote:
> > Dear Blitz++ gurus,
> >
> > I've been getting strange compilation errors involving implicit type
> > casts with Blitz++ 0.9. It boils down to the following problem:
> >
> > #include <blitz/array.h>
> >
> > int main( int argc, char *argv[] ) {
> > blitz::Array< float, 2 > x;
> > blitz::Array< int, 2 > y;
> > x =3D y;
> > return 0;
> > }
> >
> > This code doesn't compile with g++, although I think it should be able =
to
> > cast each int element to a float element ...
> >
> > Maybe some compiler issue? Or am I just blind? ;)
=2D-=20
Johannes Ball=C3=A9
Institut f=C3=BCr Nachrichtentechnik, RWTH Aachen
phone: +49 241 80-27678
jabber: balle.ient@...
http://www.ient.rwth-aachen.de/
|