This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Min/Maxcoeff functions for Sparse Matrices

Tags: None
(comma "," separated)
svalorzen
Registered Member
Posts
3
Karma
0
I was wondering whether it is possible to find the max/min coefficients in a sparse matrix in an efficient way.

It seems that the minCoeff()/maxCoeff() functions are not implemented for sparse matrices, which is a bit weird.
svalorzen
Registered Member
Posts
3
Karma
0
As I also need code which work for both dense and sparse matrices (to avoid duplicate code which I'd have to maintain), for now I've done the following:
Code: Select all
            using Tmp = typename remove_cv_ref<decltype(matrix)>::type;
            if constexpr(std::is_base_of<Eigen::SparseMatrixBase<Tmp>, Tmp>::value)
                max = Eigen::Map<const Vector>(matrix.valuePtr(), matrix.size()).maxCoeff();
            else
                max = matrix.maxCoeff();

Would be nicer if this wasn't required though..


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]