diff --git a/include/openPMD/backend/Attribute.hpp b/include/openPMD/backend/Attribute.hpp index 25e0a3972d..28bfd8b083 100644 --- a/include/openPMD/backend/Attribute.hpp +++ b/include/openPMD/backend/Attribute.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -225,3 +226,40 @@ template U Attribute::get() const } } // namespace openPMD + +namespace std +{ +inline string to_string(openPMD::Attribute const &attr) +{ + return std::visit( + [](auto const &val) { + using Val_t = remove_cv_t >; + + std::stringstream os; + if constexpr ( + openPMD::auxiliary::IsVector_v || + openPMD::auxiliary::IsArray_v) + { + if (val.empty()) + { + os << "[]"; + } + else + { + os << "[" << val[0]; + for (size_t i = 1; i < val.size(); ++i) + { + os << ", " << val[i]; + } + os << "]"; + } + } + else + { + os << val; + } + return os.str(); + }, + attr.getResource()); +} +} // namespace std diff --git a/src/binding/python/Attributable.cpp b/src/binding/python/Attributable.cpp index 69708fc948..16d7519c65 100644 --- a/src/binding/python/Attributable.cpp +++ b/src/binding/python/Attributable.cpp @@ -462,6 +462,9 @@ void init_Attributable(py::module &m) "get_attribute", [](Attributable &attr, std::string const &key) { auto v = attr.getAttribute(key); + std::cout << "Attribute '" << key << "' has type: " << v.dtype + << std::endl + << " and value: " << std::to_string(v) << std::endl; return v.getResource(); // TODO instead of returning lists, return all arrays (ndim > 0) // as numpy arrays? diff --git a/src/binding/python/PatchRecordComponent.cpp b/src/binding/python/PatchRecordComponent.cpp index cecd57b252..7d47445e6a 100644 --- a/src/binding/python/PatchRecordComponent.cpp +++ b/src/binding/python/PatchRecordComponent.cpp @@ -104,8 +104,14 @@ void init_PatchRecordComponent(py::module &m) py::ssize_t numElements = 1; if (buf.ndim > 0) { + std::cout << "Buffer has dimensionality: " << buf.ndim + << std::endl; for (auto d = 0; d < buf.ndim; ++d) + { + std::cout << "Extent of dimensionality " << d << ": " + << buf.shape.at(d) << std::endl; numElements *= buf.shape.at(d); + } } // Numpy: Handling of arrays and scalars @@ -177,7 +183,8 @@ void init_PatchRecordComponent(py::module &m) { throw std::runtime_error( "store: " - "Only scalar values supported!"); + "Only scalar values supported! (found " + + std::to_string(numElements) + "values)"); } }, py::arg("idx"), diff --git a/src/binding/python/RecordComponent.cpp b/src/binding/python/RecordComponent.cpp index 23de7da58c..2ae7185e17 100644 --- a/src/binding/python/RecordComponent.cpp +++ b/src/binding/python/RecordComponent.cpp @@ -775,8 +775,14 @@ void init_RecordComponent(py::module &m) py::ssize_t numElements = 1; if (buf.ndim > 0) { + std::cout << "Buffer has dimensionality: " << buf.ndim + << std::endl; for (auto d = 0; d < buf.ndim; ++d) + { + std::cout << "Extent of dimensionality " << d << ": " + << buf.shape.at(d) << std::endl; numElements *= buf.shape.at(d); + } } // Numpy: Handling of arrays and scalars @@ -867,7 +873,8 @@ void init_RecordComponent(py::module &m) { throw std::runtime_error( "make_constant: " - "Only scalar values supported!"); + "Only scalar values supported! (found " + + std::to_string(numElements) + "values)"); } }, py::arg("value"))