Skip to content

Commit 22c2b27

Browse files
committed
[tmp] printf CI debugging
1 parent 37d5e29 commit 22c2b27

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

include/openPMD/backend/Attribute.hpp

+38-1
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
#include <complex>
3030
#include <cstdint>
3131
#include <iterator>
32+
#include <sstream>
3233
#include <stdexcept>
3334
#include <string>
3435
#include <type_traits>
3536
#include <utility>
3637
#include <vector>
3738

38-
3939
namespace openPMD
4040
{
4141
//TODO This might have to be a Writable
@@ -220,3 +220,40 @@ U Attribute::get() const
220220
}
221221

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

src/binding/python/Attributable.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ void init_Attributable(py::module &m) {
442442
// C++ pass-through API: Getter
443443
.def("get_attribute", []( Attributable & attr, std::string const& key ) {
444444
auto v = attr.getAttribute(key);
445+
std::cout << "Attribute '" << key << "' has type: " << v.dtype
446+
<< std::endl
447+
<< " and value: " << std::to_string(v) << std::endl;
445448
return v.getResource();
446449
// TODO instead of returning lists, return all arrays (ndim > 0) as numpy arrays?
447450
})

src/binding/python/PatchRecordComponent.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ void init_PatchRecordComponent(py::module &m) {
8686

8787
// allow one-element n-dimensional buffers as well
8888
py::ssize_t numElements = 1;
89-
if( buf.ndim > 0 ) {
89+
if( buf.ndim > 0 )
90+
{
91+
std::cout << "Buffer has dimensionality: " << buf.ndim
92+
<< std::endl;
9093
for( auto d = 0; d < buf.ndim; ++d )
91-
numElements *= buf.shape.at(d);
94+
{
95+
std::cout << "Extent of dimensionality " << d << ": "
96+
<< buf.shape.at( d ) << std::endl;
97+
numElements *= buf.shape.at( d );
98+
}
9299
}
93100

94101
// Numpy: Handling of arrays and scalars
@@ -149,8 +156,10 @@ void init_PatchRecordComponent(py::module &m) {
149156
}
150157
else
151158
{
152-
throw std::runtime_error("store: "
153-
"Only scalar values supported!");
159+
throw std::runtime_error(
160+
"store: "
161+
"Only scalar values supported! (found " +
162+
std::to_string( numElements ) + "values)" );
154163
}
155164
}, py::arg("idx"), py::arg("data")
156165
)

src/binding/python/RecordComponent.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,16 @@ void init_RecordComponent(py::module &m) {
743743

744744
// allow one-element n-dimensional buffers as well
745745
py::ssize_t numElements = 1;
746-
if( buf.ndim > 0 ) {
746+
if( buf.ndim > 0 )
747+
{
748+
std::cout << "Buffer has dimensionality: " << buf.ndim
749+
<< std::endl;
747750
for( auto d = 0; d < buf.ndim; ++d )
748-
numElements *= buf.shape.at(d);
751+
{
752+
std::cout << "Extent of dimensionality " << d << ": "
753+
<< buf.shape.at( d ) << std::endl;
754+
numElements *= buf.shape.at( d );
755+
}
749756
}
750757

751758
// Numpy: Handling of arrays and scalars
@@ -815,14 +822,17 @@ void init_RecordComponent(py::module &m) {
815822
return rc.makeConstant( *static_cast<std::complex<long double>*>(buf.ptr) );
816823
break;
817824
default:
818-
throw std::runtime_error("make_constant: "
819-
"Unknown Datatype!");
820-
}
825+
throw std::runtime_error(
826+
"make_constant: "
827+
"Unknown Datatype!" );
828+
}
821829
}
822830
else
823831
{
824-
throw std::runtime_error("make_constant: "
825-
"Only scalar values supported!");
832+
throw std::runtime_error(
833+
"make_constant: "
834+
"Only scalar values supported! (found " +
835+
std::to_string( numElements ) + "values)" );
826836
}
827837

828838
}, py::arg("value")

0 commit comments

Comments
 (0)