Hi Charles,

> Right now, if I want to take the negative of every element in a matrix I
> end up doing the following:
>
> // previously assigned
> viennacl::matrix<T> vcl_A;
>
> // matrix of zeros to subtract from
> viennacl::matrix<T> vcl_Z =
> viennacl::zero_matrix<T>(vcl_A.size1(),vcl_A.size2());
>
> // subtract in-place
> vcl_Z -= vcl_A;
> vcl_A = vcl_Z;
>
> Is there a more efficient way to approach this?  Allocating an
> additional entire matrix is proving quite wasteful in some of my benchmarks.

What about just

vcl_A = T(-1) * vcl_A;

? This is 'inplace' as requested :-)

Best regards,
Karli



------------------------------------------------------------------------------
_______________________________________________
ViennaCL-devel mailing list
ViennaCL-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viennacl-devel

Reply via email to