aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2008-01-11 15:08:04 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2008-01-11 15:08:04 +0000
commite092cbc75cadef1158d43f07b32e4ae0bf9372e2 (patch)
treef95fb0f3e6c36c6e6badbed4fcd8d136b8483880
parentaae0667e1e120b5809a7e2fe442d67832ff9ed0f (diff)
-add set...() methods and their documentation; remove Generic
-use row-major traversal when the number of columns is fixed and the number of rows is dynamic -other minor changes
-rw-r--r--Eigen/src/Core/Cast.h2
-rw-r--r--Eigen/src/Core/Conjugate.h2
-rw-r--r--Eigen/src/Core/DiagonalMatrix.h8
-rw-r--r--Eigen/src/Core/Dot.h4
-rw-r--r--Eigen/src/Core/Identity.h15
-rw-r--r--Eigen/src/Core/Map.h2
-rw-r--r--Eigen/src/Core/Matrix.h6
-rw-r--r--Eigen/src/Core/MatrixBase.h7
-rw-r--r--Eigen/src/Core/Ones.h15
-rw-r--r--Eigen/src/Core/OperatorEquals.h28
-rw-r--r--Eigen/src/Core/Opposite.h2
-rw-r--r--Eigen/src/Core/Random.h15
-rw-r--r--Eigen/src/Core/Util.h1
-rw-r--r--Eigen/src/Core/Zero.h15
-rw-r--r--doc/benchmark.cpp2
-rw-r--r--doc/snippets/MatrixBase_setIdentity.cpp3
-rw-r--r--doc/snippets/MatrixBase_setOnes.cpp3
-rw-r--r--doc/snippets/MatrixBase_setRandom.cpp3
-rw-r--r--doc/snippets/MatrixBase_setZero.cpp3
-rw-r--r--test/map.cpp2
20 files changed, 112 insertions, 26 deletions
diff --git a/Eigen/src/Core/Cast.h b/Eigen/src/Core/Cast.h
index 6963003cc..fb90217f8 100644
--- a/Eigen/src/Core/Cast.h
+++ b/Eigen/src/Core/Cast.h
@@ -71,7 +71,7 @@ template<typename NewScalar, typename MatrixType> class Cast : NoOperatorEquals,
}
protected:
- MatRef m_matrix;
+ const MatRef m_matrix;
};
/** \returns an expression of *this with the \a Scalar type casted to
diff --git a/Eigen/src/Core/Conjugate.h b/Eigen/src/Core/Conjugate.h
index e99ca547c..c36a64eff 100644
--- a/Eigen/src/Core/Conjugate.h
+++ b/Eigen/src/Core/Conjugate.h
@@ -64,7 +64,7 @@ template<typename MatrixType> class Conjugate : NoOperatorEquals,
}
protected:
- MatRef m_matrix;
+ const MatRef m_matrix;
};
/** \returns an expression of the complex conjugate of *this.
diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h
index b36bce15a..c1031d032 100644
--- a/Eigen/src/Core/DiagonalMatrix.h
+++ b/Eigen/src/Core/DiagonalMatrix.h
@@ -52,7 +52,7 @@ class DiagonalMatrix : NoOperatorEquals,
DiagonalMatrix(const CoeffsVecRef& coeffs) : m_coeffs(coeffs)
{
assert(CoeffsVectorType::Traits::IsVectorAtCompileTime
- && coeffs.coeffs() > 0);
+ && coeffs.size() > 0);
}
private:
@@ -62,8 +62,8 @@ class DiagonalMatrix : NoOperatorEquals,
};
const DiagonalMatrix& _ref() const { return *this; }
- int _rows() const { return m_coeffs.coeffs(); }
- int _cols() const { return m_coeffs.coeffs(); }
+ int _rows() const { return m_coeffs.size(); }
+ int _cols() const { return m_coeffs.size(); }
Scalar _coeff(int row, int col) const
{
@@ -71,7 +71,7 @@ class DiagonalMatrix : NoOperatorEquals,
}
protected:
- CoeffsVecRef m_coeffs;
+ const CoeffsVecRef m_coeffs;
};
/** \returns an expression of a diagonal matrix with *this as vector of diagonal coefficients
diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h
index 4b84cfbab..3ff416fba 100644
--- a/Eigen/src/Core/Dot.h
+++ b/Eigen/src/Core/Dot.h
@@ -74,7 +74,7 @@ Scalar MatrixBase<Scalar, Derived>::dot(const OtherDerived& other) const
{
assert(Traits::IsVectorAtCompileTime
&& OtherDerived::Traits::IsVectorAtCompileTime
- && coeffs() == other.coeffs());
+ && size() == other.size());
Scalar res;
if(EIGEN_UNROLLED_LOOPS
&& Traits::SizeAtCompileTime != Dynamic
@@ -85,7 +85,7 @@ Scalar MatrixBase<Scalar, Derived>::dot(const OtherDerived& other) const
else
{
res = (*this).coeff(0) * conj(other.coeff(0));
- for(int i = 1; i < coeffs(); i++)
+ for(int i = 1; i < size(); i++)
res += (*this).coeff(i)* conj(other.coeff(i));
}
return res;
diff --git a/Eigen/src/Core/Identity.h b/Eigen/src/Core/Identity.h
index bf7b2de27..93b3c7cae 100644
--- a/Eigen/src/Core/Identity.h
+++ b/Eigen/src/Core/Identity.h
@@ -60,7 +60,7 @@ template<typename MatrixType> class Identity : NoOperatorEquals,
}
protected:
- int m_rows;
+ const int m_rows;
};
/** \returns an expression of the identity matrix of given type and size.
@@ -108,5 +108,18 @@ bool MatrixBase<Scalar, Derived>::isIdentity
return true;
}
+/** Writes the identity expression into *this.
+ *
+ * Example: \include MatrixBase_setIdentity.cpp
+ * Output: \verbinclude MatrixBase_setIdentity.out
+ *
+ * \sa class Identity, identity()
+ */
+template<typename Scalar, typename Derived>
+Derived& MatrixBase<Scalar, Derived>::setIdentity()
+{
+ return *this = Identity<Derived>(rows());
+}
+
#endif // EIGEN_IDENTITY_H
diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h
index cf4a3c3fb..28ab3f657 100644
--- a/Eigen/src/Core/Map.h
+++ b/Eigen/src/Core/Map.h
@@ -86,7 +86,7 @@ template<typename MatrixType> class Map
protected:
const Scalar* m_data;
- int m_rows, m_cols;
+ const int m_rows, m_cols;
};
/** This is the const version of map(Scalar*,int,int). */
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index 78eb64a9c..fc80959a8 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -70,7 +70,7 @@
* \c Matrix<double,3,5>.
*
* Note that most of the API is in the base class MatrixBase, and that the base class
- * MatrixStorage also provides the MatrixStorage::recoeffs() public method.
+ * MatrixStorage also provides the MatrixStorage::resize() public method.
*/
template<typename _Scalar, int _Rows, int _Cols,
int _StorageOrder = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER>
@@ -135,12 +135,12 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _Storage
if(RowsAtCompileTime == 1)
{
assert(other.isVector());
- resize(1, other.coeffs());
+ resize(1, other.size());
}
else if(ColsAtCompileTime == 1)
{
assert(other.isVector());
- resize(other.coeffs(), 1);
+ resize(other.size(), 1);
}
else resize(other.rows(), other.cols());
return Base::operator=(other);
diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h
index 8d9bd6491..3a62b8e34 100644
--- a/Eigen/src/Core/MatrixBase.h
+++ b/Eigen/src/Core/MatrixBase.h
@@ -115,7 +115,7 @@ template<typename Scalar, typename Derived> class MatrixBase
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
/** \returns the number of coefficients, which is \a rows()*cols().
* \sa rows(), cols(), Traits::SizeAtCompileTime. */
- int coeffs() const { return rows() * cols(); }
+ int size() const { return rows() * cols(); }
/** \returns true if either the number of rows or the number of columns is equal to 1.
* In other words, this function returns
* \code rows()==1 || cols()==1 \endcode
@@ -189,6 +189,11 @@ template<typename Scalar, typename Derived> class MatrixBase
bool isIdentity(RealScalar prec = precision<Scalar>()) const;
bool isDiagonal(RealScalar prec = precision<Scalar>()) const;
+ Derived& setZero();
+ Derived& setOnes();
+ Derived& setRandom();
+ Derived& setIdentity();
+
const DiagonalMatrix<Derived> asDiagonal() const;
DiagonalCoeffs<Derived> diagonal();
diff --git a/Eigen/src/Core/Ones.h b/Eigen/src/Core/Ones.h
index 1822d6090..bb52889c9 100644
--- a/Eigen/src/Core/Ones.h
+++ b/Eigen/src/Core/Ones.h
@@ -64,7 +64,7 @@ template<typename MatrixType> class Ones : NoOperatorEquals,
}
protected:
- int m_rows, m_cols;
+ const int m_rows, m_cols;
};
/** \returns an expression of a matrix where all coefficients equal one.
@@ -146,4 +146,17 @@ bool MatrixBase<Scalar, Derived>::isOnes
return true;
}
+/** Sets all coefficients in this expression to one.
+ *
+ * Example: \include MatrixBase_setOnes.cpp
+ * Output: \verbinclude MatrixBase_setOnes.out
+ *
+ * \sa class Ones, ones()
+ */
+template<typename Scalar, typename Derived>
+Derived& MatrixBase<Scalar, Derived>::setOnes()
+{
+ return *this = Ones<Derived>(rows(), cols());
+}
+
#endif // EIGEN_ONES_H
diff --git a/Eigen/src/Core/OperatorEquals.h b/Eigen/src/Core/OperatorEquals.h
index 49da872c0..01086ad40 100644
--- a/Eigen/src/Core/OperatorEquals.h
+++ b/Eigen/src/Core/OperatorEquals.h
@@ -106,27 +106,45 @@ Derived& MatrixBase<Scalar, Derived>
if(Traits::IsVectorAtCompileTime && OtherDerived::Traits::IsVectorAtCompileTime)
// copying a vector expression into a vector
{
- assert(coeffs() == other.coeffs());
+ assert(size() == other.size());
if(EIGEN_UNROLLED_LOOPS && Traits::SizeAtCompileTime != Dynamic && Traits::SizeAtCompileTime <= 25)
VectorOperatorEqualsUnroller
<Derived, OtherDerived, Traits::SizeAtCompileTime>::run
(*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other));
else
- for(int i = 0; i < coeffs(); i++)
+ for(int i = 0; i < size(); i++)
coeffRef(i) = other.coeff(i);
return *static_cast<Derived*>(this);
}
else // copying a matrix expression into a matrix
{
assert(rows() == other.rows() && cols() == other.cols());
- if(EIGEN_UNROLLED_LOOPS && Traits::SizeAtCompileTime != Dynamic && Traits::SizeAtCompileTime <= 25)
+ if(EIGEN_UNROLLED_LOOPS
+ && Traits::SizeAtCompileTime != Dynamic
+ && Traits::SizeAtCompileTime <= 25)
+ {
MatrixOperatorEqualsUnroller
<Derived, OtherDerived, Traits::SizeAtCompileTime>::run
(*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other));
+ }
else
- for(int j = 0; j < cols(); j++)
+ {
+ if(Traits::ColsAtCompileTime == Dynamic || Traits::RowsAtCompileTime != Dynamic)
+ {
+ // traverse in column-major order
+ for(int j = 0; j < cols(); j++)
+ for(int i = 0; i < rows(); i++)
+ coeffRef(i, j) = other.coeff(i, j);
+ }
+ else
+ {
+ // traverse in row-major order
+ // in order to allow the compiler to unroll the inner loop
for(int i = 0; i < rows(); i++)
- coeffRef(i, j) = other.coeff(i, j);
+ for(int j = 0; j < cols(); j++)
+ coeffRef(i, j) = other.coeff(i, j);
+ }
+ }
return *static_cast<Derived*>(this);
}
}
diff --git a/Eigen/src/Core/Opposite.h b/Eigen/src/Core/Opposite.h
index 93f0fe13f..6ef2e9f77 100644
--- a/Eigen/src/Core/Opposite.h
+++ b/Eigen/src/Core/Opposite.h
@@ -64,7 +64,7 @@ template<typename MatrixType> class Opposite : NoOperatorEquals,
}
protected:
- MatRef m_matrix;
+ const MatRef m_matrix;
};
/** \returns an expression of the opposite of \c *this
diff --git a/Eigen/src/Core/Random.h b/Eigen/src/Core/Random.h
index ad6142f4d..f07fa792a 100644
--- a/Eigen/src/Core/Random.h
+++ b/Eigen/src/Core/Random.h
@@ -64,7 +64,7 @@ template<typename MatrixType> class Random : NoOperatorEquals,
}
protected:
- int m_rows, m_cols;
+ const int m_rows, m_cols;
};
/** \returns a random matrix (not an expression, the matrix is immediately evaluated).
@@ -128,4 +128,17 @@ const Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random()
return Random<Derived>(Traits::RowsAtCompileTime, Traits::ColsAtCompileTime).eval();
}
+/** Sets all coefficients in this expression to random values.
+ *
+ * Example: \include MatrixBase_setRandom.cpp
+ * Output: \verbinclude MatrixBase_setRandom.out
+ *
+ * \sa class Random, random()
+ */
+template<typename Scalar, typename Derived>
+Derived& MatrixBase<Scalar, Derived>::setRandom()
+{
+ return *this = Random<Derived>(rows(), cols());
+}
+
#endif // EIGEN_RANDOM_H
diff --git a/Eigen/src/Core/Util.h b/Eigen/src/Core/Util.h
index 91e51a476..7c68d25ca 100644
--- a/Eigen/src/Core/Util.h
+++ b/Eigen/src/Core/Util.h
@@ -89,7 +89,6 @@ EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
const int Dynamic = -10;
-const int Generic = -20;
const int ColumnMajor = 0;
const int RowMajor = 1;
diff --git a/Eigen/src/Core/Zero.h b/Eigen/src/Core/Zero.h
index a854acc1d..f90bb2849 100644
--- a/Eigen/src/Core/Zero.h
+++ b/Eigen/src/Core/Zero.h
@@ -64,7 +64,7 @@ template<typename MatrixType> class Zero : NoOperatorEquals,
}
protected:
- int m_rows, m_cols;
+ const int m_rows, m_cols;
};
/** \returns an expression of a zero matrix.
@@ -146,4 +146,17 @@ bool MatrixBase<Scalar, Derived>::isZero
return true;
}
+/** Sets all coefficients in this expression to zero.
+ *
+ * Example: \include MatrixBase_setZero.cpp
+ * Output: \verbinclude MatrixBase_setZero.out
+ *
+ * \sa class Zero, zero()
+ */
+template<typename Scalar, typename Derived>
+Derived& MatrixBase<Scalar, Derived>::setZero()
+{
+ return *this = Zero<Derived>(rows(), cols());
+}
+
#endif // EIGEN_ZERO_H
diff --git a/doc/benchmark.cpp b/doc/benchmark.cpp
index b2ab9a3b0..51f594583 100644
--- a/doc/benchmark.cpp
+++ b/doc/benchmark.cpp
@@ -16,7 +16,7 @@ int main(int argc, char *argv[])
}
for(int a = 0; a < 400000000; a++)
{
- m = I + 0.00005 * (m + m*m);
+ m = Matrix3d::identity() + 0.00005 * (m + m*m);
}
cout << m << endl;
return 0;
diff --git a/doc/snippets/MatrixBase_setIdentity.cpp b/doc/snippets/MatrixBase_setIdentity.cpp
new file mode 100644
index 000000000..17a706ca2
--- /dev/null
+++ b/doc/snippets/MatrixBase_setIdentity.cpp
@@ -0,0 +1,3 @@
+Matrix4i m = Matrix4i::zero();
+m.block<3,3>(1,0).setIdentity();
+cout << m << endl;
diff --git a/doc/snippets/MatrixBase_setOnes.cpp b/doc/snippets/MatrixBase_setOnes.cpp
new file mode 100644
index 000000000..c4d0ac1de
--- /dev/null
+++ b/doc/snippets/MatrixBase_setOnes.cpp
@@ -0,0 +1,3 @@
+Matrix4i m = Matrix4i::random();
+m.row(1).setOnes();
+cout << m << endl;
diff --git a/doc/snippets/MatrixBase_setRandom.cpp b/doc/snippets/MatrixBase_setRandom.cpp
new file mode 100644
index 000000000..242306ee3
--- /dev/null
+++ b/doc/snippets/MatrixBase_setRandom.cpp
@@ -0,0 +1,3 @@
+Matrix4i m = Matrix4i::zero();
+m.col(1).setRandom();
+cout << m << endl;
diff --git a/doc/snippets/MatrixBase_setZero.cpp b/doc/snippets/MatrixBase_setZero.cpp
new file mode 100644
index 000000000..22575494d
--- /dev/null
+++ b/doc/snippets/MatrixBase_setZero.cpp
@@ -0,0 +1,3 @@
+Matrix4i m = Matrix4i::random();
+m.row(1).setZero();
+cout << m << endl;
diff --git a/test/map.cpp b/test/map.cpp
index 99de551a5..4f28a8513 100644
--- a/test/map.cpp
+++ b/test/map.cpp
@@ -31,7 +31,7 @@ template<typename VectorType> void tmap(const VectorType& m)
{
typedef typename VectorType::Scalar Scalar;
- int size = m.coeffs();
+ int size = m.size();
// test Map.h
Scalar* array1 = new Scalar[size];