File tree 4 files changed +57
-2
lines changed
4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 29
29
#include < complex>
30
30
#include < cstdint>
31
31
#include < iterator>
32
+ #include < sstream>
32
33
#include < stdexcept>
33
34
#include < string>
34
35
#include < type_traits>
@@ -229,3 +230,40 @@ U Attribute::get() const
229
230
}
230
231
231
232
} // 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
Original file line number Diff line number Diff line change @@ -462,6 +462,9 @@ void init_Attributable(py::module &m)
462
462
" get_attribute" ,
463
463
[](Attributable &attr, std::string const &key) {
464
464
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;
465
468
return v.getResource ();
466
469
// TODO instead of returning lists, return all arrays (ndim > 0)
467
470
// as numpy arrays?
Original file line number Diff line number Diff line change @@ -104,8 +104,14 @@ void init_PatchRecordComponent(py::module &m)
104
104
py::ssize_t numElements = 1 ;
105
105
if (buf.ndim > 0 )
106
106
{
107
+ std::cout << " Buffer has dimensionality: " << buf.ndim
108
+ << std::endl;
107
109
for (auto d = 0 ; d < buf.ndim ; ++d)
110
+ {
111
+ std::cout << " Extent of dimensionality " << d << " : "
112
+ << buf.shape .at (d) << std::endl;
108
113
numElements *= buf.shape .at (d);
114
+ }
109
115
}
110
116
111
117
// Numpy: Handling of arrays and scalars
@@ -177,7 +183,8 @@ void init_PatchRecordComponent(py::module &m)
177
183
{
178
184
throw std::runtime_error (
179
185
" store: "
180
- " Only scalar values supported!" );
186
+ " Only scalar values supported! (found " +
187
+ std::to_string (numElements) + " values)" );
181
188
}
182
189
},
183
190
py::arg (" idx" ),
Original file line number Diff line number Diff line change @@ -775,8 +775,14 @@ void init_RecordComponent(py::module &m)
775
775
py::ssize_t numElements = 1 ;
776
776
if (buf.ndim > 0 )
777
777
{
778
+ std::cout << " Buffer has dimensionality: " << buf.ndim
779
+ << std::endl;
778
780
for (auto d = 0 ; d < buf.ndim ; ++d)
781
+ {
782
+ std::cout << " Extent of dimensionality " << d << " : "
783
+ << buf.shape .at (d) << std::endl;
779
784
numElements *= buf.shape .at (d);
785
+ }
780
786
}
781
787
782
788
// Numpy: Handling of arrays and scalars
@@ -867,7 +873,8 @@ void init_RecordComponent(py::module &m)
867
873
{
868
874
throw std::runtime_error (
869
875
" make_constant: "
870
- " Only scalar values supported!" );
876
+ " Only scalar values supported! (found " +
877
+ std::to_string (numElements) + " values)" );
871
878
}
872
879
},
873
880
py::arg (" value" ))
You can’t perform that action at this time.
0 commit comments