diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-03 04:53:03 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-03 04:53:03 +0000 |
commit | 0904df84e296c10fe0ccb37a3b689e6b96d87e41 (patch) | |
tree | 8f8f452df068b789b3ffe15405e7b3cabc87225a /modules/rng_philox.py | |
parent | fca42949a3593c5a2f646e30cc99be2c02566aa2 (diff) | |
download | stable-diffusion-webui-gfx803-0904df84e296c10fe0ccb37a3b689e6b96d87e41.tar.gz stable-diffusion-webui-gfx803-0904df84e296c10fe0ccb37a3b689e6b96d87e41.tar.bz2 stable-diffusion-webui-gfx803-0904df84e296c10fe0ccb37a3b689e6b96d87e41.zip |
minor performance improvements for philox
Diffstat (limited to 'modules/rng_philox.py')
-rw-r--r-- | modules/rng_philox.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/modules/rng_philox.py b/modules/rng_philox.py index b5c02483..5532cf9d 100644 --- a/modules/rng_philox.py +++ b/modules/rng_philox.py @@ -26,7 +26,7 @@ two_pow32_inv_2pi = np.array([2.3283064e-10 * 6.2831855], dtype=np.float32) def uint32(x):
"""Converts (N,) np.uint64 array into (2, N) np.unit32 array."""
- return np.moveaxis(x.view(np.uint32).reshape(-1, 2), 0, 1)
+ return x.view(np.uint32).reshape(-1, 2).transpose(1, 0)
def philox4_round(counter, key):
@@ -65,8 +65,8 @@ def philox4_32(counter, key, rounds=10): def box_muller(x, y):
"""Returns just the first out of two numbers generated by Box–Muller transform algorithm."""
- u = x.astype(np.float32) * two_pow32_inv + two_pow32_inv / 2
- v = y.astype(np.float32) * two_pow32_inv_2pi + two_pow32_inv_2pi / 2
+ u = x * two_pow32_inv + two_pow32_inv / 2
+ v = y * two_pow32_inv_2pi + two_pow32_inv_2pi / 2
s = np.sqrt(-2.0 * np.log(u))
@@ -93,7 +93,9 @@ class Generator: counter[2] = np.arange(n, dtype=np.uint32) # up to 2^32 numbers can be generated - if you want more you'd need to spill into counter[3]
self.offset += 1
- key = uint32(np.array([[self.seed] * n], dtype=np.uint64))
+ key = np.empty(n, dtype=np.uint64)
+ key.fill(self.seed)
+ key = uint32(key)
g = philox4_32(counter, key)
|