Skip to content
Snippets Groups Projects

Draft: Resolve "Use Numpy arrays instead of `ForEachObject` instances"

2 unresolved threads
Files
2
+ 104
0
@@ -285,3 +285,107 @@ def mosa2adjacent(x):
raise IndexError(f"invalid MOSA index '{index}'")
# Transform index
return ADJACENT_MOSAS[mosa2index(x)]
def empty_mosa(shape, *args, **kwargs):
"""Return a new MOSA array of given shape and type, without initializing entries.
Returns:
MOSA array of shape (6, shape).
"""
if isinstance(shape, int):
shape = (6, shape)
else:
shape = (6, *shape)
return np.empty(shape, *args, **kwargs)
def empty_sc(shape, *args, **kwargs):
"""Return a new SC array of given shape and type, without initializing entries.
Returns:
SC array of shape (3, shape).
"""
if isinstance(shape, int):
shape = (3, shape)
else:
shape = (3, *shape)
return np.empty(shape, *args, **kwargs)
def ones_mosa(shape, *args, **kwargs):
"""Return a new MOSA array of given shape and type, filled with ones.
Returns:
MOSA array of shape (6, shape).
"""
if isinstance(shape, int):
shape = (6, shape)
else:
shape = (6, *shape)
return np.ones(shape, *args, **kwargs)
def ones_sc(shape, *args, **kwargs):
"""Return a new SC array of given shape and type, filled with ones.
Returns:
SC array of shape (3, shape).
"""
if isinstance(shape, int):
shape = (3, shape)
else:
shape = (3, *shape)
return np.ones(shape, *args, **kwargs)
def zeros_mosa(shape, *args, **kwargs):
"""Return a new MOSA array of given shape and type, filled with zeros.
Returns:
MOSA array of shape (6, shape).
"""
if isinstance(shape, int):
shape = (6, shape)
else:
shape = (6, *shape)
return np.zeros(shape, *args, **kwargs)
def zeros_sc(shape, *args, **kwargs):
"""Return a new SC array of given shape and type, filled with zeros.
Returns:
SC array of shape (3, shape).
"""
if isinstance(shape, int):
shape = (3, shape)
else:
shape = (3, *shape)
return np.zeros(shape, *args, **kwargs)
def full_mosa(shape, fill_value, *args, **kwargs):
"""Return a new MOSA array of given shape and type, filled with `fill_value`.
Returns:
MOSA array of shape (6, shape).
"""
if isinstance(shape, int):
shape = (6, shape)
else:
shape = (6, *shape)
return np.full(shape, fill_value, *args, **kwargs)
def full_sc(shape, fill_value, *args, **kwargs):
"""Return a new SC array of given shape and type, filled with `fill_value`.
Returns:
SC array of shape (3, shape).
"""
if isinstance(shape, int):
shape = (3, shape)
else:
shape = (3, *shape)
return np.full(shape, fill_value, *args, **kwargs)
Loading