From 1b77a6cf4519274e0e32ac9f6018147ff30a1087 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 30 Aug 2019 15:59:44 +0200 Subject: Start to use vectorizable indexing for material initialization `utility.ndindex` adds support for specifying the traversal order to `numpy.ndindex`. --- utility/ndindex.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 utility/ndindex.py (limited to 'utility') diff --git a/utility/ndindex.py b/utility/ndindex.py new file mode 100644 index 0000000..0c5ed9b --- /dev/null +++ b/utility/ndindex.py @@ -0,0 +1,14 @@ +import numpy +from numpy.lib.stride_tricks import as_strided +import numpy.core.numeric as _nx + +class ndindex(numpy.ndindex): + pass + + def __init__(self, *shape, order): + if len(shape) == 1 and isinstance(shape[0], tuple): + shape = shape[0] + x = as_strided(_nx.zeros(1), shape=shape, + strides=_nx.zeros_like(shape)) + self._it = _nx.nditer(x, flags=['multi_index', 'zerosize_ok'], + order=order) -- cgit v1.2.3