Skip to content

Commit

Permalink
Merge pull request #4044 from pnorbert/fix-python-scalar
Browse files Browse the repository at this point in the history
Return a 0-dim numpy array of size 1  when reading a scalar variable …
  • Loading branch information
pnorbert committed Feb 25, 2024
2 parents 3fa1140 + 223e3fe commit 61324e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions python/adios2/file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Distributed under the OSI-approved Apache License, Version 2.0. See
accompanying file Copyright.txt for details.
"""

from functools import singledispatchmethod
from adios2 import Stream, IO

Expand Down
7 changes: 6 additions & 1 deletion python/adios2/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Distributed under the OSI-approved Apache License, Version 2.0. See
accompanying file Copyright.txt for details.
"""

from functools import singledispatchmethod
from sys import maxsize
import numpy as np
Expand Down Expand Up @@ -349,7 +350,11 @@ def read(self, variable: Variable):
output_shape[0] *= steps
else:
# scalar
output_shape = (variable.selection_size(),)
size_all_steps = variable.selection_size()
if size_all_steps > 1:
output_shape = [size_all_steps]
else:
output_shape = []

output = np.zeros(output_shape, dtype=dtype)
self._engine.get(variable, output)
Expand Down

0 comments on commit 61324e8

Please sign in to comment.