PSCF v1.5.0
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, David Morse (morse012@um.edu)
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/containers/Matrix.h>
12
13namespace Util
14{
15
27 template <typename Data, int M, int N>
28 class FMatrix : public Matrix<Data>
29 {
30
31 public:
32
37
42
47
52
59 template <class Archive>
60 void serialize(Archive& ar, const unsigned int version);
61
62 private:
63
65 Data fixedArray_[M*N];
66
67 using Matrix<Data>::data_;
68 using Matrix<Data>::capacity1_;
69 using Matrix<Data>::capacity2_;
70
71 };
72
73 /*
74 * Default constructor.
75 */
76 template <typename Data, int M, int N>
78 : Matrix<Data>()
79 #ifdef UTIL_CXX11
80 , fixedArray_{}
81 #endif
82 {
83 data_ = fixedArray_;
84 capacity1_ = M;
85 capacity2_ = N;
86 }
87
88 /*
89 * Copy constructor.
90 */
91 template <typename Data, int M, int N>
93 : Matrix<Data>()
94 {
95 data_ = fixedArray_;
96 capacity1_ = M;
97 capacity2_ = N;
98 for (int i = 0; i < M*N; ++i) {
99 fixedArray_[i] = other.fixedArray_[i];
100 }
101 }
102
103 /*
104 * Destructor.
105 */
106 template <typename Data, int M, int N>
109
110 /*
111 * Assignment.
112 */
113 template <typename Data, int M, int N>
116 {
117 // Check for self assignment
118 if (this == &other) return *this;
119
120 // Copy all elements
121 for (int i = 0; i < M*N; ++i) {
122 fixedArray_[i] = other.fixedArray_[i];
123 }
124
125 return *this;
126 }
127
128 /*
129 * Serialize a FMatrix to/from an Archive.
130 */
131 template <typename Data, int M, int N>
132 template <class Archive>
133 void
134 FMatrix<Data, M, N>::serialize(Archive& ar, const unsigned int version)
135 {
136 for (int i = 0; i < M*N; ++i) {
137 ar & fixedArray_[i];
138 }
139 }
140
141}
142#endif
Fixed Size Matrix.
Definition FMatrix.h:29
~FMatrix()
Destructor.
Definition FMatrix.h:107
FMatrix< Data, M, N > & operator=(FMatrix< Data, M, N > const &other)
Assignment.
Definition FMatrix.h:115
FMatrix(FMatrix< Data, M, N > const &other)
Copy constructor.
Definition FMatrix.h:92
void serialize(Archive &ar, const unsigned int version)
Serialize an FMatrix to/from an Archive.
Definition FMatrix.h:134
FMatrix()
Default constructor.
Definition FMatrix.h:77
Data * data_
Pointer to 1D C array of all elements.
Definition Matrix.h:85
int capacity2_
Number of columns (range of first index).
Definition Matrix.h:91
int capacity1_
Number of rows (range of first index).
Definition Matrix.h:88
Utility classes for scientific computation.