From 7d3d2101f9ac015439bd914425d9b308cdfa6407 Mon Sep 17 00:00:00 2001 From: Ivan Afanasyev Date: Tue, 20 Aug 2024 15:35:59 +0700 Subject: [PATCH] speedup random forest getVotes method. --- modules/ml/src/rtrees.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/ml/src/rtrees.cpp b/modules/ml/src/rtrees.cpp index 41ffa03a5e..ec21403f15 100644 --- a/modules/ml/src/rtrees.cpp +++ b/modules/ml/src/rtrees.cpp @@ -388,9 +388,10 @@ public: results = output.getMat(); for( i = 0; i < nsamples; i++ ) { + const Mat sampleRow = samples.row(i); for( j = 0; j < ntrees; j++ ) { - float val = predictTrees( Range(j, j+1), samples.row(i), flags); + float val = predictTrees( Range(j, j+1), sampleRow, flags); results.at (i, j) = val; } } @@ -408,9 +409,10 @@ public: for( i = 0; i < nsamples; i++ ) { votes.clear(); + const Mat sampleRow = samples.row(i); for( j = 0; j < ntrees; j++ ) { - int val = (int)predictTrees( Range(j, j+1), samples.row(i), flags); + int val = (int)predictTrees( Range(j, j+1), sampleRow, flags); votes.push_back(val); }