mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-08-04 01:00:43 -05:00
refactor: reorganize the file structure (#1266)
This commit is contained in:
35
src/rng.hpp
Normal file
35
src/rng.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef __RNG_H__
|
||||
#define __RNG_H__
|
||||
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
class RNG {
|
||||
public:
|
||||
virtual void manual_seed(uint64_t seed) = 0;
|
||||
virtual std::vector<float> randn(uint32_t n) = 0;
|
||||
};
|
||||
|
||||
class STDDefaultRNG : public RNG {
|
||||
private:
|
||||
std::default_random_engine generator;
|
||||
|
||||
public:
|
||||
void manual_seed(uint64_t seed) override {
|
||||
generator.seed((unsigned int)seed);
|
||||
}
|
||||
|
||||
std::vector<float> randn(uint32_t n) override {
|
||||
std::vector<float> result;
|
||||
float mean = 0.0;
|
||||
float stddev = 1.0;
|
||||
std::normal_distribution<float> distribution(mean, stddev);
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
float random_number = distribution(generator);
|
||||
result.push_back(random_number);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __RNG_H__
|
||||
Reference in New Issue
Block a user