Commit 38db1fcb authored by Davis King's avatar Davis King

Changed code to avoid triggering one of visual studio's bug checking hooks (when…

Changed code to avoid triggering one of visual studio's bug checking hooks (when there isn't a bug).

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403638
parent 5e98f184
......@@ -151,13 +151,16 @@ namespace dlib
// within the inner for loop we have:
// [begin_i, end_i) == the range in edges that contains neighbors of samples[i]
// [begin_j, end_j) == the range in edges that contains neighbors of samples[j]
for (unsigned long i = 0; i < samples.size(); ++i)
for (unsigned long i = 0; i+1 < samples.size(); ++i)
{
begin_j = begin_i + k;
end_j = begin_j + k;
begin_j = begin_i;
end_j = end_i;
for (unsigned long j = i+1; j < samples.size(); ++j)
{
begin_j += k;
end_j += k;
const float dist = dist_funct(samples[i], samples[j]);
if (dist < worst_dists[i])
......@@ -171,9 +174,6 @@ namespace dlib
*iterator_of_worst(begin_j, end_j) = sample_pair(i, j, dist);
worst_dists[j] = iterator_of_worst(begin_j, end_j)->distance();
}
begin_j += k;
end_j += k;
}
begin_i += k;
......
......@@ -188,6 +188,54 @@ namespace
}
void test_knn1()
{
std::vector<matrix<double,2,1> > samples;
matrix<double,2,1> test;
test = 0,0; samples.push_back(test);
test = 1,1; samples.push_back(test);
test = 1,-1; samples.push_back(test);
test = -1,1; samples.push_back(test);
test = -1,-1; samples.push_back(test);
std::vector<sample_pair> edges;
find_k_nearest_neighbors(samples, squared_euclidean_distance(), 1, edges);
DLIB_TEST(edges.size() == 4);
std::sort(edges.begin(), edges.end(), &order_by_index);
DLIB_TEST(edges[0] == sample_pair(0,1,0));
DLIB_TEST(edges[1] == sample_pair(0,2,0));
DLIB_TEST(edges[2] == sample_pair(0,3,0));
DLIB_TEST(edges[3] == sample_pair(0,4,0));
}
void test_knn2()
{
std::vector<matrix<double,2,1> > samples;
matrix<double,2,1> test;
test = 1,1; samples.push_back(test);
test = 1,-1; samples.push_back(test);
test = -1,1; samples.push_back(test);
test = -1,-1; samples.push_back(test);
std::vector<sample_pair> edges;
find_k_nearest_neighbors(samples, squared_euclidean_distance(), 2, edges);
DLIB_TEST(edges.size() == 4);
std::sort(edges.begin(), edges.end(), &order_by_index);
DLIB_TEST(edges[0] == sample_pair(0,1,0));
DLIB_TEST(edges[1] == sample_pair(0,2,0));
DLIB_TEST(edges[2] == sample_pair(1,3,0));
DLIB_TEST(edges[3] == sample_pair(2,3,0));
}
void perform_test (
)
......@@ -195,7 +243,10 @@ namespace
for (int i = 0; i < 5; ++i)
{
do_the_test();
}
test_knn1();
test_knn2();
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment