Tomographer  v5.2
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) 2016 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  * Copyright (c) 2017 Caltech, Institute for Quantum Information and Matter, Philippe Faist
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 
28 #ifndef TOMOGRAPHER_DENSEDM_DMTYPES_H
29 #define TOMOGRAPHER_DENSEDM_DMTYPES_H
30 
31 #include <cstddef>
32 #include <cassert>
33 
34 #include <Eigen/Eigen>
35 
36 #include <tomographer/tools/cxxutil.h> // StaticOrDynamic, TOMOGRAPHER_ENABLED_IF
37 
44 namespace Tomographer {
45 namespace DenseDM {
46 
47 
99 template<int FixedDim_, typename RealScalar_ = double, int MaxFixedDim_ = FixedDim_>
100 struct TOMOGRAPHER_EXPORT DMTypes
101 {
102 
103  // assert: either FixedDim_ is dynamic (in which case MaxFixedDim_ can be anything, or
104  // FixedDim_ is static, and has to be equal to MaxFixedDim_ (or less than is also ok but
105  // no idea why you'd do it).
106  TOMO_STATIC_ASSERT_EXPR((FixedDim_ == Eigen::Dynamic) ||
107  (FixedDim_ <= MaxFixedDim_)) ;
108 
110  static constexpr bool IsDynamicDim = (FixedDim_ == Eigen::Dynamic);
112  static constexpr int FixedDim = FixedDim_;
114  static constexpr int FixedDim2 = ((FixedDim!=Eigen::Dynamic) ? FixedDim*FixedDim : Eigen::Dynamic);
118  static constexpr int FixedNdof = ((FixedDim2!=Eigen::Dynamic) ? FixedDim2-1 : Eigen::Dynamic);
119 
121  typedef RealScalar_ RealScalar;
124 
126  static inline ComplexScalar cplx(RealScalar a, RealScalar b)
127  {
128  return ComplexScalar(a, b);
129  }
130 
132  typedef Eigen::Matrix<ComplexScalar, FixedDim, FixedDim,
134  MaxFixedDim_, MaxFixedDim_> MatrixType;
137 
142 
151 
152 
153 
157  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
158  inline DMTypes()
159  : _dim()
160  {
161  }
162 
171  inline DMTypes(Eigen::Index d)
172  : _dim(d)
173  {
174  }
175 
182  inline Eigen::Index dim() const { return _dim.value(); }
183 
190  inline Eigen::Index dim2() const { return _dim.value()*_dim.value(); }
191 
197  inline Eigen::Index ndof() const { return dim2()-1; }
198 
199 
205  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
206  inline typename MatrixType::ConstantReturnType initMatrixType() const
207  {
208  return MatrixType::Zero();
209  }
215  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
216  inline typename MatrixType::ConstantReturnType initMatrixType() const
217  {
218  return MatrixType::Zero(_dim.value(), _dim.value());
219  }
220 
226  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
227  inline typename VectorParamType::ConstantReturnType initVectorParamType() const
228  {
229  return VectorParamType::Zero();
230  }
236  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
237  inline typename VectorParamType::ConstantReturnType initVectorParamType() const
238  {
239  return VectorParamType::Zero(dim2());
240  }
241 
248  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
249  inline typename VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
250  {
251  return VectorParamNdofType::Zero();
252  }
259  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
260  inline typename VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
261  {
262  return VectorParamNdofType::Zero(ndof());
263  }
264 
265 
266 private:
268 };
269 
270 
271 
272 
273 
274 } // namespace DenseDM
275 } // namespace Tomographer
276 
277 
278 
279 
280 
281 
282 
283 
284 #endif
Eigen::Matrix< RealScalar, FixedDim2, 1 > VectorParamType
Real vector with dim*dim elements.
Definition: dmtypes.h:139
Base namespace for the Tomographer project.
Definition: densellh.h:45
std::complex< RealScalar > ComplexScalar
The corresponding complex scalar type.
Definition: dmtypes.h:123
const Eigen::Ref< const MatrixType > & MatrixTypeConstRef
Shorthand for a const reference to a MatrixType-like Eigen object.
Definition: dmtypes.h:136
STL class.
Eigen::Matrix< RealScalar, FixedNdof, 1 > VectorParamNdofType
Real vector with dim*dim-1 elements.
Definition: dmtypes.h:148
static ComplexScalar cplx(RealScalar a, RealScalar b)
Utility to initialize a complex number using the current scalar type.
Definition: dmtypes.h:126
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
Definition: cxxdefs.h:77
Eigen::Index dim() const
get the dimension of the quantum system (dimension of the Hilbert space)
Definition: dmtypes.h:182
Eigen::Index dim2() const
get the square of the dimension of the quantum system
Definition: dmtypes.h:190
Some C++ utilities, with a tad of C++11 tricks.
DMTypes(Eigen::Index d)
Constructor [works for both static or dynamic dim].
Definition: dmtypes.h:171
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:134
const Eigen::Ref< const VectorParamType > & VectorParamTypeConstRef
Shorthand for a const reference to a VectorParamType-like Eigen object.
Definition: dmtypes.h:141
C++ types needed to store a quantum state as a dense matrix.
Definition: dmtypes.h:100
const Eigen::Ref< const VectorParamNdofType > & VectorParamNdofTypeConstRef
Shorthand for a const reference to a VectorParamNdofType-like Eigen object.
Definition: dmtypes.h:150
Eigen::Index ndof() const
get the square of the dimension of the quantum system, minus one
Definition: dmtypes.h:197
RealScalar_ RealScalar
Real scalar type, given in template parameter. Usually double is fine.
Definition: dmtypes.h:121