Skip to content

Commit

Permalink
Tasking: Test returning multiple outputs of type std::any. (#5529)
Browse files Browse the repository at this point in the history
Test handling of multiple outputs of type std::any.
The desired behavior is that passing an iterable object with element type std::any doesn't wrap any into another layer of any,
but rather forwards the contained object.

When returning:
```C++
return vector<any>{ 1, 2.5f, string("cat") };
```
When getting the results:
```C+++
int integer = task->GetInputValue<int>(0);
float fraction = task->GetInputValue<float>(1);
string mammal = task->GetInputValue<string>(2);
```

----

Signed-off-by: Michał Zientkiewicz <[email protected]>
  • Loading branch information
mzient authored Sep 2, 2024
1 parent 623c258 commit 6efdeef
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions dali/core/exec/tasking_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,35 @@ TEST(TaskingTest, MultiOutputIterable) {
EXPECT_EQ(ret, 1 + 3 + 42 + 5 + 10);
}

TEST(TaskingTest, MultiOutputIterableOfAny) {
Executor ex(4);
ex.Start();
auto producer = Task::Create(2, []() {
return std::vector<std::any>{1.0, 42};
});

auto consumer1 = Task::Create([](Task *t) {
return t->GetInputValue<double>(0) + 3;
});
consumer1->Subscribe(producer, 0);

auto consumer2 = Task::Create([](Task *t) {
return t->GetInputValue<int>(0) + 5;
});
consumer2->Subscribe(producer, 1);

auto apex = Task::Create([](Task *t) {
return t->GetInputValue<double>(0) + t->GetInputValue<int>(1) + 10;
});
apex->Subscribe(consumer1)->Subscribe(consumer2);

ex.AddSilentTask(producer);
ex.AddSilentTask(consumer1);
ex.AddSilentTask(consumer2);
int ret = ex.AddTask(apex).Value<double>();
EXPECT_EQ(ret, 1 + 3 + 42 + 5 + 10);
}

TEST(TaskingTest, MultiOutputTuple) {
Executor ex(4);
ex.Start();
Expand Down

0 comments on commit 6efdeef

Please sign in to comment.