-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from picanumber/MultiplierStage
Hatching stage
- Loading branch information
Showing
14 changed files
with
348 additions
and
19 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,56 @@ | ||
#include "yap/pipeline.h" | ||
#include "yap/runtime_utilities.h" | ||
#include "yap/topology.h" | ||
|
||
#include <chrono> | ||
#include <iostream> | ||
#include <optional> | ||
|
||
using namespace std::chrono_literals; | ||
|
||
int main() | ||
{ | ||
std::vector<int> input{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
|
||
// Accepts Hatchable values, which means each input can produce multiple | ||
// outputs. Such a production happens in a "piecewise" manner meaning that | ||
// the stage does not return a collection of values; instead every piece of | ||
// output is immediately pushed to the next stage and the stage is invoked | ||
// again to produce the rest of the output. | ||
auto hatchingTransform = [curVal = 0, | ||
curChar = 'a'](yap::Hatchable<int> val) mutable { | ||
std::optional<char> ret; | ||
|
||
if (val) | ||
{ | ||
// New Input from previous stage. | ||
curChar = 'a' + *val.data; | ||
curVal = *val.data; | ||
ret.emplace(curChar); | ||
} | ||
else if (curVal-- > 0) | ||
{ | ||
// Keep processing the last input from previous stage. | ||
ret.emplace(curChar); | ||
} | ||
|
||
return ret; // Returning a contextually "false" object, here empty | ||
// optional, means the input won't be hatched any more and | ||
// the stage can process new values produced from the | ||
// previous stage. | ||
}; | ||
|
||
auto sink = [](std::optional<char> val) { | ||
std::cout << "Output: " << val.value() << std::endl; | ||
}; | ||
|
||
auto pl = yap::Pipeline{} | | ||
yap::OutputHatchable(yap::Consume(input.begin(), input.end())) | | ||
hatchingTransform | sink; | ||
|
||
std::cout << "Processing\n"; | ||
pl.consume(); | ||
std::cout << "Finished\n"; | ||
|
||
return 0; | ||
} |
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,27 @@ | ||
// © 2022 Nikolaos Athanasiou, github.com/picanumber | ||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
namespace yap | ||
{ | ||
|
||
namespace detail | ||
{ | ||
|
||
template <class T, template <class...> class Template> | ||
struct is_instantiation : std::false_type | ||
{ | ||
}; | ||
|
||
template <template <class...> class Template, class... Args> | ||
struct is_instantiation<Template<Args...>, Template> : std::true_type | ||
{ | ||
}; | ||
|
||
} // namespace detail | ||
|
||
template <class T, template <class...> class G> | ||
concept instantiation_of = detail::is_instantiation<T, G>::value; | ||
|
||
} // namespace yap |
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
File renamed without changes.
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.