int j, k, sv_count = df[i].sv_count;
for( j = 0; j < sv_count; j++ )
{
- const float* src = class_count > 1 ? sv[df[i].sv_index[j]] : sv[j];
+ const float* src = class_count > 1 && df[i].sv_index ? sv[df[i].sv_index[j]] : sv[j];
double a = df[i].alpha[j];
for( k = 0; k < var_count; k++ )
dst[k] = (float)(dst[k] + src[k]*a);
}
df[i].sv_count = 1;
df[i].alpha[0] = 1.;
- if( class_count > 1 )
+ if( class_count > 1 && df[i].sv_index )
df[i].sv_index[0] = i;
}
if( code == cvtest::TS::OK )
{
get_error( testCaseIdx, CV_TEST_ERROR, &test_resps1 );
- fname1 = tempfile(".yml.gz");
+ fname1 = tempfile(".yml");
save( fname1.c_str() );
load( fname1.c_str() );
get_error( testCaseIdx, CV_TEST_ERROR, &test_resps2 );
- fname2 = tempfile(".yml.gz");
+ fname2 = tempfile(".yml");
save( fname2.c_str() );
}
else
// 1. compare files
ifstream f1( fname1.c_str() ), f2( fname2.c_str() );
string s1, s2;
- int lineIdx = 0;
+ int lineIdx = 1;
CV_Assert( f1.is_open() && f2.is_open() );
for( ; !f1.eof() && !f2.eof(); lineIdx++ )
{
getline( f1, s1 );
getline( f2, s2 );
- if( s1.compare(s2) )
+ if( s1.compare(s2) != 0 )
{
- ts->printf( cvtest::TS::LOG, "first and second saved files differ in %n-line; first %n line: %s; second %n-line: %s",
- lineIdx, lineIdx, s1.c_str(), lineIdx, s2.c_str() );
+ ts->printf( cvtest::TS::LOG,
+ "in test case %d first (%s) and second (%s) saved files differ in %d-th line:\n%s\n\tvs\n%s\n",
+ testCaseIdx, fname1.c_str(), fname2.c_str(),
+ lineIdx, s1.empty() ? "" : s1.c_str(), s2.empty() ? "" : s2.c_str() );
code = cvtest::TS::FAIL_INVALID_OUTPUT;
+ break;
}
}
- if( !f1.eof() || !f2.eof() )
- {
- ts->printf( cvtest::TS::LOG, "in test case %d first and second saved files differ in %n-line; first %n line: %s; second %n-line: %s",
- testCaseIdx, lineIdx, lineIdx, s1.c_str(), lineIdx, s2.c_str() );
- code = cvtest::TS::FAIL_INVALID_OUTPUT;
- }
f1.close();
f2.close();
// delete temporary files
- remove( fname1.c_str() );
- remove( fname2.c_str() );
+ if( code == cvtest::TS::OK )
+ {
+ remove( fname1.c_str() );
+ remove( fname2.c_str() );
+ }
// 2. compare responses
CV_Assert( test_resps1.size() == test_resps2.size() );