Line data Source code
1 : /** \file clGainOpt.cpp
2 : * \author Jared R. Males (jaredmales@gmail.com)
3 : * \brief clGainOpt specializations for pre-compiled boost brent minimization
4 : * \ingroup mxAO_files
5 : *
6 : */
7 :
8 : //***********************************************************************//
9 : // Copyright 2020 Jared R. Males (jaredmales@gmail.com)
10 : //
11 : // This file is part of mxlib.
12 : //
13 : // mxlib is free software: you can redistribute it and/or modify
14 : // it under the terms of the GNU General Public License as published by
15 : // the Free Software Foundation, either version 3 of the License, or
16 : // (at your option) any later version.
17 : //
18 : // mxlib is distributed in the hope that it will be useful,
19 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 : // GNU General Public License for more details.
22 : //
23 : // You should have received a copy of the GNU General Public License
24 : // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25 : //***********************************************************************//
26 :
27 : #include "ao/analysis/clGainOpt.hpp"
28 :
29 : #include <boost/math/tools/minima.hpp>
30 :
31 : #define aaaa
32 :
33 : namespace mx
34 : {
35 : namespace AO
36 : {
37 : namespace analysis
38 : {
39 : namespace impl
40 : {
41 :
42 : template <typename realT>
43 125 : mx::error_t _optGainOpenLoop( realT &gain,
44 : realT &var,
45 : clGainOptOptGain_OL<realT> &olgo,
46 : const realT &minimumGain,
47 : const realT &maximumGain,
48 : int minFindBits,
49 : uintmax_t minFindMaxIter,
50 : uintmax_t &iters )
51 : {
52 125 : gain = std::numeric_limits<realT>::quiet_NaN();
53 125 : var = std::numeric_limits<realT>::quiet_NaN();
54 125 : iters = minFindMaxIter;
55 :
56 : try
57 : {
58 125 : std::pair<realT, realT> brack;
59 125 : brack = boost::math::tools::brent_find_minima<clGainOptOptGain_OL<realT>, realT>( olgo,
60 : minimumGain,
61 : maximumGain,
62 : minFindBits,
63 : iters );
64 125 : gain = brack.first;
65 125 : var = brack.second;
66 : }
67 0 : catch( ... )
68 : {
69 0 : return error_t::exception;
70 : }
71 :
72 125 : if( iters >= minFindMaxIter )
73 : {
74 1 : return error_t::timeout;
75 : }
76 :
77 124 : return error_t::noerror;
78 : }
79 :
80 : template <>
81 0 : mx::error_t optGainOpenLoop<float>( float &gain,
82 : float &var,
83 : clGainOptOptGain_OL<float> &olgo,
84 : const float &minimumGain,
85 : const float &maximumGain,
86 : int minFindBits,
87 : uintmax_t minFindMaxIter,
88 : uintmax_t &iters )
89 : {
90 0 : return _optGainOpenLoop<float>( gain, var, olgo, minimumGain, maximumGain, minFindBits, minFindMaxIter, iters );
91 : }
92 :
93 : template <>
94 125 : mx::error_t optGainOpenLoop<double>( double &gain,
95 : double &var,
96 : clGainOptOptGain_OL<double> &olgo,
97 : const double &minimumGain,
98 : const double &maximumGain,
99 : int minFindBits,
100 : uintmax_t minFindMaxIter,
101 : uintmax_t &iters )
102 : {
103 125 : return _optGainOpenLoop<double>( gain, var, olgo, minimumGain, maximumGain, minFindBits, minFindMaxIter, iters );
104 : }
105 :
106 : template <>
107 0 : mx::error_t optGainOpenLoop<long double>( long double &gain,
108 : long double &var,
109 : clGainOptOptGain_OL<long double> &olgo,
110 : const long double &minimumGain,
111 : const long double &maximumGain,
112 : int minFindBits,
113 : uintmax_t minFindMaxIter,
114 : uintmax_t &iters )
115 : {
116 0 : return _optGainOpenLoop<long double>( gain,
117 : var,
118 : olgo,
119 : minimumGain,
120 : maximumGain,
121 : minFindBits,
122 : minFindMaxIter,
123 0 : iters );
124 : }
125 :
126 : #ifdef HASQUAD
127 : template <>
128 : mx::error_t optGainOpenLoop<__float128>( __float128 &gain,
129 : __float128 &var,
130 : clGainOptOptGain_OL<__float128> &olgo,
131 : const __float128 &minimumGain,
132 : const __float128 &maximumGain,
133 : int minFindBits,
134 : uintmax_t minFindMaxIter,
135 : uintmax_t &iters )
136 : {
137 : return _optGainOpenLoop<__float128>( gain,
138 : var,
139 : olgo,
140 : minimumGain,
141 : maximumGain,
142 : minFindBits,
143 : minFindMaxIter,
144 : iters );
145 : }
146 : #endif
147 :
148 : } // namespace impl
149 :
150 : // Explicit Instantiation
151 : template class clGainOpt<float>;
152 :
153 : template class clGainOpt<double>;
154 :
155 : template class clGainOpt<long double>;
156 :
157 : #ifdef HASQUAD
158 : template class clGainOpt<__float128>;
159 : #endif
160 :
161 : } // namespace analysis
162 : } // namespace AO
163 : } // namespace mx
|