Boost logo

Ublas :

Subject: Re: [ublas] [bindings] [lapack] geev and the type of the input matrix
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-07-14 02:56:38


Marco Guazzone wrote:

> Hi,
>
> I've found in geev.hpp that some definition of geev takes a "const&"
> for the input matrix.
> For instance (the input matrix is "a"):
>
> --- [code] ---
> template< typename MatrixA, typename VectorW, typename MatrixVL,
> typename MatrixVR, typename Workspace >
> inline typename boost::enable_if< detail::is_workspace< Workspace >,
> std::ptrdiff_t >::type
> geev( const char jobvl, const char jobvr, const MatrixA& a, VectorW& w,
> const MatrixVL& vl, const MatrixVR& vr, Workspace work ) {
> return geev_impl< typename bindings::value_type<
> MatrixA >::type >::invoke( jobvl, jobvr, a, w, vl, vr, work );
> }
> --- [/code] ---
>
> However, inside of these functions "a" is passed as-is, whithout
> making a temporary copy.
> Moreover, none of the "invoke" methods seems to accept a "const&" for
> the input matrix.
>
> Is it correct?

Yes, this is correct due to forwarding temporary views/adaptors on your
input matrix.

Consider

geev( a, ... )

here, you will need MatrixA& to be able to modify the matrix. But if you
pass

geev( some_operation( a ), ... )

then the result of some_operation will be a temporary. The current solution
accepts a RValue for this. The matrix itself will be stored as a mutable
reference inside the structure returned by some_operation.

Having said this, this overloaf will probably be removed due to a different
solution to the same problem -- see the Perfect Forwarding stuff Thomas has
been writing about.

Cheers,

Rutger