![]() |
Blitz Support : |
From: Markus Christen (markus_at_[hidden])
Date: 2003-05-30 06:26:16
Hi all
i just can not get my 3D vector calculations to compile!
(i'm sure it's my fault but that does not help me ;-)
assume the typedefs:
typedef blitz::TinyVector<double, 3> Vec;
typedef blitz::Array<Vec, 1> VArray;
typedef blitz::Array<double, 1> SArray;
i would now like to write
VArray v1(10), v2(10);
SArray s(10);
s = dot(v1, v2);
[ or actually:
range r(0,5);
double q = sum( s(r) * dot(v1(r)+v2(r), v1(r)+v2(r)) )
is there a way to get around calculating the sum twice - i guess this
is asked too much ('cause it is not replaceable without temporary...)
]
and it complains:
myfile.cc:35: no matching function for call
to `dot(blitz::Array<math::Vec, 1>&,
blitz::Array<math::Vec,1>&)'
but
Vec v3(1, 1, 1), v4(2, 2, 2);
double d = dot(v3, v4);
works!
i can get the code to compile by providing this function:
inline SArray dot(VArray const &v1, VArray const &v2)
{
assert(v1.size() == v2.size());
SArray s(v1.size());
for(int i=0; i<v1.size(); ++i)
s(i) = dot(v1(i), v2(i));
return s;
}
but then i am creating a temporary.
is there a better way to do this?
and if i use a range in the call to my function dot,
it does not compile anymore!
thank you in advance
____________________________________
Markus Christen
Physikalische Chemie
federal institute of technology
Switzerland