X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=tests%2Fcxcore%2Fsrc%2Famath.cpp;fp=tests%2Fcxcore%2Fsrc%2Famath.cpp;h=4d4c97bdb967593988b7df3612445bfd8f47c80c;hb=e4c14cdbdf2fe805e79cd96ded236f57e7b89060;hp=03e5c325a3e524c5f07d4166e4efd7b25fad3585;hpb=454138ff8a20f6edb9b65a910101403d8b520643;p=opencv diff --git a/tests/cxcore/src/amath.cpp b/tests/cxcore/src/amath.cpp index 03e5c32..4d4c97b 100644 --- a/tests/cxcore/src/amath.cpp +++ b/tests/cxcore/src/amath.cpp @@ -165,9 +165,9 @@ void CxCore_ExpTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** { CxCore_MathTest::get_test_array_types_and_sizes( test_case_idx, sizes, types ); out_type = types[OUTPUT][0]; - if( CV_MAT_DEPTH(types[INPUT][0]) == CV_32F && (cvRandInt(ts->get_rng()) & 3) == 0 ) + /*if( CV_MAT_DEPTH(types[INPUT][0]) == CV_32F && (cvRandInt(ts->get_rng()) & 3) == 0 ) types[OUTPUT][0] = types[REF_OUTPUT][0] = - out_type = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|CV_64F; + out_type = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|CV_64F;*/ } void CxCore_ExpTest::get_minmax_bounds( int /*i*/, int /*j*/, int /*type*/, CvScalar* low, CvScalar* high ) @@ -246,8 +246,8 @@ CxCore_LogTest::CxCore_LogTest() void CxCore_LogTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types ) { CxCore_MathTest::get_test_array_types_and_sizes( test_case_idx, sizes, types ); - if( CV_MAT_DEPTH(types[INPUT][0]) == CV_32F && (cvRandInt(ts->get_rng()) & 3) == 0 ) - types[INPUT][0] = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|CV_64F; + /*if( CV_MAT_DEPTH(types[INPUT][0]) == CV_32F && (cvRandInt(ts->get_rng()) & 3) == 0 ) + types[INPUT][0] = (types[INPUT][0] & ~CV_MAT_DEPTH_MASK)|CV_64F;*/ } @@ -1175,7 +1175,7 @@ protected: }; CxCore_ScaleAddTest::CxCore_ScaleAddTest() : - CxCore_MatrixTest( "matrix-scaleadd", "cvScaleAdd", 3, 1, false, false, 2 ) + CxCore_MatrixTest( "matrix-scaleadd", "cvScaleAdd", 3, 1, false, false, 4 ) { alpha = cvScalarAll(0); } @@ -1185,6 +1185,7 @@ void CxCore_ScaleAddTest::get_test_array_types_and_sizes( int test_case_idx, CvS { CxCore_MatrixTest::get_test_array_types_and_sizes( test_case_idx, sizes, types ); sizes[INPUT][2] = cvSize(1,1); + types[INPUT][2] &= CV_MAT_DEPTH_MASK; } @@ -1195,6 +1196,7 @@ void CxCore_ScaleAddTest::get_timing_test_array_types_and_sizes( int test_case_i CxCore_MatrixTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types, whole_sizes, are_images ); sizes[INPUT][2] = cvSize(1,1); + types[INPUT][2] &= CV_MAT_DEPTH_MASK; } @@ -1215,50 +1217,9 @@ void CxCore_ScaleAddTest::run_func() void CxCore_ScaleAddTest::prepare_to_validation( int ) { - int rows = test_mat[INPUT][0].rows; - int type = CV_MAT_TYPE(test_mat[INPUT][0].type); - int cn = CV_MAT_CN(type); - int ncols = test_mat[INPUT][0].cols*cn; - int i, j; - - for( i = 0; i < rows; i++ ) - { - uchar* src1 = test_mat[INPUT][0].data.ptr + test_mat[INPUT][0].step*i; - uchar* src2 = test_mat[INPUT][1].data.ptr + test_mat[INPUT][1].step*i; - uchar* dst = test_mat[REF_OUTPUT][0].data.ptr + test_mat[REF_OUTPUT][0].step*i; - - switch( type ) - { - case CV_32FC1: - for( j = 0; j < ncols; j++ ) - ((float*)dst)[j] = (float)(((float*)src1)[j]*alpha.val[0] + ((float*)src2)[j]); - break; - case CV_32FC2: - for( j = 0; j < ncols; j += 2 ) - { - double re = ((float*)src1)[j]; - double im = ((float*)src1)[j+1]; - ((float*)dst)[j] = (float)(re*alpha.val[0] - im*alpha.val[1] + ((float*)src2)[j]); - ((float*)dst)[j+1] = (float)(re*alpha.val[1] + im*alpha.val[0] + ((float*)src2)[j+1]); - } - break; - case CV_64FC1: - for( j = 0; j < ncols; j++ ) - ((double*)dst)[j] = ((double*)src1)[j]*alpha.val[0] + ((double*)src2)[j]; - break; - case CV_64FC2: - for( j = 0; j < ncols; j += 2 ) - { - double re = ((double*)src1)[j]; - double im = ((double*)src1)[j+1]; - ((double*)dst)[j] = (double)(re*alpha.val[0] - im*alpha.val[1] + ((double*)src2)[j]); - ((double*)dst)[j+1] = (double)(re*alpha.val[1] + im*alpha.val[0] + ((double*)src2)[j+1]); - } - break; - default: - assert(0); - } - } + cvTsAdd( &test_mat[INPUT][0], cvScalarAll(alpha.val[0]), + &test_mat[INPUT][1], cvScalarAll(1.), + cvScalarAll(0.), &test_mat[REF_OUTPUT][0], 0 ); } CxCore_ScaleAddTest scaleadd_test; @@ -1589,9 +1550,12 @@ protected: void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types, CvSize** whole_sizes, bool* are_images ); + int prepare_test_case( int test_case_idx ); void print_timing_params( int test_case_idx, char* ptr, int params_left ); void run_func(); void prepare_to_validation( int test_case_idx ); + + double scale; }; @@ -1621,6 +1585,8 @@ void CxCore_TransformTest::get_test_array_types_and_sizes( int test_case_idx, Cv mattype = depth < CV_32S ? CV_32F : depth == CV_64F ? CV_64F : bits & 1 ? CV_32F : CV_64F; types[INPUT][1] = mattype; types[INPUT][2] = CV_MAKETYPE(mattype, dst_cn); + + scale = 1./((cvTsRandInt(rng)%4)*50+1); if( bits & 2 ) { @@ -1651,8 +1617,17 @@ void CxCore_TransformTest::get_timing_test_array_types_and_sizes( int test_case_ sizes[INPUT][1] = cvSize(cn + (cn < 4), cn); sizes[INPUT][2] = cvSize(0,0); types[INPUT][1] = types[INPUT][2] = CV_64FC1; + scale = 1./1000; } +int CxCore_TransformTest::prepare_test_case( int test_case_idx ) +{ + int code = CxCore_MatrixTest::prepare_test_case( test_case_idx ); + if( code > 0 ) + cvTsAdd(&test_mat[INPUT][1], cvScalarAll(scale), &test_mat[INPUT][1], + cvScalarAll(0), cvScalarAll(0), &test_mat[INPUT][1], 0 ); + return code; +} void CxCore_TransformTest::print_timing_params( int test_case_idx, char* ptr, int params_left ) { @@ -1995,10 +1970,22 @@ void CxCore_CovarMatrixTest::get_test_array_types_and_sizes( int test_case_idx, single_matrix = flags & CV_COVAR_ROWS; t_flag = (bits & 256) != 0; + const int min_count = 2; + if( !t_flag ) - len = sizes[INPUT][0].width, count = sizes[INPUT][0].height; + { + len = sizes[INPUT][0].width; + count = sizes[INPUT][0].height; + count = MAX(count, min_count); + sizes[INPUT][0] = cvSize(len, count); + } else - len = sizes[INPUT][0].height, count = sizes[INPUT][0].width; + { + len = sizes[INPUT][0].height; + count = sizes[INPUT][0].width; + count = MAX(count, min_count); + sizes[INPUT][0] = cvSize(count, len); + } if( single_matrix && t_flag ) flags = (flags & ~CV_COVAR_ROWS) | CV_COVAR_COLS; @@ -2470,16 +2457,16 @@ static double cvTsSVDet( CvMat* mat ) void CxCore_InvertTest::prepare_to_validation( int ) { CvMat* input = &test_mat[INPUT][0]; - double det = method != CV_LU ? cvTsSVDet( input ) : 0; - double threshold = (CV_MAT_DEPTH(input->type) == CV_32F ? FLT_EPSILON : DBL_EPSILON)*100; + double det = cvTsSVDet( input ); + double threshold = (CV_MAT_DEPTH(input->type) == CV_32F ? FLT_EPSILON : DBL_EPSILON)*500; if( CV_MAT_TYPE(input->type) == CV_32FC1 ) cvTsConvert( input, &test_mat[TEMP][1] ); else cvTsCopy( input, &test_mat[TEMP][1], 0 ); - if( method == CV_LU && result == 0 || method != CV_LU && - det < threshold || result < threshold ) + if( (method == CV_LU && result == 0) || + (det < threshold || result < threshold) ) { cvTsZero( &test_mat[OUTPUT][0] ); cvTsZero( &test_mat[REF_OUTPUT][0] ); @@ -2677,6 +2664,7 @@ protected: void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types, CvSize** whole_sizes, bool* are_images ); + double get_success_error_level( int test_case_idx, int i, int j ); int write_default_params( CvFileStorage* fs ); void print_timing_params( int test_case_idx, char* ptr, int params_left ); void get_minmax_bounds( int /*i*/, int /*j*/, int /*type*/, CvScalar* low, CvScalar* high ); @@ -2854,6 +2842,14 @@ void CxCore_SVDTest::get_minmax_bounds( int /*i*/, int /*j*/, int /*type*/, CvSc *high = cvScalarAll(2.); } +double CxCore_SVDTest::get_success_error_level( int test_case_idx, int i, int j ) +{ + int input_depth = CV_MAT_DEPTH(cvGetElemType( test_array[INPUT][0] )); + double input_precision = input_depth < CV_32F ? 0 : input_depth == CV_32F ? + 5e-5 : 5e-11; + double output_precision = CvArrTest::get_success_error_level( test_case_idx, i, j ); + return MAX(input_precision, output_precision); +} void CxCore_SVDTest::run_func() {