Skip to content

Commit d497560

Browse files
franzpoeschelax3l
authored andcommitted
[tmp] printf CI debugging
1 parent 564b49f commit d497560

4 files changed

Lines changed: 81 additions & 30 deletions

File tree

include/openPMD/backend/Attribute.hpp

Lines changed: 38 additions & 0 deletions
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+
}

src/binding/python/Attributable.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -458,25 +458,23 @@ void init_Attributable(py::module &m)
458458
// double, 7 > >)
459459

460460
// C++ pass-through API: Getter
461-
.def(
462-
"get_attribute",
463-
[](Attributable &attr, std::string const &key) {
464-
auto v = attr.getAttribute(key);
465-
return v.getResource();
466-
// TODO instead of returning lists, return all arrays (ndim > 0)
467-
// as numpy arrays?
468-
})
469-
.def_property_readonly(
470-
"attribute_dtypes",
471-
[](Attributable const &attributable) {
472-
std::map<std::string, pybind11::dtype> dtypes;
473-
for (auto const &attr : attributable.attributes())
474-
{
475-
dtypes[attr] =
476-
dtype_to_numpy(attributable.getAttribute(attr).dtype);
477-
}
478-
return dtypes;
479-
})
461+
.def("get_attribute", []( Attributable & attr, std::string const& key ) {
462+
auto v = attr.getAttribute(key);
463+
std::cout << "Attribute '" << key << "' has type: " << v.dtype
464+
<< std::endl
465+
<< " and value: " << std::to_string(v) << std::endl;
466+
return v.getResource();
467+
// TODO instead of returning lists, return all arrays (ndim > 0) as numpy arrays?
468+
})
469+
.def_property_readonly("attribute_dtypes", []( Attributable const & attributable ) {
470+
std::map< std::string, pybind11::dtype > dtypes;
471+
for( auto const & attr : attributable.attributes() )
472+
{
473+
dtypes[ attr ] =
474+
dtype_to_numpy( attributable.getAttribute( attr ).dtype );
475+
}
476+
return dtypes;
477+
})
480478
.def("delete_attribute", &Attributable::deleteAttribute)
481479
.def("contains_attribute", &Attributable::containsAttribute)
482480

src/binding/python/PatchRecordComponent.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ void init_PatchRecordComponent(py::module &m)
102102

103103
// allow one-element n-dimensional buffers as well
104104
py::ssize_t numElements = 1;
105-
if (buf.ndim > 0)
105+
if( buf.ndim > 0 )
106106
{
107-
for (auto d = 0; d < buf.ndim; ++d)
108-
numElements *= buf.shape.at(d);
107+
std::cout << "Buffer has dimensionality: " << buf.ndim
108+
<< std::endl;
109+
for( auto d = 0; d < buf.ndim; ++d )
110+
{
111+
std::cout << "Extent of dimensionality " << d << ": "
112+
<< buf.shape.at( d ) << std::endl;
113+
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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,16 @@ void init_RecordComponent(py::module &m)
773773

774774
// allow one-element n-dimensional buffers as well
775775
py::ssize_t numElements = 1;
776-
if (buf.ndim > 0)
776+
if( buf.ndim > 0 )
777777
{
778-
for (auto d = 0; d < buf.ndim; ++d)
779-
numElements *= buf.shape.at(d);
778+
std::cout << "Buffer has dimensionality: " << buf.ndim
779+
<< std::endl;
780+
for( auto d = 0; d < buf.ndim; ++d )
781+
{
782+
std::cout << "Extent of dimensionality " << d << ": "
783+
<< buf.shape.at( d ) << std::endl;
784+
numElements *= buf.shape.at( d );
785+
}
780786
}
781787

782788
// Numpy: Handling of arrays and scalars
@@ -860,17 +866,19 @@ void init_RecordComponent(py::module &m)
860866
default:
861867
throw std::runtime_error(
862868
"make_constant: "
863-
"Unknown Datatype!");
869+
"Unknown Datatype!" );
864870
}
865871
}
866872
else
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
}
872-
},
873-
py::arg("value"))
879+
880+
}, py::arg("value")
881+
)
874882
// allowed python intrinsics, after (!) buffer matching
875883
.def(
876884
"make_constant",

0 commit comments

Comments
 (0)