Skip to content

Commit

Permalink
[tmp] printf CI debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Feb 18, 2022
1 parent 2fb607a commit e5a4718
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
38 changes: 38 additions & 0 deletions include/openPMD/backend/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <complex>
#include <cstdint>
#include <iterator>
#include <sstream>
#include <stdexcept>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -225,3 +226,40 @@ template <typename U> 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<remove_reference_t<decltype(val)> >;

std::stringstream os;
if constexpr (
openPMD::auxiliary::IsVector_v<Val_t> ||
openPMD::auxiliary::IsArray_v<Val_t>)
{
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
3 changes: 3 additions & 0 deletions src/binding/python/Attributable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 8 additions & 1 deletion src/binding/python/PatchRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down
9 changes: 8 additions & 1 deletion src/binding/python/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit e5a4718

Please sign in to comment.