Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions phlex/core/edge_creation_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ namespace phlex::experimental {
std::multimap<product_name_t, named_output_port> result;
for (auto const& [node_name, node] : nodes) {
for (auto const& product_name : node->output()) {
if (empty(product_name.name()))
continue;
result.emplace(
product_name.name(),
named_output_port{node_name, &node->sender(), &node->to_output(), product_name.type()});
Expand Down
7 changes: 7 additions & 0 deletions phlex/core/product_query.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "phlex/core/product_query.hpp"

#include "fmt/format.h"
#include "phlex/model/algorithm_name.hpp"
#include "phlex/model/product_specification.hpp"

#include <ostream>
#include <stdexcept>
Expand All @@ -23,6 +25,11 @@ namespace phlex::experimental {
return fmt::format("{} ϵ {}", spec.full(), layer);
}

product_tag from(char const* creator)
{
return {.spec = product_specification(algorithm_name(creator), "", type_id())};
}

product_tag operator""_in(char const* product_name, std::size_t length)
{
if (length == 0ull) {
Expand Down
6 changes: 6 additions & 0 deletions phlex/core/product_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ namespace phlex::experimental {
struct product_tag {
product_specification spec;
product_query operator()(std::string layer) &&;
product_query in(std::string layer) &&
{
// std::move(*this) required to forward to rvalue ref qualified operator()
return std::move(*this).operator()(std::move(layer));
}
};

using product_queries = std::vector<product_query>;

inline auto& to_name(product_query const& query) { return query.spec.name(); }
inline auto& to_layer(product_query& query) { return query.layer; }

product_tag from(char const* creator);
product_tag operator""_in(char const* str, std::size_t);
bool operator==(product_query const& a, product_query const& b);
bool operator!=(product_query const& a, product_query const& b);
Expand Down
9 changes: 9 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ cet_test(
Boost::json
phlex::core
)
cet_test(
anonymous_products
USE_CATCH2_MAIN
SOURCE
anonymous_products.cpp
LIBRARIES
Boost::json
phlex::core
)
cet_test(
data_cell_counting
USE_CATCH2_MAIN
Expand Down
58 changes: 58 additions & 0 deletions test/anonymous_products.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "phlex/core/framework_graph.hpp"
#include "phlex/model/data_layer_hierarchy.hpp"
#include "phlex/model/product_store.hpp"

#include "catch2/catch_test_macros.hpp"

#include <algorithm>
#include <numeric>
#include <vector>

using namespace phlex::experimental;

namespace {
auto square_numbers(std::vector<unsigned> const& numbers)
{
std::vector<unsigned> result(size(numbers));
std::ranges::transform(numbers, begin(result), [](unsigned i) { return i * i; });
return result;
}

auto sum_numbers(std::vector<unsigned> const& squared_numbers)
{
std::vector<unsigned> const expected_squared_numbers{0, 1, 4, 9, 16};
CHECK(squared_numbers == expected_squared_numbers);
return std::accumulate(begin(squared_numbers), end(squared_numbers), 0u);
}

double sqrt_sum_numbers(unsigned summed_numbers, unsigned offset)
{
CHECK(summed_numbers == 30u);
return std::sqrt(static_cast<double>(summed_numbers + offset));
}
}

TEST_CASE("Test resolution without product suffixes", "[programming model]")
{
framework_graph g{data_cell_index::base_ptr()};
g.provide("provide_numbers",
[](data_cell_index const&) -> std::vector<unsigned> { return {0, 1, 2, 3, 4}; })
.output_product("numbers"_in("job"));
g.provide("provide_offset", [](data_cell_index const&) -> unsigned { return 6u; })
.output_product("offset"_in("job"));

g.transform("square_numbers", square_numbers, concurrency::unlimited)
.input_family("numbers"_in("job"))
.output_products("");
g.transform("sum_numbers", sum_numbers, concurrency::unlimited)
.input_family(from("square_numbers").in("job"))
.output_products("");
g.transform("sqrt_sum_numbers", sqrt_sum_numbers, concurrency::unlimited)
.input_family(from("sum_numbers").in("job"), "offset"_in("job"))
.output_products("result");

// The following is invoked for *each* section above
g.observe("verify_result", [](double actual) { assert(actual == 6.); })
.input_family("result"_in("job"));
g.execute();
}
Loading