1 #include "sources/utils/algebra.h"
5 // small useful function to transform a matrix as given by R
6 // into a easier-to-handle one.
7 double* transpose(double* M
, int nrow
, int ncol
)
9 double* Mtr
= (double*)malloc(nrow
*ncol
*sizeof(double));
10 for (int i
=0; i
<nrow
; i
++)
12 for (int j
=0; j
<ncol
; j
++)
13 Mtr
[i
*ncol
+j
] = M
[i
+nrow
*j
];
18 // auxiliary to compute euclidian norm
19 double norm2(double* v
, int length
)
22 for (int j
=0; j
<length
; j
++)
27 // auxiliary to compute euclidian distance
28 double distance2(double* v1
, double* v2
, int length
)
30 double distance
= 0.0, diff
;
31 for (int j
=0; j
<length
; j
++)
34 distance
+= diff
*diff
;
36 return sqrt(distance
);