significantly reduced sparse matrix footprint:
http://code.opencv.org/issues/2206, http://code.opencv.org/issues/2924
This commit is contained in:
parent
7dd67f4997
commit
66eb270cf7
@ -4714,8 +4714,8 @@ SparseMat::Hdr::Hdr( int _dims, const int* _sizes, int _type )
|
||||
refcount = 1;
|
||||
|
||||
dims = _dims;
|
||||
valueOffset = (int)alignSize(sizeof(SparseMat::Node) +
|
||||
sizeof(int)*std::max(dims - CV_MAX_DIM, 0), CV_ELEM_SIZE1(_type));
|
||||
valueOffset = (int)alignSize(sizeof(SparseMat::Node) - MAX_DIM*sizeof(int) +
|
||||
dims*sizeof(int), CV_ELEM_SIZE1(_type));
|
||||
nodeSize = alignSize(valueOffset +
|
||||
CV_ELEM_SIZE(_type), (int)sizeof(size_t));
|
||||
|
||||
@ -5114,7 +5114,8 @@ uchar* SparseMat::newNode(const int* idx, size_t hashval)
|
||||
if( !hdr->freeList )
|
||||
{
|
||||
size_t i, nsz = hdr->nodeSize, psize = hdr->pool.size(),
|
||||
newpsize = std::max(psize*2, 8*nsz);
|
||||
newpsize = std::max(psize*3/2, 8*nsz);
|
||||
newpsize = (newpsize/nsz)*nsz;
|
||||
hdr->pool.resize(newpsize);
|
||||
uchar* pool = &hdr->pool[0];
|
||||
hdr->freeList = std::max(psize, nsz);
|
||||
|
@ -1248,3 +1248,27 @@ TEST(Core_SVD, orthogonality)
|
||||
ASSERT_LT(norm(mat_U, Mat::eye(2, 2, type), NORM_INF), 1e-5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(Core_SparseMat, footprint)
|
||||
{
|
||||
int n = 1000000;
|
||||
int sz[] = { n, n };
|
||||
SparseMat m(2, sz, CV_64F);
|
||||
|
||||
int nodeSize0 = (int)m.hdr->nodeSize;
|
||||
double dataSize0 = ((double)m.hdr->pool.size() + (double)m.hdr->hashtab.size()*sizeof(size_t))*1e-6;
|
||||
printf("before: node size=%d bytes, data size=%.0f Mbytes\n", nodeSize0, dataSize0);
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
m.ref<double>(i, i) = 1;
|
||||
}
|
||||
|
||||
double dataSize1 = ((double)m.hdr->pool.size() + (double)m.hdr->hashtab.size()*sizeof(size_t))*1e-6;
|
||||
double threshold = (n*nodeSize0*1.6 + n*2.*sizeof(size_t))*1e-6;
|
||||
printf("after: data size=%.0f Mbytes, threshold=%.0f MBytes\n", dataSize1, threshold);
|
||||
|
||||
ASSERT_LE((int)m.hdr->nodeSize, 32);
|
||||
ASSERT_LE(dataSize1, threshold);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user