Skip to content

Commit

Permalink
200184257 fix - replaced EXPECT_EQ by EXPECT_NEAR to make sure we com…
Browse files Browse the repository at this point in the history
…pare floating point numbers correctly.

Adjusted relative tolerance from 1.e-6 to 1.e-5
  • Loading branch information
drnikolaev committed Mar 25, 2016
1 parent cd18a08 commit 9029a15
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/caffe/test/test_gradient_based_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,21 +555,25 @@ class GradientBasedSolverTest : public MultiDeviceTest<TypeParam> {
const vector<Blob<Dtype>*>& params = solver_->net()->learnable_params();
for (int i = 0; i < params.size(); ++i) {
for (int j = 0; j < params[i]->count(); ++j) {
EXPECT_EQ(param_copies[i]->cpu_data()[j], params[i]->cpu_data()[j])
<< "param " << i << " data differed at dim " << j;
EXPECT_EQ(param_copies[i]->cpu_diff()[j], params[i]->cpu_diff()[j])
<< "param " << i << " diff differed at dim " << j;
Dtype rel_error = Dtype(std::max(1., fabs(params[i]->cpu_data()[j])) *
1.e-5);
EXPECT_NEAR(param_copies[i]->cpu_data()[j], params[i]->cpu_data()[j],
rel_error) << "param " << i << " data differed at dim " << j;
EXPECT_NEAR(param_copies[i]->cpu_diff()[j], params[i]->cpu_diff()[j],
rel_error) << "param " << i << " diff differed at dim " << j;
}
}

// Check that history now matches.
const vector<shared_ptr<Blob<Dtype> > >& history = solver_->history();
for (int i = 0; i < history.size(); ++i) {
for (int j = 0; j < history[i]->count(); ++j) {
EXPECT_EQ(history_copies[i]->cpu_data()[j], history[i]->cpu_data()[j])
<< "history blob " << i << " data differed at dim " << j;
EXPECT_EQ(history_copies[i]->cpu_diff()[j], history[i]->cpu_diff()[j])
<< "history blob " << i << " diff differed at dim " << j;
Dtype rel_error = Dtype(std::max(1., fabs(history[i]->cpu_data()[j])) *
1.e-5);
EXPECT_NEAR(history_copies[i]->cpu_data()[j], history[i]->cpu_data()[j],
rel_error) << "history blob " << i << " data differed at dim " << j;
EXPECT_NEAR(history_copies[i]->cpu_diff()[j], history[i]->cpu_diff()[j],
rel_error) << "history blob " << i << " diff differed at dim " << j;
}
}
}
Expand Down

0 comments on commit 9029a15

Please sign in to comment.