dimanche 7 mai 2023

1B pseudo-random boolean permutations of vector set N by M

Let's say we have a set of pseudo-random boolean/binary vectors of length N, and each vector is length M.

e.g. {[0,1,0,1], [0,0,0,1]}

We need one billion unique vectors.

Now, the question is, what is the fastest way to do this?? (also please keep in mind we need to keep the vector set in memory, so that later we can use the same set to do other stuff)

For example... here are some approaches I have tried...

## where N = 10 and M = 10,000
def idx_v(idx, ivals=vector_set(N,M), ival=np.zeros(10_000)):
  divs = idx // 10
  remains = idx % 10
  a = [divs,remains]
  hv = str( abs( hash( str(a) ) ) )
  ival = ivals[remains]
  for i in hv:
    ival = np.roll(ival, int(i))
  return ival, divs, remains

for idx in range(1_000_000_000):
  ival = idx_v(idx)

that takes about 0.006 seconds per generation of 10 vectors

##where N = 100 and M = 10,000 
def idx_v(idx, ivals=vector_set(N,M), ival=np.zeros(10_000)):
  divs = idx // 100
  remains = idx % 100
  ival = np.roll(ivals[remains], divs )
  return ival, divs, remains

for idx in range(1_000_000_000):
  ival = idx_v(idx)

that takes about 0.005 seconds per generation of 10 vectors




Aucun commentaire:

Enregistrer un commentaire