Skip to content

Commit

Permalink
[tmp] printf CI debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel authored and ax3l committed Feb 18, 2022
1 parent 564b49f commit d497560
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 30 deletions.
38 changes: 38 additions & 0 deletions include/openPMD/backend/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <complex>
#include <cstdint>
#include <iterator>
#include <sstream>
#include <stdexcept>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -225,3 +226,40 @@ template <typename U> U Attribute::get() const
}

} // namespace openPMD

namespace std
{
inline string to_string( openPMD::Attribute const & attr )
{
return std::visit(
[]( auto const & val ) {
using Val_t = remove_cv_t< remove_reference_t< decltype( val ) > >;

std::stringstream os;
if constexpr(
openPMD::auxiliary::IsVector_v< Val_t > ||
openPMD::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;
}
return os.str();
},
attr.getResource() );
}
}
36 changes: 17 additions & 19 deletions src/binding/python/Attributable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,25 +458,23 @@ void init_Attributable(py::module &m)
// double, 7 > >)

// C++ pass-through API: Getter
.def(
"get_attribute",
[](Attributable &attr, std::string const &key) {
auto v = attr.getAttribute(key);
return v.getResource();
// TODO instead of returning lists, return all arrays (ndim > 0)
// as numpy arrays?
})
.def_property_readonly(
"attribute_dtypes",
[](Attributable const &attributable) {
std::map<std::string, pybind11::dtype> dtypes;
for (auto const &attr : attributable.attributes())
{
dtypes[attr] =
dtype_to_numpy(attributable.getAttribute(attr).dtype);
}
return dtypes;
})
.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: " << std::to_string(v) << std::endl;
return v.getResource();
// TODO instead of returning lists, return all arrays (ndim > 0) as numpy arrays?
})
.def_property_readonly("attribute_dtypes", []( Attributable const & attributable ) {
std::map< std::string, pybind11::dtype > dtypes;
for( auto const & attr : attributable.attributes() )
{
dtypes[ attr ] =
dtype_to_numpy( attributable.getAttribute( attr ).dtype );
}
return dtypes;
})
.def("delete_attribute", &Attributable::deleteAttribute)
.def("contains_attribute", &Attributable::containsAttribute)

Expand Down
15 changes: 11 additions & 4 deletions src/binding/python/PatchRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,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 )
{
for (auto d = 0; d < buf.ndim; ++d)
numElements *= buf.shape.at(d);
std::cout << "Buffer has dimensionality: " << buf.ndim
<< std::endl;
for( auto d = 0; d < buf.ndim; ++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 @@ -177,7 +183,8 @@ void init_PatchRecordComponent(py::module &m)
{
throw std::runtime_error(
"store: "
"Only scalar values supported!");
"Only scalar values supported! (found " +
std::to_string( numElements ) + "values)" );
}
},
py::arg("idx"),
Expand Down
22 changes: 15 additions & 7 deletions src/binding/python/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,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 )
{
for (auto d = 0; d < buf.ndim; ++d)
numElements *= buf.shape.at(d);
std::cout << "Buffer has dimensionality: " << buf.ndim
<< std::endl;
for( auto d = 0; d < buf.ndim; ++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 @@ -860,17 +866,19 @@ void init_RecordComponent(py::module &m)
default:
throw std::runtime_error(
"make_constant: "
"Unknown Datatype!");
"Unknown Datatype!" );
}
}
else
{
throw std::runtime_error(
"make_constant: "
"Only scalar values supported!");
"Only scalar values supported! (found " +
std::to_string( numElements ) + "values)" );
}
},
py::arg("value"))

}, py::arg("value")
)
// allowed python intrinsics, after (!) buffer matching
.def(
"make_constant",
Expand Down

0 comments on commit d497560

Please sign in to comment.