From 3380429e3a93dff0f70fbe3e9646924acafb28cd Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 18 Dec 2007 15:29:28 +0000 Subject: [PATCH] Improve the "map" API and corresponding Matrix constructors --- src/Core/Map.h | 36 ++++++++++++++++++++++++++++++++++-- src/Core/Matrix.h | 5 +++-- src/Core/MatrixBase.h | 5 +++-- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Core/Map.h b/src/Core/Map.h index 835d54d91..02852a9f6 100644 --- a/src/Core/Map.h +++ b/src/Core/Map.h @@ -66,7 +66,23 @@ template class Map template Map MatrixBase::map(const Scalar* data, int rows, int cols) { - return Map(const_cast(data),rows, cols); + return Map(const_cast(data), rows, cols); +} + +template +Map MatrixBase::map(const Scalar* data, int size) +{ + assert(IsVector); + if(ColsAtCompileTime == 1) + return Map(const_cast(data), size, 1); + else + return Map(const_cast(data), 1, size); +} + +template +Map MatrixBase::map(const Scalar* data) +{ + return Map(const_cast(data), RowsAtCompileTime, ColsAtCompileTime); } template @@ -74,7 +90,23 @@ Matrix<_Scalar, _Rows, _Cols> ::Matrix(const Scalar *data, int rows, int cols) : Storage(rows, cols) { - *this = Map(const_cast(data), rows, cols); + *this = map(data, rows, cols); +} + +template +Matrix<_Scalar, _Rows, _Cols> + ::Matrix(const Scalar *data, int size) + : Storage(size) +{ + *this = map(data, size); +} + +template +Matrix<_Scalar, _Rows, _Cols> + ::Matrix(const Scalar *data) + : Storage() +{ + *this = map(data); } #endif // EIGEN_FROMARRAY_H diff --git a/src/Core/Matrix.h b/src/Core/Matrix.h index b2a747aba..92eb38725 100644 --- a/src/Core/Matrix.h +++ b/src/Core/Matrix.h @@ -144,8 +144,9 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols> >, (Storage::m_data)[2] = z; (Storage::m_data)[3] = w; } - explicit Matrix(const Scalar *data, int rows = RowsAtCompileTime, - int cols = ColsAtCompileTime); + Matrix(const Scalar *data, int rows, int cols); + Matrix(const Scalar *data, int size); + explicit Matrix(const Scalar *data); template Matrix(const MatrixBase& other) diff --git a/src/Core/MatrixBase.h b/src/Core/MatrixBase.h index e1ee000d8..b2eebe791 100644 --- a/src/Core/MatrixBase.h +++ b/src/Core/MatrixBase.h @@ -95,8 +95,9 @@ template class MatrixBase diagonal(const OtherDerived& coeffs); DiagonalCoeffs diagonal() const; - static Map - map(const Scalar* array, int rows = RowsAtCompileTime, int cols = ColsAtCompileTime); + static Map map(const Scalar* array, int rows, int cols); + static Map map(const Scalar* array, int size); + static Map map(const Scalar* array); template bool isApprox(