Skip to content

Commit 17a3063

Browse files
committed
[tmp] printf CI debugging
1 parent a74a4a1 commit 17a3063

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

include/openPMD/backend/Attribute.hpp

+38
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <complex>
3030
#include <cstdint>
3131
#include <iterator>
32+
#include <sstream>
3233
#include <stdexcept>
3334
#include <string>
3435
#include <type_traits>
@@ -229,3 +230,40 @@ U Attribute::get() const
229230
}
230231

231232
} // namespace openPMD
233+
234+
namespace std
235+
{
236+
inline string to_string(openPMD::Attribute const &attr)
237+
{
238+
return std::visit(
239+
[](auto const &val) {
240+
using Val_t = remove_cv_t<remove_reference_t<decltype(val)> >;
241+
242+
std::stringstream os;
243+
if constexpr (
244+
openPMD::auxiliary::IsVector_v<Val_t> ||
245+
openPMD::auxiliary::IsArray_v<Val_t>)
246+
{
247+
if (val.empty())
248+
{
249+
os << "[]";
250+
}
251+
else
252+
{
253+
os << "[" << val[0];
254+
for (size_t i = 1; i < val.size(); ++i)
255+
{
256+
os << ", " << val[i];
257+
}
258+
os << "]";
259+
}
260+
}
261+
else
262+
{
263+
os << val;
264+
}
265+
return os.str();
266+
},
267+
attr.getResource());
268+
}
269+
} // namespace std

src/binding/python/Attributable.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ void init_Attributable(py::module &m)
462462
"get_attribute",
463463
[](Attributable &attr, std::string const &key) {
464464
auto v = attr.getAttribute(key);
465+
std::cout << "Attribute '" << key << "' has type: " << v.dtype
466+
<< std::endl
467+
<< " and value: " << std::to_string(v) << std::endl;
465468
return v.getResource();
466469
// TODO instead of returning lists, return all arrays (ndim > 0)
467470
// as numpy arrays?

src/binding/python/PatchRecordComponent.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ void init_PatchRecordComponent(py::module &m)
104104
py::ssize_t numElements = 1;
105105
if (buf.ndim > 0)
106106
{
107+
std::cout << "Buffer has dimensionality: " << buf.ndim
108+
<< std::endl;
107109
for (auto d = 0; d < buf.ndim; ++d)
110+
{
111+
std::cout << "Extent of dimensionality " << d << ": "
112+
<< buf.shape.at(d) << std::endl;
108113
numElements *= buf.shape.at(d);
114+
}
109115
}
110116

111117
// Numpy: Handling of arrays and scalars
@@ -177,7 +183,8 @@ void init_PatchRecordComponent(py::module &m)
177183
{
178184
throw std::runtime_error(
179185
"store: "
180-
"Only scalar values supported!");
186+
"Only scalar values supported! (found " +
187+
std::to_string(numElements) + "values)");
181188
}
182189
},
183190
py::arg("idx"),

src/binding/python/RecordComponent.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,14 @@ void init_RecordComponent(py::module &m)
775775
py::ssize_t numElements = 1;
776776
if (buf.ndim > 0)
777777
{
778+
std::cout << "Buffer has dimensionality: " << buf.ndim
779+
<< std::endl;
778780
for (auto d = 0; d < buf.ndim; ++d)
781+
{
782+
std::cout << "Extent of dimensionality " << d << ": "
783+
<< buf.shape.at(d) << std::endl;
779784
numElements *= buf.shape.at(d);
785+
}
780786
}
781787

782788
// Numpy: Handling of arrays and scalars
@@ -867,7 +873,8 @@ void init_RecordComponent(py::module &m)
867873
{
868874
throw std::runtime_error(
869875
"make_constant: "
870-
"Only scalar values supported!");
876+
"Only scalar values supported! (found " +
877+
std::to_string(numElements) + "values)");
871878
}
872879
},
873880
py::arg("value"))

0 commit comments

Comments
 (0)