Skip to content

Commit

Permalink
[tmp] printf CI debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 18, 2022
1 parent 37d5e29 commit 4dd9fda
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 18 deletions.
33 changes: 33 additions & 0 deletions include/openPMD/backend/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,39 @@ class Attribute :
U get() const;
};

inline std::ostream & operator<<( std::ostream & os, Attribute const & attr )
{
std::visit(
[ &os ]( auto const & val ) {
using Val_t =
std::remove_cv_t< std::remove_reference_t< decltype( val ) > >;
if constexpr(
auxiliary::IsVector_v< Val_t > ||
auxiliary::IsArray_v< Val_t > )
{
if( val.empty() )
{
os << "[]";
}
else
{
os << "[" << val[ 0 ];
for( size_t i = 1; i < val.size(); ++i )
{
os << ", " << val[ i ];
}
os << "]";
}
}
else
{
os << val;
}
},
attr.getResource() );
return os;
}

template< typename T, typename U >
auto doConvert( T * pv ) -> U
{
Expand Down
3 changes: 3 additions & 0 deletions src/binding/python/Attributable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ void init_Attributable(py::module &m) {
// C++ pass-through API: Getter
.def("get_attribute", []( Attributable & attr, std::string const& key ) {
auto v = attr.getAttribute(key);
std::cout << "Attribute '" << key << "' has type: " << v.dtype
<< std::endl
<< " and value: " << v << std::endl;
return v.getResource();
// TODO instead of returning lists, return all arrays (ndim > 0) as numpy arrays?
})
Expand Down
14 changes: 7 additions & 7 deletions src/binding/python/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ namespace detail
cl.def( py::init<Map const &>() );

// Register stream insertion operator (if possible)
py::detail::map_if_insertion_operator<
Map,
Class_
>(
cl,
name
);
// py::detail::map_if_insertion_operator<
// Map,
// Class_
// >(
// cl,
// name
// );

cl.def(
"__bool__",
Expand Down
17 changes: 13 additions & 4 deletions src/binding/python/PatchRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ void init_PatchRecordComponent(py::module &m) {

// allow one-element n-dimensional buffers as well
py::ssize_t numElements = 1;
if( buf.ndim > 0 ) {
if( buf.ndim > 0 )
{
std::cout << "Buffer has dimensionality: " << buf.ndim
<< std::endl;
for( auto d = 0; d < buf.ndim; ++d )
numElements *= buf.shape.at(d);
{
std::cout << "Extent of dimensionality " << d << ": "
<< buf.shape.at( d ) << std::endl;
numElements *= buf.shape.at( d );
}
}

// Numpy: Handling of arrays and scalars
Expand Down Expand Up @@ -149,8 +156,10 @@ void init_PatchRecordComponent(py::module &m) {
}
else
{
throw std::runtime_error("store: "
"Only scalar values supported!");
throw std::runtime_error(
"store: "
"Only scalar values supported! (found " +
std::to_string( numElements ) + "values)" );
}
}, py::arg("idx"), py::arg("data")
)
Expand Down
24 changes: 17 additions & 7 deletions src/binding/python/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,16 @@ void init_RecordComponent(py::module &m) {

// allow one-element n-dimensional buffers as well
py::ssize_t numElements = 1;
if( buf.ndim > 0 ) {
if( buf.ndim > 0 )
{
std::cout << "Buffer has dimensionality: " << buf.ndim
<< std::endl;
for( auto d = 0; d < buf.ndim; ++d )
numElements *= buf.shape.at(d);
{
std::cout << "Extent of dimensionality " << d << ": "
<< buf.shape.at( d ) << std::endl;
numElements *= buf.shape.at( d );
}
}

// Numpy: Handling of arrays and scalars
Expand Down Expand Up @@ -815,14 +822,17 @@ void init_RecordComponent(py::module &m) {
return rc.makeConstant( *static_cast<std::complex<long double>*>(buf.ptr) );
break;
default:
throw std::runtime_error("make_constant: "
"Unknown Datatype!");
}
throw std::runtime_error(
"make_constant: "
"Unknown Datatype!" );
}
}
else
{
throw std::runtime_error("make_constant: "
"Only scalar values supported!");
throw std::runtime_error(
"make_constant: "
"Only scalar values supported! (found " +
std::to_string( numElements ) + "values)" );
}

}, py::arg("value")
Expand Down

0 comments on commit 4dd9fda

Please sign in to comment.