mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-10-15 09:31:29 +08:00
bug #1172: make valuePtr and innderIndexPtr properly return null for empty matrices.
This commit is contained in:
parent
b71ee76d8d
commit
bd6e042f49
@ -102,6 +102,11 @@ class CompressedStorage
|
|||||||
inline size_t allocatedSize() const { return m_allocatedSize; }
|
inline size_t allocatedSize() const { return m_allocatedSize; }
|
||||||
inline void clear() { m_size = 0; }
|
inline void clear() { m_size = 0; }
|
||||||
|
|
||||||
|
const Scalar* valuePtr() const { return m_values; }
|
||||||
|
Scalar* valuePtr() { return m_values; }
|
||||||
|
const Index* indexPtr() const { return m_indices; }
|
||||||
|
Index* indexPtr() { return m_indices; }
|
||||||
|
|
||||||
inline Scalar& value(size_t i) { return m_values[i]; }
|
inline Scalar& value(size_t i) { return m_values[i]; }
|
||||||
inline const Scalar& value(size_t i) const { return m_values[i]; }
|
inline const Scalar& value(size_t i) const { return m_values[i]; }
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -128,20 +128,20 @@ class SparseMatrix
|
|||||||
/** \returns a const pointer to the array of values.
|
/** \returns a const pointer to the array of values.
|
||||||
* This function is aimed at interoperability with other libraries.
|
* This function is aimed at interoperability with other libraries.
|
||||||
* \sa innerIndexPtr(), outerIndexPtr() */
|
* \sa innerIndexPtr(), outerIndexPtr() */
|
||||||
inline const Scalar* valuePtr() const { return &m_data.value(0); }
|
inline const Scalar* valuePtr() const { return m_data.valuePtr(); }
|
||||||
/** \returns a non-const pointer to the array of values.
|
/** \returns a non-const pointer to the array of values.
|
||||||
* This function is aimed at interoperability with other libraries.
|
* This function is aimed at interoperability with other libraries.
|
||||||
* \sa innerIndexPtr(), outerIndexPtr() */
|
* \sa innerIndexPtr(), outerIndexPtr() */
|
||||||
inline Scalar* valuePtr() { return &m_data.value(0); }
|
inline Scalar* valuePtr() { return m_data.valuePtr(); }
|
||||||
|
|
||||||
/** \returns a const pointer to the array of inner indices.
|
/** \returns a const pointer to the array of inner indices.
|
||||||
* This function is aimed at interoperability with other libraries.
|
* This function is aimed at interoperability with other libraries.
|
||||||
* \sa valuePtr(), outerIndexPtr() */
|
* \sa valuePtr(), outerIndexPtr() */
|
||||||
inline const Index* innerIndexPtr() const { return &m_data.index(0); }
|
inline const Index* innerIndexPtr() const { return m_data.indexPtr(); }
|
||||||
/** \returns a non-const pointer to the array of inner indices.
|
/** \returns a non-const pointer to the array of inner indices.
|
||||||
* This function is aimed at interoperability with other libraries.
|
* This function is aimed at interoperability with other libraries.
|
||||||
* \sa valuePtr(), outerIndexPtr() */
|
* \sa valuePtr(), outerIndexPtr() */
|
||||||
inline Index* innerIndexPtr() { return &m_data.index(0); }
|
inline Index* innerIndexPtr() { return m_data.indexPtr(); }
|
||||||
|
|
||||||
/** \returns a const pointer to the array of the starting positions of the inner vectors.
|
/** \returns a const pointer to the array of the starting positions of the inner vectors.
|
||||||
* This function is aimed at interoperability with other libraries.
|
* This function is aimed at interoperability with other libraries.
|
||||||
@ -697,8 +697,8 @@ class SparseMatrix
|
|||||||
{
|
{
|
||||||
eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES");
|
eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES");
|
||||||
this->m_data.resize(rows());
|
this->m_data.resize(rows());
|
||||||
Eigen::Map<Matrix<Index, Dynamic, 1> >(&this->m_data.index(0), rows()).setLinSpaced(0, rows()-1);
|
Eigen::Map<Matrix<Index, Dynamic, 1> >(this->m_data.indexPtr(), rows()).setLinSpaced(0, rows()-1);
|
||||||
Eigen::Map<Matrix<Scalar, Dynamic, 1> >(&this->m_data.value(0), rows()).setOnes();
|
Eigen::Map<Matrix<Scalar, Dynamic, 1> >(this->m_data.valuePtr(), rows()).setOnes();
|
||||||
Eigen::Map<Matrix<Index, Dynamic, 1> >(this->m_outerIndex, rows()+1).setLinSpaced(0, rows());
|
Eigen::Map<Matrix<Index, Dynamic, 1> >(this->m_outerIndex, rows()+1).setLinSpaced(0, rows());
|
||||||
std::free(m_innerNonZeros);
|
std::free(m_innerNonZeros);
|
||||||
m_innerNonZeros = 0;
|
m_innerNonZeros = 0;
|
||||||
|
@ -29,7 +29,7 @@ typename internal::traits<SparseMatrix<_Scalar,_Options,_Index> >::Scalar
|
|||||||
SparseMatrix<_Scalar,_Options,_Index>::sum() const
|
SparseMatrix<_Scalar,_Options,_Index>::sum() const
|
||||||
{
|
{
|
||||||
eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
|
eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
|
||||||
return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
|
return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Scalar, int _Options, typename _Index>
|
template<typename _Scalar, int _Options, typename _Index>
|
||||||
@ -37,7 +37,7 @@ typename internal::traits<SparseVector<_Scalar,_Options, _Index> >::Scalar
|
|||||||
SparseVector<_Scalar,_Options,_Index>::sum() const
|
SparseVector<_Scalar,_Options,_Index>::sum() const
|
||||||
{
|
{
|
||||||
eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
|
eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
|
||||||
return Matrix<Scalar,1,Dynamic>::Map(&m_data.value(0), m_data.size()).sum();
|
return Matrix<Scalar,1,Dynamic>::Map(m_data.valuePtr(), m_data.size()).sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
@ -84,12 +84,12 @@ class SparseVector
|
|||||||
EIGEN_STRONG_INLINE Index innerSize() const { return m_size; }
|
EIGEN_STRONG_INLINE Index innerSize() const { return m_size; }
|
||||||
EIGEN_STRONG_INLINE Index outerSize() const { return 1; }
|
EIGEN_STRONG_INLINE Index outerSize() const { return 1; }
|
||||||
|
|
||||||
EIGEN_STRONG_INLINE const Scalar* valuePtr() const { return &m_data.value(0); }
|
EIGEN_STRONG_INLINE const Scalar* valuePtr() const { return m_data.valuePtr(); }
|
||||||
EIGEN_STRONG_INLINE Scalar* valuePtr() { return &m_data.value(0); }
|
EIGEN_STRONG_INLINE Scalar* valuePtr() { return m_data.valuePtr(); }
|
||||||
|
|
||||||
|
EIGEN_STRONG_INLINE const Index* innerIndexPtr() const { return m_data.indexPtr(); }
|
||||||
|
EIGEN_STRONG_INLINE Index* innerIndexPtr() { return m_data.indexPtr(); }
|
||||||
|
|
||||||
EIGEN_STRONG_INLINE const Index* innerIndexPtr() const { return &m_data.index(0); }
|
|
||||||
EIGEN_STRONG_INLINE Index* innerIndexPtr() { return &m_data.index(0); }
|
|
||||||
|
|
||||||
/** \internal */
|
/** \internal */
|
||||||
inline Storage& data() { return m_data; }
|
inline Storage& data() { return m_data; }
|
||||||
/** \internal */
|
/** \internal */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user