Skip to content

Commit

Permalink
Fix for nanobind v2.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ManifoldFR committed Aug 30, 2024
1 parent c7c2b2a commit d719663
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions bindings/python/src/optional-eigen-fix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ NAMESPACE_BEGIN(detail)
/// https://github.com/wjakob/nanobind/issues/682#issuecomment-2310746145
template<typename T>
struct type_caster<std::optional<Eigen::Ref<const T>>>
: optional_caster<std::optional<Eigen::Ref<const T>>>
{
using Ref = Eigen::Ref<const T>;
using Optional = std::optional<Ref>;
using Caster = typename type_caster::optional_caster::Caster;
using Caster = make_caster<Ref>;
using Map = typename Caster::Map;
using DMap = typename Caster::DMap;
NB_TYPE_CASTER(Optional, optional_name(Caster::Name))

type_caster()
: value(std::nullopt)
{
}

bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept
{
if (src.is_none())
Expand All @@ -39,6 +43,17 @@ struct type_caster<std::optional<Eigen::Ref<const T>>>
value.emplace(caster.caster.operator Map());
return true;
}

template<typename T_>
static handle from_cpp(T_&& value,
rv_policy policy,
cleanup_list* cleanup) noexcept
{
if (!value)
return none().release();

return Caster::from_cpp(forward_like_<T_>(*value), policy, cleanup);
}
};

NAMESPACE_END(detail)
Expand Down

0 comments on commit d719663

Please sign in to comment.