SOPT
Sparse OPTimisation
Functions
conjugate_gradient.cc File Reference
#include "sopt/conjugate_gradient.h"
#include <sstream>
#include <benchmark/benchmark.h>
+ Include dependency graph for conjugate_gradient.cc:

Go to the source code of this file.

Functions

template<typename TYPE >
void matrix_cg (benchmark::State &state)
 
template<typename TYPE >
void function_cg (benchmark::State &state)
 
 BENCHMARK_TEMPLATE (matrix_cg, sopt::t_complex) -> RangePair(1, 256, 4, 12) ->UseRealTime()
 
 BENCHMARK_TEMPLATE (matrix_cg, sopt::t_real) -> RangePair(1, 256, 4, 12) ->UseRealTime()
 
 BENCHMARK_TEMPLATE (function_cg, sopt::t_complex) -> RangePair(1, 256, 4, 12) ->UseRealTime()
 
 BENCHMARK_TEMPLATE (function_cg, sopt::t_real) -> RangePair(1, 256, 4, 12) ->UseRealTime()
 
 BENCHMARK_MAIN ()
 

Function Documentation

◆ BENCHMARK_MAIN()

BENCHMARK_MAIN ( )

◆ BENCHMARK_TEMPLATE() [1/4]

BENCHMARK_TEMPLATE ( function_cg  ,
sopt::t_complex   
) -> RangePair(1, 256, 4, 12) ->UseRealTime()

◆ BENCHMARK_TEMPLATE() [2/4]

BENCHMARK_TEMPLATE ( function_cg  ,
sopt::t_real   
) -> RangePair(1, 256, 4, 12) ->UseRealTime()

◆ BENCHMARK_TEMPLATE() [3/4]

BENCHMARK_TEMPLATE ( matrix_cg  ,
sopt::t_complex   
) -> RangePair(1, 256, 4, 12) ->UseRealTime()

◆ BENCHMARK_TEMPLATE() [4/4]

BENCHMARK_TEMPLATE ( matrix_cg  ,
sopt::t_real   
) -> RangePair(1, 256, 4, 12) ->UseRealTime()

◆ function_cg()

template<typename TYPE >
void function_cg ( benchmark::State &  state)

Definition at line 21 of file conjugate_gradient.cc.

21  {
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 }
constexpr auto N
Definition: wavelets.cc:57
sopt::Vector< Scalar > t_Vector
constexpr Scalar b
Solves $Ax = b$ for $x$, given $A$ and $b$.
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

References b, sopt::epsilon(), and N.

◆ matrix_cg()

template<typename TYPE >
void matrix_cg ( benchmark::State &  state)

Definition at line 6 of file conjugate_gradient.cc.

6  {
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 }

References b, sopt::epsilon(), and N.