1 #ifndef SOPT_SAMPLING_H
2 #define SOPT_SAMPLING_H
4 #include "sopt/config.h"
5 #include <initializer_list>
22 template <
typename RNG>
26 :
Sampling(size, samples, std::mt19937_64(std::random_device()())) {}
29 template <
typename T0,
typename T1>
30 void operator()(Eigen::DenseBase<T0> &out, Eigen::DenseBase<T1>
const &x)
const;
32 template <
typename T0,
typename T1>
33 void operator()(Eigen::DenseBase<T0> &&out, Eigen::DenseBase<T1>
const &x)
const {
37 template <
typename T0,
typename T1>
38 void adjoint(Eigen::DenseBase<T0> &out, Eigen::DenseBase<T1>
const &x)
const;
40 template <
typename T0,
typename T1>
41 void adjoint(Eigen::DenseBase<T0> &&out, Eigen::DenseBase<T1>
const &x)
const {
51 std::vector<t_uint>
const &
indices()
const {
return indices_; }
55 std::vector<t_uint> indices_;
60 template <
typename T0,
typename T1>
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]];
69 template <
typename T0,
typename T1>
71 assert(
static_cast<t_uint>(x.size()) == indices_.size());
72 out.resize(out.size());
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];
83 return linear_transform<Vector<T>>(
85 {{0, 1,
static_cast<t_int>(sampling.
rows())}},
87 {{0, 1,
static_cast<t_int>(sampling.
cols())}});
90 template <
typename RNG>
92 std::iota(indices_.begin(), indices_.end(), 0);
93 std::shuffle(indices_.begin(), indices_.end(), rng);
94 indices_.resize(samples);
An operator that samples a set of measurements.
Sampling(t_uint size, std::vector< t_uint > const &indices)
Constructs from a vector.
Sampling(t_uint size, t_uint samples)
Constructs from the size and the number of samples to pick.
void adjoint(Eigen::DenseBase< T0 > &&out, Eigen::DenseBase< T1 > const &x) const
void adjoint(Eigen::DenseBase< T0 > &out, Eigen::DenseBase< T1 > const &x) const
void operator()(Eigen::DenseBase< T0 > &&out, Eigen::DenseBase< T1 > const &x) const
t_uint rows() const
Number of measurements.
void operator()(Eigen::DenseBase< T0 > &out, Eigen::DenseBase< T1 > const &x) const
std::vector< t_uint > const & indices() const
Indices of sampled points.
t_uint cols() const
Size of the vector returned by the adjoint operation.
LinearTransform< VECTOR > linear_transform(OperatorFunction< VECTOR > const &direct, OperatorFunction< VECTOR > const &indirect, std::array< t_int, 3 > const &sizes={{1, 1, 0}})
int t_int
Root of the type hierarchy for signed integers.
size_t t_uint
Root of the type hierarchy for unsigned integers.
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.