aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/Reverse.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2015-03-31 20:17:10 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2015-03-31 20:17:10 +0200
commitdfb674a25ead137118eebf0230c4c8a4c81db5d0 (patch)
tree14c9538d9ead098a71e1d6cf757ec1faa63a4ce0 /Eigen/src/Core/Reverse.h
parent20d030f207a8f92d75e8e4aca9d515b9939aa58a (diff)
Make reverseInPlace really work in-place.
Diffstat (limited to 'Eigen/src/Core/Reverse.h')
-rw-r--r--Eigen/src/Core/Reverse.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/Eigen/src/Core/Reverse.h b/Eigen/src/Core/Reverse.h
index 291300a4a..b3fba9704 100644
--- a/Eigen/src/Core/Reverse.h
+++ b/Eigen/src/Core/Reverse.h
@@ -210,7 +210,26 @@ DenseBase<Derived>::reverse() const
template<typename Derived>
inline void DenseBase<Derived>::reverseInPlace()
{
- derived() = derived().reverse().eval();
+ if(cols()>rows())
+ {
+ Index half = cols()/2;
+ leftCols(half).swap(rightCols(half).reverse());
+ if((cols()%2)==1)
+ {
+ Index half2 = rows()/2;
+ col(half).head(half2).swap(col(half).tail(half2).reverse());
+ }
+ }
+ else
+ {
+ Index half = rows()/2;
+ topRows(half).swap(bottomRows(half).reverse());
+ if((rows()%2)==1)
+ {
+ Index half2 = cols()/2;
+ row(half).head(half2).swap(row(half).tail(half2).reverse());
+ }
+ }
}
} // end namespace Eigen