File: l1_proximal.cc

package info (click to toggle)
sopt 3.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,604 kB
  • sloc: cpp: 11,137; xml: 182; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 1,335 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <sstream>
#include <benchmark/benchmark.h>
#include <sopt/l1_proximal.h>
#include <sopt/real_type.h>
#include <sopt/types.h>

template <class TYPE>
void function_l1p(benchmark::State &state) {
  typedef typename sopt::real_type<TYPE>::type Real;
  auto const N = state.range_x();
  auto const input = sopt::Vector<TYPE>::Random(N).eval();
  auto const Psi = sopt::Matrix<TYPE>::Random(input.size(), input.size() * 10).eval();
  sopt::Vector<Real> const weights =
      sopt::Vector<TYPE>::Random(Psi.cols()).normalized().array().abs();

  auto const l1 = sopt::proximal::L1<TYPE>()
                      .tolerance(std::pow(10, -state.range_y()))
                      .itermax(100)
                      .fista_mixing(true)
                      .positivity_constraint(true)
                      .nu(1)
                      .Psi(Psi)
                      .weights(weights);

  Real const gamma = 1e-2 / Psi.array().abs().sum();
  auto output = sopt::Vector<TYPE>::Zero(N).eval();
  while (state.KeepRunning()) l1(output, gamma, input);
  state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(N) * sizeof(TYPE));
}

BENCHMARK_TEMPLATE(function_l1p, sopt::t_complex)->RangePair(1, 256, 4, 12)->UseRealTime();
BENCHMARK_TEMPLATE(function_l1p, sopt::t_real)->RangePair(1, 256, 4, 12)->UseRealTime();

BENCHMARK_MAIN()