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