SOPT
Sparse OPTimisation
conjugate_gradient.cc
Go to the documentation of this file.
2 #include <sstream>
3 #include <benchmark/benchmark.h>
4 
5 template <typename TYPE>
6 void matrix_cg(benchmark::State &state) {
7  auto const N = state.range_x();
8  auto const epsilon = std::pow(10, -state.range_y());
9  auto const A = sopt::Image<TYPE>::Random(N, N).eval();
10  auto const b = sopt::Array<TYPE>::Random(N).eval();
11 
12  auto const AhA = A.matrix().transpose().conjugate() * A.matrix();
13  auto const Ahb = A.matrix().transpose().conjugate() * b.matrix();
14  auto output = sopt::Vector<TYPE>::Zero(N).eval();
16  while (state.KeepRunning()) cg(output, AhA, Ahb);
17  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(N) * sizeof(TYPE));
18 }
19 
20 template <typename TYPE>
21 void function_cg(benchmark::State &state) {
22  auto const N = state.range_x();
23  auto const epsilon = std::pow(10, -state.range_y());
24  auto const A = sopt::Image<TYPE>::Random(N, N).eval();
25  auto const b = sopt::Array<TYPE>::Random(N).eval();
26 
27  auto const AhA = A.matrix().transpose().conjugate() * A.matrix();
28  auto const Ahb = A.matrix().transpose().conjugate() * b.matrix();
30  auto func = [&AhA](t_Vector &out, t_Vector const &input) { out = AhA * input; };
31  auto output = sopt::Vector<TYPE>::Zero(N).eval();
33  while (state.KeepRunning()) cg(output, func, Ahb);
34  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(N) * sizeof(TYPE));
35 }
36 
37 BENCHMARK_TEMPLATE(matrix_cg, sopt::t_complex)->RangePair(1, 256, 4, 12)->UseRealTime();
38 BENCHMARK_TEMPLATE(matrix_cg, sopt::t_real)->RangePair(1, 256, 4, 12)->UseRealTime();
39 BENCHMARK_TEMPLATE(function_cg, sopt::t_complex)->RangePair(1, 256, 4, 12)->UseRealTime();
40 BENCHMARK_TEMPLATE(function_cg, sopt::t_real)->RangePair(1, 256, 4, 12)->UseRealTime();
41 
void function_cg(benchmark::State &state)
BENCHMARK_MAIN()
BENCHMARK_TEMPLATE(matrix_cg, sopt::t_complex) -> RangePair(1, 256, 4, 12) ->UseRealTime()
void matrix_cg(benchmark::State &state)
constexpr auto N
Definition: wavelets.cc:57
sopt::Vector< Scalar > t_Vector
constexpr Scalar b
Solves $Ax = b$ for $x$, given $A$ and $b$.
double t_real
Root of the type hierarchy for real numbers.
Definition: types.h:17
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
Definition: types.h:39
real_type< T >::type epsilon(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
Definition: inpainting.h:38
Eigen::Array< T, Eigen::Dynamic, 1 > Array
A 1-dimensional list of elements of given type.
Definition: types.h:34
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
Definition: types.h:24
std::complex< t_real > t_complex
Root of the type hierarchy for (real) complex numbers.
Definition: types.h:19