diff --git a/alignedarray.py b/alignedarray.py index f10c9980d69da820d446f02f3d395a9208876d11..687ebf9f737f8d2b5921e000da1ca07e85564bc6 100644 --- a/alignedarray.py +++ b/alignedarray.py @@ -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 diff --git a/datahandling/serial_datahandling.py b/datahandling/serial_datahandling.py index 3e681c1bdeaa29f1c3153f9351bcf567301fc122..888b82ffd0aa32e3c0f152297759fd137ea4e175 100644 --- a/datahandling/serial_datahandling.py +++ b/datahandling/serial_datahandling.py @@ -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] diff --git a/field.py b/field.py index 92156f9c4611d442e4a47f614654785942ba2721..2f03f2ca651fcfd7db55800c78584bf1d204e453 100644 --- a/field.py +++ b/field.py @@ -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)