| 20 | namespace embedx { |
| 21 | |
| 22 | class AliasSampling : public Sampling { |
| 23 | private: |
| 24 | vec_float_t alias_probs_; |
| 25 | vec_int_t alias_tables_; |
| 26 | |
| 27 | public: |
| 28 | static std::unique_ptr<Sampling> Create(const vec_float_t& probs); |
| 29 | |
| 30 | public: |
| 31 | int_t Next() const noexcept override; |
| 32 | int_t Next(int begin, int end) const noexcept override; |
| 33 | |
| 34 | private: |
| 35 | // Always return true. |
| 36 | bool Init(const vec_float_t& probs); |
| 37 | |
| 38 | void Clear() noexcept { |
| 39 | alias_probs_.clear(); |
| 40 | alias_tables_.clear(); |
| 41 | } |
| 42 | |
| 43 | void Resize(size_t size) { |
| 44 | alias_probs_.resize(size, 0); |
| 45 | alias_tables_.resize(size, 0); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | std::unique_ptr<Sampling> AliasSampling::Create(const vec_float_t& probs) { |
| 50 | std::unique_ptr<Sampling> sampling(new AliasSampling); |
nothing calls this directly
no outgoing calls
no test coverage detected