Tomographer  v5.2
Tomographer C++ Framework Documentation
pymhrw.h
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 TOMOGRAPHERPY_MHRW_H
29 #define TOMOGRAPHERPY_MHRW_H
30 
31 #include <string>
32 
33 #include <tomographerpy/common.h>
34 
35 #include <tomographer/mhrw.h>
36 //#include <tomographer/mhrwtasks.h>
37 
38 
39 namespace tpy {
40 
45 
46 
47 
62 template<typename MHWalkerParams>
63 struct TOMOGRAPHER_EXPORT PyMHWalkerParamsToDict
64 {
65  static inline py::dict makeDict(const MHWalkerParams & ) { return {}; }
66  static inline MHWalkerParams fromPyObj(py::object ) { return {}; }
67 };
69 template<typename StepRealType>
70 struct TOMOGRAPHER_EXPORT PyMHWalkerParamsToDict<Tomographer::MHWalkerParamsStepSize<StepRealType> >
71 {
72  static inline py::dict makeDict(const Tomographer::MHWalkerParamsStepSize<StepRealType> & p) {
73  return py::dict(py::arg("step_size") = p.step_size);
74  }
75  static Tomographer::MHWalkerParamsStepSize<tpy::RealType> fromPyObj(py::object d)
76  {
77  if ( d.is_none() ) {
78  // None: let the underlying mhwalker decide what to do with this
79  return 0;
80  }
81  if ( py::hasattr(d, "__getitem__") ) {
82  // dict or dict-like, go. If key doesn't exist, send in zero and let the underlying
83  // mhwalker handle it
84  return d.attr("get")("step_size", 0).cast<tpy::RealType>();
85  }
86  // try to iterpret the object itself as a float
87  return d.cast<tpy::RealType>();
88  }
89 };
90 
94 template<typename MHWalkerParams>
95 inline py::dict pyMHWalkerParamsToDictInvoke(const MHWalkerParams & p)
96 {
98 }
101 template<typename MHWalkerParams>
102 inline MHWalkerParams pyMHWalkerParamsFromPyObj(py::object o)
103 {
105 }
106 
107 
108 
109 
110 } // namespace Py
111 
112 
113 
114 #endif
Base namespace for the Tomographer project.
Definition: densellh.h:45
An MHWalkerParams type which just stores a step size.
Definition: mhrw.h:93
C++ utility to convert a Python dictionary of fields into a valid C++ MHWalkerParams object...
Definition: pymhrw.h:63
double RealType
Real type for template arguments (double)
Definition: common.h:90
Tomographer::MHRWParams< py::object, CountIntType > MHRWParams
The Tomographer::MHRWParams type exposed to Python (the MHWalkerParam can be represented by any Pytho...
Definition: pymhrw.h:44
py::dict pyMHWalkerParamsToDictInvoke(const MHWalkerParams &p)
Helper for converting any MHWalkerParams into a dictionary, using automatic template parameter deduct...
Definition: pymhrw.h:95
Specify the parameters of a Metropolis-Hastings random walk.
Definition: mhrw.h:120
Routines for performing a Metropolis-Hastings random walk.
C++ Classes and Utilities for Python Modules.
Definition: common.h:87
MHWalkerParams pyMHWalkerParamsFromPyObj(py::object o)
Helper for converting any Python object into a given MHWalkerParams.
Definition: pymhrw.h:102