1 #include <catch2/catch_all.hpp>
13 auto constexpr
N = 10;
15 SECTION(
"Functions") {
16 auto direct = [](
t_Vector &out,
t_Vector const &input) { out = input * 2 - 1; };
17 auto indirect = [](
t_Vector &out,
t_Vector const &input) { out = input * 4 - 1; };
18 t_Vector const x = t_Vector::Random(2 *
N) * 5;
20 auto op = sopt::linear_transform<t_Vector>(direct, indirect);
22 CHECK((op * x).eval().
cols() == x.cols());
23 CHECK((op * x).eval().
rows() == x.rows());
24 CHECK((op * x).
cols() == x.cols());
25 CHECK((op * x).
rows() == x.rows());
26 CHECK((op * x).matrix() == (2 * x - 1).matrix());
27 CHECK((op.adjoint() * x).matrix() == (4 * x - 1).matrix());
32 t_Vector const x = t_Vector::Random(
N) * 5;
36 CHECK((op * x.matrix()).eval().cols() == x.cols());
37 CHECK((op * x.matrix()).eval().rows() == x.rows());
38 CHECK((op * x.matrix()).cols() == x.cols());
39 CHECK((op * x.matrix()).rows() == x.rows());
40 CHECK(op * x.matrix() == L.matrix() * x.matrix());
41 CHECK(op.adjoint() * x.matrix() == L.conjugate().transpose().matrix() * x.matrix());
44 SECTION(
"Rectangular matrix") {
46 t_Vector const x = t_Vector::Random(2 *
N) * 5;
50 CHECK((op * x.matrix()).eval().cols() == 1);
51 CHECK((op * x.matrix()).eval().rows() ==
N);
52 CHECK((op * x.matrix()).cols() == 1);
53 CHECK((op * x.matrix()).rows() ==
N);
54 CHECK(op * x.matrix() == L.matrix() * x.matrix());
55 CHECK(op.adjoint() * x.head(
N).matrix() ==
56 L.conjugate().transpose().matrix() * x.head(
N).matrix());
67 auto constexpr
N = 10;
68 t_Vector const x = t_Vector::Random(
N) * 5;
69 std::vector<t_Matrix> Ls{t_Matrix::Random(
N,
N), t_Matrix::Random(
N,
N)};
70 std::vector<LinearTransform<t_Vector>> ops;
71 ops.reserve(Ls.size());
74 for (decltype(Ls)::size_type i(0); i < ops.size(); ++i) {
75 CHECK(ops[i] * x == Ls[i] * x);
76 CHECK(ops[i].adjoint() * x == Ls[i].conjugate().transpose() * x);
sopt::Vector< Scalar > t_Vector
sopt::Matrix< Scalar > t_Matrix
LinearTransform< VECTOR > linear_transform(OperatorFunction< VECTOR > const &direct, OperatorFunction< VECTOR > const &indirect, std::array< t_int, 3 > const &sizes={{1, 1, 0}})
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
Eigen::Array< T, Eigen::Dynamic, 1 > Array
A 1-dimensional list of elements of given type.
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A matrix of a given type.