Add free-function swap.

This commit is contained in:
Antonio Sánchez
2024-10-14 15:51:40 +00:00
committed by Rasmus Munk Larsen
parent 820e8a45fb
commit b396a6fbb2
4 changed files with 48 additions and 0 deletions

View File

@@ -829,6 +829,8 @@ class SparseMatrix : public SparseCompressedBase<SparseMatrix<Scalar_, Options_,
std::swap(m_innerNonZeros, other.m_innerNonZeros);
m_data.swap(other.m_data);
}
/** Free-function swap. */
friend EIGEN_DEVICE_FUNC void swap(SparseMatrix& a, SparseMatrix& b) { a.swap(b); }
/** Sets *this to the identity matrix.
* This function also turns the matrix into compressed mode, and drop any reserved memory. */

View File

@@ -278,6 +278,7 @@ class SparseVector : public SparseCompressedBase<SparseVector<Scalar_, Options_,
std::swap(m_size, other.m_size);
m_data.swap(other.m_data);
}
friend EIGEN_DEVICE_FUNC void swap(SparseVector& a, SparseVector& b) { a.swap(b); }
template <int OtherOptions>
inline void swap(SparseMatrix<Scalar, OtherOptions, StorageIndex>& other) {
@@ -285,6 +286,14 @@ class SparseVector : public SparseCompressedBase<SparseVector<Scalar_, Options_,
std::swap(m_size, other.m_innerSize);
m_data.swap(other.m_data);
}
template <int OtherOptions>
friend EIGEN_DEVICE_FUNC void swap(SparseVector& a, SparseMatrix<Scalar, OtherOptions, StorageIndex>& b) {
a.swap(b);
}
template <int OtherOptions>
friend EIGEN_DEVICE_FUNC void swap(SparseMatrix<Scalar, OtherOptions, StorageIndex>& a, SparseVector& b) {
b.swap(a);
}
inline SparseVector& operator=(const SparseVector& other) {
if (other.isRValue()) {