Commit 04cd0614 authored by Martin Bauer's avatar Martin Bauer
Browse files

Fixes in numpy array alignment

parent 9fe16eda
......@@ -19,16 +19,17 @@ def aligned_empty(shape, byteAlignment=32, dtype=np.float64, byteOffset=0, order
tmp = np.empty(N * d.itemsize + byteAlignment, dtype=np.uint8)
address = tmp.__array_interface__['data'][0]
offset = (byteAlignment - (address + byteOffset) % byteAlignment) % byteAlignment
t1 = tmp[offset:offset + N * d.itemsize]
return tmp[offset:offset + N * d.itemsize].view(dtype=d).reshape(shape, order=order)
else:
if order == 'C':
ndim0 = shape[-1]
dim0 = -1
ndim1 = shape[-2]
ndim1 = np.prod(shape[:-1])
else:
ndim0 = shape[0]
dim0 = 0
ndim1 = shape[1]
ndim1 = np.prod(shape[1:])
d = np.dtype(dtype)
assert byteAlignment >= d.itemsize and byteAlignment % d.itemsize == 0
......
......@@ -103,6 +103,9 @@ class SerialDataHandling(DataHandling):
cpuArr = createNumpyArrayWithLayout(layout=layoutTuple, alignment=alignment, byteOffset=byteOffset, **kwargs)
cpuArr.fill(np.inf)
if alignment and gpu:
raise NotImplementedError("Alignment for GPU fields not supported")
if cpu:
if name in self.cpuArrays:
raise ValueError("CPU Field with this name already exists")
......@@ -113,8 +116,7 @@ class SerialDataHandling(DataHandling):
self.gpuArrays[name] = gpuarray.to_gpu(cpuArr)
assert all(f.name != name for f in self.fields.values()), "Symbolic field with this name already exists"
self.fields[name] = Field.createFixedSize(name, shape=kwargs['shape'], indexDimensions=indexDimensions,
dtype=kwargs['dtype'], layout=layoutTuple)
self.fields[name] = Field.createFromNumpyArray(name, cpuArr, indexDimensions=indexDimensions)
self.fields[name].latexName = latexName
return self.fields[name]
......
......@@ -502,7 +502,7 @@ def createNumpyArrayWithLayout(shape, layout, alignment=False, byteOffset=0, **k
else:
if alignment is True:
alignment = 8 * 4
res = aligned_empty(shape, alignment, byteOffset=byteOffset)
res = aligned_empty(shape, alignment, byteOffset=byteOffset, **kwargs)
for a, b in reversed(swaps):
res = res.swapaxes(a, b)
......
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