Squashed 'third_party/eigen/' changes from 61d72f6..cf794d3


Change-Id: I9b814151b01f49af6337a8605d0c42a3a1ed4c72
git-subtree-dir: third_party/eigen
git-subtree-split: cf794d3b741a6278df169e58461f8529f43bce5d
diff --git a/test/constructor.cpp b/test/constructor.cpp
new file mode 100644
index 0000000..eec9e21
--- /dev/null
+++ b/test/constructor.cpp
@@ -0,0 +1,84 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// 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 TEST_ENABLE_TEMPORARY_TRACKING
+
+#include "main.h"
+
+template<typename MatrixType> struct Wrapper
+{
+  MatrixType m_mat;
+  inline Wrapper(const MatrixType &x) : m_mat(x) {}
+  inline operator const MatrixType& () const { return m_mat; }
+  inline operator MatrixType& () { return m_mat; }
+};
+
+template<typename MatrixType> void ctor_init1(const MatrixType& m)
+{
+  // Check logic in PlainObjectBase::_init1
+  Index rows = m.rows();
+  Index cols = m.cols();
+
+  MatrixType m0 = MatrixType::Random(rows,cols);
+
+  VERIFY_EVALUATION_COUNT( MatrixType m1(m0), 1);
+  VERIFY_EVALUATION_COUNT( MatrixType m2(m0+m0), 1);
+  VERIFY_EVALUATION_COUNT( MatrixType m2(m0.block(0,0,rows,cols)) , 1);
+
+  Wrapper<MatrixType> wrapper(m0);
+  VERIFY_EVALUATION_COUNT( MatrixType m3(wrapper) , 1);
+}
+
+
+void test_constructor()
+{
+  for(int i = 0; i < g_repeat; i++) {
+    CALL_SUBTEST_1( ctor_init1(Matrix<float, 1, 1>()) );
+    CALL_SUBTEST_1( ctor_init1(Matrix4d()) );
+    CALL_SUBTEST_1( ctor_init1(MatrixXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
+    CALL_SUBTEST_1( ctor_init1(MatrixXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
+  }
+  {
+    Matrix<Index,1,1> a(123);
+    VERIFY_IS_EQUAL(a[0], 123);
+  }
+  {
+    Matrix<Index,1,1> a(123.0);
+    VERIFY_IS_EQUAL(a[0], 123);
+  }
+  {
+    Matrix<float,1,1> a(123);
+    VERIFY_IS_EQUAL(a[0], 123.f);
+  }
+  {
+    Array<Index,1,1> a(123);
+    VERIFY_IS_EQUAL(a[0], 123);
+  }
+  {
+    Array<Index,1,1> a(123.0);
+    VERIFY_IS_EQUAL(a[0], 123);
+  }
+  {
+    Array<float,1,1> a(123);
+    VERIFY_IS_EQUAL(a[0], 123.f);
+  }
+  {
+    Array<Index,3,3> a(123);
+    VERIFY_IS_EQUAL(a(4), 123);
+  }
+  {
+    Array<Index,3,3> a(123.0);
+    VERIFY_IS_EQUAL(a(4), 123);
+  }
+  {
+    Array<float,3,3> a(123);
+    VERIFY_IS_EQUAL(a(4), 123.f);
+  }
+}