bug #1381: fix sparse.diagonal() used as a rvalue.

The problem was that is "sparse" is not const, then sparse.diagonal() must have the
LValueBit flag meaning that sparse.diagonal().coeff(i) must returns a const reference,
const Scalar&. However, sparse::coeff() cannot returns a reference for a non-existing
zero coefficient. The trick is to return a reference to a local member of
evaluator<SparseMatrix>.
(grafted from 296d24be4d
)
This commit is contained in:
Gael Guennebaud
2017-01-25 17:39:01 +01:00
parent b4d2b404b0
commit b8cf157e8c
4 changed files with 33 additions and 15 deletions

View File

@@ -1556,9 +1556,7 @@ struct evaluator<Diagonal<ArgType, DiagIndex> >
{ }
typedef typename XprType::Scalar Scalar;
// FIXME having to check whether ArgType is sparse here i not very nice.
typedef typename internal::conditional<!internal::is_same<typename ArgType::StorageKind,Sparse>::value,
typename XprType::CoeffReturnType,Scalar>::type CoeffReturnType;
typedef typename XprType::CoeffReturnType CoeffReturnType;
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
CoeffReturnType coeff(Index row, Index) const

View File

@@ -638,7 +638,7 @@ struct plain_constant_type
template<typename ExpressionType>
struct is_lvalue
{
enum { value = !bool(is_const<ExpressionType>::value) &&
enum { value = (!bool(is_const<ExpressionType>::value)) &&
bool(traits<ExpressionType>::Flags & LvalueBit) };
};