File tree 4 files changed +71
-12
lines changed
4 files changed +71
-12
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>
35
36
#include < utility>
36
37
#include < vector>
37
38
38
-
39
39
namespace openPMD
40
40
{
41
41
// TODO This might have to be a Writable
@@ -220,3 +220,40 @@ U Attribute::get() const
220
220
}
221
221
222
222
} // 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
+ }
Original file line number Diff line number Diff line change @@ -442,6 +442,9 @@ void init_Attributable(py::module &m) {
442
442
// C++ pass-through API: Getter
443
443
.def (" get_attribute" , []( Attributable & attr, std::string const & key ) {
444
444
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;
445
448
return v.getResource ();
446
449
// TODO instead of returning lists, return all arrays (ndim > 0) as numpy arrays?
447
450
})
Original file line number Diff line number Diff line change @@ -86,9 +86,16 @@ void init_PatchRecordComponent(py::module &m) {
86
86
87
87
// allow one-element n-dimensional buffers as well
88
88
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;
90
93
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
+ }
92
99
}
93
100
94
101
// Numpy: Handling of arrays and scalars
@@ -149,8 +156,10 @@ void init_PatchRecordComponent(py::module &m) {
149
156
}
150
157
else
151
158
{
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)" );
154
163
}
155
164
}, py::arg (" idx" ), py::arg (" data" )
156
165
)
Original file line number Diff line number Diff line change @@ -743,9 +743,16 @@ void init_RecordComponent(py::module &m) {
743
743
744
744
// allow one-element n-dimensional buffers as well
745
745
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;
747
750
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
+ }
749
756
}
750
757
751
758
// Numpy: Handling of arrays and scalars
@@ -815,14 +822,17 @@ void init_RecordComponent(py::module &m) {
815
822
return rc.makeConstant ( *static_cast <std::complex<long double >*>(buf.ptr ) );
816
823
break ;
817
824
default :
818
- throw std::runtime_error (" make_constant: "
819
- " Unknown Datatype!" );
820
- }
825
+ throw std::runtime_error (
826
+ " make_constant: "
827
+ " Unknown Datatype!" );
828
+ }
821
829
}
822
830
else
823
831
{
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)" );
826
836
}
827
837
828
838
}, py::arg (" value" )
You can’t perform that action at this time.
0 commit comments