15
15
** limitations under the License.
16
16
*****************************************************************************/
17
17
18
+ #include < cfloat> // for FLT_MAX
19
+ #include < cmath>
20
+ #include < vector> // for std::vector
21
+
18
22
#include " cluster.h"
19
- #include " cutil.h" // for void_proc
23
+ #include " cutil.h" // for void_proc
20
24
#include " emalloc.h"
21
25
#include " genericheap.h"
22
26
#include " helpers.h"
23
27
#include " kdpair.h"
24
28
#include " matrix.h"
25
29
#include " tprintf.h"
26
- #include < cfloat> // for FLT_MAX
27
- #include < cmath>
28
30
29
31
#define HOTELLING 1 // If true use Hotelling's test to decide where to split.
30
32
#define FTABLE_X 10 // Size of FTable.
@@ -1084,10 +1086,9 @@ PROTOTYPE *TestEllipticalProto(CLUSTERER *Clusterer,
1084
1086
int TotalDims = Left->SampleCount + Right->SampleCount ;
1085
1087
if (TotalDims < N + 1 || TotalDims < 2 )
1086
1088
return nullptr ;
1087
- const int kMatrixSize = N * N * sizeof (float );
1088
- float *Covariance = static_cast <float *>(Emalloc (kMatrixSize ));
1089
- float *Inverse = static_cast <float *>(Emalloc (kMatrixSize ));
1090
- float *Delta = static_cast <float *>(Emalloc (N * sizeof (float )));
1089
+ std::vector<float > Covariance (N * N);
1090
+ std::vector<float > Inverse (N * N);
1091
+ std::vector<float > Delta (N);
1091
1092
// Compute a new covariance matrix that only uses essential features.
1092
1093
for (int i = 0 ; i < N; ++i) {
1093
1094
int row_offset = i * N;
@@ -1107,7 +1108,7 @@ PROTOTYPE *TestEllipticalProto(CLUSTERER *Clusterer,
1107
1108
}
1108
1109
}
1109
1110
}
1110
- double err = InvertMatrix (Covariance, N, Inverse);
1111
+ double err = InvertMatrix (& Covariance[ 0 ] , N, & Inverse[ 0 ] );
1111
1112
if (err > 1 ) {
1112
1113
tprintf (" Clustering error: Matrix inverse failed with error %g\n " , err);
1113
1114
}
@@ -1129,9 +1130,6 @@ PROTOTYPE *TestEllipticalProto(CLUSTERER *Clusterer,
1129
1130
}
1130
1131
Tsq += Delta[x] * temp;
1131
1132
}
1132
- free (Covariance);
1133
- free (Inverse);
1134
- free (Delta);
1135
1133
// Changed this function to match the formula in
1136
1134
// Statistical Methods in Medical Research p 473
1137
1135
// By Peter Armitage, Geoffrey Berry, J. N. S. Matthews.
0 commit comments