SOPT
Sparse OPTimisation
Public Member Functions | List of all members
sopt::wavelets::SARA Class Reference

Sparsity Averaging Reweighted Analysis. More...

#include <sara.h>

+ Inheritance diagram for sopt::wavelets::SARA:
+ Collaboration diagram for sopt::wavelets::SARA:

Public Member Functions

 SARA (std::initializer_list< std::tuple< std::string, t_uint >> const &init)
 Easy constructor. More...
 
template<typename ITERATOR , class T = typename std::enable_if< std::is_convertible<decltype(std::get<0>(*std::declval<ITERATOR>())), std::string>::value and std::is_convertible<decltype(std::get<1>(*std::declval<ITERATOR>())), t_uint>::value, ::type >
 SARA (ITERATOR first, ITERATOR last)
 Construct from any iterator over a (std:string, t_uint) tuple. More...
 
 SARA (const_iterator first, const_iterator last)
 
virtual ~SARA ()
 Destructor. More...
 
template<typename T0 >
T0::PlainObject direct (Eigen::ArrayBase< T0 > const &signal) const
 Direct transform. More...
 
template<typename T0 , typename T1 >
void direct (Eigen::ArrayBase< T1 > &coefficients, Eigen::ArrayBase< T0 > const &signal) const
 Direct transform. More...
 
template<typename T0 , typename T1 >
void direct (Eigen::ArrayBase< T1 > &&coefficients, Eigen::ArrayBase< T0 > const &signal) const
 Direct transform. More...
 
template<typename T0 >
T0::PlainObject indirect (Eigen::ArrayBase< T0 > const &coeffs) const
 Indirect transform. More...
 
template<typename T0 , typename T1 >
void indirect (Eigen::ArrayBase< T1 > const &coefficients, Eigen::ArrayBase< T0 > &signal) const
 Indirect transform. More...
 
template<typename T0 , typename T1 >
void indirect (Eigen::ArrayBase< T1 > const &coeffs, Eigen::ArrayBase< T0 > &&signal) const
 Indirect transform. More...
 
t_uint max_levels () const
 Number of levels over which to do transform. More...
 
void emplace_back (std::string const &name, t_uint nlevels)
 Adds a wavelet of specific type. More...
 

Detailed Description

Sparsity Averaging Reweighted Analysis.

Definition at line 20 of file sara.h.

Constructor & Destructor Documentation

◆ SARA() [1/3]

sopt::wavelets::SARA::SARA ( std::initializer_list< std::tuple< std::string, t_uint >> const &  init)
inline

Easy constructor.

Definition at line 30 of file sara.h.

31  : SARA(init.begin(), init.end()) {}
SARA(std::initializer_list< std::tuple< std::string, t_uint >> const &init)
Easy constructor.
Definition: sara.h:30
std::shared_ptr< details::initializer > init(int argc, const char **argv)
Definition: session.cc:27

◆ SARA() [2/3]

template<typename ITERATOR , class T = typename std::enable_if< std::is_convertible<decltype(std::get<0>(*std::declval<ITERATOR>())), std::string>::value and std::is_convertible<decltype(std::get<1>(*std::declval<ITERATOR>())), t_uint>::value, ::type >
sopt::wavelets::SARA::SARA ( ITERATOR  first,
ITERATOR  last 
)
inline

Construct from any iterator over a (std:string, t_uint) tuple.

Definition at line 39 of file sara.h.

39  {
40  for (; first != last; ++first) emplace_back(std::get<0>(*first), std::get<1>(*first));
41  }
void emplace_back(std::string const &name, t_uint nlevels)
Adds a wavelet of specific type.
Definition: sara.h:114

References emplace_back().

◆ SARA() [3/3]

sopt::wavelets::SARA::SARA ( const_iterator  first,
const_iterator  last 
)
inline

Definition at line 43 of file sara.h.

43 : std::vector<Wavelet>(first, last) {}

◆ ~SARA()

virtual sopt::wavelets::SARA::~SARA ( )
inlinevirtual

Destructor.

Definition at line 45 of file sara.h.

45 {}

Member Function Documentation

◆ direct() [1/3]

template<typename T0 >
T0::PlainObject sopt::wavelets::SARA::direct ( Eigen::ArrayBase< T0 > const &  signal) const

Direct transform.

Parameters
[in]signalcomputes wavelet coefficients for this signal. Its size must be a multiple of $2^l$ where $l$ is the maximum number of levels. Can be a matrix (2d-transform) or a column vector (1-d transform).
Returns
wavelets coefficients arranged by columns: if the input is n by m, then the output is n by m * d, with d the number of wavelets.

Supports 1 and 2 dimensional tranforms for real and complex data.

Definition at line 189 of file sara.h.

189  {
190  using t_Output = decltype(this->front().direct(signal));
191  t_Output result = t_Output::Zero(signal.rows(), signal.cols() * size());
192  (*this).direct(result, signal);
193  return result;
194 }
T0::PlainObject direct(Eigen::ArrayBase< T0 > const &signal) const
Direct transform.
Definition: sara.h:189

Referenced by direct().

◆ direct() [2/3]

template<typename T0 , typename T1 >
void sopt::wavelets::SARA::direct ( Eigen::ArrayBase< T1 > &&  coefficients,
Eigen::ArrayBase< T0 > const &  signal 
) const
inline

Direct transform.

Parameters
[in,out]coefficientsOutput wavelet coefficients. Must be of the type as the input. If the input is n by m, and l is the number of wavelets, then the output should be n by (m * l).
[in]signalcomputes wavelet coefficients for this signal. Its size must be a multiple of $2^l$ where $l$ is the number of levels. Can be a matrix (2d-transform) or a column vector (1-d transform).

Supports 1 and 2 dimensional tranforms for real and complex data. This version allows non-constant Eigen expressions to be passe on without the ugly const_cast of the cannonical approach.

Definition at line 77 of file sara.h.

77  {
78  direct(coefficients, signal);
79  }

References direct().

◆ direct() [3/3]

template<typename T0 , typename T1 >
void sopt::wavelets::SARA::direct ( Eigen::ArrayBase< T1 > &  coefficients,
Eigen::ArrayBase< T0 > const &  signal 
) const

Direct transform.

Parameters
[in,out]coefficientsOutput wavelet coefficients. Must be of the type as the input. If the input is n by m, and d is the number of wavelets, then the output should be n by (m * d).
[in]signalcomputes wavelet coefficients for this signal. Its size must be a multiple of $2^l$ where $l$ is the maximum number of levels. Can be a matrix (2d-transform) or a column vector (1-d transform).

Supports 1 and 2 dimensional tranforms for real and complex data.

Definition at line 126 of file sara.h.

126  {
127  SOPT_WAVELET_ERROR_MACRO(signal);
128  if (coeffs.rows() != signal.rows() or coeffs.cols() != signal.cols() * static_cast<t_int>(size()))
129  coeffs.derived().resize(signal.rows(), signal.cols() * size());
130  if (coeffs.rows() != signal.rows() or coeffs.cols() != signal.cols() * static_cast<t_int>(size()))
131  throw std::length_error("Incorrect size for output matrix(or could not resize)");
132  if (size() == 0) return;
133  auto const Ncols = signal.cols();
134  {
135 #ifndef SOPT_OPENMP
136  SOPT_TRACE("Calling direct sara without threads");
137 #endif
138  if (Ncols == 1)
139  for (size_type i = 0; i < size(); ++i) at(i).direct(coeffs.col(i), signal.col(0));
140  else
141  for (size_type i = 0; i < size(); ++i)
142  at(i).direct(coeffs.leftCols((i + 1) * Ncols).rightCols(Ncols), signal);
143  }
144 
145  coeffs /= std::sqrt(size());
146 }
#define SOPT_TRACE(...)
Definition: logging.h:220
int t_int
Root of the type hierarchy for signed integers.
Definition: types.h:13
#define SOPT_WAVELET_ERROR_MACRO(INPUT)
Definition: sara.h:119

References SOPT_TRACE, and SOPT_WAVELET_ERROR_MACRO.

◆ emplace_back()

void sopt::wavelets::SARA::emplace_back ( std::string const &  name,
t_uint  nlevels 
)
inline

Adds a wavelet of specific type.

Definition at line 114 of file sara.h.

114  {
115  std::vector<Wavelet>::emplace_back(factory(name, nlevels));
116  }
Wavelet factory(const std::string &name, t_uint nlevels)
Creates a wavelet transform object.
Definition: wavelets.cc:8

References sopt::wavelets::factory().

Referenced by main(), and SARA().

◆ indirect() [1/3]

template<typename T0 >
T0::PlainObject sopt::wavelets::SARA::indirect ( Eigen::ArrayBase< T0 > const &  coeffs) const

Indirect transform.

Parameters
[in]coefficientsInput wavelet coefficients. Its size must be a multiple of $2^l$ where $l$ is the number of levels. Can be a matrix (2d-transform) or a column vector (1-d transform).

Supports 1 and 2 dimensional tranforms for real and complex data.

Definition at line 181 of file sara.h.

181  {
182  using t_Output = decltype(this->front().indirect(coeffs));
183  t_Output signal = t_Output::Zero(coeffs.rows(), coeffs.cols() / size());
184  (*this).indirect(coeffs, signal);
185  return signal;
186 }
T0::PlainObject indirect(Eigen::ArrayBase< T0 > const &coeffs) const
Indirect transform.
Definition: sara.h:181

Referenced by indirect().

◆ indirect() [2/3]

template<typename T0 , typename T1 >
void sopt::wavelets::SARA::indirect ( Eigen::ArrayBase< T1 > const &  coefficients,
Eigen::ArrayBase< T0 > &  signal 
) const

Indirect transform.

Parameters
[in]coefficientsInput wavelet coefficients. Its size must be a multiple of $2^l$ where $l$ is the number of levels. Can be a matrix (2d-transform) or a column vector (1-d
[in,out]signalReconstructed signal. Must be of the same size and type as the input.

Supports 1 and 2 dimensional tranforms for real and complex data.

Definition at line 149 of file sara.h.

149  {
150  if (size() == 0) throw std::runtime_error("Empty wavelets: adjoint operation undefined");
151  if (signal.cols() == 1) {
152  if (coeffs.rows() % (1u << max_levels()) != 0)
153  throw std::length_error("Inconsistent number of columns and wavelet levels");
154  } else
155  SOPT_WAVELET_ERROR_MACRO(coeffs);
156  if (coeffs.cols() % size() != 0)
157  throw std::length_error(
158  "Columns of coefficient matrix and number of wavelets are inconsistent");
159  if (coeffs.rows() != signal.rows() or coeffs.cols() != signal.cols() * static_cast<t_int>(size()))
160  signal.derived().resize(coeffs.rows(), coeffs.cols() / size());
161  if (coeffs.rows() != signal.rows() or coeffs.cols() != signal.cols() * static_cast<t_int>(size()))
162  throw std::length_error("Incorrect size for output matrix(or could not resize)");
163  auto const Ncols = signal.cols();
164  {
165 #ifndef SOPT_OPENMP
166  SOPT_TRACE("Calling indirect sara without threads");
167 #endif
168  signal = T0::Zero(signal.rows(), signal.cols());
169  if (Ncols == 1)
170  for (size_type i = 0; i < size(); ++i) signal.col(0) += at(i).indirect(coeffs.col(i));
171  else
172  for (size_type i = 0; i < size(); ++i)
173  signal += at(i).indirect(coeffs.leftCols((i + 1) * Ncols).rightCols(Ncols));
174  }
175  signal /= std::sqrt(size());
176 }
t_uint max_levels() const
Number of levels over which to do transform.
Definition: sara.h:107

References max_levels(), SOPT_TRACE, and SOPT_WAVELET_ERROR_MACRO.

◆ indirect() [3/3]

template<typename T0 , typename T1 >
void sopt::wavelets::SARA::indirect ( Eigen::ArrayBase< T1 > const &  coeffs,
Eigen::ArrayBase< T0 > &&  signal 
) const
inline

Indirect transform.

Parameters
[in]coefficientsInput wavelet coefficients. Its size must be a multiple of $2^l$ where $l$ is the number of levels. Can be a matrix (2d-transform) or a column vector (1-d
[in,out]signalReconstructed signal. Must be of the same size and type as the input.

Supports 1 and 2 dimensional tranforms for real and complex data. This version allows non-constant Eigen expressions to be passe on without the ugly const_cast of the cannonical approach.

Definition at line 102 of file sara.h.

102  {
103  indirect(coeffs, signal);
104  }

References indirect().

◆ max_levels()

t_uint sopt::wavelets::SARA::max_levels ( ) const
inline

Number of levels over which to do transform.

Definition at line 107 of file sara.h.

107  {
108  if (size() == 0) return 0;
109  auto cmp = [](Wavelet const &a, Wavelet const &b) { return a.levels() < b.levels(); };
110  return std::max_element(begin(), end(), cmp)->levels();
111  }
constexpr Scalar b
constexpr Scalar a

References a, and b.

Referenced by indirect().


The documentation for this class was generated from the following file: