Lines 48-64
template<typename TranspositionType, typ
Link Here
|
48 |
template<typename Derived> |
48 |
template<typename Derived> |
49 |
class TranspositionsBase |
49 |
class TranspositionsBase |
50 |
{ |
50 |
{ |
51 |
typedef internal::traits<Derived> Traits; |
51 |
typedef internal::traits<Derived> Traits; |
52 |
|
52 |
|
53 |
public: |
53 |
public: |
54 |
|
54 |
|
55 |
typedef typename Traits::IndicesType IndicesType; |
55 |
typedef typename Traits::IndicesType IndicesType; |
56 |
typedef typename IndicesType::Scalar Index; |
56 |
typedef typename IndicesType::Scalar IndexType; |
|
|
57 |
typedef typename IndicesType::Index Index; |
57 |
|
58 |
|
58 |
Derived& derived() { return *static_cast<Derived*>(this); } |
59 |
Derived& derived() { return *static_cast<Derived*>(this); } |
59 |
const Derived& derived() const { return *static_cast<const Derived*>(this); } |
60 |
const Derived& derived() const { return *static_cast<const Derived*>(this); } |
60 |
|
61 |
|
61 |
/** Copies the \a other transpositions into \c *this */ |
62 |
/** Copies the \a other transpositions into \c *this */ |
62 |
template<typename OtherDerived> |
63 |
template<typename OtherDerived> |
63 |
Derived& operator=(const TranspositionsBase<OtherDerived>& other) |
64 |
Derived& operator=(const TranspositionsBase<OtherDerived>& other) |
64 |
{ |
65 |
{ |
Lines 76-118
class TranspositionsBase
Link Here
|
76 |
return derived(); |
77 |
return derived(); |
77 |
} |
78 |
} |
78 |
#endif |
79 |
#endif |
79 |
|
80 |
|
80 |
/** \returns the number of transpositions */ |
81 |
/** \returns the number of transpositions */ |
81 |
inline Index size() const { return indices().size(); } |
82 |
inline Index size() const { return indices().size(); } |
82 |
|
83 |
|
83 |
/** Direct access to the underlying index vector */ |
84 |
/** Direct access to the underlying index vector */ |
84 |
inline const Index& coeff(Index i) const { return indices().coeff(i); } |
85 |
inline const IndexType& coeff(Index i) const { return indices().coeff(i); } |
85 |
/** Direct access to the underlying index vector */ |
86 |
/** Direct access to the underlying index vector */ |
86 |
inline Index& coeffRef(Index i) { return indices().coeffRef(i); } |
87 |
inline IndexType& coeffRef(Index i) { return indices().coeffRef(i); } |
87 |
/** Direct access to the underlying index vector */ |
88 |
/** Direct access to the underlying index vector */ |
88 |
inline const Index& operator()(Index i) const { return indices()(i); } |
89 |
inline const IndexType& operator()(Index i) const { return indices()(i); } |
89 |
/** Direct access to the underlying index vector */ |
90 |
/** Direct access to the underlying index vector */ |
90 |
inline Index& operator()(Index i) { return indices()(i); } |
91 |
inline IndexType& operator()(Index i) { return indices()(i); } |
91 |
/** Direct access to the underlying index vector */ |
92 |
/** Direct access to the underlying index vector */ |
92 |
inline const Index& operator[](Index i) const { return indices()(i); } |
93 |
inline const IndexType& operator[](Index i) const { return indices()(i); } |
93 |
/** Direct access to the underlying index vector */ |
94 |
/** Direct access to the underlying index vector */ |
94 |
inline Index& operator[](Index i) { return indices()(i); } |
95 |
inline IndexType& operator[](Index i) { return indices()(i); } |
95 |
|
96 |
|
96 |
/** const version of indices(). */ |
97 |
/** const version of indices(). */ |
97 |
const IndicesType& indices() const { return derived().indices(); } |
98 |
const IndicesType& indices() const { return derived().indices(); } |
98 |
/** \returns a reference to the stored array representing the transpositions. */ |
99 |
/** \returns a reference to the stored array representing the transpositions. */ |
99 |
IndicesType& indices() { return derived().indices(); } |
100 |
IndicesType& indices() { return derived().indices(); } |
100 |
|
101 |
|
101 |
/** Resizes to given size. */ |
102 |
/** Resizes to given size. */ |
102 |
inline void resize(int newSize) |
103 |
inline void resize(Index newSize) |
103 |
{ |
104 |
{ |
104 |
indices().resize(newSize); |
105 |
indices().resize(newSize); |
105 |
} |
106 |
} |
106 |
|
107 |
|
107 |
/** Sets \c *this to represents an identity transformation */ |
108 |
/** Sets \c *this to represents an identity transformation */ |
108 |
void setIdentity() |
109 |
void setIdentity() |
109 |
{ |
110 |
{ |
110 |
for(int i = 0; i < indices().size(); ++i) |
111 |
for(IndexType i = 0; i < indices().size(); ++i) |
111 |
coeffRef(i) = i; |
112 |
coeffRef(i) = i; |
112 |
} |
113 |
} |
113 |
|
114 |
|
114 |
// FIXME: do we want such methods ? |
115 |
// FIXME: do we want such methods ? |
115 |
// might be usefull when the target matrix expression is complex, e.g.: |
116 |
// might be usefull when the target matrix expression is complex, e.g.: |
116 |
// object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..); |
117 |
// object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..); |
117 |
/* |
118 |
/* |
118 |
template<typename MatrixType> |
119 |
template<typename MatrixType> |
Lines 139-171
class TranspositionsBase
Link Here
|
139 |
/** \returns the tranpose transformation */ |
140 |
/** \returns the tranpose transformation */ |
140 |
inline Transpose<TranspositionsBase> transpose() const |
141 |
inline Transpose<TranspositionsBase> transpose() const |
141 |
{ return Transpose<TranspositionsBase>(derived()); } |
142 |
{ return Transpose<TranspositionsBase>(derived()); } |
142 |
|
143 |
|
143 |
protected: |
144 |
protected: |
144 |
}; |
145 |
}; |
145 |
|
146 |
|
146 |
namespace internal { |
147 |
namespace internal { |
147 |
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType> |
148 |
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType> |
148 |
struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType> > |
149 |
struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType> > |
149 |
{ |
150 |
{ |
150 |
typedef IndexType Index; |
151 |
typedef Matrix<_IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType; |
151 |
typedef Matrix<Index, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType; |
152 |
typedef typename IndicesType::Index Index; |
|
|
153 |
typedef _IndexType IndexType; |
152 |
}; |
154 |
}; |
153 |
} |
155 |
} |
154 |
|
156 |
|
155 |
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType> |
157 |
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType> |
156 |
class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType> > |
158 |
class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType> > |
157 |
{ |
159 |
{ |
158 |
typedef internal::traits<Transpositions> Traits; |
160 |
typedef internal::traits<Transpositions> Traits; |
159 |
public: |
161 |
public: |
160 |
|
162 |
|
161 |
typedef TranspositionsBase<Transpositions> Base; |
163 |
typedef TranspositionsBase<Transpositions> Base; |
162 |
typedef typename Traits::IndicesType IndicesType; |
164 |
typedef typename Traits::IndicesType IndicesType; |
163 |
typedef typename IndicesType::Scalar Index; |
165 |
typedef typename IndicesType::Scalar IndexType; |
|
|
166 |
typedef typename IndicesType::Index Index; |
167 |
|
164 |
|
168 |
|
165 |
inline Transpositions() {} |
169 |
inline Transpositions() {} |
166 |
|
170 |
|
167 |
/** Copy constructor. */ |
171 |
/** Copy constructor. */ |
168 |
template<typename OtherDerived> |
172 |
template<typename OtherDerived> |
169 |
inline Transpositions(const TranspositionsBase<OtherDerived>& other) |
173 |
inline Transpositions(const TranspositionsBase<OtherDerived>& other) |
170 |
: m_indices(other.indices()) {} |
174 |
: m_indices(other.indices()) {} |
171 |
|
175 |
|
Lines 210-249
class Transpositions : public Transposit
Link Here
|
210 |
|
214 |
|
211 |
protected: |
215 |
protected: |
212 |
|
216 |
|
213 |
IndicesType m_indices; |
217 |
IndicesType m_indices; |
214 |
}; |
218 |
}; |
215 |
|
219 |
|
216 |
|
220 |
|
217 |
namespace internal { |
221 |
namespace internal { |
218 |
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int _PacketAccess> |
222 |
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType, int _PacketAccess> |
219 |
struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,_PacketAccess> > |
223 |
struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType>,_PacketAccess> > |
220 |
{ |
224 |
{ |
221 |
typedef IndexType Index; |
225 |
typedef Map<const Matrix<_IndexType,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType; |
222 |
typedef Map<const Matrix<Index,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType; |
226 |
typedef typename IndicesType::Index Index; |
|
|
227 |
typedef _IndexType IndexType; |
223 |
}; |
228 |
}; |
224 |
} |
229 |
} |
225 |
|
230 |
|
226 |
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int PacketAccess> |
231 |
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType, int PacketAccess> |
227 |
class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,PacketAccess> |
232 |
class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType>,PacketAccess> |
228 |
: public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,PacketAccess> > |
233 |
: public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType>,PacketAccess> > |
229 |
{ |
234 |
{ |
230 |
typedef internal::traits<Map> Traits; |
235 |
typedef internal::traits<Map> Traits; |
231 |
public: |
236 |
public: |
232 |
|
237 |
|
233 |
typedef TranspositionsBase<Map> Base; |
238 |
typedef TranspositionsBase<Map> Base; |
234 |
typedef typename Traits::IndicesType IndicesType; |
239 |
typedef typename Traits::IndicesType IndicesType; |
235 |
typedef typename IndicesType::Scalar Index; |
240 |
typedef typename IndicesType::Scalar IndexType; |
|
|
241 |
typedef typename IndicesType::Index Index; |
236 |
|
242 |
|
237 |
inline Map(const Index* indicesPtr) |
243 |
inline Map(const IndexType* indicesPtr) |
238 |
: m_indices(indicesPtr) |
244 |
: m_indices(indicesPtr) |
239 |
{} |
245 |
{} |
240 |
|
246 |
|
241 |
inline Map(const Index* indicesPtr, Index size) |
247 |
inline Map(const IndexType* indicesPtr, Index size) |
242 |
: m_indices(indicesPtr,size) |
248 |
: m_indices(indicesPtr,size) |
243 |
{} |
249 |
{} |
244 |
|
250 |
|
245 |
/** Copies the \a other transpositions into \c *this */ |
251 |
/** Copies the \a other transpositions into \c *this */ |
246 |
template<typename OtherDerived> |
252 |
template<typename OtherDerived> |
247 |
Map& operator=(const TranspositionsBase<OtherDerived>& other) |
253 |
Map& operator=(const TranspositionsBase<OtherDerived>& other) |
248 |
{ |
254 |
{ |
249 |
return Base::operator=(other); |
255 |
return Base::operator=(other); |
Lines 270-300
class Map<Transpositions<SizeAtCompileTi
Link Here
|
270 |
|
276 |
|
271 |
IndicesType m_indices; |
277 |
IndicesType m_indices; |
272 |
}; |
278 |
}; |
273 |
|
279 |
|
274 |
namespace internal { |
280 |
namespace internal { |
275 |
template<typename _IndicesType> |
281 |
template<typename _IndicesType> |
276 |
struct traits<TranspositionsWrapper<_IndicesType> > |
282 |
struct traits<TranspositionsWrapper<_IndicesType> > |
277 |
{ |
283 |
{ |
278 |
typedef typename _IndicesType::Scalar Index; |
284 |
typedef typename _IndicesType::Scalar IndexType; |
|
|
285 |
typedef typename _IndicesType::Index Index; |
279 |
typedef _IndicesType IndicesType; |
286 |
typedef _IndicesType IndicesType; |
280 |
}; |
287 |
}; |
281 |
} |
288 |
} |
282 |
|
289 |
|
283 |
template<typename _IndicesType> |
290 |
template<typename _IndicesType> |
284 |
class TranspositionsWrapper |
291 |
class TranspositionsWrapper |
285 |
: public TranspositionsBase<TranspositionsWrapper<_IndicesType> > |
292 |
: public TranspositionsBase<TranspositionsWrapper<_IndicesType> > |
286 |
{ |
293 |
{ |
287 |
typedef internal::traits<TranspositionsWrapper> Traits; |
294 |
typedef internal::traits<TranspositionsWrapper> Traits; |
288 |
public: |
295 |
public: |
289 |
|
296 |
|
290 |
typedef TranspositionsBase<TranspositionsWrapper> Base; |
297 |
typedef TranspositionsBase<TranspositionsWrapper> Base; |
291 |
typedef typename Traits::IndicesType IndicesType; |
298 |
typedef typename Traits::IndicesType IndicesType; |
292 |
typedef typename IndicesType::Scalar Index; |
299 |
typedef typename IndicesType::Scalar IndexType; |
|
|
300 |
typedef typename IndicesType::Index Index; |
293 |
|
301 |
|
294 |
inline TranspositionsWrapper(IndicesType& a_indices) |
302 |
inline TranspositionsWrapper(IndicesType& a_indices) |
295 |
: m_indices(a_indices) |
303 |
: m_indices(a_indices) |
296 |
{} |
304 |
{} |
297 |
|
305 |
|
298 |
/** Copies the \a other transpositions into \c *this */ |
306 |
/** Copies the \a other transpositions into \c *this */ |
299 |
template<typename OtherDerived> |
307 |
template<typename OtherDerived> |
300 |
TranspositionsWrapper& operator=(const TranspositionsBase<OtherDerived>& other) |
308 |
TranspositionsWrapper& operator=(const TranspositionsBase<OtherDerived>& other) |
Lines 358-391
struct traits<transposition_matrix_produ
Link Here
|
358 |
}; |
366 |
}; |
359 |
|
367 |
|
360 |
template<typename TranspositionType, typename MatrixType, int Side, bool Transposed> |
368 |
template<typename TranspositionType, typename MatrixType, int Side, bool Transposed> |
361 |
struct transposition_matrix_product_retval |
369 |
struct transposition_matrix_product_retval |
362 |
: public ReturnByValue<transposition_matrix_product_retval<TranspositionType, MatrixType, Side, Transposed> > |
370 |
: public ReturnByValue<transposition_matrix_product_retval<TranspositionType, MatrixType, Side, Transposed> > |
363 |
{ |
371 |
{ |
364 |
typedef typename remove_all<typename MatrixType::Nested>::type MatrixTypeNestedCleaned; |
372 |
typedef typename remove_all<typename MatrixType::Nested>::type MatrixTypeNestedCleaned; |
365 |
typedef typename TranspositionType::Index Index; |
373 |
typedef typename TranspositionType::Index Index; |
|
|
374 |
typedef typename TranspositionType::IndexType IndexType; |
366 |
|
375 |
|
367 |
transposition_matrix_product_retval(const TranspositionType& tr, const MatrixType& matrix) |
376 |
transposition_matrix_product_retval(const TranspositionType& tr, const MatrixType& matrix) |
368 |
: m_transpositions(tr), m_matrix(matrix) |
377 |
: m_transpositions(tr), m_matrix(matrix) |
369 |
{} |
378 |
{} |
370 |
|
379 |
|
371 |
inline int rows() const { return m_matrix.rows(); } |
380 |
inline Index rows() const { return m_matrix.rows(); } |
372 |
inline int cols() const { return m_matrix.cols(); } |
381 |
inline Index cols() const { return m_matrix.cols(); } |
373 |
|
382 |
|
374 |
template<typename Dest> inline void evalTo(Dest& dst) const |
383 |
template<typename Dest> inline void evalTo(Dest& dst) const |
375 |
{ |
384 |
{ |
376 |
const int size = m_transpositions.size(); |
385 |
const Index size = m_transpositions.size(); |
377 |
Index j = 0; |
386 |
IndexType j = 0; |
378 |
|
387 |
|
379 |
if(!(is_same<MatrixTypeNestedCleaned,Dest>::value && extract_data(dst) == extract_data(m_matrix))) |
388 |
if(!(is_same<MatrixTypeNestedCleaned,Dest>::value && extract_data(dst) == extract_data(m_matrix))) |
380 |
dst = m_matrix; |
389 |
dst = m_matrix; |
381 |
|
390 |
|
382 |
for(int k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k) |
391 |
for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k) |
383 |
if((j=m_transpositions.coeff(k))!=k) |
392 |
if(Index(j=m_transpositions.coeff(k))!=k) |
384 |
{ |
393 |
{ |
385 |
if(Side==OnTheLeft) |
394 |
if(Side==OnTheLeft) |
386 |
dst.row(k).swap(dst.row(j)); |
395 |
dst.row(k).swap(dst.row(j)); |
387 |
else if(Side==OnTheRight) |
396 |
else if(Side==OnTheRight) |
388 |
dst.col(k).swap(dst.col(j)); |
397 |
dst.col(k).swap(dst.col(j)); |
389 |
} |
398 |
} |
390 |
} |
399 |
} |
391 |
|
400 |
|