CV_Assert(hdr != 0);
if( hdr != m.hdr )
- m.create( m.hdr->dims, m.hdr->size, rtype );
+ m.create( hdr->dims, hdr->size, rtype );
SparseMatConstIterator from = begin();
size_t i, N = nzcount();
{
if( normType == NORM_INF )
for( i = 0; i < N; i++, ++it )
- result = std::max(result, (double)*(const float*)it.ptr);
+ result = std::max(result, std::abs((double)*(const float*)it.ptr));
else if( normType == NORM_L1 )
for( i = 0; i < N; i++, ++it )
result += std::abs(*(const float*)it.ptr);
{
if( normType == NORM_INF )
for( i = 0; i < N; i++, ++it )
- result = std::max(result, *(const double*)it.ptr);
+ result = std::max(result, std::abs(*(const double*)it.ptr));
else if( normType == NORM_L1 )
for( i = 0; i < N; i++, ++it )
result += std::abs(*(const double*)it.ptr);
char* dst_ptr = read_buf;
int read_max = read_buf_size /MAX(src_elem_size, 1), read_count = 0;
CvSeqReader reader;
- cvStartReadRawData( fs, k == 0 ? vtx_node : edge_node, &reader );
+ if(dt)
+ cvStartReadRawData( fs, k == 0 ? vtx_node : edge_node, &reader );
for( i = 0; i < elem_count; i++ )
{
cvCopy(test_array[INPUT][0], test_array[INPUT_OUTPUT][0], mask);
else
{
+ cv::MatND a = cv::cvarrToMatND(test_array[INPUT][0]);
cv::MatND c = cv::cvarrToMatND(test_array[INPUT_OUTPUT][0]);
- cv::cvarrToMatND(test_array[INPUT][0]).copyTo(c, mask ? cv::cvarrToMatND(mask) : cv::MatND());
+ if(!mask)
+ a.copyTo(c);
+ else
+ a.copyTo(c, cv::cvarrToMatND(mask));
}
}
int i, k, size[MAX_DIM]={0}, idx[MAX_DIM]={0};
vector<string> all_idxs;
vector<double> all_vals;
+ vector<double> all_vals2;
string sidx, min_sidx, max_sidx;
double min_val=0, max_val=0;
int nz0 = (unsigned)rng % max(p/5,10);
nz0 = min(max(nz0, 1), p);
all_vals.resize(nz0);
- Mat_<double> _all_vals(all_vals);
+ all_vals2.resize(nz0);
+ Mat_<double> _all_vals(all_vals), _all_vals2(all_vals2);
rng.fill(_all_vals, CV_RAND_UNI, Scalar(-1000), Scalar(1000));
if( depth == CV_32F )
{
_all_vals.convertTo(_all_vals_f, CV_32F);
_all_vals_f.convertTo(_all_vals, CV_64F);
}
+ _all_vals.convertTo(_all_vals2, _all_vals2.type(), 2);
+ if( depth == CV_32F )
+ {
+ Mat _all_vals2_f;
+ _all_vals2.convertTo(_all_vals2_f, CV_32F);
+ _all_vals2_f.convertTo(_all_vals2, CV_64F);
+ }
minMaxLoc(_all_vals, &min_val, &max_val);
+ double _norm0 = norm(_all_vals, CV_C);
+ double _norm1 = norm(_all_vals, CV_L1);
+ double _norm2 = norm(_all_vals, CV_L2);
for( i = 0; i < nz0; i++ )
{
Ptr<CvSparseMat> M2 = (CvSparseMat*)M;
MatND Md;
M.copyTo(Md);
- SparseMat M3 = Md;
+ SparseMat M3; SparseMat(Md).convertTo(M3, Md.type(), 2);
int nz1 = M.nzcount(), nz2 = M3.nzcount();
- if( nz1 != nz0 || nz2 != nz0 )
+ double norm0 = norm(M, CV_C);
+ double norm1 = norm(M, CV_L1);
+ double norm2 = norm(M, CV_L2);
+ double eps = depth == CV_32F ? FLT_EPSILON*100 : DBL_EPSILON*1000;
+
+ if( nz1 != nz0 || nz2 != nz0)
+ {
+ errcount++;
+ ts->printf(CvTS::LOG, "%d: The number of non-zero elements before/after converting to/from dense matrix is not correct: %d/%d (while it should be %d)\n",
+ si, nz1, nz2, nz0 );
+ break;
+ }
+
+ if( fabs(norm0 - _norm0) > fabs(_norm0)*eps ||
+ fabs(norm1 - _norm1) > fabs(_norm1)*eps ||
+ fabs(norm2 - _norm2) > fabs(_norm2)*eps )
{
errcount++;
- ts->printf(CvTS::LOG, "%d: The number of non-zero elements before/after converting to/from dense matrix is not correct: %d/%d (while it should be %d)\n", si, nz1, nz2, nz0 );
+ ts->printf(CvTS::LOG, "%d: The norms are different: %.20g/%.20g/%.20g vs %.20g/%.20g/%.20g\n",
+ si, norm0, norm1, norm2, _norm0, _norm1, _norm2 );
break;
}
val2 = getValue(M2, idx);
val3 = getValue(M3, idx, rng);
- if( val1 != val0 || val2 != val0 || val3 != val0 )
+ if( val1 != val0 || val2 != val0 || fabs(val3 - val0*2) > fabs(val0*2)*FLT_EPSILON )
{
errcount++;
ts->printf(CvTS::LOG, "SparseMat M[%s] = %g/%g/%g (while it should be %g)\n", sidx.c_str(), val1, val2, val3, val0 );
int idx1[MAX_DIM], idx2[MAX_DIM];
double val1 = 0, val2 = 0;
+ M3 = SparseMat(Md);
minMaxLoc(M3, &val1, &val2, idx1, idx2);
string s1 = idx2string(idx1, dims), s2 = idx2string(idx2, dims);
if( val1 != min_val || val2 != max_val || s1 != min_sidx || s2 != max_sidx )
test_mat.elemSize(), storage);
cvSeqPushMulti(seq, test_mat.data, test_mat.cols*test_mat.rows);
+ CvGraph* graph = cvCreateGraph( CV_ORIENTED_GRAPH,
+ sizeof(CvGraph), sizeof(CvGraphVtx),
+ sizeof(CvGraphEdge), storage );
+ int edges[][2] = {{0,1},{1,2},{2,0},{0,3},{3,4},{4,1}};
+ int i, vcount = 5, ecount = 6;
+ for( i = 0; i < vcount; i++ )
+ cvGraphAddVtx(graph);
+ for( i = 0; i < ecount; i++ )
+ {
+ CvGraphEdge* edge;
+ cvGraphAddEdge(graph, edges[i][0], edges[i][1], 0, &edge);
+ edge->weight = (float)(i+1);
+ }
+
depth = cvTsRandInt(rng) % (CV_64F+1);
cn = cvTsRandInt(rng) % 4 + 1;
int sz[] = {cvTsRandInt(rng)%10+1, cvTsRandInt(rng)%10+1, cvTsRandInt(rng)%10+1};
cvWriteComment(*fs, "test comment", 0);
fs.writeObj("test_seq", seq);
+ fs.writeObj("test_graph",graph);
+ CvGraph* graph2 = cvCloneGraph(graph,storage);
fs.release();
cvRelease((void**)&m_nd);
- CvSparseMat* m_s = (CvSparseMat*)fs["test_sparse_mat"].readObj();
- CvSparseMat* _test_sparse_ = (CvSparseMat*)test_sparse_mat;
- CvSparseMat* _test_sparse = (CvSparseMat*)cvClone(_test_sparse_);
- cvReleaseSparseMat(&_test_sparse_);
+ Ptr<CvSparseMat> m_s = (CvSparseMat*)fs["test_sparse_mat"].readObj();
+ Ptr<CvSparseMat> _test_sparse_ = (CvSparseMat*)test_sparse_mat;
+ Ptr<CvSparseMat> _test_sparse = (CvSparseMat*)cvClone(_test_sparse_);
SparseMat m_s2;
fs["test_sparse_mat"] >> m_s2;
- CvSparseMat* _m_s2 = (CvSparseMat*)m_s2;
+ Ptr<CvSparseMat> _m_s2 = (CvSparseMat*)m_s2;
if( !m_s || !CV_IS_SPARSE_MAT(m_s) ||
!cvTsCheckSparse(m_s, _test_sparse,0) ||
return;
}
- if( m_s && CV_IS_SPARSE_MAT(m_s))
- cvReleaseSparseMat(&m_s);
- cvReleaseSparseMat(&_test_sparse);
- cvReleaseSparseMat(&_m_s2);
-
FileNode tl = fs["test_list"];
if( tl.type() != FileNode::SEQ || tl.size() != 6 ||
fabs((double)tl[0] - 0.0000000000001) >= DBL_EPSILON ||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
return;
}
+
+ CvGraph* graph3 = (CvGraph*)fs["test_graph"].readObj();
+ if(graph2->active_count != vcount || graph3->active_count != vcount ||
+ graph2->edges->active_count != ecount || graph3->edges->active_count != ecount)
+ {
+ ts->printf( CvTS::LOG, "the cloned or read graph have wrong number of vertices or edges\n" );
+ ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
+ return;
+ }
+
+ for( i = 0; i < ecount; i++ )
+ {
+ CvGraphEdge* edge2 = cvFindGraphEdge(graph2, edges[i][0], edges[i][1]);
+ CvGraphEdge* edge3 = cvFindGraphEdge(graph3, edges[i][0], edges[i][1]);
+ if( !edge2 || edge2->weight != (float)(i+1) ||
+ !edge3 || edge3->weight != (float)(i+1) )
+ {
+ ts->printf( CvTS::LOG, "the cloned or read graph do not have the edge (%d, %d)\n", edges[i][0], edges[i][1] );
+ ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
+ return;
+ }
+ }
+
fs.release();
#ifdef _MSC_VER
_unlink(filename);
void run_func();
void prepare_to_validation( int test_case_idx );
CvScalar alpha;
+ bool test_nd;
};
CxCore_ScaleAddTest::CxCore_ScaleAddTest() :
CxCore_MatrixTest( "matrix-scaleadd", "cvScaleAdd", 3, 1, false, false, 4 )
{
alpha = cvScalarAll(0);
+ test_nd = false;
}
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;
+ test_nd = cvTsRandInt(ts->get_rng()) % 2 != 0;
}
int code = CxCore_MatrixTest::prepare_test_case( test_case_idx );
if( code > 0 )
alpha = cvGet1D( &test_mat[INPUT][2], 0 );
+ if( test_nd )
+ alpha.val[1] = 0;
return code;
}
void CxCore_ScaleAddTest::run_func()
{
- cvScaleAdd( test_array[INPUT][0], alpha, test_array[INPUT][1], test_array[OUTPUT][0] );
+ if(!test_nd)
+ cvScaleAdd( test_array[INPUT][0], alpha, test_array[INPUT][1], test_array[OUTPUT][0] );
+ else
+ {
+ cv::MatND c = cv::cvarrToMatND(test_array[OUTPUT][0]);
+ cv::scaleAdd( cv::cvarrToMatND(test_array[INPUT][0]), alpha.val[0],
+ cv::cvarrToMatND(test_array[INPUT][1]), c);
+ }
}