aboutsummaryrefslogtreecommitdiff
path: root/utility
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-08-30 15:59:44 +0200
committerAdrian Kummerlaender2019-08-30 15:59:44 +0200
commit1b77a6cf4519274e0e32ac9f6018147ff30a1087 (patch)
treee59c8df26d7f31e38d57d9554efb066b82d5d5c8 /utility
parentbcc087a36ea7d84ac61a2c756458a208f6bc3ff3 (diff)
downloadsymlbm_playground-1b77a6cf4519274e0e32ac9f6018147ff30a1087.tar
symlbm_playground-1b77a6cf4519274e0e32ac9f6018147ff30a1087.tar.gz
symlbm_playground-1b77a6cf4519274e0e32ac9f6018147ff30a1087.tar.bz2
symlbm_playground-1b77a6cf4519274e0e32ac9f6018147ff30a1087.tar.lz
symlbm_playground-1b77a6cf4519274e0e32ac9f6018147ff30a1087.tar.xz
symlbm_playground-1b77a6cf4519274e0e32ac9f6018147ff30a1087.tar.zst
symlbm_playground-1b77a6cf4519274e0e32ac9f6018147ff30a1087.zip
Start to use vectorizable indexing for material initialization
`utility.ndindex` adds support for specifying the traversal order to `numpy.ndindex`.
Diffstat (limited to 'utility')
-rw-r--r--utility/ndindex.py14
1 files changed, 14 insertions, 0 deletions
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)