You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.9 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "main.h"
  10. template<typename MatrixType> void miscMatrices(const MatrixType& m)
  11. {
  12. /* this test covers the following files:
  13. DiagonalMatrix.h Ones.h
  14. */
  15. typedef typename MatrixType::Index Index;
  16. typedef typename MatrixType::Scalar Scalar;
  17. typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
  18. typedef Matrix<Scalar, 1, MatrixType::ColsAtCompileTime> RowVectorType;
  19. Index rows = m.rows();
  20. Index cols = m.cols();
  21. Index r = internal::random<Index>(0, rows-1), r2 = internal::random<Index>(0, rows-1), c = internal::random<Index>(0, cols-1);
  22. VERIFY_IS_APPROX(MatrixType::Ones(rows,cols)(r,c), static_cast<Scalar>(1));
  23. MatrixType m1 = MatrixType::Ones(rows,cols);
  24. VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1));
  25. VectorType v1 = VectorType::Random(rows);
  26. v1[0];
  27. Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
  28. square(v1.asDiagonal());
  29. if(r==r2) VERIFY_IS_APPROX(square(r,r2), v1[r]);
  30. else VERIFY_IS_MUCH_SMALLER_THAN(square(r,r2), static_cast<Scalar>(1));
  31. square = MatrixType::Zero(rows, rows);
  32. square.diagonal() = VectorType::Ones(rows);
  33. VERIFY_IS_APPROX(square, MatrixType::Identity(rows, rows));
  34. }
  35. void test_miscmatrices()
  36. {
  37. for(int i = 0; i < g_repeat; i++) {
  38. CALL_SUBTEST_1( miscMatrices(Matrix<float, 1, 1>()) );
  39. CALL_SUBTEST_2( miscMatrices(Matrix4d()) );
  40. CALL_SUBTEST_3( miscMatrices(MatrixXcf(3, 3)) );
  41. CALL_SUBTEST_4( miscMatrices(MatrixXi(8, 12)) );
  42. CALL_SUBTEST_5( miscMatrices(MatrixXcd(20, 20)) );
  43. }
  44. }