1 
2 #include "RTE_Components.h"
3 #include  CMSIS_device_header
4 
5 #if defined(MPS3)
6 #include "cmsis_driver_config.h"
7 #include "stdout_USART.h"
8 #endif
9 
10 #include <iostream>
11 
12 #include <dsppp/memory_pool.hpp>
13 #include <dsppp/fixed_point.hpp>
14 #include <dsppp/matrix.hpp>
15 
16 using namespace arm_cmsis_dsp;
17 
18 
main(void)19 int main(void)
20 {
21 #if defined(MPS3)
22     stdout_init();
23 #endif
24 
25     std::cout << "Matrix operation examples\r\n";
26 
27     constexpr int ROWS = 8;
28     constexpr int COLS = 8;
29 
30     Matrix<float32_t,ROWS,COLS> a;
31     Matrix<float32_t,ROWS,COLS> b;
32 
33     for(std::size_t i=0;i<ROWS*COLS;i++)
34     {
35        a[i] = float32_t(i);
36     }
37 
38     for(std::size_t row=0; row<ROWS; row++)
39     {
40        for(std::size_t col=0; col<COLS; col++)
41        {
42             b(row,col) = float32_t(row*col);
43        }
44     }
45 
46     Matrix<float32_t,ROWS,COLS> result = a * a + b;
47 
48     std::cout << "Result = " << std::endl << result ;
49 
50     // Vector views
51 
52     // Rows
53     result.row(1) = 0.0f;
54     std::cout << "Result = " << std::endl << result ;
55 
56     // Row with stride
57     // setting odd elements of 3rd row to 0
58     result.row<2>(2,1) = 0.0f;
59     std::cout << "Result = " << std::endl << result ;
60 
61     // Column with stride
62     result.col<2>(2,1) = 5.0f;
63     std::cout << "Result = " << std::endl << result ;
64 
65     // Matrix view
66     result.sub(4,8,4,8) = result.sub(4,8,4,8) + result.sub(4,8,4,8);
67     std::cout << "Result = " << std::endl << result ;
68 
69     // operators
70     // dot
71     result = dot(a,b);
72     std::cout << "Result = " << std::endl << result ;
73 
74     // diagonal
75     Vector<float32_t,ROWS> c;
76 
77     for(int i = 0;i< ROWS;i++)
78     {
79         c[i] = i;
80     }
81     result = Matrix<float32_t,ROWS,COLS>::diagonal(c);
82 
83     std::cout << "Result = " << std::endl << result ;
84 
85     // identity matrix
86     result = Matrix<float32_t,ROWS,COLS>::identity();
87 
88     std::cout << "Result = " << std::endl << result ;
89 
90     // transpose matrix
91     result = a.transpose();
92 
93     std::cout << "Result = " << std::endl << result ;
94 
95     transposeTo(result,a);
96 
97     std::cout << "Result = " << std::endl << result ;
98 
99     // outer product
100     result = outer(c,c);
101     std::cout << "Result = " << std::endl << result ;
102 
103 
104 #if defined(MPS3)
105     while(1);
106 #endif
107 }
108 
109 
110