Skip to content

Commit 8748b40

Browse files
author
Tae Hyoun Park
committed
Merge branch 'master' of github.com:taehyounpark/queryosity
2 parents 8e3f585 + 0a2a619 commit 8748b40

File tree

8 files changed

+96
-60
lines changed

8 files changed

+96
-60
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
88

99

10-
Queryosity is a row-wise analysis description language for (semi-)structured data.
10+
Queryosity is a row-wise data analysis library for (semi-)structured data.
1111

1212
- Dataflow interface.
1313
- Arbitrary data types.
@@ -42,21 +42,19 @@ int main() {
4242
dataflow df(multithread::enable(10));
4343

4444
std::ifstream data("data.json");
45-
auto [x, v, w] = df.read(
46-
dataset::input<json>(data), dataset::column<double>("x"),
47-
dataset::column<std::vector<double>>("v"), dataset::column<double>("w"));
45+
auto [x, w] = df.read(
46+
dataset::input<json>(data), dataset::column<std::vector<double>>("x"), dataset::column<double>("w"));
4847

4948
auto zero = df.define(column::constant(0));
50-
auto v0 = v[zero];
49+
auto x0 = x[zero];
5150

5251
auto sel =
5352
df.weight(w)
5453
.filter(column::expression(
55-
[](std::vector<double> const &v) { return v.size(); }))(v)
56-
.filter(column::expression([](double x) { return x > 100.0; }))(x);
54+
[](std::vector<double> const &v) { return v.size(); }))(x);
5755

5856
auto h_x0_w = df.get(query::output<h1d>(linax(20, 0.0, 200.0)))
59-
.fill(v0)
57+
.fill(x0)
6058
.at(sel)
6159
.result();
6260

docs/examples/iris.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ using VecI = Vec<int>;
2323
using VecF = Vec<float>;
2424
using VecD = Vec<double>;
2525

26-
using dataflow = queryosity::dataflow;
27-
namespace multithread = queryosity::multithread;
28-
namespace dataset = queryosity::dataset;
29-
namespace column = queryosity::column;
30-
namespace query = queryosity::query;
31-
namespace systematic = queryosity::systematic;
26+
using dataflow = qty::dataflow;
27+
namespace multithread = qty::multithread;
28+
namespace dataset = qty::dataset;
29+
namespace column = qty::column;
30+
namespace query = qty::query;
31+
namespace systematic = qty::systematic;
3232

3333
class DRMinMaxSel
3434
: public column::definition<VecI(VecF, VecF, VecF, VecF, VecF)> {

docs/examples/xaod.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ using VecD = ROOT::RVec<double>;
1616

1717
#include "queryosity.h"
1818

19-
using dataflow = queryosity::dataflow;
20-
namespace multithread = queryosity::multithread;
21-
namespace dataset = queryosity::dataset;
22-
namespace column = queryosity::column;
23-
namespace query = queryosity::query;
24-
namespace systematic = queryosity::systematic;
19+
using dataflow = qty::dataflow;
20+
namespace multithread = qty::multithread;
21+
namespace dataset = qty::dataset;
22+
namespace column = qty::column;
23+
namespace query = qty::query;
24+
namespace systematic = qty::systematic;
2525

2626
#include "TCanvas.h"
2727
#include "TH1F.h"

docs/guide/dataflow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using dataflow = qty::dataflow;
77
namespace multithread = qty::multithread;
88
namespace dataset = qty::dataset;
99
namespace column = qty::column;
10+
namespace selection = qty::selection;
1011
namespace query = qty::query;
1112
namespace systematic = qty::systematic;
1213

docs/guide/datasets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ auto col = ds.read(dataset::column<DTYPE>(NAME));
1313

1414
## Loading-in a dataset
1515

16-
Call `queryosity::dataflow::load()` with an input dataset and its constructor arguments.
16+
Call `dataflow::load()` with an input dataset and its constructor arguments.
1717

1818
```cpp
1919
using json = qty::json;

docs/guide/queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ auto q = df.get(query::output<DEF>(ARGS...))
1717

1818
## Defining a query
1919

20-
Call `queryosity::dataflow::get()` specifying the definition and constructor arguments of the query.
20+
Call `dataflow::get()` specifying the definition and constructor arguments of the query.
2121

2222
```{code} cpp
2323
using h1d = qty::hist::hist<double>;

docs/guide/variations.md

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Systematic variations
22

3-
To specifying systematic variations on a column, provide the nominal argument and a mapping of variation name to alternate arguments to queryosity::dataflow::vary() instead of the usual queryosity::dataflow::define().
3+
To specifying systematic variations on a column, provide the nominal argument and a mapping of variation name to alternate arguments to `dataflow::vary()` instead of the usual `dataflow::define()`.
44

55
## Varying columns
66

@@ -15,7 +15,7 @@ auto x = ds.read(dataset::column<double>("x_nom"));
1515
:sync: var
1616
```{code} cpp
1717
auto x = ds.vary(dataset::column<double>("x_nom"),
18-
{{"shift_x", "x_shifted"}, {"smear_x", "x_smeared"}});
18+
{{"x_up", "x_up"}, {"x_down", "x_dn"}});
1919
```
2020
:::
2121
::::
@@ -24,13 +24,13 @@ auto x = ds.vary(dataset::column<double>("x_nom"),
2424
:::{tab-item} Constant
2525
:sync: nom
2626
```{code} cpp
27-
auto zero = df.define(column::constant(0));
27+
auto x = df.define(column::constant(0));
2828
```
2929
:::
3030
:::{tab-item} Varied
3131
:sync: var
3232
```{code} cpp
33-
auto pm1 = df.vary(column::constant(0), {{"plus_1", 1}, {"minus_1", -1}});
33+
auto x = df.vary(column::constant(0), {{"plus_1", 1}, {"minus_1", -1}});
3434
```
3535
:::
3636
::::
@@ -39,15 +39,31 @@ auto pm1 = df.vary(column::constant(0), {{"plus_1", 1}, {"minus_1", -1}});
3939
:::{tab-item} Expression
4040
:sync: nom
4141
```cpp
42-
auto x = df.define(column::constant(0));
42+
auto z = df.define(column::expression([](float x, double y) { return x + y; })(x, y);
43+
```
44+
:::
45+
:::{tab-item} Varied
46+
:sync: var
47+
```cpp
48+
auto z =
49+
df.vary(column::expression([](float x, double y) { return x + y; }),
50+
{{"times", [](double x, float y) { return x * y; }}})(x, y);
51+
```
52+
:::
53+
::::
54+
55+
::::{tab-set}
56+
:::{tab-item} Definition
57+
:sync: nom
58+
```cpp
59+
auto z = df.define(column::definition<DEF>(ARGS...))(x, y);
4360
```
4461
:::
4562
:::{tab-item} Varied
4663
:sync: var
4764
```cpp
48-
auto x =
49-
df.vary(column::expression([](float x, float y) { return x + y; }),
50-
{{"kill_x", [](double x, double y) { return x * y; }}})(x, pm1);
65+
auto z = df.vary(column::definition<DEF>(ARGS_NOM...),
66+
{{"var_name", {ARGS_VAR...}}})(x, y);
5167
```
5268
:::
5369
::::
@@ -65,9 +81,8 @@ auto z_half =
6581
:::{tab-item} Varied
6682
:sync: var
6783
```cpp
68-
auto z = systematic::vary(systematic::nominal(z_nom),
69-
systematic::variation("z_fixed", f_fixed),
70-
systematic::variation("z_half", z_half));
84+
auto z =
85+
df.vary(column::nominal(z_nom), {{"z_fixed", f_fixed}, {"z_half", z_half}});
7186
```
7287
:::
7388
::::
@@ -77,43 +92,37 @@ auto z = systematic::vary(systematic::nominal(z_nom),
7792
The set of variations active in a lazy action can be checked as they are propagated through the dataflow by:
7893
7994
```cpp
80-
// check variations
81-
x.has_variation("shift_x"); // true, x_shifted + 0
82-
x.has_variation("smear_x"); // true, x_smeared + 0
83-
x.has_variation("plus_1"); // true, x_nom + 1
84-
x.has_variation("minus_1"); // true, x_nom - 1
85-
x.has_variation("kill_x"); // true: x_nom * 0
86-
x.has_variation("no"); // false
87-
88-
// propagation through selection and query
95+
auto x = ds.vary(dataset::column<double>("x_nom"),
96+
{{"x_up", "x_up"}, {"x_down", "x_dn"}});
8997
auto yn = df.vary(column::constant(true), {{"no", false}});
9098
91-
systematic::get_variation_names(
92-
x, yn); // {"shift_x", "smear_x", "plus_1", "minus_1", "kill_x", "no"}
99+
// check variations
100+
x.has_variation("x_up"); // true
101+
x.has_variation("x_dn"); // true
102+
x.has_variation("no"); // false
93103
104+
// helper function to get active systematic variations in a set of actions
105+
systematic::get_variation_names(x, yn); // {"x_up", "x_dn", "no"}
106+
107+
// systematic variations get propagated through selections & queries
94108
auto cut = df.filter(yn);
95109
auto q = df.get(column::series(x)).at(cut);
96-
97-
q.get_variation_names(); // same set as (x, yn) above
110+
q.get_variation_names(); // {"x_up", "x_dn", "no"}
98111
```
99112

100113
## Accessing varied results
101114

102115
```cpp
103-
// access nominal+variation results
104-
q.nominal().result(); // {x_nom_0, ..., x_nom_N}
105-
q["shift_x"].result(); // {x_shifted_0, ..., x_shifted_N}
106-
q["plus_1"].result(); // {x_nom_0 + 1, ..., x_nom_N + 1}
107-
q["kill_x"].result(); // {0, ..., 0}
108-
q["no"].result(); // {}
109-
```
116+
// access nominal+variation queries and their results
117+
q.nominal().result(); // {x_nom_0, ..., x_nom_N}
118+
q["x_up"].result(); // {x_up_0, ..., x_up_N}
119+
q["x_dn"].result(); // {x_dn_0, ..., x_dn_N}
120+
q["no"].result(); // {}
110121

111-
```cpp
122+
// alternatively, use this helper function to retrieve the results
112123
auto q_results = systematic::get_results(q);
113-
114-
q_results.nominal; // {x_nom_0, ..., x_nom_N}
115-
q_results["shift_x"]; // {x_shifted_0, ..., x_shifted_N}
116-
q_results["plus_1"]; // {x_nom_0 + 1, ..., x_nom_N + 1}
117-
q_results["kill_x"]; // {0, ..., 0}
118-
q_results["no"]; // {}
124+
q_results.nominal;
125+
q_results["x_up"];
126+
q_results["x_dn"];
127+
q_results["no"];
119128
```

include/queryosity/dataflow.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,50 @@ class dataflow {
237237
*/
238238
template <typename... Sels> auto get(selection::yield<Sels...> const &sels);
239239

240+
/**
241+
* @brief Vary a column constant.
242+
* @tparam Val Constant value type.
243+
* @param[in] cnst Column constant.
244+
* @param[in] vars Map of variation to value.
245+
* @return Varied lazy column.
246+
*/
240247
template <typename Val>
241248
auto vary(column::constant<Val> const &cnst, std::map<std::string, Val> vars)
242249
-> varied<lazy<column::valued<Val>>>;
243250

251+
/**
252+
* @brief Vary a column expression.
253+
* @tparam Fn Expression function type.
254+
* @param[in] expr Column expression.
255+
* @param[in] vars Map of variation to expression.
256+
* @return Varied todo column evaluator.
257+
*/
244258
template <typename Fn>
245259
auto
246260
vary(column::expression<Fn> const &expr,
247261
std::map<std::string,
248262
typename column::expression<Fn>::function_type> const &vars)
249263
-> varied<todo<column::evaluator<column::equation_t<Fn>>>>;
250264

265+
/**
266+
* @brief Vary a column definition.
267+
* @tparam Def Definition type.
268+
* @param[in] defn Column definition.
269+
* @param[in] vars Map of variation to definition.
270+
* @return Varied todo column evaluator.
271+
*/
251272
template <typename Def>
252273
auto vary(column::definition<Def> const &defn,
253274
std::map<std::string, column::definition<Def>> const &vars)
254275
-> varied<todo<column::evaluator<Def>>>;
255276

277+
/**
278+
* @brief Vary a column.
279+
* @tparam Col Column type.
280+
* @param[in] nom Nominal lazy column.
281+
* @param[in] vars Map of variation to lazy column.
282+
* @return Varied lazy column.
283+
*/
256284
template <typename Col>
257285
auto vary(column::nominal<Col> const &nom,
258286
std::map<std::string, column::variation<column::value_t<Col>>> const

0 commit comments

Comments
 (0)