Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tom Harke
pystencils
Commits
04cd0614
Commit
04cd0614
authored
Mar 25, 2018
by
Martin Bauer
Browse files
Fixes in numpy array alignment
parent
9fe16eda
Changes
3
Hide whitespace changes
Inline
Side-by-side
alignedarray.py
View file @
04cd0614
...
...
@@ -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
...
...
datahandling/serial_datahandling.py
View file @
04cd0614
...
...
@@ -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
]
...
...
field.py
View file @
04cd0614
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment