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.

76 lines
2.5 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2013 Hauke Heibel <hauke.heibel@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. #include <Eigen/Core>
  11. template <typename T, int Rows, int Cols>
  12. void dense_storage_copy()
  13. {
  14. static const int Size = ((Rows==Dynamic || Cols==Dynamic) ? Dynamic : Rows*Cols);
  15. typedef DenseStorage<T,Size, Rows,Cols, 0> DenseStorageType;
  16. const int rows = (Rows==Dynamic) ? 4 : Rows;
  17. const int cols = (Cols==Dynamic) ? 3 : Cols;
  18. const int size = rows*cols;
  19. DenseStorageType reference(size, rows, cols);
  20. T* raw_reference = reference.data();
  21. for (int i=0; i<size; ++i)
  22. raw_reference[i] = static_cast<T>(i);
  23. DenseStorageType copied_reference(reference);
  24. const T* raw_copied_reference = copied_reference.data();
  25. for (int i=0; i<size; ++i)
  26. VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
  27. }
  28. template <typename T, int Rows, int Cols>
  29. void dense_storage_assignment()
  30. {
  31. static const int Size = ((Rows==Dynamic || Cols==Dynamic) ? Dynamic : Rows*Cols);
  32. typedef DenseStorage<T,Size, Rows,Cols, 0> DenseStorageType;
  33. const int rows = (Rows==Dynamic) ? 4 : Rows;
  34. const int cols = (Cols==Dynamic) ? 3 : Cols;
  35. const int size = rows*cols;
  36. DenseStorageType reference(size, rows, cols);
  37. T* raw_reference = reference.data();
  38. for (int i=0; i<size; ++i)
  39. raw_reference[i] = static_cast<T>(i);
  40. DenseStorageType copied_reference;
  41. copied_reference = reference;
  42. const T* raw_copied_reference = copied_reference.data();
  43. for (int i=0; i<size; ++i)
  44. VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
  45. }
  46. void test_dense_storage()
  47. {
  48. dense_storage_copy<int,Dynamic,Dynamic>();
  49. dense_storage_copy<int,Dynamic,3>();
  50. dense_storage_copy<int,4,Dynamic>();
  51. dense_storage_copy<int,4,3>();
  52. dense_storage_copy<float,Dynamic,Dynamic>();
  53. dense_storage_copy<float,Dynamic,3>();
  54. dense_storage_copy<float,4,Dynamic>();
  55. dense_storage_copy<float,4,3>();
  56. dense_storage_assignment<int,Dynamic,Dynamic>();
  57. dense_storage_assignment<int,Dynamic,3>();
  58. dense_storage_assignment<int,4,Dynamic>();
  59. dense_storage_assignment<int,4,3>();
  60. dense_storage_assignment<float,Dynamic,Dynamic>();
  61. dense_storage_assignment<float,Dynamic,3>();
  62. dense_storage_assignment<float,4,Dynamic>();
  63. dense_storage_assignment<float,4,3>();
  64. }