Simpatico  v1.10
FMatrix.h
1 #ifndef UTIL_F_MATRIX_H
2 #define UTIL_F_MATRIX_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/containers/Matrix.h>
12 
13 namespace Util
14 {
15 
27  template <typename Data, int M, int N>
28  class FMatrix : public Matrix<Data>
29  {
30 
31  using Matrix<Data>::data_;
34 
35  public:
36 
40  FMatrix();
41 
45  FMatrix(const FMatrix<Data, M, N>& other);
46 
50  ~FMatrix();
51 
56 
63  template <class Archive>
64  void serialize(Archive& ar, const unsigned int version);
65 
66  private:
67 
69  Data fixedArray_[M*N];
70 
71  };
72 
73  /*
74  * Default constructor.
75  */
76  template <typename Data, int M, int N>
78  : Matrix<Data>()
79  {
80  data_ = fixedArray_;
81  capacity1_ = M;
82  capacity2_ = N;
83  }
84 
85  /*
86  * Copy constructor.
87  */
88  template <typename Data, int M, int N>
90  : Matrix<Data>()
91  {
92  data_ = fixedArray_;
93  capacity1_ = M;
94  capacity2_ = N;
95  for (int i = 0; i < M*N; ++i) {
96  fixedArray_[i] = other.fixedArray_[i];
97  }
98  }
99 
100  /*
101  * Destructor.
102  */
103  template <typename Data, int M, int N>
105  {}
106 
107  /*
108  * Assignment.
109  */
110  template <typename Data, int M, int N>
113  {
114  //Check for self assignment
115  if (this == &other) return *this;
116 
117  // Copy elements
118  for (int i = 0; i < M*N; ++i) {
119  fixedArray_[i] = other.fixedArray_[i];
120  }
121 
122  return *this;
123  }
124 
125  /*
126  * Serialize a FMatrix to/from an Archive.
127  */
128  template <class Data, int M, int N>
129  template <class Archive>
130  void FMatrix<Data,M,N>::serialize(Archive& ar, const unsigned int version)
131  {
132  for (int i = 0; i < M*N; ++i) {
133  ar & fixedArray_[i];
134  }
135  }
136 
137 }
138 #endif
int capacity2_
Number of columns (range of first index).
Definition: Matrix.h:79
void serialize(Archive &ar, const unsigned int version)
Serialize an FMatrix to/from an Archive.
Definition: FMatrix.h:130
FMatrix()
Default constructor.
Definition: FMatrix.h:77
int capacity1_
Number of rows (range of first index).
Definition: Matrix.h:76
Utility classes for scientific computation.
Definition: accumulators.mod:1
FMatrix< Data, M, N > & operator=(const FMatrix< Data, M, N > &other)
Assignment.
Definition: FMatrix.h:112
Two-dimensional array container template (abstract).
Definition: Matrix.h:30
Data * data_
Pointer to 1D C array of all elements.
Definition: Matrix.h:73
Fixed Size Matrix.
Definition: FMatrix.h:28
~FMatrix()
Destructor.
Definition: FMatrix.h:104