> Dear all,
>
> Can C++/STL/Boost do the vectorized calculation as those in Matlab?
>
> For example, in the following code, what I really want to do is to
> send in a vector of u's.
>
> All other parameters such as t, l1, l2, l3, etc. are scalars...
>
> But u is a vector.
>
> Thus, t6 becomes a vector.
>
> t9 is an element-wise multiplication...
>
> The following code was actually converted from Matlab.
>
> If vectorized computation is not facilitated, then I have to call this
> function millions of times.
>
> But if vectorized computation is okay, then I can send in just a u
> vector with batch elements a time.
>
> I have many such code in Matlab need to be converted into C++ with
> vectorization.
>
> Any thoughts?
>
> Thank you!
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 double t5, t6, t7, t9, t11, t13, t16,
t20=
, t23, t27, t32, t34, t36,
> t37, t38, t42,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t44, t47, t48, t51, t52,
=
t54, t59, t60, t61, t66, t67, t69, t74,
> t75, t76, t81,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t82, t84, t87, t105,
t106=
, t110, t112;
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t5 =3D exp(-t * l1 - t * l2 - t * l3);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t6 =3D t * u;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t7 =3D mu1 * mu1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t9 =3D u * u;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t11 =3D kappa * kappa;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 t13 =3D 0.1e1 / (t9 * t7 + t11);
Hi.
I think matlab provides a c++ api. Have you checked it out? There's
also the matrix template library for general algebra computations. You
might find it useful.
--
Leandro T. C. Melo


|