alpaqa
conan-profiles
Nonconvex constrained optimization
Loading...
Searching...
No Matches
src
alpaqa
include
alpaqa
util
check-dim.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
alpaqa/config/config.hpp
>
4
#include <optional>
5
#include <stdexcept>
6
#include <string>
7
8
namespace
alpaqa::util
{
9
10
template
<
class
V>
11
void
check_dim_msg
(
const
V &v,
auto
sz, std::string msg) {
12
if
(v.size() != sz) {
13
msg +=
"\n(should be "
;
14
msg += std::to_string(sz);
15
msg +=
", got "
;
16
msg += std::to_string(v.size());
17
msg +=
")"
;
18
throw
std::invalid_argument(msg);
19
}
20
}
21
22
template
<
class
V>
23
void
check_dim_msg
(std::optional<V> &v,
auto
sz, std::string msg) {
24
if
(!v) {
25
v = V::Zero(sz);
26
}
else
if
(v->size() != sz) {
27
msg +=
"\n(should be "
;
28
msg += std::to_string(sz);
29
msg +=
", got "
;
30
msg += std::to_string(v->size());
31
msg +=
")"
;
32
throw
std::invalid_argument(msg);
33
}
34
}
35
36
template
<
class
V>
37
void
check_dim
(std::string name, V &&v,
auto
sz) {
38
name +=
": dimension mismatch"
;
39
check_dim_msg
(std::forward<V>(v), sz, name);
40
}
41
42
template
<
class
M>
43
void
check_dim_msg
(
const
M &m,
auto
rows,
auto
cols, std::string msg) {
44
if
(m.cols() != cols || m.rows() != rows) {
45
msg +=
"\n(should be "
;
46
msg += std::to_string(rows);
47
msg +=
"×"
;
48
msg += std::to_string(cols);
49
msg +=
", got "
;
50
msg += std::to_string(m.rows());
51
msg +=
"×"
;
52
msg += std::to_string(m.cols());
53
msg +=
")"
;
54
throw
std::invalid_argument(msg);
55
}
56
}
57
58
template
<
class
M>
59
void
check_dim
(std::string name, M &&m,
auto
rows,
auto
cols) {
60
name +=
": dimension mismatch"
;
61
check_dim_msg
(std::forward<M>(m), rows, cols, name);
62
}
63
64
}
// namespace alpaqa::util
config.hpp
alpaqa::util
Definition
check-dim.hpp:8
alpaqa::util::check_dim
void check_dim(std::string name, V &&v, auto sz)
Definition
check-dim.hpp:37
alpaqa::util::check_dim_msg
void check_dim_msg(const V &v, auto sz, std::string msg)
Definition
check-dim.hpp:11
Generated on
for alpaqa by
1.14.0