Previous Up Next

Chapter 4  Example 4: repetition and library in algorithm

From the principal window, choose File / Save as and save your fourth application under your tutorial folder with the name example4.

4.1  An algorithm with repetition without any library

In this section, we create a multiplication function of a N elements vector by a scalar by repeating N times a multiplication function on scalars.

4.1.1  Definition of the scalar ins and the function mul on scalars

In a new algorithm window:

4.1.2  Definition of the vectors inv and outv

To create the vectors:

4.1.3  Definition of the algorithm AlgorithmMain1

To create the AlgorithmMain1 algorithm:

The repetition consists in multiplying each of the 3 elements of the v_input vector with the s_input scalar and placing the result in the 3 elements v_output vector.

The parameter N is here the repetition factor of the mul function.


Figure 4.2: AlgorithmMain1 of the Example 4

4.2  An algorithm with repetition with the int library

In this section, we create a multiplication function of a vector by a scalar by using the int library.

4.2.1  Inclusion of the library int

From the principal window choose File / Specify Library Directories and add the SYNDEXPATH/libs where SYNDEXPATH is the absolute path of the SynDEx distribution.

From the principal window, choose File / Included Libraries / int (cf. figure 4.3).


Figure 4.3: File / Included Libraries / int

4.2.2  Definition of the algorithm AlgorithmMain2

Notice that this library contains input, mul, and output definitions parameterized with length.

We will need to set it to 1 for the scalar and the multiplication function, and to N for the vectors:

Notice the difference of the mul reference when it is seen from the AlgorithmMain2 definition mode or from the main mode (Main button).


Figure 4.5: AlgorithmMain2 of the Example 4

4.3  An algorithm with repetition with the float library

In this section, we create a multiplication function of a N*M matrix by a M elements vector by repeating N times a multiplication function on vectors.

4.3.1  Inclusion of the library float

Include the library float (File / Included Libraries / Float).

4.3.2  Definition of the function dpacc

This function is a multiplication function on scalars with an accumulator:

Notice that acc is an input port and an output port of the function. It will be used as an accumulator to store the partial sum.


Figure 4.6: Algorithm of the function dpacc

4.3.3  Definition of the function dp

This function is a multiplication function on vectors with an accumulator:

The repetition consists in multiplying two dpaccn elements vectors by calling dpaccn times the dpacc multiplication function on scalars with accumulator. The initial value of its accumulator is given by the zero constant and the following are given by the accumulator itself.

4.3.4  Definition of the function prodmatvec

This function is a multiplication function of a matrix by a vector:

The repetition consists in multiplying a a*b matrix by a b elements vector by calling a times the dp multiplication function on vectors.

4.3.5  Definition of the algorithm AlgorithmMain3

To create the AlgorithmMain3 algorithm:

From the principal window, choose File / Close. In the dialog window, click on the Save button.


Previous Up Next