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.

42 lines
1.2 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra. Eigen itself is part of the KDE project.
  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 Scalar> void smallVectors()
  11. {
  12. typedef Matrix<Scalar, 1, 2> V2;
  13. typedef Matrix<Scalar, 3, 1> V3;
  14. typedef Matrix<Scalar, 1, 4> V4;
  15. Scalar x1 = ei_random<Scalar>(),
  16. x2 = ei_random<Scalar>(),
  17. x3 = ei_random<Scalar>(),
  18. x4 = ei_random<Scalar>();
  19. V2 v2(x1, x2);
  20. V3 v3(x1, x2, x3);
  21. V4 v4(x1, x2, x3, x4);
  22. VERIFY_IS_APPROX(x1, v2.x());
  23. VERIFY_IS_APPROX(x1, v3.x());
  24. VERIFY_IS_APPROX(x1, v4.x());
  25. VERIFY_IS_APPROX(x2, v2.y());
  26. VERIFY_IS_APPROX(x2, v3.y());
  27. VERIFY_IS_APPROX(x2, v4.y());
  28. VERIFY_IS_APPROX(x3, v3.z());
  29. VERIFY_IS_APPROX(x3, v4.z());
  30. VERIFY_IS_APPROX(x4, v4.w());
  31. }
  32. void test_eigen2_smallvectors()
  33. {
  34. for(int i = 0; i < g_repeat; i++) {
  35. CALL_SUBTEST( smallVectors<int>() );
  36. CALL_SUBTEST( smallVectors<float>() );
  37. CALL_SUBTEST( smallVectors<double>() );
  38. }
  39. }