1 /* { dg-do compile } */
2 /* { dg-options "-O3 -Warray-bounds" } */
3 
4 #include <stdio.h>
5 #include <math.h>
6 
7 #define MAX_MATRIX_SIZE      (10)
8 
9 typedef struct
10 {
11   unsigned int nof_rows;
12   unsigned int nof_cols;
13   float data[MAX_MATRIX_SIZE][MAX_MATRIX_SIZE];
14 } MATRIX_TYPE;
15 
16 extern void mtrx_decompose_matrix (MATRIX_TYPE * p_input_matrix);
17 
18 void
mtrx_decompose_matrix(MATRIX_TYPE * p_input_matrix)19 mtrx_decompose_matrix (MATRIX_TYPE * p_input_matrix)
20 {
21   unsigned int row;
22   unsigned int col;
23   unsigned int sub;
24   float sum;
25   MATRIX_TYPE tmp;
26 
27   for (row = 0; row < MAX_MATRIX_SIZE; row++) {
28     for (col = 0; col < MAX_MATRIX_SIZE; col++) {
29       tmp.data[row][col] = 0.0;
30     }
31   }
32   tmp.nof_cols = 0;
33   tmp.nof_rows = 0;
34 
35   for (row = 0; row < p_input_matrix->nof_rows; row++) {
36     for (col = row; col < p_input_matrix->nof_cols; col++) {
37       sum = 0.0f;
38       for (sub = 0; sub < row; sub++) {
39 	sum += tmp.data[row][sub] * tmp.data[col][sub];
40       }
41       sum = p_input_matrix->data[col][row] - sum;
42       if (row == col) {
43 	if (sum >= 0.0) {
44 #if ERROR
45 	  tmp.data[row][col] = sqrtf (sum);
46 #else
47 	  tmp.data[row][col] = sum;
48 #endif
49 	}
50 	else {
51 	  tmp.data[row][col] = 0.0f;
52 	}
53       }
54       else {
55 	tmp.data[col][row] = sum / tmp.data[row][row];
56       }
57     }
58   }
59 }
60 
61