Tomographer  v1.0a
Tomographer C++ Framework Documentation
matrq.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 _MATRQ_H
28 #define _MATRQ_H
29 
30 #include <cstddef> // std::size_t
31 #include <complex>
32 
33 #include <Eigen/Core>
34 
35 
44 namespace Tomographer {
45 
46 
47 
48 template<int FixedDim_ = Eigen::Dynamic, int FixedMaxParamList_ = Eigen::Dynamic,
49  typename RealScalar_ = double, typename IntFreqType_ = int> struct MatrQ;
50 
51 namespace tomo_internal
52 {
54  template<typename Derived>
55  struct matrq_traits { };
56 
65  template<int FixedDim_, int FixedMaxParamList_,
66  typename RealScalar_, typename IntFreqType_>
67  struct matrq_traits<MatrQ<FixedDim_, FixedMaxParamList_, RealScalar_, IntFreqType_> >
68  {
70  enum {
73  FixedDim = FixedDim_,
77  FixedMaxParamList = FixedMaxParamList_
78  };
82  typedef RealScalar_ RealScalar;
86  typedef std::complex<RealScalar> ComplexScalar;
92  typedef IntFreqType_ IntFreqType;
93  };
94 
95 };
96 
97 
104 template<typename Derived>
105 struct MatrQBase
106 {
108  enum {
110  FixedDim = tomo_internal::matrq_traits<Derived>::FixedDim,
112  FixedDim2 = ((FixedDim!=Eigen::Dynamic) ? FixedDim*FixedDim : Eigen::Dynamic),
116  FixedNdof = ((FixedDim2!=Eigen::Dynamic) ? FixedDim2-1 : Eigen::Dynamic),
122  FixedMaxParamList = tomo_internal::matrq_traits<Derived>::FixedMaxParamList
123  };
125  typedef typename tomo_internal::matrq_traits<Derived>::RealScalar RealScalar;
127  typedef typename tomo_internal::matrq_traits<Derived>::ComplexScalar ComplexScalar;
129  typedef typename tomo_internal::matrq_traits<Derived>::IntFreqType IntFreqType;
130 
133 
136 
139 
143  typedef Eigen::Matrix<RealScalar, Eigen::Dynamic, FixedDim2, Eigen::RowMajor,
145 
148  typedef Eigen::Array<IntFreqType, Eigen::Dynamic, 1, 0 /*Options*/,
150 
151 };
152 
153 
170 template<typename Derived, bool has_fixed_dim>
171 struct MatrQBaseDimStore : public MatrQBase<Derived>
172 {
174  inline std::size_t dim() const { return MatrQBase<Derived>::FixedDim; }
176  inline std::size_t dim2() const { return MatrQBase<Derived>::FixedDim2; }
180  inline std::size_t ndof() const { return MatrQBase<Derived>::FixedNdof; }
181 
191  {
192  (void)dim_; // don't warn of unused variable if eigen_assert() gets optimized out
193 
194  // use eigen_assert() here for our test suite to check this without abort()ing.
195  eigen_assert(MatrQBase<Derived>::FixedDim != Eigen::Dynamic);
196  eigen_assert(dim_ == MatrQBase<Derived>::FixedDim);
197  }
198 
206  {
208  }
209 
217  {
219  }
220 
228  {
230  }
231 
239  {
242  }
243 
251  {
253  }
254 };
255 
260 template<typename Derived>
261 struct MatrQBaseDimStore<Derived, false> : public MatrQBase<Derived>
262 {
263 private:
265  const std::size_t _dim;
266 public:
267 
269  inline std::size_t dim() const { return _dim; }
271  inline std::size_t dim2() const { return _dim*_dim; }
275  inline std::size_t ndof() const { return _dim*_dim - 1; }
276 
282  : _dim(dim_)
283  {
284  eigen_assert(MatrQBase<Derived>::FixedDim == Eigen::Dynamic);
285  }
286 
291  {
292  return MatrQBase<Derived>::MatrixType::Zero(_dim, _dim);
293  }
298  {
300  }
305  {
307  }
313  {
314  return MatrQBase<Derived>::VectorParamListType::Zero(len, _dim*_dim);
315  }
320  {
322  }
323 };
324 
325 
326 
335 template<int FixedDim_, int FixedMaxParamList_, typename RealScalar_, typename IntFreqType_>
336 struct MatrQ
337  : public MatrQBaseDimStore<MatrQ<FixedDim_, FixedMaxParamList_, RealScalar_, IntFreqType_>,
338  FixedDim_ != Eigen::Dynamic>
339 {
348  : MatrQBaseDimStore<MatrQ<FixedDim_, FixedMaxParamList_, RealScalar_, IntFreqType_>,
349  FixedDim_ != Eigen::Dynamic>(dim_)
350  {
351  }
352 };
353 
354 
355 
365 
372 
373 
374 
375 } // namespace Tomographer
376 
377 
378 #endif
MatrQBase< Derived >::FreqListType::ConstantReturnType initFreqListType(std::size_t len) const
initializer for FreqListType. See MatrQBaseDimStore::initFreqListType() ...
Definition: matrq.h:319
MatrQBase< Derived >::VectorParamListType::ConstantReturnType initVectorParamListType(std::size_t len) const
initializer for VectorParamListType. See MatrQBaseDimStore::initVectorParamLis...
Definition: matrq.h:312
std::size_t dim2() const
The squared dimension of the quantum system. See MatrQBase::FixedDim2.
Definition: matrq.h:271
Eigen::Matrix< std::complex< RealScalar >, FixedDim, FixedDim > MatrixType
Complex dim x dim Matrix.
Definition: matrq.h:132
Defines the data types for a particular problem setting.
Definition: matrq.h:49
MatrQBase< Derived >::MatrixType::ConstantReturnType initMatrixType() const
initializer for MatrixType. See MatrQBaseDimStore::initMatrixType() ...
Definition: matrq.h:290
std::size_t ndof() const
The squared dimension of the quantum system, minus one. See MatrQBase::FixedNdof.
Definition: matrq.h:275
Base namespace for the Tomographer project.
Definition: dmmhrw.h:51
The square of the dimension of the quantum system, or Eigen::Dynamic.
Definition: matrq.h:112
Eigen::Matrix< RealScalar, FixedNdof, 1 > VectorParamNdofType
Real dim*dim-1 Vector.
Definition: matrq.h:138
MatrQBase< Derived >::VectorParamType::ConstantReturnType initVectorParamType() const
Zero initializer for a VectorParamType.
Definition: matrq.h:216
STL class.
MatrQBaseDimStore(std::size_t dim_)
Definition: matrq.h:190
Eigen::Array< IntFreqType, Eigen::Dynamic, 1, 0, FixedMaxParamList, 1 > FreqListType
dynamic Array of integers [maximum FixedMaxParamList entries or Dynamic]
Definition: matrq.h:149
Helper intermediate class for MatrQ.
Definition: matrq.h:171
std::size_t ndof() const
The squared dimension of the quantum system, minus one. See MatrQBase::FixedNdof.
Definition: matrq.h:180
MatrQBaseDimStore(std::size_t dim_)
Constructor, initialized to the given dimension.
Definition: matrq.h:281
std::size_t dim() const
The dimension of the quantum system. See MatrQBase::FixedDim.
Definition: matrq.h:174
MatrQBase< Derived >::VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
Zero initializer for a VectorParamNdofType.
Definition: matrq.h:227
tomo_internal::matrq_traits< Derived >::RealScalar RealScalar
Real scalar type (usually double)
Definition: matrq.h:125
MatrQBase< Derived >::MatrixType::ConstantReturnType initMatrixType() const
Zero initializer for a MatrixType.
Definition: matrq.h:205
MatrQBase< Derived >::VectorParamNdofType::ConstantReturnType initVectorParamNdofType() const
initializer for VectorParamNdofType. See MatrQBaseDimStore::initVectorParamNdo...
Definition: matrq.h:304
The dimension of the quantum system, or Eigen::Dynamic.
Definition: matrq.h:110
std::size_t dim2() const
The squared dimension of the quantum system. See MatrQBase::FixedDim2.
Definition: matrq.h:176
Maximum number of matrices in a list of X Parameterization form, or Eigen::Dynamic.
Definition: matrq.h:122
Eigen::Matrix< RealScalar, Eigen::Dynamic, FixedDim2, Eigen::RowMajor, FixedMaxParamList, FixedDim2 > VectorParamListType
dynamic Matrix with rows = dim*dim Vectors (row-major) [maximum FixedMaxParamList rows...
Definition: matrq.h:144
tomo_internal::matrq_traits< Derived >::ComplexScalar ComplexScalar
Complex scalar type (usually std::complex)
Definition: matrq.h:127
tomo_internal::matrq_traits< Derived >::IntFreqType IntFreqType
Integer type, used to count measurement frequencies. (int is fine)
Definition: matrq.h:129
MatrQ(std::size_t dim_)
Constructs a data type storage and initializer of given dimension.
Definition: matrq.h:347
MatrQBase< Derived >::FreqListType::ConstantReturnType initFreqListType(std::size_t len) const
Zero initializer for a FreqListType.
Definition: matrq.h:250
The square of the dimension of the quantum system minus one, or Eigen::Dynamic.
Definition: matrq.h:116
MatrQ< Eigen::Dynamic, Eigen::Dynamic, double, int > DefaultMatrQ
Data types for all arguments set at run-time.
Definition: matrq.h:364
MatrQBase< Derived >::VectorParamListType::ConstantReturnType initVectorParamListType(std::size_t len) const
Zero initializer for a VectorParamListType.
Definition: matrq.h:238
std::size_t dim() const
The dimension of the quantum system. See MatrQBase::FixedDim.
Definition: matrq.h:269
Eigen::Matrix< RealScalar, FixedDim2, 1 > VectorParamType
Real dim*dim Vector.
Definition: matrq.h:135
MatrQ< 2, 6, double, int > QubitPaulisMatrQ
Data types for Pauli measurements on a single qubit.
Definition: matrq.h:371
RowMajor
Basic definitions for MatrQ.
Definition: matrq.h:105
MatrQBase< Derived >::VectorParamType::ConstantReturnType initVectorParamType() const
initializer for VectorParamType. See MatrQBaseDimStore::initVectorParamType() ...
Definition: matrq.h:297