-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e062a40
commit 0e53e3e
Showing
14 changed files
with
222 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
```cpp | ||
#include "analogical.h" | ||
|
||
auto df = ana::dataflow( ana::multithread::enable(10) ); | ||
|
||
auto [x, w] = df.open<Json>("data.json")\ | ||
.read<std::vector<float>, float>({"x", "w"}); | ||
|
||
auto zero = df.constant(0); | ||
auto x0 = x[zero]; | ||
|
||
auto mask = [](std::vector<float> const& v){return v.size()}; | ||
auto masked = df.filter("mask",mask)(x).weight("weight")(w); | ||
|
||
auto hist_x0 = df.agg<Hist<float>>(axis::regular(10,0,1.0)).fill(x0); | ||
auto hist_x0_result = masked.book(hist_x0).result(); | ||
|
||
std::cout << *(hist_x0.result()) << std::endl; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <boost/histogram.hpp> // make_histogram, regular, weight, indexed | ||
#include <functional> // std::ref | ||
#include <utility> | ||
|
||
#include "ana/analogical.h" | ||
|
||
using BooleanAxis = boost::histogram::axis::boolean<>; | ||
using IntegerAxis = boost::histogram::axis::integer<>; | ||
using LinearAxis = boost::histogram::axis::regular<>; | ||
using VariableAxis = boost::histogram::axis::variable<>; | ||
|
||
using Axis_t = boost::histogram::axis::variant<BooleanAxis, IntegerAxis, | ||
LinearAxis, VariableAxis>; | ||
using Axes_t = std::vector<Axis_t>; | ||
using Histogram_t = boost::histogram::histogram<Axes_t>; | ||
|
||
template <typename... Cols> | ||
class Histogram | ||
: public ana::aggregation::logic<std::shared_ptr<Histogram_t>(Cols...)> { | ||
|
||
public: | ||
public: | ||
template <typename... Axes> Histogram(Axes &&...axes); | ||
~Histogram() = default; | ||
|
||
virtual void fill(ana::observable<Cols>... columns, double w) override; | ||
virtual std::shared_ptr<Histogram_t> result() const override; | ||
virtual std::shared_ptr<Histogram_t> | ||
merge(std::vector<std::shared_ptr<Histogram_t>> results) const override; | ||
|
||
protected: | ||
std::shared_ptr<Histogram_t> m_hist; | ||
}; | ||
|
||
template <typename... Cols> | ||
template <typename... Axes> | ||
Histogram<Cols...>::hist(Axes &&...axes) { | ||
m_hist = std::make_shared<Histogram_t>(std::move( | ||
boost::histogram::make_weighted_histogram(std::forward<Axes>(axes)...))); | ||
} | ||
|
||
template <typename... Cols> | ||
void Histogram<Cols...>::fill(ana::observable<Cols>... columns, double w) { | ||
(*m_hist)(columns.value()..., boost::histogram::weight(w)); | ||
} | ||
|
||
template <typename... Cols> | ||
std::shared_ptr<Histogram_t> Histogram<Cols...>::result() const { | ||
return m_hist; | ||
} | ||
|
||
template <typename... Cols> | ||
std::shared_ptr<Histogram_t> Histogram<Cols...>::merge( | ||
std::vector<std::shared_ptr<Histogram_t>> results) const { | ||
auto sum = std::make_shared<Histogram_t>(*results[0]); | ||
sum->reset(); | ||
for (const auto &result : results) { | ||
*sum += *result; | ||
} | ||
return sum; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.