Re: [eigen] generic argument declaration taking a matrix, vector or expression |

[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]

On 11.01.2012 07:19, Bernhard Zeisl wrote:

If we understand the tutorial correctly, foo should look like
template <typename TypeT>
void foo (const Eigen::MatrixBase<TypeT> &mat);
where a const cast needs to be used to write data back to mat.

`Yes, the const_cast is indeed not very nice. The problem is that you
``can't pass a temporary object (such as A.col(i)) as a non-const
``reference (unless you use C++11's RValue references).
``Of course this bears the problem that you can also pass a const
``Matrix<...> to foo and modify it -- which actually should be prohibited.
`

`Another problem in my opinion is that you can't easily achieve type
``safety of foo, i.e. if you only want to allow Matrices of a certain size
``or scalar type (but you can achieve this by static assertions).
`

I attached a an example, which should make more clear what we are trying
to achieve.

You need to give every matrix a different template parameter, e.g.:
template <typename Type_A, typename Type_b, typename Type_x> void

`solveLeastSquares (const Eigen::MatrixBase<Type_A> &A, const
``Eigen::MatrixBase<Type_b> &b, Eigen::MatrixBase<Type_x> const &x_,
``LEAST_SQUARES_METHOD method = SVD)
`

`Maybe the documentation could point that out more explicitly. Especially
``in the quoted tutorial parameters x and y should get different template
``arguments (in the last two examples)
`
HTH
Christoph
--
----------------------------------------------
Dipl.-Inf. Christoph Hertzberg
Cartesium 0.051
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: (+49) 421-218-64252
----------------------------------------------