File: SylvParams.cc

package info (click to toggle)
dynare 4.6.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 74,896 kB
  • sloc: cpp: 98,057; ansic: 28,929; pascal: 13,844; sh: 5,947; objc: 4,236; yacc: 4,215; makefile: 2,583; lex: 1,534; fortran: 877; python: 647; ruby: 291; lisp: 152; xml: 22
file content (227 lines) | stat: -rw-r--r-- 8,660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
 * Copyright © 2004-2011 Ondra Kamenik
 * Copyright © 2019 Dynare Team
 *
 * This file is part of Dynare.
 *
 * Dynare is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dynare is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "SylvParams.hh"

#include <iostream>

void
SylvParams::print(const std::string &prefix) const
{
  print(std::cout, prefix);
}

void
SylvParams::print(std::ostream &fdesc, const std::string &prefix) const
{
  method.print(fdesc, prefix,     "method             ");
  rcondA1.print(fdesc, prefix,    "reci. cond1 A      ");
  rcondAI.print(fdesc, prefix,  u8"reci. cond∞ A      ");
  bs_norm.print(fdesc, prefix,  u8"log₁₀ diag norm    ");
  f_err1.print(fdesc, prefix,     "abs. err 1 F diag  ");
  f_errI.print(fdesc, prefix,   u8"abs. err ∞ F diag  ");
  viv_err1.print(fdesc, prefix, u8"abs. err 1 V·V⁻¹   ");
  viv_errI.print(fdesc, prefix, u8"abs. err ∞ V·V⁻¹   ");
  ivv_err1.print(fdesc, prefix, u8"abs. err 1 V⁻¹·V   ");
  ivv_errI.print(fdesc, prefix, u8"abs. err ∞ V⁻¹·V   ");
  f_blocks.print(fdesc, prefix,   "num blocks in F    ");
  f_largest.print(fdesc, prefix,  "largest block in F ");
  f_zeros.print(fdesc, prefix,    "num zeros in F     ");
  f_offdiag.print(fdesc, prefix,  "num offdiag in F   ");
  if (*method == solve_method::iter)
    {
      converged.print(fdesc, prefix,       "converged          ");
      convergence_tol.print(fdesc, prefix, "convergence tol.   ");
      iter_last_norm.print(fdesc, prefix,  "last norm          ");
      max_num_iter.print(fdesc, prefix,    "max num iter       ");
      num_iter.print(fdesc, prefix,        "num iter           ");
    }
  else
    eig_min.print(fdesc, prefix,         "minimum eigenvalue ");

  mat_err1.print(fdesc, prefix,   "rel. matrix norm1  ");
  mat_errI.print(fdesc, prefix, u8"rel. matrix norm∞  ");
  mat_errF.print(fdesc, prefix,   "rel. matrix normFro");
  vec_err1.print(fdesc, prefix,   "rel. vector norm1  ");
  vec_errI.print(fdesc, prefix, u8"rel. vector norm∞  ");
  cpu_time.print(fdesc, prefix,   "time (CPU secs)    ");
}

void
SylvParams::setArrayNames(int &num, const char **names) const
{
  num = 0;
  if (method.getStatus() != status::undef)
    names[num++] = "method";
  if (convergence_tol.getStatus() != status::undef)
    names[num++] = "convergence_tol";
  if (max_num_iter.getStatus() != status::undef)
    names[num++] = "max_num_iter";
  if (bs_norm.getStatus() != status::undef)
    names[num++] = "bs_norm";
  if (converged.getStatus() != status::undef)
    names[num++] = "converged";
  if (iter_last_norm.getStatus() != status::undef)
    names[num++] = "iter_last_norm";
  if (num_iter.getStatus() != status::undef)
    names[num++] = "num_iter";
  if (f_err1.getStatus() != status::undef)
    names[num++] = "f_err1";
  if (f_errI.getStatus() != status::undef)
    names[num++] = "f_errI";
  if (viv_err1.getStatus() != status::undef)
    names[num++] = "viv_err1";
  if (viv_errI.getStatus() != status::undef)
    names[num++] = "viv_errI";
  if (ivv_err1.getStatus() != status::undef)
    names[num++] = "ivv_err1";
  if (ivv_errI.getStatus() != status::undef)
    names[num++] = "ivv_errI";
  if (f_blocks.getStatus() != status::undef)
    names[num++] = "f_blocks";
  if (f_largest.getStatus() != status::undef)
    names[num++] = "f_largest";
  if (f_zeros.getStatus() != status::undef)
    names[num++] = "f_zeros";
  if (f_offdiag.getStatus() != status::undef)
    names[num++] = "f_offdiag";
  if (rcondA1.getStatus() != status::undef)
    names[num++] = "rcondA1";
  if (rcondAI.getStatus() != status::undef)
    names[num++] = "rcondAI";
  if (eig_min.getStatus() != status::undef)
    names[num++] = "eig_min";
  if (mat_err1.getStatus() != status::undef)
    names[num++] = "mat_err1";
  if (mat_errI.getStatus() != status::undef)
    names[num++] = "mat_errI";
  if (mat_errF.getStatus() != status::undef)
    names[num++] = "mat_errF";
  if (vec_err1.getStatus() != status::undef)
    names[num++] = "vec_err1";
  if (vec_errI.getStatus() != status::undef)
    names[num++] = "vec_errI";
  if (cpu_time.getStatus() != status::undef)
    names[num++] = "cpu_time";
}

#if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
mxArray *
SylvParams::DoubleParamItem::createMatlabArray() const
{
  return mxCreateDoubleScalar(value);
}

mxArray *
SylvParams::IntParamItem::createMatlabArray() const
{
  mxArray *res = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
# if MX_HAS_INTERLEAVED_COMPLEX
  *mxGetInt32s(res) = value;
# else
  *static_cast<int *>(mxGetData(res)) = value;
# endif
  return res;
}

mxArray *
SylvParams::BoolParamItem::createMatlabArray() const
{
  if (value)
    return mxCreateString("true");
  else
    return mxCreateString("false");
}

mxArray *
SylvParams::MethodParamItem::createMatlabArray() const
{
  if (value == solve_method::iter)
    return mxCreateString("iterative");
  else
    return mxCreateString("recursive");
}

mxArray *
SylvParams::createStructArray() const
{
  const char *names[50];
  int num;
  setArrayNames(num, names);
  const mwSize dims[] = {1, 1};
  mxArray *const res = mxCreateStructArray(2, dims, num, names);

  int i = 0;
  if (method.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, method.createMatlabArray());
  if (convergence_tol.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, convergence_tol.createMatlabArray());
  if (max_num_iter.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, max_num_iter.createMatlabArray());
  if (bs_norm.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, bs_norm.createMatlabArray());
  if (converged.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, converged.createMatlabArray());
  if (iter_last_norm.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, iter_last_norm.createMatlabArray());
  if (num_iter.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, num_iter.createMatlabArray());
  if (f_err1.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, f_err1.createMatlabArray());
  if (f_errI.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, f_errI.createMatlabArray());
  if (viv_err1.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, viv_err1.createMatlabArray());
  if (viv_errI.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, viv_errI.createMatlabArray());
  if (ivv_err1.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, ivv_err1.createMatlabArray());
  if (ivv_errI.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, ivv_errI.createMatlabArray());
  if (f_blocks.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, f_blocks.createMatlabArray());
  if (f_largest.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, f_largest.createMatlabArray());
  if (f_zeros.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, f_zeros.createMatlabArray());
  if (f_offdiag.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, f_offdiag.createMatlabArray());
  if (rcondA1.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, rcondA1.createMatlabArray());
  if (rcondAI.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, rcondAI.createMatlabArray());
  if (eig_min.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, eig_min.createMatlabArray());
  if (mat_err1.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, mat_err1.createMatlabArray());
  if (mat_errI.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, mat_errI.createMatlabArray());
  if (mat_errF.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, mat_errF.createMatlabArray());
  if (vec_err1.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, vec_err1.createMatlabArray());
  if (vec_errI.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, vec_errI.createMatlabArray());
  if (cpu_time.getStatus() != status::undef)
    mxSetFieldByNumber(res, 0, i++, cpu_time.createMatlabArray());

  return res;
}
#endif