Skip to content

Commit e5a4718

Browse files
committed
[tmp] printf CI debugging
1 parent 2fb607a commit e5a4718

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>
@@ -225,3 +226,40 @@ template <typename U> U Attribute::get() const
225226
}
226227

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