Bugzilla – Attachment 404 Details for
Bug 710
SparseMatrix< shared_ptr<X> > is not working (patch attached)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
Proposed patch file for 3.2.0
patch.txt (text/plain), 8.00 KB, created by
Takaki Makino
on 2013-12-06 16:26:17 UTC
(
hide
)
Description:
Proposed patch file for 3.2.0
Filename:
MIME Type:
Creator:
Takaki Makino
Created:
2013-12-06 16:26:17 UTC
Size:
8.00 KB
patch
obsolete
>diff -u -r eigen-eigen-ffa86ffb5570/Eigen/src/Core/util/Memory.h Eigen/src/Core/util/Memory.h >--- eigen-eigen-ffa86ffb5570/Eigen/src/Core/util/Memory.h 2013-07-24 10:48:35.000000000 +0900 >+++ Eigen/src/Core/util/Memory.h 2013-12-07 00:18:37.682190821 +0900 >@@ -497,21 +497,57 @@ > > // std::copy is much slower than memcpy, so let's introduce a smart_copy which > // use memcpy on trivial types, i.e., on types that does not require an initialization ctor. >+// smart_move is a variant using C++11 move semantics if possible (avoid copying) >+// smart_move_overlap is like memmove (correctly handle overlapping move). > template<typename T, bool UseMemcpy> struct smart_copy_helper; > > template<typename T> void smart_copy(const T* start, const T* end, T* target) > { > smart_copy_helper<T,!NumTraits<T>::RequireInitialization>::run(start, end, target); > } >+template<typename T> void smart_move(const T* start, const T* end, T* target) >+{ >+ smart_copy_helper<T,!NumTraits<T>::RequireInitialization>::run_move(start, end, target); >+} >+template<typename T> void smart_move_overlap(const T* start, const T* end, T* target) >+{ >+ smart_copy_helper<T,!NumTraits<T>::RequireInitialization>::run_overlap(start, end, target); >+} > > template<typename T> struct smart_copy_helper<T,true> { > static inline void run(const T* start, const T* end, T* target) > { memcpy(target, start, std::ptrdiff_t(end)-std::ptrdiff_t(start)); } >+ static inline void run_move(const T* start, const T* end, T* target) >+ { memcpy(target, start, std::ptrdiff_t(end)-std::ptrdiff_t(start)); } >+ static inline void run_overlap(const T* start, const T* end, T* target) >+ { memmove(target, start, std::ptrdiff_t(end)-std::ptrdiff_t(start)); } > }; > > template<typename T> struct smart_copy_helper<T,false> { > static inline void run(const T* start, const T* end, T* target) > { std::copy(start, end, target); } >+ static inline void run_move(const T* start, const T* end, T* target) >+ { >+#if ( __cplusplus >= 201103L ) >+ std::move(start, end, target); >+#else >+ std::copy(start, end, target); >+#endif >+ } >+ static inline void run_overlap(const T* start, const T* end, T* target) >+ { >+#if ( __cplusplus >= 201103L ) >+ if( target < start ) >+ std::move(start, end, target); >+ else >+ std::move_backward(start, end, target); >+#else >+ if( target < start ) >+ std::copy(start, end, target); >+ else >+ std::copy_backward(start, end, target); >+#endif >+ } > }; > > >diff -u -r eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/AmbiVector.h Eigen/src/SparseCore/AmbiVector.h >--- eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/AmbiVector.h 2013-07-24 10:48:35.000000000 +0900 >+++ Eigen/src/SparseCore/AmbiVector.h 2013-12-06 23:53:12.278509539 +0900 >@@ -90,7 +90,7 @@ > Index allocSize = m_allocatedElements * sizeof(ListEl); > allocSize = allocSize/sizeof(Scalar) + (allocSize%sizeof(Scalar)>0?1:0); > Scalar* newBuffer = new Scalar[allocSize]; >- memcpy(newBuffer, m_buffer, copyElements * sizeof(ListEl)); >+ internal::smart_move( m_buffer, m_buffer + copyElements, newBuffer ); > delete[] m_buffer; > m_buffer = newBuffer; > } >diff -u -r eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/CompressedStorage.h Eigen/src/SparseCore/CompressedStorage.h >--- eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/CompressedStorage.h 2013-07-24 10:48:35.000000000 +0900 >+++ Eigen/src/SparseCore/CompressedStorage.h 2013-12-06 23:52:50.646895012 +0900 >@@ -51,8 +51,8 @@ > CompressedStorage& operator=(const CompressedStorage& other) > { > resize(other.size()); >- memcpy(m_values, other.m_values, m_size * sizeof(Scalar)); >- memcpy(m_indices, other.m_indices, m_size * sizeof(Index)); >+ internal::smart_copy( other.m_values, other.m_values + m_size, m_values ); >+ internal::smart_copy( other.m_indices, other.m_indices + m_size, m_indices ); > return *this; > } > >@@ -208,8 +208,8 @@ > Index* newIndices = new Index[size]; > size_t copySize = (std::min)(size, m_size); > // copy >- internal::smart_copy(m_values, m_values+copySize, newValues); >- internal::smart_copy(m_indices, m_indices+copySize, newIndices); >+ internal::smart_move(m_values, m_values+copySize, newValues); >+ internal::smart_move(m_indices, m_indices+copySize, newIndices); > // delete old stuff > delete[] m_values; > delete[] m_indices; >diff -u -r eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/SparseBlock.h Eigen/src/SparseCore/SparseBlock.h >--- eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/SparseBlock.h 2013-07-24 10:48:35.000000000 +0900 >+++ Eigen/src/SparseCore/SparseBlock.h 2013-12-07 00:19:18.505463350 +0900 >@@ -145,15 +145,21 @@ > // realloc manually to reduce copies > typename SparseMatrixType::Storage newdata(m_matrix.data().allocatedSize() - block_size + nnz); > >- std::memcpy(&newdata.value(0), &m_matrix.data().value(0), start*sizeof(Scalar)); >- std::memcpy(&newdata.index(0), &m_matrix.data().index(0), start*sizeof(Index)); >+ Scalar *src1 = &m_matrix.data().value(0), dst1 = &newdata.value(0); >+ internal::smart_move( src1, src1+start, dst1 ); >+ Index *src2 = &m_matrix.data().index(0), dst2 = &newdata.index(0); >+ internal::smart_move( src2, src2+start, dst2 ); >+ >+ Scalar *src3 = &tmp.data().value(0), dst3 = &newdata.value(start); >+ internal::smart_copy( src3, src3+nnz, dst3 ); >+ Index *src4 = &tmp.data().index(0), dst4 = &newdata.index(start); >+ internal::smart_copy( src4, src4+nnz, dst4 ); >+ >+ Scalar *src5 = &matrix.data().value(end), dst5 = &newdata.value(start+nnz); >+ internal::smart_move( src5, src5+tail_size, dst5 ); >+ Index *src6 = &matrix.data().index(end), dst6 = &newdata.index(start+nnz); >+ internal::smart_move( src6, src6+tail_size, dst6 ); > >- std::memcpy(&newdata.value(start), &tmp.data().value(0), nnz*sizeof(Scalar)); >- std::memcpy(&newdata.index(start), &tmp.data().index(0), nnz*sizeof(Index)); >- >- std::memcpy(&newdata.value(start+nnz), &matrix.data().value(end), tail_size*sizeof(Scalar)); >- std::memcpy(&newdata.index(start+nnz), &matrix.data().index(end), tail_size*sizeof(Index)); >- > newdata.resize(m_matrix.outerIndexPtr()[m_matrix.outerSize()] - block_size + nnz); > > matrix.data().swap(newdata); >@@ -163,11 +169,15 @@ > // no need to realloc, simply copy the tail at its respective position and insert tmp > matrix.data().resize(start + nnz + tail_size); > >- std::memmove(&matrix.data().value(start+nnz), &matrix.data().value(end), tail_size*sizeof(Scalar)); >- std::memmove(&matrix.data().index(start+nnz), &matrix.data().index(end), tail_size*sizeof(Index)); >- >- std::memcpy(&matrix.data().value(start), &tmp.data().value(0), nnz*sizeof(Scalar)); >- std::memcpy(&matrix.data().index(start), &tmp.data().index(0), nnz*sizeof(Index)); >+ Scalar *src5 = &matrix.data().value(end), dst5 = &matrix.value(start+nnz); >+ internal::smart_move_overlap( src5, src5+tail_size, dst5 ); >+ Index *src6 = &matrix.data().index(end), dst6 = &matrix.index(start+nnz); >+ internal::smart_move_overlap( src6, src6+tail_size, dst6 ); >+ >+ Scalar *src3 = &tmp.data().value(0), dst3 = &matrix.value(start); >+ internal::smart_copy( src3, src3+nnz, dst3 ); >+ Index *src4 = &tmp.data().index(0), dst4 = &matrix.index(start); >+ internal::smart_copy( src4, src4+nnz, dst4 ); > } > > // update innerNonZeros >diff -u -r eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/SparseMatrix.h Eigen/src/SparseCore/SparseMatrix.h >--- eigen-eigen-ffa86ffb5570/Eigen/src/SparseCore/SparseMatrix.h 2013-07-24 10:48:35.000000000 +0900 >+++ Eigen/src/SparseCore/SparseMatrix.h 2013-12-06 23:30:31.754753935 +0900 >@@ -711,7 +711,7 @@ > initAssignment(other); > if(other.isCompressed()) > { >- memcpy(m_outerIndex, other.m_outerIndex, (m_outerSize+1)*sizeof(Index)); >+ internal::smart_copy( other.m_outerIndex, other.m_outerIndex + m_outerSize+1, m_outerIndex ); > m_data = other.m_data; > } > else
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 710
: 404