Skip to content

Commit

Permalink
Add static assertion on selfadjoint-view's UpLo parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggael committed Mar 9, 2018
1 parent adb134d commit d820ab9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Eigen/src/Core/SelfAdjointView.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ template<typename _MatrixType, unsigned int UpLo> class SelfAdjointView

EIGEN_DEVICE_FUNC
explicit inline SelfAdjointView(MatrixType& matrix) : m_matrix(matrix)
{}
{
EIGEN_STATIC_ASSERT(UpLo==Lower || UpLo==Upper,SELFADJOINTVIEW_ACCEPTS_UPPER_AND_LOWER_MODE_ONLY);
}

EIGEN_DEVICE_FUNC
inline Index rows() const { return m_matrix.rows(); }
Expand Down
3 changes: 2 additions & 1 deletion Eigen/src/Core/util/StaticAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
THIS_TYPE_IS_NOT_SUPPORTED=1,
STORAGE_KIND_MUST_MATCH=1,
STORAGE_INDEX_MUST_MATCH=1,
CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY=1
CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY=1,
SELFADJOINTVIEW_ACCEPTS_UPPER_AND_LOWER_MODE_ONLY=1
};
};

Expand Down
4 changes: 4 additions & 0 deletions test/selfadjoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#define EIGEN_NO_STATIC_ASSERT
#include "main.h"

// This file tests the basic selfadjointView API,
Expand Down Expand Up @@ -45,6 +46,9 @@ template<typename MatrixType> void selfadjoint(const MatrixType& m)
m4 = m2;
m4 -= m1.template selfadjointView<Lower>();
VERIFY_IS_APPROX(m4, m2-m3);

VERIFY_RAISES_ASSERT(m2.template selfadjointView<StrictlyUpper>());
VERIFY_RAISES_ASSERT(m2.template selfadjointView<UnitLower>());
}

void bug_159()
Expand Down

0 comments on commit d820ab9

Please sign in to comment.