Skip to content

Commit

Permalink
Add BasketAutoDiff aggregate type
Browse files Browse the repository at this point in the history
  • Loading branch information
mazestic committed Oct 6, 2023
1 parent 8cf2836 commit 5567398
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Ponca/src/Fitting/basket.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ namespace internal
struct BasketDiffAggregate : BasketDiffAggregateImpl<BasketType, Type, BasketType, PrimitiveDer, Exts...>
{
};

/*! \brief Internal class used to build the BasketAutoDiff structure */
template <class P, class W, int Type,
template <class, class, typename> class Ext0,
template <class, class, typename> class... Exts>
struct BasketAutoDiffAggregate
{
private:
using Base = Ext0<P, W, PrimitiveBase<P, W>>;
using Aggregate = typename BasketAggregateImpl<P, W, Base, Exts...>::type; // Same impl

public:
using type = typename Base::template DDerType<P, W, Type, PrimitiveDer<P, W, Type, Aggregate>>;
};
}
#endif

Expand Down Expand Up @@ -241,5 +255,12 @@ namespace internal
}
}; // class Basket

template <class P, class W, int Type,
template <class, class, int, typename> class Ext0,
template <class, class, int, typename> class... Exts>
class BasketAutoDiff : public internal::BasketAutoDiffAggregate<P, W, Type, Ext0, Exts...>::type
{
}; // class BasketAutoDiff

} //namespace Ponca

12 changes: 12 additions & 0 deletions tests/src/basket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ void hasSamePlaneDerivatives(const Fit1& fit1, const Fit2& fit2) {
VERIFY(dnor1.isApprox( dnor2 ));
}

// For BasketAutoDiff
template <class P, class W, typename T>
struct AutoDiffExt : public T
{
template <class D, class W_, int Di, typename TT>
using DDerType = OrientedSphereDerImpl<D, W_, Di, TT>;
};

template<typename Scalar, int Dim>
void callSubTests()
{
Expand Down Expand Up @@ -230,6 +238,10 @@ void callSubTests()
using HybridSpaceDiff = BasketDiff<Hybrid, FitSpaceDer, CovariancePlaneDer>;
using HybridScaleSpaceDiff = BasketDiff<Hybrid, FitScaleSpaceDer, CovariancePlaneDer>;

//! [BasketAutoDiff]
using AutoDiff = BasketAutoDiff<Point, WeightFunc, FitScaleDer, AutoDiffExt>;
//! [BasketAutoDiff]

KdTree<Point>tree;
Scalar scale = generateData(tree);

Expand Down

0 comments on commit 5567398

Please sign in to comment.