'Fold in Scade Suite is confusing me
So I know how the reduce, accumulator and how fold works in C++, Python, etc... But for some reason in Scade Suite it's kinda confusing to me.
Scade Suite Example That is confusing me
What I'm not understanding from the example is are the two arrays multiplying with each other without the accumulator value? How are both arrays being stepped through, how are they being multiplied by each other and if that can happen what's the point of having an accumulator value in the first place. Can someone break this down for me. I'm dumb.
Solution 1:[1]
In the way the fold in Scade is defined, the output of the operator contained in the fold construct (here, Output1 of mult_scalar) from the previous iteration is fed as input (here, Acc) for the next iteration as we progress through the array.
There is an accumulator, defined implicitly as the "+"-operation in mult_scalar. Its initial value is defined as "a"-marked input of fold. Note that in each iteration mult_scalar adds the product of two elements from the input arrays to the Acc producing Output1.
Fold calls an operator (here, mult_scalar) iteratively supplying it with the following arguments: accumulator values (it may be more than one, there is just one in this case) and respective elements of the input arrays. After each iteration the accumulator value is updated and fed into the next iteration.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | lyskiman |