[eigen] Iterators with dense matrices: (was: Areas of eigen3 variation and using eigen2/3 in generic code) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
On Monday 04 January 2010 06:02:43 Benoit Jacob wrote:
> 2010/1/3 Jesse Perla <jesseperla@xxxxxxxxx>:
> > Or any way to return a
> > random access iterator for begin() and end() that I could use with
> > std::transform, etc? The "start" and "end" seem different than normal
> > iterators
>
> Indeed, we do not have any iterators in Eigen for dense matrices and
> vectors. Do you have a use case for that? So far, index-based access
> has been all we have needed, as we were 100% focused on linear
> algebra.
Hi all,
Sorry to break into the discussion at this point, but I am also thinking of
migrating from uBLAS to Eigen. My GluCat code ( http://glucat.sf.net )
compiles with an optional macro definition, GLUCAT_USE_DENSE_MATRICES
which is used as follows.
typedef ublas::column_major orientation_t;
typedef ublas::compressed_matrix< Scalar_T, orientation_t > basis_matrix_t;
#ifdef _GLUCAT_USE_DENSE_MATRICES
typedef ublas::matrix< Scalar_T, orientation_t > matrix_t;
#else
typedef basis_matrix_t matrix_t;
#endif
Code which uses matrices does not know if the matrix is dense or sparse, and
so uses uBLAS begin1(), end1(), begin(), end(), as follows:
/// Square of Frobenius norm
template< typename Matrix_T >
typename Matrix_T::value_type
norm_frob2(const Matrix_T& val)
{
typedef typename Matrix_T::value_type Scalar_T;
typedef typename Matrix_T::size_type matrix_index_t;
Scalar_T result = Scalar_T(0);
for (typename Matrix_T::const_iterator1
val_it1 = val.begin1();
val_it1 != val.end1();
++val_it1)
for (typename Matrix_T::const_iterator2
val_it2 = val_it1.begin();
val_it2 != val_it1.end();
++val_it2)
{
if (numeric_traits<Scalar_T>::isNaN(*val_it2))
return numeric_traits<Scalar_T>::NaN();
result += (*val_it2) * (*val_it2);
}
return result;
}
What is the equivalent code using Eigen? Do I need to code dense and sparse
versions of every matrix routine so that the code can take advantage of
iterators when using sparse matrices?
Best, Paul