SOPT
Sparse OPTimisation
Functions
linear_transform.cc File Reference
#include <catch2/catch_all.hpp>
#include <complex>
#include <iomanip>
#include "sopt/linear_transform.h"
+ Include dependency graph for linear_transform.cc:

Go to the source code of this file.

Functions

 TEST_CASE ("Linear Transforms", "[ops]")
 
 TEST_CASE ("Array of Linear transforms", "[ops]")
 

Function Documentation

◆ TEST_CASE() [1/2]

TEST_CASE ( "Array of Linear transforms"  ,
""  [ops] 
)

Definition at line 60 of file linear_transform.cc.

60  {
61  using namespace sopt;
62 
63  using SCALAR = int;
64  using t_Vector = Vector<SCALAR>;
65  using t_Matrix = Matrix<SCALAR>;
66 
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());
72  for (auto const &matrix : Ls) ops.emplace_back(sopt::linear_transform(matrix));
73 
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);
77  }
78 }
constexpr auto N
Definition: wavelets.cc:57
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::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
Definition: types.h:24
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A matrix of a given type.
Definition: types.h:29

References sopt::linear_transform(), and N.

◆ TEST_CASE() [2/2]

TEST_CASE ( "Linear Transforms"  ,
""  [ops] 
)

Definition at line 7 of file linear_transform.cc.

7  {
8  using namespace sopt;
9 
10  using SCALAR = int;
11  using t_Vector = Array<SCALAR>;
12  using t_Matrix = Image<SCALAR>;
13  auto constexpr N = 10;
14 
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;
19 
20  auto op = sopt::linear_transform<t_Vector>(direct, indirect);
21 
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());
28  }
29 
30  SECTION("Matrix") {
31  t_Matrix const L = t_Matrix::Random(N, N);
32  t_Vector const x = t_Vector::Random(N) * 5;
33 
34  auto op = sopt::linear_transform(L.matrix());
35 
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());
42  }
43 
44  SECTION("Rectangular matrix") {
45  t_Matrix const L = t_Matrix::Random(N, 2 * N);
46  t_Vector const x = t_Vector::Random(2 * N) * 5;
47 
48  auto op = sopt::linear_transform(L.matrix());
49 
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());
57  }
58 }
t_uint rows
t_uint cols
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
Definition: types.h:39
Eigen::Array< T, Eigen::Dynamic, 1 > Array
A 1-dimensional list of elements of given type.
Definition: types.h:34

References cols, sopt::linear_transform(), N, and rows.