Tomographer  v3.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) 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 DMTypes {
101 
102  // assert: either FixedDim_ is dynamic (in which case MaxFixedDim_ can be anything, or
103  // FixedDim_ is static, and has to be equal to MaxFixedDim_ (or less than is also ok but
104  // no idea why you'd do it).
105  TOMO_STATIC_ASSERT_EXPR((FixedDim_ == Eigen::Dynamic) ||
106  (FixedDim_ <= MaxFixedDim_)) ;
107 
109  static constexpr bool IsDynamicDim = (FixedDim_ == Eigen::Dynamic);
111  static constexpr int FixedDim = FixedDim_;
113  static constexpr int FixedDim2 = ((FixedDim!=Eigen::Dynamic) ? FixedDim*FixedDim : Eigen::Dynamic);
117  static constexpr int FixedNdof = ((FixedDim2!=Eigen::Dynamic) ? FixedDim2-1 : Eigen::Dynamic);
118 
120  typedef RealScalar_ RealScalar;
123 
125  static inline ComplexScalar cplx(RealScalar a, RealScalar b)
126  {
127  return ComplexScalar(a, b);
128  }
129 
133  MaxFixedDim_, MaxFixedDim_> MatrixType;
136 
141 
150 
151 
152 
156  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
157  inline DMTypes()
158  : _dim()
159  {
160  }
161 
171  : _dim(d)
172  {
173  }
174 
181  inline std::size_t dim() const { return _dim.value(); }
182 
189  inline std::size_t dim2() const { return _dim.value()*_dim.value(); }
190 
196  inline std::size_t ndof() const { return dim2()-1; }
197 
198 
204  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
205  inline typename MatrixType::ConstantReturnType initMatrixType() const
206  {
207  return MatrixType::Zero();
208  }
214  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
215  inline typename MatrixType::ConstantReturnType initMatrixType() const
216  {
217  return MatrixType::Zero(_dim.value(), _dim.value());
218  }
219 
225  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
226  inline typename VectorParamType::ConstantReturnType initVectorParamType() const
227  {
228  return VectorParamType::Zero();
229  }
235  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
236  inline typename VectorParamType::ConstantReturnType initVectorParamType() const
237  {
238  return VectorParamType::Zero(dim2());
239  }
240 
247  TOMOGRAPHER_ENABLED_IF(!IsDynamicDim)
248  inline typename VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
249  {
250  return VectorParamNdofType::Zero();
251  }
258  TOMOGRAPHER_ENABLED_IF(IsDynamicDim)
259  inline typename VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
260  {
261  return VectorParamNdofType::Zero(ndof());
262  }
263 
264 
265 private:
267 };
268 
269 
270 
271 
272 
273 } // namespace DenseDM
274 } // namespace Tomographer
275 
276 
277 
278 
279 
280 
281 
282 
283 #endif
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
Definition: cxxutil.h:62
std::size_t dim2() const
get the square of the dimension of the quantum system
Definition: dmtypes.h:189
Eigen::Matrix< RealScalar, FixedDim2, 1 > VectorParamType
Real vector with dim*dim elements.
Definition: dmtypes.h:138
Base namespace for the Tomographer project.
Definition: densellh.h:45
std::complex< RealScalar > ComplexScalar
The corresponding complex scalar type.
Definition: dmtypes.h:122
const Eigen::Ref< const MatrixType > & MatrixTypeConstRef
Shorthand for a const reference to a MatrixType-like Eigen object.
Definition: dmtypes.h:135
STL class.
Eigen::Matrix< RealScalar, FixedNdof, 1 > VectorParamNdofType
Real vector with dim*dim-1 elements.
Definition: dmtypes.h:147
static ComplexScalar cplx(RealScalar a, RealScalar b)
Utility to initialize a complex number using the current scalar type.
Definition: dmtypes.h:125
VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
Zero initializer for a VectorParamNdofType [implementation for static dimension]. ...
Definition: dmtypes.h:248
static constexpr int FixedDim2
The square of the dimension of the quantum system, or Eigen::Dynamic.
Definition: dmtypes.h:113
static constexpr bool IsDynamicDim
Whether the dimension is specified dynamically at run-time or statically at compile-time.
Definition: dmtypes.h:109
static constexpr int FixedDim
The fixed dimension of the quantum system, or Eigen::Dynamic.
Definition: dmtypes.h:111
Some C++ utilities, with a tad of C++11 tricks.
std::size_t ndof() const
get the square of the dimension of the quantum system, minus one
Definition: dmtypes.h:196
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:133
const Eigen::Ref< const VectorParamType > & VectorParamTypeConstRef
Shorthand for a const reference to a VectorParamType-like Eigen object.
Definition: dmtypes.h:140
static constexpr int FixedNdof
The square of the dimension of the quantum system minus one, or Eigen::Dynamic.
Definition: dmtypes.h:117
MatrixType::ConstantReturnType initMatrixType() const
Zero initializer for a MatrixType [implementation for static dimension].
Definition: dmtypes.h:205
C++ types needed to store a quantum state as a dense matrix.
Definition: dmtypes.h:100
DMTypes(std::size_t d)
Constructor [works for both static or dynamic dim].
Definition: dmtypes.h:170
std::size_t dim() const
get the dimension of the quantum system (dimension of the Hilbert space)
Definition: dmtypes.h:181
const Eigen::Ref< const VectorParamNdofType > & VectorParamNdofTypeConstRef
Shorthand for a const reference to a VectorParamNdofType-like Eigen object.
Definition: dmtypes.h:149
T value() const
Get the value stored.
Definition: cxxutil.h:189
VectorParamType::ConstantReturnType initVectorParamType() const
Zero initializer for a VectorParamType [implementation for static dimension].
Definition: dmtypes.h:226
RealScalar_ RealScalar
Real scalar type, given in template parameter. Usually double is fine.
Definition: dmtypes.h:120