• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  
10  #include "main.h"
11  
12  #include <Eigen/Core>
13  
14  template <typename T, int Rows, int Cols>
dense_storage_copy()15  void dense_storage_copy()
16  {
17    static const int Size = ((Rows==Dynamic || Cols==Dynamic) ? Dynamic : Rows*Cols);
18    typedef DenseStorage<T,Size, Rows,Cols, 0> DenseStorageType;
19  
20    const int rows = (Rows==Dynamic) ? 4 : Rows;
21    const int cols = (Cols==Dynamic) ? 3 : Cols;
22    const int size = rows*cols;
23    DenseStorageType reference(size, rows, cols);
24    T* raw_reference = reference.data();
25    for (int i=0; i<size; ++i)
26      raw_reference[i] = static_cast<T>(i);
27  
28    DenseStorageType copied_reference(reference);
29    const T* raw_copied_reference = copied_reference.data();
30    for (int i=0; i<size; ++i)
31      VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
32  }
33  
34  template <typename T, int Rows, int Cols>
dense_storage_assignment()35  void dense_storage_assignment()
36  {
37    static const int Size = ((Rows==Dynamic || Cols==Dynamic) ? Dynamic : Rows*Cols);
38    typedef DenseStorage<T,Size, Rows,Cols, 0> DenseStorageType;
39  
40    const int rows = (Rows==Dynamic) ? 4 : Rows;
41    const int cols = (Cols==Dynamic) ? 3 : Cols;
42    const int size = rows*cols;
43    DenseStorageType reference(size, rows, cols);
44    T* raw_reference = reference.data();
45    for (int i=0; i<size; ++i)
46      raw_reference[i] = static_cast<T>(i);
47  
48    DenseStorageType copied_reference;
49    copied_reference = reference;
50    const T* raw_copied_reference = copied_reference.data();
51    for (int i=0; i<size; ++i)
52      VERIFY_IS_EQUAL(raw_reference[i], raw_copied_reference[i]);
53  }
54  
test_dense_storage()55  void test_dense_storage()
56  {
57    dense_storage_copy<int,Dynamic,Dynamic>();
58    dense_storage_copy<int,Dynamic,3>();
59    dense_storage_copy<int,4,Dynamic>();
60    dense_storage_copy<int,4,3>();
61  
62    dense_storage_copy<float,Dynamic,Dynamic>();
63    dense_storage_copy<float,Dynamic,3>();
64    dense_storage_copy<float,4,Dynamic>();
65    dense_storage_copy<float,4,3>();
66  
67    dense_storage_assignment<int,Dynamic,Dynamic>();
68    dense_storage_assignment<int,Dynamic,3>();
69    dense_storage_assignment<int,4,Dynamic>();
70    dense_storage_assignment<int,4,3>();
71  
72    dense_storage_assignment<float,Dynamic,Dynamic>();
73    dense_storage_assignment<float,Dynamic,3>();
74    dense_storage_assignment<float,4,Dynamic>();
75    dense_storage_assignment<float,4,3>();
76  }
77