Skip to content

Commit

Permalink
make pytest run again
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzburger committed Feb 4, 2025
1 parent e57bbb3 commit 3d63ac1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
16 changes: 11 additions & 5 deletions Examples/Python/src/Covfie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,31 @@ using namespace pybind11::literals;
namespace Acts::Python {

namespace {
template <typename field_t>
template <typename field_t, typename scalar_type>
void declareCovfieField(py::module& m, const std::string& fieldName) {
using view_t = typename field_t::view_t;
m.def("toView",
[](const field_t& field) { return typename field_t::view_t(field); });
py::class_<field_t, std::shared_ptr<field_t>>(m, fieldName.c_str());
py::class_<view_t, std::shared_ptr<view_t>>(
m, (fieldName + std::string("View")).c_str())
.def("at", &view_t::template at<float, float, float>);
.def("at", &view_t::template at<scalar_type, scalar_type, scalar_type>);
}
} // namespace

void addCovfie(Context& ctx) {
auto main = ctx.get("main");
auto m = main.def_submodule("covfie", "Submodule for covfie conversion");

declareCovfieField<Acts::CovfiePlugin::ConstantField>(m,
"CovfieConstantField");
declareCovfieField<Acts::CovfiePlugin::InterpolatedField>(
py::class_<covfie::array::array<float, 3ul>,
std::shared_ptr<covfie::array::array<float, 3ul>>>(m,
"ArrayFloat3")
.def("at", [](const covfie::array::array<float, 3ul>& self,
std::size_t i) { return self[i]; });

declareCovfieField<Acts::CovfiePlugin::ConstantField, float>(
m, "CovfieConstantField");
declareCovfieField<Acts::CovfiePlugin::InterpolatedField, float>(
m, "CovfieAffineLinearStridedField");

m.def("makeCovfieField",
Expand Down
14 changes: 9 additions & 5 deletions Examples/Python/tests/test_covfie.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def test_constant_field_conversion():
cf = covfie.makeCovfieField(af)
view = covfie.toView(cf)
points = [(0, 0, 1), (1, 1, 1), (1, 0, 2)]
for x, y, z in points:
assert view.at(x, y, z) == [1, 2, 3]
for [x, y, z] in points:
field = view.at(x, y, z)
assert field.at(0) == 1
assert field.at(1) == 2
assert field.at(2) == 3


@pytest.mark.skipif(not covfieEnabled, reason="Covfie plugin not available")
Expand Down Expand Up @@ -51,10 +54,11 @@ def test_root_field_conversion():

error_margin_half_width = 0.0001
for x, y, z in points:
val = af.getField(acts.Vector3(x, y, z), fc)
Bx1, By1, Bz1 = val[0], val[1], val[2]
rfield = af.getField(acts.Vector3(x, y, z), fc)
Bx1, By1, Bz1 = rfield[0], rfield[1], rfield[2]

Bx2, By2, Bz2 = tuple(view.at(x, y, z))
tfield = view.at(x, y, z)
Bx2, By2, Bz2 = tfield.at(0), tfield.at(1), tfield.at(2)

assert (
abs(Bx1 - Bx2) < error_margin_half_width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DetrayConverter {
}

// (2b) material grids
if constexpr (detray::concepts::has_material_rods<detector_t>) {
if constexpr (detray::concepts::has_material_maps<detector_t>) {
if (options.convertMaterial) {
detray::io::detector_grids_payload<detray::io::material_slab_payload,
detray::io::material_id>
Expand Down

0 comments on commit 3d63ac1

Please sign in to comment.