Skip to content

Commit

Permalink
Merge pull request #1677 from germasch/pr/python-scalar
Browse files Browse the repository at this point in the history
python/hl: return single GlobalValue as scalar/0-d array
  • Loading branch information
williamfgc authored Aug 13, 2019
2 parents 0ea7d66 + 5370336 commit 6ceccc2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
5 changes: 5 additions & 0 deletions bindings/Python/py11File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ pybind11::array File::ReadAttribute(const std::string &name,
{ \
core::Attribute<T> *attribute = m_Stream->m_IO->InquireAttribute<T>( \
name, variableName, separator); \
if (attribute->m_IsSingleValue) \
{ \
pybind11::array_t<T> pyArray({}); \
pyArray.mutable_data()[0] = attribute->m_DataSingleValue; \
} \
pybind11::array_t<T> pyArray(attribute->m_Elements); \
m_Stream->ReadAttribute<T>(name, pyArray.mutable_data(), variableName, \
separator); \
Expand Down
5 changes: 0 additions & 5 deletions bindings/Python/py11File.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ pybind11::array File::DoRead(const std::string &name, const Dims &_start,
throw std::invalid_argument("when reading a scalar, start and "
"count cannot be specified.\n");
}
if (stepCount == 0)
{
// for compatiblity, return 1-d arrays rather than 0-d
count = Dims{1};
}
}

if (variable.m_ShapeID == ShapeID::LocalArray)
Expand Down
20 changes: 10 additions & 10 deletions testing/adios2/bindings/python/TestBPWriteTypesHighLevelAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,34 +142,34 @@
print("InTag: " + str(inTag))
raise ValueError('tag variable read failed')

if(inI8[0] != data.I8[0]):
if(inI8 != data.I8[0]):
raise ValueError('gvarI8 read failed')

if(inI16[0] != data.I16[0]):
if(inI16 != data.I16[0]):
raise ValueError('gvarI16 read failed')

if(inI32[0] != data.I32[0]):
if(inI32 != data.I32[0]):
raise ValueError('gvarI32 read failed')

if(inI64[0] != data.I64[0]):
if(inI64 != data.I64[0]):
raise ValueError('gvarI64 read failed')

if(inU8[0] != data.U8[0]):
if(inU8 != data.U8[0]):
raise ValueError('gvarU8 read failed')

if(inU16[0] != data.U16[0]):
if(inU16 != data.U16[0]):
raise ValueError('gvarU16 read failed')

if(inU32[0] != data.U32[0]):
if(inU32 != data.U32[0]):
raise ValueError('gvarU32 read failed')

if(inU64[0] != data.U64[0]):
if(inU64 != data.U64[0]):
raise ValueError('gvarU64 read failed')

if(inR32[0] != data.R32[0]):
if(inR32 != data.R32[0]):
raise ValueError('gvarR32 read failed')

if(inR64[0] != data.R64[0]):
if(inR64 != data.R64[0]):
raise ValueError('gvarR64 read failed')

# attributes
Expand Down
20 changes: 10 additions & 10 deletions testing/adios2/bindings/python/TestBPWriteTypesHighLevelAPI_HDF5.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,34 +138,34 @@
print("InTag: " + str(inTag))
raise ValueError('tag variable read failed')

if(inI8[0] != data.I8[0]):
if(inI8 != data.I8[0]):
raise ValueError('gvarI8 read failed')

if(inI16[0] != data.I16[0]):
if(inI16 != data.I16[0]):
raise ValueError('gvarI16 read failed')

if(inI32[0] != data.I32[0]):
if(inI32 != data.I32[0]):
raise ValueError('gvarI32 read failed')

if(inI64[0] != data.I64[0]):
if(inI64 != data.I64[0]):
raise ValueError('gvarI64 read failed')

if(inU8[0] != data.U8[0]):
if(inU8 != data.U8[0]):
raise ValueError('gvarU8 read failed')

if(inU16[0] != data.U16[0]):
if(inU16 != data.U16[0]):
raise ValueError('gvarU16 read failed')

if(inU32[0] != data.U32[0]):
if(inU32 != data.U32[0]):
raise ValueError('gvarU32 read failed')

if(inU64[0] != data.U64[0]):
if(inU64 != data.U64[0]):
raise ValueError('gvarU64 read failed')

if(inR32[0] != data.R32[0]):
if(inR32 != data.R32[0]):
raise ValueError('gvarR32 read failed')

if(inR64[0] != data.R64[0]):
if(inR64 != data.R64[0]):
raise ValueError('gvarR64 read failed')

# attributes
Expand Down
3 changes: 1 addition & 2 deletions testing/adios2/bindings/python/TestHighLevelAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def test_GlobalValue(self):
for fh_step in fh:
t = fh_step.current_step()
val = fh_step.read("global_value", (), ())
self.assertTrue(np.array_equal(
val, np.array([global_values[t]])))
self.assertTrue(val == global_values[t])

def test_GlobalArray(self):
with adios2.open(filename, 'r') as fh:
Expand Down

0 comments on commit 6ceccc2

Please sign in to comment.