Tomographer  v2.0
Tomographer C++ Framework Documentation
dmtypes.h
Go to the documentation of this file.
1 /* This file is part of the Tomographer project, which is distributed under the
2  * terms of the MIT license.
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2015 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
27 #ifndef TOMOGRAPHER_DENSEDM_DMTYPES_H
28 #define TOMOGRAPHER_DENSEDM_DMTYPES_H
29 
30 #include <cstddef>
31 #include <cassert>
32 
33 #include <Eigen/Eigen>
34 
35 #include <tomographer2/tools/cxxutil.h> // StaticOrDynamic, TOMOGRAPHER_ENABLED_IF
36 
43 namespace Tomographer {
44 namespace DenseDM {
45 
46 
98 template<int FixedDim_, typename RealScalar_ = double, int MaxFixedDim_ = FixedDim_>
99 struct DMTypes {
100 
101  // assert: either FixedDim_ is dynamic (in which case MaxFixedDim_ can be anything, or
102  // FixedDim_ is static, and has to be equal to MaxFixedDim_ (or less than is also ok but
103  // no idea why you'd do it).
104  TOMO_STATIC_ASSERT_EXPR((FixedDim_ == Eigen::Dynamic) ||
105  (FixedDim_ <= MaxFixedDim_)) ;
106 
108  static constexpr bool IsDynamicDim = (FixedDim_ == Eigen::Dynamic);
110  static constexpr int FixedDim = FixedDim_;
112  static constexpr int FixedDim2 = ((FixedDim!=Eigen::Dynamic) ? FixedDim*FixedDim : Eigen::Dynamic);
116  static constexpr int FixedNdof = ((FixedDim2!=Eigen::Dynamic) ? FixedDim2-1 : Eigen::Dynamic);
117 
119  typedef RealScalar_ RealScalar;
122 
124  static inline ComplexScalar cplx(RealScalar a, RealScalar b)
125  {
126  return ComplexScalar(a, b);
127  }
128 
132  MaxFixedDim_, MaxFixedDim_> MatrixType;
135 
140 
149 
150 
151 
155  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
156  inline DMTypes()
157  : _dim()
158  {
159  }
160 
170  : _dim(d)
171  {
172  }
173 
180  inline std::size_t dim() const { return _dim.value(); }
181 
188  inline std::size_t dim2() const { return _dim.value()*_dim.value(); }
189 
195  inline std::size_t ndof() const { return dim2()-1; }
196 
197 
203  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
204  inline typename MatrixType::ConstantReturnType initMatrixType() const
205  {
206  return MatrixType::Zero();
207  }
213  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
214  inline typename MatrixType::ConstantReturnType initMatrixType() const
215  {
216  return MatrixType::Zero(_dim.value(), _dim.value());
217  }
218 
224  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
225  inline typename VectorParamType::ConstantReturnType initVectorParamType() const
226  {
227  return VectorParamType::Zero();
228  }
234  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
235  inline typename VectorParamType::ConstantReturnType initVectorParamType() const
236  {
237  return VectorParamType::Zero(dim2());
238  }
239 
246  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
247  inline typename VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
248  {
249  return VectorParamNdofType::Zero();
250  }
257  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
258  inline typename VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
259  {
260  return VectorParamNdofType::Zero(ndof());
261  }
262 
263 
264 private:
266 };
267 
268 
269 
270 
271 
272 } // namespace DenseDM
273 } // namespace Tomographer
274 
275 
276 
277 
278 
279 
280 
281 
282 #endif
Eigen::Matrix< RealScalar, FixedDim2, 1 > VectorParamType
Real vector with dim*dim elements.
Definition: dmtypes.h:137
Base namespace for the Tomographer project.
Definition: densellh.h:44
std::complex< RealScalar > ComplexScalar
The corresponding complex scalar type.
Definition: dmtypes.h:121
const Eigen::Ref< const MatrixType > & MatrixTypeConstRef
Shorthand for a const reference to a MatrixType-like Eigen object.
Definition: dmtypes.h:134
VectorParamType::ConstantReturnType initVectorParamType() const
Zero initializer for a VectorParamType [implementation for static dimension].
Definition: dmtypes.h:225
STL class.
Eigen::Matrix< RealScalar, FixedNdof, 1 > VectorParamNdofType
Real vector with dim*dim-1 elements.
Definition: dmtypes.h:146
static ComplexScalar cplx(RealScalar a, RealScalar b)
Utility to initialize a complex number using the current scalar type.
Definition: dmtypes.h:124
std::size_t ndof() const
get the square of the dimension of the quantum system, minus one
Definition: dmtypes.h:195
static constexpr int FixedDim2
The square of the dimension of the quantum system, or Eigen::Dynamic.
Definition: dmtypes.h:112
static constexpr bool IsDynamicDim
Whether the dimension is specified dynamically at run-time or statically at compile-time.
Definition: dmtypes.h:108
std::size_t dim2() const
get the square of the dimension of the quantum system
Definition: dmtypes.h:188
static constexpr int FixedDim
The fixed dimension of the quantum system, or Eigen::Dynamic.
Definition: dmtypes.h:110
Some C++ utilities, with a tad of C++11 tricks.
T value() const
Get the value stored.
Definition: cxxutil.h:186
std::size_t dim() const
get the dimension of the quantum system (dimension of the Hilbert space)
Definition: dmtypes.h:180
Eigen::Matrix< ComplexScalar, FixedDim, FixedDim, Eigen::Matrix< ComplexScalar, FixedDim, FixedDim >::Options, MaxFixedDim_, MaxFixedDim_ > MatrixType
Matrix type, to store the density operator as a dense matrix.
Definition: dmtypes.h:132
const Eigen::Ref< const VectorParamType > & VectorParamTypeConstRef
Shorthand for a const reference to a VectorParamType-like Eigen object.
Definition: dmtypes.h:139
static constexpr int FixedNdof
The square of the dimension of the quantum system minus one, or Eigen::Dynamic.
Definition: dmtypes.h:116
MatrixType::ConstantReturnType initMatrixType() const
Zero initializer for a MatrixType [implementation for static dimension].
Definition: dmtypes.h:204
C++ types needed to store a quantum state as a dense matrix.
Definition: dmtypes.h:99
VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
Zero initializer for a VectorParamNdofType [implementation for static dimension]. ...
Definition: dmtypes.h:247
DMTypes(std::size_t d)
Constructor [works for both static or dynamic dim].
Definition: dmtypes.h:169
const Eigen::Ref< const VectorParamNdofType > & VectorParamNdofTypeConstRef
Shorthand for a const reference to a VectorParamNdofType-like Eigen object.
Definition: dmtypes.h:148
RealScalar_ RealScalar
Real scalar type, given in template parameter. Usually double is fine.
Definition: dmtypes.h:119