Re: Symmetric Matrix Resize
"Peter J. Stieber" <[email protected]> Sun, 04 Nov 2007 19:44:16 -0800
| Newsgroups | gmane.comp.lib.mtl.devel |
|---|---|
| Message-ID | <[email protected]> |
PS = Pete Stieber
PS>> MTL version: mtl-2.1.2-23.tenative
PS>> Compiler: g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27)
PS>> Platform: Fedora 7 x86_64
PS>>
PS>> I'm trying to resize a symmetric matrix using a simple
PS>> test jig called SymmetricPackedResize.cpp ...
PS>>
PS>> #include <mtl/mtl.h>
PS>>
PS>> int main()
PS>> {
PS>> typedef mtl::matrix<
PS>> double,
PS>> mtl::symmetric<mtl::lower>,
PS>> mtl::packed<> >::type TDSymmetricMatrix;
PS>>
PS>> TDSymmetricMatrix Symmetric(6, 6);
PS>>
PS>> Symmetric.resize(16, 16);
PS>>
PS>> return 0;
PS>> }
PS>>
PS>> I'm compiling with
PS>>
PS>> g++ -IPathToMtlHeaders SymmetricPackedResize.cpp
PS>>
PS>> The first set of errors I receive follow...
Snip
PS>> So the packed_offset class has the dim data member
PS>> declared private. Looking at the rect_offset class
PS>> for which resize actually works, there is a
PS>> suspicious commenting out for the private: scope
PS>> qualifier ahead of the data members.
PS>>
PS>> I could do the same in packed_offset, but this
PS>> would still leave me with the "packed_offset<...>
PS>> has no member named ld. It looks like resize
PS>> will only work for rect_offset storage.
PS>>
PS>> Does anyone see a workaround for this?
PS>>
PS>> Peter, does version 4 deal with this?
PS>>
PS>> How do I become an alpha tester of version 4?
PS> Instead of explicitly setting the values of the
PS> offset class in the resize function, I changed
PS> the code to call a new resize member function of
PS> the offset class. The following code implements
PS> resize for the rect_offset class by performing
PS> the same functionality that was in the dense2D
PS> class resize function.
PS>
PS> inline void resize(size_type m, size_type n)
PS> {
PS> dim = dim_type(m, n);
PS> ld = n;
PS> }
PS>
PS> Now I need to add a resize function to the
PS> packed_offset class. Here's my first cut...
PS>
PS> inline void resize(size_type m, size_type n)
PS> {
PS> dim = dim_type(m, n);
PS> }
PS>
PS> but the packed_offset class has an addition
PS> data member called bw. Can anyone explain the
PS> purpose of this data member so I can figure out
PS> if I need to alter it in packed_offset::resize?
OK. I believe bw stands for band width, as in which bands are required
with respect to the storage scheme. My new packed_offset resize now
looks like the following:
inline void resize(size_type m, size_type n)
{
dim = dim_type(m, n);
bw = band_type(0, n);
}
since my symmetric matrix is full. I also had to modify the storage
allocation call in dense2d::resize from
rep_ptr newdata = new reptype(Offset::size(m, n, 0, 0));
to
rep_ptr newdata = new reptype(Offset::size(m, n, 0, n));
to generate the proper amount of storage for a full symmetric matrix. A
general dense matrix using rect_offset doesn't use the last two
parameters, so it still works.
Unfortunately, I couldn't figure out how to copy the previously existing
existing matrix elements to the new storage. The (size_type, size_type)
operator doesn't work properly at this level of scope. If anyone can
help me with that it would be greatly appreciated.
I also noticed that the following code to zero out any extra matrix
elements if the new matrix is bigger
for (; i < m; ++i)
for (; j < n; ++j)
(*newdata)[i * n + j] = T();
was incorrect and seemed to be unneeded because the allocation code
seems to zero out the data.
If anyone is interested in a patch to the dense2d.h file that will
resize both general and symmetric matrices, but will not copy old
elements, I believe I have one.
If anyone can help me figure out how to copy the old elements, I would
greatly appreciate it.
Pete
_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/