I was forced to make a small addition to the default constructor of the Ranvec1 class. I couldn't use the provided init(int seed,...) ... functions to initialize with the desired seeds because I used it as a static thread_local object. So the seed initialization must happen in this case in the constructor. Is this something that could be changed in your repository and can be of any use in other projects?
#if defined(DNN_AVX512BW) || defined(DNN_AVX512)
typedef Vec16f VecFloat;
constexpr auto VectorSize = 16ull;
#elif defined(DNN_AVX2) || defined(DNN_AVX)
typedef Vec8f VecFloat;
constexpr auto VectorSize = 8ull;
#elif defined(DNN_SSE42) || defined(DNN_SSE41)
typedef Vec4f VecFloat;
constexpr auto VectorSize = 4ull;
#endif
inline static auto BernoulliVecFloat(const Float p = Float(0.5)) noexcept
{
static thread_local auto generator = Ranvec1(Seed<int>(), static_cast<int>(std::hash<std::thread::id>()(std::this_thread::get_id())), 3);
#if defined(DNN_AVX512BW) || defined(DNN_AVX512)
return select(generator.random16f() < p, VecFloat(1), VecFloat(0));
#elif defined(DNN_AVX2) || defined(DNN_AVX)
return select(generator.random8f() < p, VecFloat(1), VecFloat(0));
#elif defined(DNN_SSE42) || defined(DNN_SSE41)
return select(generator.random4f() < p, VecFloat(1), VecFloat(0));
#endif
}
/******************************************************************************
Ranvec1: Class for combined random number generator
Make one instance of Ranvec1 for each thread.
Remember to initialize it with a seed.
Each instance must have a different seed if you want different random sequences
******************************************************************************/
// Combined random number generator. Derived class with various output functions
// (Total size depends on INSTRSET and MAX_VECTOR_SIZE)
class Ranvec1 : public Ranvec1base {
public:
// Constructor
Ranvec1(int gtype = 3) : Ranvec1base(gtype), buf32(this), buf64(this), buf128(this)
#if MAX_VECTOR_SIZE >= 256
, buf256(this)
#endif
#if MAX_VECTOR_SIZE >= 512
, buf512(this)
#endif
{
randomixInterval = randomixLimit = 0;
}
Ranvec1(int seed1, int gtype = 3) : Ranvec1base(gtype), buf32(this), buf64(this), buf128(this)
#if MAX_VECTOR_SIZE >= 256
, buf256(this)
#endif
#if MAX_VECTOR_SIZE >= 512
, buf512(this)
#endif
{
randomixInterval = randomixLimit = 0;
Ranvec1base::init(seed1);
resetBuffers();
}
Ranvec1(int seed1, int seed2, int gtype = 3) : Ranvec1base(gtype), buf32(this), buf64(this), buf128(this)
#if MAX_VECTOR_SIZE >= 256
, buf256(this)
#endif
#if MAX_VECTOR_SIZE >= 512
, buf512(this)
#endif
{
randomixInterval = randomixLimit = 0;
Ranvec1base::init(seed1, seed2);
resetBuffers();
}
Ranvec1(int32_t const seeds[], int numSeeds, int gtype = 3) : Ranvec1base(gtype), buf32(this), buf64(this), buf128(this)
#if MAX_VECTOR_SIZE >= 256
, buf256(this)
#endif
#if MAX_VECTOR_SIZE >= 512
, buf512(this)
#endif
{
randomixInterval = randomixLimit = 0;
Ranvec1base::initByArray(seeds, numSeeds);
resetBuffers();
}