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

An operator that samples a set of measurements. More...

#include <sampling.h>

Public Member Functions

 Sampling (t_uint size, std::vector< t_uint > const &indices)
 Constructs from a vector. More...
 
template<typename RNG >
 Sampling (t_uint size, t_uint samples, RNG &&rng)
 Constructs from the size and the number of samples to pick. More...
 
 Sampling (t_uint size, t_uint samples)
 Constructs from the size and the number of samples to pick. More...
 
template<typename T0 , typename T1 >
void operator() (Eigen::DenseBase< T0 > &out, Eigen::DenseBase< T1 > const &x) const
 
template<typename T0 , typename T1 >
void operator() (Eigen::DenseBase< T0 > &&out, Eigen::DenseBase< T1 > const &x) const
 
template<typename T0 , typename T1 >
void adjoint (Eigen::DenseBase< T0 > &out, Eigen::DenseBase< T1 > const &x) const
 
template<typename T0 , typename T1 >
void adjoint (Eigen::DenseBase< T0 > &&out, Eigen::DenseBase< T1 > const &x) const
 
t_uint cols () const
 Size of the vector returned by the adjoint operation. More...
 
t_uint rows () const
 Number of measurements. More...
 
std::vector< t_uint > const & indices () const
 Indices of sampled points. More...
 

Detailed Description

An operator that samples a set of measurements.

Picks some elements from a vector

Definition at line 17 of file sampling.h.

Constructor & Destructor Documentation

◆ Sampling() [1/3]

sopt::Sampling::Sampling ( t_uint  size,
std::vector< t_uint > const &  indices 
)
inline

Constructs from a vector.

Definition at line 20 of file sampling.h.

20 : indices_(indices), size(size) {}
std::vector< t_uint > const & indices() const
Indices of sampled points.
Definition: sampling.h:51

◆ Sampling() [2/3]

template<typename RNG >
sopt::Sampling::Sampling ( t_uint  size,
t_uint  samples,
RNG &&  rng 
)

Constructs from the size and the number of samples to pick.

Definition at line 91 of file sampling.h.

91  : indices_(size), size(size) {
92  std::iota(indices_.begin(), indices_.end(), 0);
93  std::shuffle(indices_.begin(), indices_.end(), rng);
94  indices_.resize(samples);
95 }

◆ Sampling() [3/3]

sopt::Sampling::Sampling ( t_uint  size,
t_uint  samples 
)
inline

Constructs from the size and the number of samples to pick.

Definition at line 25 of file sampling.h.

26  : Sampling(size, samples, std::mt19937_64(std::random_device()())) {}
Sampling(t_uint size, std::vector< t_uint > const &indices)
Constructs from a vector.
Definition: sampling.h:20

Member Function Documentation

◆ adjoint() [1/2]

template<typename T0 , typename T1 >
void sopt::Sampling::adjoint ( Eigen::DenseBase< T0 > &&  out,
Eigen::DenseBase< T1 > const &  x 
) const
inline

Definition at line 41 of file sampling.h.

41  {
42  adjoint(out, x);
43  }
void adjoint(Eigen::DenseBase< T0 > &out, Eigen::DenseBase< T1 > const &x) const
Definition: sampling.h:70

References adjoint().

◆ adjoint() [2/2]

template<typename T0 , typename T1 >
void sopt::Sampling::adjoint ( Eigen::DenseBase< T0 > &  out,
Eigen::DenseBase< T1 > const &  x 
) const

Definition at line 70 of file sampling.h.

70  {
71  assert(static_cast<t_uint>(x.size()) == indices_.size());
72  out.resize(out.size());
73  out.fill(0);
74  for (decltype(indices_.size()) i(0); i < indices_.size(); ++i) {
75  assert(indices_[i] < static_cast<t_uint>(out.size()));
76  out[indices_[i]] = x[i];
77  }
78 }
size_t t_uint
Root of the type hierarchy for unsigned integers.
Definition: types.h:15

Referenced by adjoint(), and sopt::linear_transform().

◆ cols()

t_uint sopt::Sampling::cols ( ) const
inline

Size of the vector returned by the adjoint operation.

Definition at line 46 of file sampling.h.

46 { return size; }

Referenced by sopt::linear_transform().

◆ indices()

std::vector<t_uint> const& sopt::Sampling::indices ( ) const
inline

Indices of sampled points.

Definition at line 51 of file sampling.h.

51 { return indices_; }

Referenced by TEST_CASE().

◆ operator()() [1/2]

template<typename T0 , typename T1 >
void sopt::Sampling::operator() ( Eigen::DenseBase< T0 > &&  out,
Eigen::DenseBase< T1 > const &  x 
) const
inline

Definition at line 33 of file sampling.h.

33  {
34  operator()(out, x);
35  }
void operator()(Eigen::DenseBase< T0 > &out, Eigen::DenseBase< T1 > const &x) const
Definition: sampling.h:61

References operator()().

◆ operator()() [2/2]

template<typename T0 , typename T1 >
void sopt::Sampling::operator() ( Eigen::DenseBase< T0 > &  out,
Eigen::DenseBase< T1 > const &  x 
) const

Definition at line 61 of file sampling.h.

61  {
62  out.resize(indices_.size());
63  for (decltype(indices_.size()) i(0); i < indices_.size(); ++i) {
64  assert(indices_[i] < static_cast<t_uint>(x.size()));
65  out[i] = x[indices_[i]];
66  }
67 }

Referenced by operator()().

◆ rows()

t_uint sopt::Sampling::rows ( ) const
inline

Number of measurements.

Definition at line 48 of file sampling.h.

48 { return indices_.size(); }

Referenced by sopt::linear_transform().


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