Commit 9e1072c6 authored by Theo Steininger's avatar Theo Steininger
Browse files

Optimized np.prod(shape)

parent c9edd78f
Pipeline #9525 passed with stages
in 37 minutes and 35 seconds
......@@ -7,7 +7,7 @@ class Random(object):
@staticmethod
def pm1(dtype=np.dtype('int'), shape=1):
size = int(np.prod(shape))
size = int(reduce(lambda x,y: x*y, shape))
if issubclass(dtype.type, np.complexfloating):
x = np.array([1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j], dtype=dtype)
x = x[np.random.randint(4, high=None, size=size)]
......@@ -19,7 +19,7 @@ class Random(object):
@staticmethod
def normal(dtype=np.dtype('float64'), shape=(1,), mean=None, std=None):
size = int(np.prod(shape))
size = int(reduce(lambda x,y: x*y, shape))
if issubclass(dtype.type, np.complexfloating):
x = np.empty(size, dtype=dtype)
x.real = np.random.normal(loc=0, scale=np.sqrt(0.5), size=size)
......@@ -41,7 +41,7 @@ class Random(object):
@staticmethod
def uniform(dtype=np.dtype('float64'), shape=1, low=0, high=1):
size = int(np.prod(shape))
size = int(reduce(lambda x,y: x*y, shape))
if issubclass(dtype.type, np.complexfloating):
x = np.empty(size, dtype=dtype)
x.real = (high - low) * np.random.random(size=size) + low
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment