Commit 38cd41a8 authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'Replace-np-prod-all-occurances' into 'feature/field_multiple_space'

Replace all occurances of np.prod shape to it's faster alternative.



See merge request !17
parents d349bf74 ca0d962d
......@@ -480,7 +480,7 @@ class Field(object):
Dimension of space.
"""
return np.prod(self.shape)
return reduce(lambda x, y: x * y, self.shape)
@property
def dof(self):
......
......@@ -292,7 +292,7 @@ class power_indices(object):
local_pundex = np.zeros(shape=global_kindex.shape, dtype=np.int)
# Set the default value higher than the maximal possible pundex
# value so that MPI.MIN can sort out the default
local_pundex += np.prod(global_pindex.shape) + 1
local_pundex += reduce(lambda x, y: x * y, global_pindex.shape) + 1
# Set the default value higher than the length
global_pundex = np.empty_like(local_pundex)
# Store the individual pundices in the local_pundex array
......
......@@ -202,7 +202,7 @@ class random(object):
Random field values (with correct dtype and shape).
"""
size = np.prod(shape, axis=0, dtype=np.dtype('int'), out=None)
size = reduce(lambda x, y: x * y, shape)
if issubclass(dtype.type, np.complexfloating):
x = np.array([1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j],
......@@ -247,7 +247,7 @@ class random(object):
`shape`.
"""
size = np.prod(shape)
size = reduce(lambda x, y: x * y, shape)
if issubclass(dtype.type, np.complexfloating):
x = np.empty(size, dtype=dtype)
......@@ -304,7 +304,7 @@ class random(object):
Random field values (with correct dtype and shape).
"""
size = np.prod(shape, axis=0, dtype=np.dtype('int'), out=None)
size = reduce(lambda x, y: x * y, shape)
if(np.size(vmin) > 1):
vmin = np.array(vmin).flatten(order='C')
if(np.size(vmax) > 1):
......
......@@ -179,7 +179,7 @@ def convert_nested_list_to_object_array(x):
return x
# Prepare the carrier-object
carrier = np.empty(real_shape, dtype=np.object)
for i in xrange(np.prod(real_shape)):
for i in xrange(reduce(lambda x, y: x * y, real_shape)):
ii = np.unravel_index(i, real_shape)
try:
carrier[ii] = x[ii]
......@@ -197,7 +197,7 @@ def field_map(ishape, function, *args):
else:
if args == ():
result = np.empty(ishape, dtype=np.object)
for i in xrange(np.prod(ishape)):
for i in xrange(reduce(lambda x, y: x * y, ishape)):
ii = np.unravel_index(i, ishape)
result[ii] = function()
return result
......@@ -211,7 +211,7 @@ def field_map(ishape, function, *args):
get_tuple = tuple(np.clip(ind, 0, w_shape-1))
return w[get_tuple]
result = np.empty_like(args[0])
for i in xrange(np.prod(result.shape)):
for i in xrange(reduce(lambda x, y: x * y, result.shape)):
ii = np.unravel_index(i, result.shape)
result[ii] = function(
*map(
......
......@@ -2832,7 +2832,7 @@ class response_operator(operator):
"ERROR: Non-scalar entries of assign list all must " +
"have the same shape!"))
else:
assignments = np.prod(shape_list[0])
assignments = reduce(lambda x, y: x * y, shape_list[0])
self.assign = assign
else:
raise ValueError(about._errors.cstring(
......
......@@ -770,7 +770,7 @@ class RgSpace(Space):
return x
def get_weight(self, power=1):
return np.prod(self.distances)**power
return reduce(lambda x, y: x * y, self.distances)**power
def calc_transform(self, x, codomain=None, axes=None, **kwargs):
"""
......
......@@ -284,7 +284,7 @@ class Space(object):
dim : {int, numpy.ndarray}
Dimension(s) of the space.
"""
return np.prod(self.shape)
return reduce(lambda x, y: x * y, self.shape)
@property
def dof(self):
......@@ -322,7 +322,7 @@ class Space(object):
@property
def vol(self, split=False):
return np.prod(self.distances)
return reduce(lambda x, y: x * y, self.distances)
@property
def vol_split(self):
......@@ -615,7 +615,7 @@ class Space(object):
def get_weight(self, power=1, split=False):
splitted_weight = tuple(np.array(self.distances)**np.array(power))
if not split:
return np.prod(splitted_weight)
return reduce(lambda x, y: x * y, splitted_weight)
else:
return splitted_weight
......
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