Skip to content

Commit

Permalink
refactor T::varied -> varied<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
taehyounpark committed Apr 11, 2024
1 parent d9d1dd5 commit 7dda2d2
Show file tree
Hide file tree
Showing 10 changed files with 415 additions and 405 deletions.
8 changes: 4 additions & 4 deletions include/queryosity/column_series.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ template <typename Col> struct series {

auto make(lazy<selection::node> &sel) const;

auto make(lazy<selection::node>::varied &sel) const ->
typename lazy<query::series<value_type>>::varied;
auto make(varied<lazy<selection::node>> &sel) const ->
varied<lazy<query::series<value_type>>>;

protected:
Col m_column;
Expand All @@ -57,8 +57,8 @@ auto queryosity::column::series<Col>::make(lazy<selection::node> &sel) const {
}

template <typename Col>
auto queryosity::column::series<Col>::make(lazy<selection::node>::varied &sel)
const -> typename lazy<query::series<value_type>>::varied {
auto queryosity::column::series<Col>::make(varied<lazy<selection::node>> &sel)
const -> varied<lazy<query::series<value_type>>> {
auto df = sel.nominal().m_df;
return df->get(query::output<query::series<value_type>>())
.fill(m_column)
Expand Down
34 changes: 19 additions & 15 deletions include/queryosity/dataflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ template <typename T> class lazy;

template <typename U> class todo;

template <typename T> class varied;

/**
* @ingroup api
* @brief Main dataflow interface.
Expand All @@ -33,6 +35,7 @@ class dataflow {
template <typename> friend class dataset::loaded;
template <typename> friend class lazy;
template <typename> friend class todo;
template <typename> friend class varied;

public:
class node;
Expand Down Expand Up @@ -157,15 +160,15 @@ class dataflow {
* @param[in] column Input column used as cut decision.
* @return Lazy varied selection.
*/
template <typename Col> auto filter(Col const &col);
template <typename Lzy> auto filter(varied<Lzy> const &col);

/**
* @brief Initiate a cutflow.
* @tparam Col Lazy varied column.
* @param[in] column Input column used as weight decision.
* @return Lazy varied selection.
*/
template <typename Col> auto weight(Col const &col);
template <typename Lzy> auto weight(varied<Lzy> const &col);

/**
* @brief Initiate a cutflow.
Expand Down Expand Up @@ -236,19 +239,19 @@ class dataflow {

template <typename Val>
auto vary(column::constant<Val> const &cnst, std::map<std::string, Val> vars)
-> typename lazy<column::valued<Val>>::varied;
-> varied<lazy<column::valued<Val>>>;

template <typename Fn>
auto
vary(column::expression<Fn> const &expr,
std::map<std::string,
typename column::expression<Fn>::function_type> const &vars) ->
typename todo<column::evaluator<column::equation_t<Fn>>>::varied;
varied<todo<column::evaluator<column::equation_t<Fn>>>>;

template <typename Def>
auto vary(column::definition<Def> const &defn,
std::map<std::string, column::definition<Def>> const &vars) ->
typename todo<column::evaluator<Def>>::varied;
varied<todo<column::evaluator<Def>>>;

/* "public" API for Python layer */

Expand Down Expand Up @@ -344,6 +347,7 @@ class dataflow::node {

public:
friend class dataflow;
template <typename> friend class varied;

public:
template <typename Fn, typename... Nodes>
Expand Down Expand Up @@ -484,17 +488,17 @@ auto queryosity::dataflow::weight(lazy<Col> const &col)
return this->_apply<selection::weight>(col);
}

template <typename Col> auto queryosity::dataflow::filter(Col const &col) {
using varied_type = typename lazy<selection::node>::varied;
template <typename Lzy> auto queryosity::dataflow::filter(varied<Lzy> const &col) {
using varied_type = varied<lazy<selection::node>>;
varied_type syst(this->filter(col.nominal()));
for (auto const &var_name : col.get_variation_names()) {
syst.set_variation(var_name, this->filter(col.variation(var_name)));
}
return syst;
}

template <typename Col> auto queryosity::dataflow::weight(Col const &col) {
using varied_type = typename lazy<selection::node>::varied;
template <typename Lzy> auto queryosity::dataflow::weight(varied<Lzy> const &col) {
using varied_type = varied<lazy<selection::node>>;
varied_type syst(this->weight(col.nominal()));
for (auto const &var_name : col.get_variation_names()) {
syst.set_variation(var_name, this->weight(col.variation(var_name)));
Expand Down Expand Up @@ -612,9 +616,9 @@ inline void queryosity::dataflow::reset() { m_analyzed = false; }
template <typename Val>
auto queryosity::dataflow::vary(column::constant<Val> const &cnst,
std::map<std::string, Val> vars) ->
typename lazy<column::valued<Val>>::varied {
varied<lazy<column::valued<Val>>> {
auto nom = this->define(cnst);
using varied_type = typename lazy<column::valued<Val>>::varied;
using varied_type = varied<lazy<column::valued<Val>>>;
varied_type syst(std::move(nom));
for (auto const &var : vars) {
this->_vary(syst, var.first, column::constant<Val>(var.second));
Expand All @@ -627,9 +631,9 @@ auto queryosity::dataflow::vary(
column::expression<Fn> const &expr,
std::map<std::string, typename column::expression<Fn>::function_type> const
&vars) ->
typename todo<column::evaluator<column::equation_t<Fn>>>::varied {
varied<todo<column::evaluator<column::equation_t<Fn>>>> {
auto nom = this->_equate(expr);
using varied_type = typename decltype(nom)::varied;
using varied_type = varied<decltype(nom)>;
using function_type = typename column::expression<Fn>::function_type;
varied_type syst(std::move(nom));
for (auto const &var : vars) {
Expand All @@ -642,9 +646,9 @@ template <typename Def>
auto queryosity::dataflow::vary(
column::definition<Def> const &defn,
std::map<std::string, column::definition<Def>> const &vars) ->
typename todo<column::evaluator<Def>>::varied {
varied<todo<column::evaluator<Def>>> {
auto nom = this->_define(defn);
using varied_type = typename decltype(nom)::varied;
using varied_type = varied<decltype(nom)>;
varied_type syst(std::move(nom));
for (auto const &var : vars) {
this->_vary(syst, var.first, var.second);
Expand Down
2 changes: 1 addition & 1 deletion include/queryosity/dataset_loaded.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ auto queryosity::dataset::loaded<DS>::vary(
dataset::column<Val> const &col,
std::map<std::string, std::string> const &vars) {
auto nom = this->read(col);
typename decltype(nom)::varied varied_column(std::move(nom));
varied<decltype(nom)> varied_column(std::move(nom));
for (auto const &var : vars) {
varied_column.set_variation(var.first,
this->read(dataset::column<Val>(var.second)));
Expand Down
45 changes: 22 additions & 23 deletions include/queryosity/detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@
std::enable_if_t<queryosity::is_column_v<V> && \
queryosity::is_column_v<typename Arg::action_type>, \
bool> = false> \
auto operator op_symbol(Arg const &b) const -> typename lazy< \
typename decltype(std::declval<lazy<Act>>().operator op_symbol( \
b.nominal()))::action_type>::varied;
auto operator op_symbol(Arg const &b) const -> varied< \
lazy<typename decltype(std::declval<queryosity::lazy<Act>>(). \
operator op_symbol(b.nominal()))::action_type>>;

#define DEFINE_LAZY_VARIED_BINARY_OP(op_symbol) \
template <typename Act> \
Expand All @@ -130,15 +130,15 @@
std::enable_if_t<queryosity::is_column_v<V> && \
queryosity::is_column_v<typename Arg::action_type>, \
bool>> \
auto queryosity::lazy<Act>::varied::operator op_symbol(Arg const &b) const \
-> typename lazy< \
typename decltype(std::declval<lazy<Act>>().operator op_symbol( \
b.nominal()))::action_type>::varied { \
auto syst = typename lazy< \
typename decltype(std::declval<lazy<Act>>().operator op_symbol( \
b.nominal()))::action_type>::varied(this->nominal(). \
operator op_symbol( \
b.nominal())); \
auto queryosity::varied<queryosity::lazy<Act>>::operator op_symbol( \
Arg const &b) const \
-> varied< \
lazy<typename decltype(std::declval<lazy<Act>>().operator op_symbol( \
b.nominal()))::action_type>> { \
auto syst = varied< \
lazy<typename decltype(std::declval<lazy<Act>>().operator op_symbol( \
b.nominal()))::action_type>>( \
this->nominal().operator op_symbol(b.nominal())); \
for (auto const &var_name : systematic::get_variation_names(*this, b)) { \
syst.set_variation(var_name, variation(var_name).operator op_symbol( \
b.variation(var_name))); \
Expand All @@ -149,20 +149,19 @@
#define DECLARE_LAZY_VARIED_UNARY_OP(op_symbol) \
template <typename V = Act, \
std::enable_if_t<queryosity::is_column_v<V>, bool> = false> \
auto operator op_symbol() const -> typename lazy< \
typename decltype(std::declval<lazy<V>>(). \
operator op_symbol())::action_type>::varied;
auto operator op_symbol() const -> varied< \
queryosity::lazy<typename decltype(std::declval<lazy<V>>(). \
operator op_symbol())::action_type>>;
#define DEFINE_LAZY_VARIED_UNARY_OP(op_name, op_symbol) \
template <typename Act> \
template <typename V, std::enable_if_t<queryosity::is_column_v<V>, bool>> \
auto queryosity::lazy<Act>::varied::operator op_symbol() const -> \
typename lazy< \
typename decltype(std::declval<lazy<V>>(). \
operator op_symbol())::action_type>::varied { \
auto syst = \
typename lazy<typename decltype(std::declval<lazy<V>>(). \
operator op_symbol())::action_type>:: \
varied(this->nominal().operator op_symbol()); \
auto queryosity::varied<queryosity::lazy<Act>>::operator op_symbol() const \
-> varied<lazy<typename decltype(std::declval<lazy<V>>(). \
operator op_symbol())::action_type>> { \
auto syst = varied<queryosity::lazy< \
typename decltype(std::declval<lazy<V>>(). \
operator op_symbol())::action_type>>( \
this->nominal().operator op_symbol()); \
for (auto const &var_name : systematic::get_variation_names(*this)) { \
syst.set_variation(var_name, variation(var_name).operator op_symbol()); \
} \
Expand Down
20 changes: 9 additions & 11 deletions include/queryosity/lazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class lazy : public dataflow::node,
public systematic::resolver<lazy<Action>>,
public query::result_of<Action> {

public:
class varied;

public:
using action_type = Action;

Expand Down Expand Up @@ -56,12 +53,14 @@ class lazy : public dataflow::node,

virtual std::vector<Action *> const &get_slots() const final override;

virtual void set_variation(const std::string &var_name, lazy var) final override;
virtual void set_variation(const std::string &var_name,
lazy var) final override;

virtual lazy &nominal() final override;
virtual lazy &variation(const std::string &var_name) final override;
virtual lazy const &nominal() const final override;
virtual lazy const &variation(const std::string &var_name) const final override;
virtual lazy const &
variation(const std::string &var_name) const final override;

virtual bool has_variation(const std::string &var_name) const final override;
virtual std::set<std::string> get_variation_names() const final override;
Expand Down Expand Up @@ -163,8 +162,8 @@ class lazy : public dataflow::node,
*/
template <typename Col,
std::enable_if_t<queryosity::is_varied_v<Col>, bool> = false>
auto get(column::series<Col> const &col) -> typename lazy<
query::series<typename column::series<Col>::value_type>>::varied;
auto get(column::series<Col> const &col)
-> varied<lazy<query::series<typename column::series<Col>::value_type>>>;

/**
* @brief (Process and) retrieve the result of a query.
Expand Down Expand Up @@ -338,7 +337,7 @@ template <typename Action>
template <typename Col>
auto queryosity::lazy<Action>::filter(Col const &col) const {
if constexpr (std::is_base_of_v<selection::node, Action>) {
using varied_type = typename lazy<selection::node>::varied;
using varied_type = varied<lazy<selection::node>>;
auto syst = varied_type(this->filter(col.nominal()));
for (auto const &var_name : col.get_variation_names()) {
syst.set_variation(var_name, this->filter(col.variation(var_name)));
Expand All @@ -354,7 +353,7 @@ template <typename Action>
template <typename Col>
auto queryosity::lazy<Action>::weight(Col const &col) const {
if constexpr (std::is_base_of_v<selection::node, Action>) {
using varied_type = typename lazy<selection::node>::varied;
using varied_type = varied<lazy<selection::node>>;
auto syst = varied_type(this->weight(col.nominal()));
for (auto const &var_name : col.get_variation_names()) {
syst.set_variation(var_name, this->weight(col.variation(var_name)));
Expand Down Expand Up @@ -416,8 +415,7 @@ auto queryosity::lazy<Action>::get(queryosity::column::series<Col> const &col)
template <typename Action>
template <typename Col, std::enable_if_t<queryosity::is_varied_v<Col>, bool>>
auto queryosity::lazy<Action>::get(queryosity::column::series<Col> const &col)
-> typename lazy<
query::series<typename column::series<Col>::value_type>>::varied {
-> varied<lazy<query::series<typename column::series<Col>::value_type>>> {
return col.make(*this);
}

Expand Down
Loading

0 comments on commit 7dda2d2

Please sign in to comment.