aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-12-25 16:45:25 -0500
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-12-25 16:45:25 -0500
commit86d3711fb7e06bd1e31ae6ad5fbac35fe17e5a3d (patch)
tree38548a07a32751da7f02587d6f4649e65c767f90
parent75b7d98665dd144c44d7a113c6613f5f998be626 (diff)
remove EIGEN_REF_TO_TEMPORARY, clarify docs
-rw-r--r--Eigen/src/Core/Array.h2
-rw-r--r--Eigen/src/Core/Matrix.h2
-rw-r--r--Eigen/src/Core/PlainObjectBase.h2
-rw-r--r--Eigen/src/Core/TriangularMatrix.h4
-rw-r--r--Eigen/src/Core/util/Macros.h7
-rw-r--r--Eigen/src/Sparse/SparseMatrixBase.h2
-rw-r--r--doc/I13_FunctionsTakingEigenTypes.dox12
7 files changed, 12 insertions, 19 deletions
diff --git a/Eigen/src/Core/Array.h b/Eigen/src/Core/Array.h
index 0861d7ab1..68bd6c32c 100644
--- a/Eigen/src/Core/Array.h
+++ b/Eigen/src/Core/Array.h
@@ -230,7 +230,7 @@ class Array
* data pointers.
*/
template<typename OtherDerived>
- void swap(ArrayBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
+ void swap(ArrayBase<OtherDerived> const & other)
{ this->_swap(other.derived()); }
inline Index innerStride() const { return 1; }
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index e0dbd101e..70b7eb66c 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -323,7 +323,7 @@ class Matrix
* of same type it is enough to swap the data pointers.
*/
template<typename OtherDerived>
- void swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
+ void swap(MatrixBase<OtherDerived> const & other)
{ this->_swap(other.derived()); }
inline Index innerStride() const { return 1; }
diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h
index 5b0169f72..3b23d04ad 100644
--- a/Eigen/src/Core/PlainObjectBase.h
+++ b/Eigen/src/Core/PlainObjectBase.h
@@ -526,7 +526,7 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
* data pointers.
*/
template<typename OtherDerived>
- void _swap(DenseBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
+ void _swap(DenseBase<OtherDerived> const & other)
{
enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==Dynamic };
internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.const_cast_derived());
diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h
index 575681620..bbf1dce1f 100644
--- a/Eigen/src/Core/TriangularMatrix.h
+++ b/Eigen/src/Core/TriangularMatrix.h
@@ -324,13 +324,13 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
}
template<typename OtherDerived>
- void swap(TriangularBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
+ void swap(TriangularBase<OtherDerived> const & other)
{
TriangularView<SwapWrapper<MatrixType>,Mode>(const_cast<MatrixType&>(m_matrix)).lazyAssign(other.derived());
}
template<typename OtherDerived>
- void swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
+ void swap(MatrixBase<OtherDerived> const & other)
{
TriangularView<SwapWrapper<MatrixType>,Mode>(const_cast<MatrixType&>(m_matrix)).lazyAssign(other.derived());
}
diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h
index 35af83be4..2e1f905b7 100644
--- a/Eigen/src/Core/util/Macros.h
+++ b/Eigen/src/Core/util/Macros.h
@@ -263,13 +263,6 @@
// needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
#define EIGEN_DOCS_IO_FORMAT IOFormat(3, 0, " ", "\n", "", "")
-// C++0x features
-#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && (_MSC_VER >= 1600))
- #define EIGEN_REF_TO_TEMPORARY const &
-#else
- #define EIGEN_REF_TO_TEMPORARY const &
-#endif
-
#if defined(_MSC_VER) && (!defined(__INTEL_COMPILER))
#define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
using Base::operator =;
diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h
index bc16be955..c4c11f5fd 100644
--- a/Eigen/src/Sparse/SparseMatrixBase.h
+++ b/Eigen/src/Sparse/SparseMatrixBase.h
@@ -573,7 +573,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived>
{ return typename internal::eval<Derived>::type(derived()); }
// template<typename OtherDerived>
-// void swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other);
+// void swap(MatrixBase<OtherDerived> const & other);
// template<unsigned int Added>
// const SparseFlagged<Derived, Added, 0> marked() const;
diff --git a/doc/I13_FunctionsTakingEigenTypes.dox b/doc/I13_FunctionsTakingEigenTypes.dox
index e67430feb..ef71e6f19 100644
--- a/doc/I13_FunctionsTakingEigenTypes.dox
+++ b/doc/I13_FunctionsTakingEigenTypes.dox
@@ -110,7 +110,7 @@ the compiler will fail, because it is not possible to convert the expression ret
The solution which is preferred at the moment is based on a little \em hack. One needs to pass a const reference to the matrix and internally the constness needs to be cast away. The correct implementation for C98 compliant compilers would be
\code
template <typename Derived, typename OtherDerived>
-void cov(const MatrixBase<Derived>& x, const MatrixBase<Derived>& y, MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY C)
+void cov(const MatrixBase<Derived>& x, const MatrixBase<Derived>& y, MatrixBase<OtherDerived> const & C)
{
typedef typename Derived::Scalar Scalar;
typedef typename internal::plain_row_type<Derived>::type RowVectorType;
@@ -140,7 +140,7 @@ cov(x, y, C);
This is not the case anymore, when we are using an implementation taking MatrixBase as a parameter. In general, Eigen supports automatic resizing but it is not possible to do so on expressions. Why should resizing of a matrix Block be allowed? It is a reference to a sub-matrix and we definitely don't want to resize that. So how can we incorporate resizing if we cannot resize on MatrixBase? The solution is to resize the derived object as in this implementation.
\code
template <typename Derived, typename OtherDerived>
-void cov(const MatrixBase<Derived>& x, const MatrixBase<Derived>& y, MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY C_)
+void cov(const MatrixBase<Derived>& x, const MatrixBase<Derived>& y, MatrixBase<OtherDerived> const & C_)
{
typedef typename Derived::Scalar Scalar;
typedef typename internal::plain_row_type<Derived>::type RowVectorType;
@@ -156,16 +156,16 @@ void cov(const MatrixBase<Derived>& x, const MatrixBase<Derived>& y, MatrixBase<
C = (x.rowwise() - x_mean).transpose() * (y.rowwise() - y_mean) / num_observations;
}
\endcode
-This implementation is now working for paramters being expressions and for parameters being matrices and having the wrong size. Resizing the expressions does not do any harm in this case unless they actually require resizing. That means, passing an expression with the wrong dimensions will result in a run-time error (in debug mode only) while passing expressions of the correct size will just work fine.
+This implementation is now working for parameters being expressions and for parameters being matrices and having the wrong size. Resizing the expressions does not do any harm in this case unless they actually require resizing. That means, passing an expression with the wrong dimensions will result in a run-time error (in debug mode only) while passing expressions of the correct size will just work fine.
\b Note: In the above discussion the terms Matrix and Array and MatrixBase and ArrayBase can be exchanged and all arguments still hold.
\section TopicSummary Summary
- - To summarize, the implementation of functions taking non-writable (const referenced) objects is not a big issue and does not lead to problematic situations in terms of compiling and running your program. However, such an implementation is likely to introduce unnecessary temporary objects in your code. In case you care about optimal run-time performance, use (const) references to MatrixBase or ArrayBase, i.e. write templated functions.
+ - To summarize, the implementation of functions taking non-writable (const referenced) objects is not a big issue and does not lead to problematic situations in terms of compiling and running your program. However, a naive implementation is likely to introduce unnecessary temporary objects in your code. In order to avoid evaluating parameters into temporaries, pass them as (const) references to MatrixBase or ArrayBase (so templatize your function).
- - Writing portable functions taking parameters that are writable (non-const) requires to implement the functions such that they take const references to MatrixBase or ArrayBase. To be precise, writable objects require to use Eigen's macro EIGEN_REF_TO_TEMPORARY and casting away constness within the function. On modern compilers supporting the C++0x standard, such functions can be implemented based on r-value references though this solution is not backwards compatible with older compiler versions.
+ - Functions taking writable (non-const) parameters must take const references and cast away constness within the function body.
- - Regarding resizing objects, in particular in functions that take as parameters MatrixBase (or ArrayBase), the actual resizing has to be performed on the derived class.
+ - Functions that take as parameters MatrixBase (or ArrayBase) objects, and potentially need to resize them (in the case where they are resizable), must call resize() on the derived class, as returned by derived().
*/
}