aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2017-01-06 21:53:32 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2017-01-06 21:53:32 +0100
commit3264d3c761e6b08101e7577b4278119dea42ec09 (patch)
treec3ccee6cab6e28143dd61e5b0661d1580c2d0557
parenta875167d99cffa76a662de5475627d60238f0f36 (diff)
Add support for plain-array as indices, e.g., mat({1,2,3,4})
-rw-r--r--Eigen/src/Core/ArithmeticSequence.h6
-rw-r--r--Eigen/src/Core/DenseBase.h7
-rw-r--r--Eigen/src/Core/IndexedView.h4
-rw-r--r--test/indexed_view.cpp8
4 files changed, 23 insertions, 2 deletions
diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h
index 1585c1dbf..bfc586a61 100644
--- a/Eigen/src/Core/ArithmeticSequence.h
+++ b/Eigen/src/Core/ArithmeticSequence.h
@@ -159,6 +159,12 @@ span(FirstType first, SizeType size) {
namespace internal {
+template<typename T>
+Index size(const T& x) { return x.size(); }
+
+template<typename T,std::size_t N>
+Index size(const T (&x) [N]) { return N; }
+
template<typename T, int XprSize, typename EnableIf = void> struct get_compile_time_size {
enum { value = Dynamic };
};
diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h
index f8a6b2625..13aa3854a 100644
--- a/Eigen/src/Core/DenseBase.h
+++ b/Eigen/src/Core/DenseBase.h
@@ -566,6 +566,13 @@ template<typename Derived> class DenseBase
derived(), internal::make_indexing(rowIndices,derived().rows()), internal::make_indexing(colIndices,derived().cols()));
}
+ template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
+ IndexedView<const Derived,const RowIndicesT (&)[RowIndicesN],typename internal::MakeIndexing<ColIndices>::type>
+ operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) const {
+ return IndexedView<const Derived,const RowIndicesT (&) [RowIndicesN],typename internal::MakeIndexing<ColIndices>::type>(
+ derived(), rowIndices, internal::make_indexing(colIndices,derived().cols()));
+ }
+
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
diff --git a/Eigen/src/Core/IndexedView.h b/Eigen/src/Core/IndexedView.h
index 26c048584..5ff1c1837 100644
--- a/Eigen/src/Core/IndexedView.h
+++ b/Eigen/src/Core/IndexedView.h
@@ -70,8 +70,8 @@ public:
IndexedView(XprType& xpr, const T0& rowIndices, const T1& colIndices)
: m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices)
{}
- Index rows() const { return m_rowIndices.size(); }
- Index cols() const { return m_colIndices.size(); }
+ Index rows() const { return internal::size(m_rowIndices); }
+ Index cols() const { return internal::size(m_colIndices); }
/** \returns the nested expression */
const typename internal::remove_all<XprType>::type&
diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp
index bc69adf13..4ab1a5251 100644
--- a/test/indexed_view.cpp
+++ b/test/indexed_view.cpp
@@ -93,6 +93,7 @@ void check_indexed_view()
"600 601 602 603 604 605 606 607 608 609\n"
"500 501 502 503 504 505 506 507 508 509")
);
+
// takes the row numer 3, and repeat it 5 times
VERIFY( MATCH( A(span(3,5,0), all),
"300 301 302 303 304 305 306 307 308 309\n"
@@ -138,10 +139,17 @@ void check_indexed_view()
VERIFY_IS_EQUAL( (A(eii, eii)).InnerStrideAtCompileTime, 0);
VERIFY_IS_EQUAL( (A(eii, eii)).OuterStrideAtCompileTime, 0);
+
+
#if EIGEN_HAS_CXX11
VERIFY( (A(all, std::array<int,4>{{1,3,2,4}})).ColsAtCompileTime == 4);
VERIFY_IS_APPROX( (A(std::array<int,3>{{1,3,5}}, std::array<int,4>{{9,6,3,0}})), A(span(1,3,2), span(9,4,-3)) );
+
+#if (!EIGEN_COMP_CLANG) || (EIGEN_COMP_CLANG>=308 && !defined(__apple_build_version__))
+ VERIFY_IS_APPROX( A({3, 1, 6, 5}, all), A(std::array<int,4>{{3, 1, 6, 5}}, all) );
+#endif
+
#endif
}