Skip to content

Commit

Permalink
Enhance ParameterSet (#103)
Browse files Browse the repository at this point in the history
* Meta: Add HO function to apply function only to select indicies of a tuple

* ParameterSet: Easier application of functions by type with lambdas + discovering the count of params by type

* BufStats: Weights should be an input buffer
  • Loading branch information
weefuzzy authored Mar 10, 2022
1 parent 5a9691e commit 973961d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
41 changes: 39 additions & 2 deletions include/clients/common/ParameterSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class ParameterDescriptorSet<std::index_sequence<Os...>, std::tuple<Ts...>>
std::integral_constant<bool,
!(std::is_base_of<impl::Relational, T>::value)>;
};

template <typename T>
struct IsParamType
{
template <typename U>
using apply = std::is_same<T, typename std::tuple_element<0, U>::type>;
};


template <typename T>
using DefaultValue = decltype(std::declval<T>().defaultValue);
Expand Down Expand Up @@ -87,11 +95,14 @@ class ParameterDescriptorSet<std::index_sequence<Os...>, std::tuple<Ts...>>
typename impl::FilterTupleIndices<IsNonRelational, T, List>::type;


template<typename T>
constexpr static index NumOfType = impl::FilterTupleIndices<IsParamType<T>, DescriptorType, IndexList>::type::size();

template <typename T>
index NumOf() const
constexpr index NumOf() const
{
return
typename impl::FilterTupleIndices<T, DescriptorType, IndexList>::size();
typename impl::FilterTupleIndices<T, DescriptorType, IndexList>::type::size();
}

static constexpr index NumFixedParams = FixedIndexList::size();
Expand Down Expand Up @@ -302,6 +313,22 @@ class ParameterSetView<
IsParamType<T>, std::decay_t<DescriptorType>, IndexList>::type;
forEachParamImpl<Func>(Is{}, std::forward<Args>(args)...);
}

//lambda version
template <typename T, class Func,
typename... Args>
void forEachParamType(Func&& f, Args&&... args)
{
using Is = typename impl::FilterTupleIndices<
IsParamType<T>, std::decay_t<DescriptorType>, IndexList>::type;

ForThese(mParams,std::forward<Func>(f),Is{},std::forward<Args>(args)...);

// /forEachParamImpl<Func>(Is{}, std::forward<Args>(args)...);
}




void reset() { resetImpl(IndexList()); }

Expand Down Expand Up @@ -362,8 +389,18 @@ class ParameterSetView<
}

ValueTuple toTuple() { return {mParams}; }

template<typename T>
static constexpr index NumOfType()
{
return
typename impl::FilterTupleIndices<IsParamType<T>, DescriptorType, IndexList>::size();

}


private:

template <typename T>
struct IsParamType
{
Expand Down
2 changes: 1 addition & 1 deletion include/clients/nrt/BufStatsClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ constexpr auto BufStatsParams = defineParameters(
FloatParam("high", "High Percentile", 100, Min(0), Max(100),
LowerLimit<kMiddle>()),
FloatParam("outliersCutoff", "Outliers Cutoff", -1, Min(-1)),
BufferParam("weights", "Weights Buffer"));
InputBufferParam("weights", "Weights Buffer"));

class BufferStatsClient : public FluidBaseClient,
public OfflineIn,
Expand Down
17 changes: 16 additions & 1 deletion include/clients/nrt/FluidSharedInstanceAdaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ class ParamAliasAdaptor<NRTClient, std::tuple<Ts...>>
std::forward<Args>(args)...);
}


//lambda version
template <typename T, class Func,
typename... Args>
void forEachParamType(Func&& f, Args&&... args)
{
mParams->params.template forEachParamType<T>(std::forward<Func>(f),std::forward<Args>(args)...);
}

void reset() { mParams->params.reset(); }

template <size_t N>
Expand All @@ -196,7 +205,13 @@ class ParamAliasAdaptor<NRTClient, std::tuple<Ts...>>
{
return mParams->params.template subset<offset>();
}


template <size_t N>
auto descriptorAt()
{
return mParams->params.template descriptor<N>();
}

template <typename Tuple>
void fromTuple(Tuple vals)
{
Expand Down
9 changes: 9 additions & 0 deletions include/data/FluidMeta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ void ForEach(Tuple&& tuple, F&& f, Args&&... args)
std::make_index_sequence<N>{}, std::forward<Args>(args)...);
}

template <typename Tuple, typename F, typename Indices, typename... Args>
void ForThese(Tuple&& tuple, F&& f, Indices idx, Args&&... args)
{
constexpr size_t N = std::tuple_size<std::remove_reference_t<Tuple>>::value;
ForEachIndexImpl(std::forward<Tuple>(tuple), std::forward<F>(f), idx,
std::forward<Args>(args)...);
}


namespace impl {

template <std::size_t... Is>
Expand Down

0 comments on commit 973961d

Please sign in to comment.