Commit 0e60392a authored by Zohreh MOSTAANI's avatar Zohreh MOSTAANI

[general][doc] removing the example about groups since it is not very clear yet

parent 243fc968
Pipeline #25083 passed with stage
in 9 minutes and 26 seconds
......@@ -279,7 +279,7 @@ Here is the equivalent example for a sequential algorithm in C++:
class Algorithm: public IAlgorithmSequential
{
public:
virtual bool process(const InputList& inputs, const DataloaderList& data_load_list, const OutputList& outputs)
bool process(const InputList& inputs, const DataloaderList& data_load_list, const OutputList& outputs) override
{
// here, you read inputs, process and write results to outputs
}
......@@ -662,7 +662,7 @@ The example below illustrates how such an algorithm could be implemented:
Here, the units received at the endpoint ``in`` are accumulated as long as the
``hasMoreData()`` method attached to the input ``in2`` returns ``True``.
When ``isDataUnitDone()`` returns ``False``, the corresponding label is read
When ``hasMoreData()`` returns ``False``, the corresponding label is read
from ``in2``, and a result is produced at the endpoint ``out``. After an output
unit has been produced, the internal accumulator for ``in`` is cleared, and the
algorithm starts accumulating a new set of objects for the next label.
......@@ -765,95 +765,95 @@ unsynchronized input (``in3``).
In the example above you have several inputs which are synchronized together, but
unsynchronized with the block you're writing your algorithm for. It may also happen that you have even more data inputs that are unsynchronized. In this case,
it is safer to treat inputs using their *group*. For example:
unsynchronized with the block you're writing your algorithm for. It may also happen that you have even more data inputs that are unsynchronized. In this case, using *group* for different set of inputs makes the code easier to read.
.. it is safer to treat inputs using their *group*. For example:
.. code-block:: python
:linenos:
.. .. code-block python
.. :linenos:
class Algorithm:
.. class Algorithm:
def __init__(self):
self.models = None
.. def __init__(self):
.. self.models = None
def prepare(self, data_loaders):
.. def prepare(self, data_loaders):
#??? Is the concept of groups any use when we have dataloaders assuming this scenario???
.. #??? Is the concept of groups any use when we have dataloaders assuming this scenario???
# Loads the "model" data at the beginning
loader = data_loaders.loaderOf('in3')
for i in range(loader.count()):
view = loader.view('in3', i)
data, _, _ = view[0]
self.models.append(data['in3'].value)
.. # Loads the "model" data at the beginning
.. loader = data_loaders.loaderOf('in3')
.. for i in range(loader.count()):
.. view = loader.view('in3', i)
.. data, _, _ = view[0]
.. self.models.append(data['in3'].value)
def process(self, inputs, data_loaders, outputs):
# N.B.: this will be called for every unit in `in'
.. def process(self, inputs, data_loaders, outputs):
.. # N.B.: this will be called for every unit in `in'
# Loads the "model" data at the beginning, once
if self.models is None:
self.models = []
group = inputs.groupOf('in3')
while group.hasMoreData():
group.next() #synchronously advances the data
self.models.append(group['in3'].data.value)
.. # Loads the "model" data at the beginning, once
.. if self.models is None:
.. self.models = []
.. group = inputs.groupOf('in3')
.. while group.hasMoreData():
.. group.next() #synchronously advances the data
.. self.models.append(group['in3'].data.value)
# Processes the current input in `in' and `in2', apply the model/models
out = magical_processing(inputs['in'].data.value,
inputs['in2'].data.value,
self.models)
.. # Processes the current input in `in' and `in2', apply the model/models
.. out = magical_processing(inputs['in'].data.value,
.. inputs['in2'].data.value,
.. self.models)
# Writes the output
outputs.write({'value': out})
.. # Writes the output
.. outputs.write({'value': out})
return True
.. return True
.. code-block:: c++
:linenos:
.. code-block c++
.. :linenos:
class Algorithm: public IAlgorithmSequential
{
public:
.. class Algorithm: public IAlgorithmSequential
.. {
.. public:
bool prepare(const beat::backend::cxx::DataLoaderList& data_load_list) override
{
auto loader = data_load_list["in3"];
for (int i = 0 ; i < loader->count() ; ++i) {
auto view = loader->view("in3", i);
.. {
.. auto loader = data_load_list["in3"];
.. for (int i = 0 ; i < loader->count() ; ++i) {
.. auto view = loader->view("in3", i);
std::map<std::string, beat::backend::cxx::Data *> data;
std::tie(data, std::ignore, std::ignore) = (*view)[0];
auto model = static_cast<user::model*>(data["in3"]);
models.append(*model);
}
.. models.append(*model);
.. }
return true;
}
.. return true;
.. }
bool process(const InputList& inputs, const DataloaderList& data_load_list, const OutputList& outputs) override
{
// N.B.: this will be called for every unit in `in'
.. bool process(const InputList& inputs, const DataloaderList& data_load_list, const OutputList& outputs) override
.. {
.. // N.B.: this will be called for every unit in `in'
// Processes the current input in `in' and `in2', apply the model/models
.. // Processes the current input in `in' and `in2', apply the model/models
auto out = magical_processing(inputs["in"]->data<user::format_1>()->value,
inputs["in2"]->data<user::format_1>()->value,
models);
.. models);
// Writes the output
.. // Writes the output
user::other_1 result;
result.value = out;
.. result.value = out;
outputs["out"]->write(&result);
.. outputs["out"]->write(&result);
return true;
}
.. return true;
.. }
public:
.. public:
std::vector<user::model_1> models;
};
.. };
In practice, encoding your algorithms using *groups* instead of looping over
individual inputs makes the code more robust to changes.
.. In practice, encoding your algorithms using *groups* instead of looping over
.. individual inputs makes the code more robust to changes.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment