MTL: Symmetric Matrix Resize

View: New views
3 Messages — Rating Filter:   Alert me  

MTL: Symmetric Matrix Resize

by Peter J. Stieber :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

MTL version: mtl-2.1.2-23.tenative
Compiler: g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27)
Platform: Fedora 7 x86_64

I'm trying to resize a symmetric matrix using a simple test jig called
SymmetricPackedResize.cpp ...

#include <mtl/mtl.h>

int main()
{
   typedef mtl::matrix<
     double,
     mtl::symmetric<mtl::lower>,
     mtl::packed<> >::type TDSymmetricMatrix;

   TDSymmetricMatrix Symmetric(6, 6);

   Symmetric.resize(16, 16);

   return 0;
}

I'm compiling with

g++ -IPathToMtlHeaders SymmetricPackedResize.cpp

The first set of errors I receive follow.  I've tried to separate them
onto different lines for readability:

mtl-2.1.2-23/mtl/dense2D.h: In member function ‘void mtl::dense2D<T,
OffsetGen, MM, NN>::resize(typename mtl::generic_dense2D<std::vector<T,
std::allocator<_CharT> >, mtl::refcnt_ptr<std::vector<T,
std::allocator<_CharT> > >, OffsetGen, MM, NN>::size_type, typename
mtl::generic_dense2D<std::vector<T, std::allocator<_CharT> >,
mtl::refcnt_ptr<std::vector<T, std::allocator<_CharT> > >, OffsetGen,
MM, NN>::size_type) [with T = double, OffsetGen =
mtl::gen_packed_offset<0, 0>, int MM = 0, int NN = 0]’:
mtl-2.1.2-23/mtl/matrix_implementation.h:616:   instantiated from ‘void
mtl::row_matrix<TwoDGen, IndexerGen>::resize(typename
mtl::matrix_implementation<TwoDGen, IndexerGen>::size_type, typename
mtl::matrix_implementation<TwoDGen, IndexerGen>::size_type) [with
TwoDGen = mtl::gen_dense2D<double, mtl::gen_packed_offset<0, 0>, 0, 0>,
IndexerGen = mtl::gen_banded_indexer<mtl::row_orien, 0, 0, long unsigned
int>]’

SymmetricPackedResize.cpp:12:   instantiated from here

mtl-2.1.2-23/mtl/dense2D.h:548: error: ‘mtl::dimension<long unsigned
int, 0, 0> mtl::packed_offset<long unsigned int, 0, 0>::dim’ is private

mtl-2.1.2-23/mtl/dense2D.h:1235: error: within this context

mtl-2.1.2-23/mtl/dense2D.h:1236: error: ‘class mtl::packed_offset<long
unsigned int, 0, 0>’ has no member named ‘ld’

So the packed_offset class has the dim data member declared private.
Looking at the rect_offset class for which resize actually works, there
is a suspicious commenting out for the private: scope qualifier ahead of
the data members.

I could do the same in packed_offset, but this would still leave me with
the "packed_offset<...> has no member named ld.  It looks like resize
will only work for rect_offset storage.

Does anyone see a workaround for this?

Peter, does version 4 deal with this?

How do I become an alpha tester of version 4?

Pete

_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/

Re: MTL: Symmetric Matrix Resize

by Peter J. Stieber :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Peter J. Stieber wrote:

> MTL version: mtl-2.1.2-23.tenative
> Compiler: g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27)
> Platform: Fedora 7 x86_64
>
> I'm trying to resize a symmetric matrix using a simple test jig called
> SymmetricPackedResize.cpp ...
>
> #include <mtl/mtl.h>
>
> int main()
> {
>    typedef mtl::matrix<
>      double,
>      mtl::symmetric<mtl::lower>,
>      mtl::packed<> >::type TDSymmetricMatrix;
>
>    TDSymmetricMatrix Symmetric(6, 6);
>
>    Symmetric.resize(16, 16);
>
>    return 0;
> }
>
> I'm compiling with
>
> g++ -IPathToMtlHeaders SymmetricPackedResize.cpp
>
> The first set of errors I receive follow.  I've tried to separate them
> onto different lines for readability:
>
> mtl-2.1.2-23/mtl/dense2D.h: In member function ‘void mtl::dense2D<T,
> OffsetGen, MM, NN>::resize(typename mtl::generic_dense2D<std::vector<T,
> std::allocator<_CharT> >, mtl::refcnt_ptr<std::vector<T,
> std::allocator<_CharT> > >, OffsetGen, MM, NN>::size_type, typename
> mtl::generic_dense2D<std::vector<T, std::allocator<_CharT> >,
> mtl::refcnt_ptr<std::vector<T, std::allocator<_CharT> > >, OffsetGen,
> MM, NN>::size_type) [with T = double, OffsetGen =
> mtl::gen_packed_offset<0, 0>, int MM = 0, int NN = 0]’:
> mtl-2.1.2-23/mtl/matrix_implementation.h:616:   instantiated from ‘void
> mtl::row_matrix<TwoDGen, IndexerGen>::resize(typename
> mtl::matrix_implementation<TwoDGen, IndexerGen>::size_type, typename
> mtl::matrix_implementation<TwoDGen, IndexerGen>::size_type) [with
> TwoDGen = mtl::gen_dense2D<double, mtl::gen_packed_offset<0, 0>, 0, 0>,
> IndexerGen = mtl::gen_banded_indexer<mtl::row_orien, 0, 0, long unsigned
> int>]’
>
> SymmetricPackedResize.cpp:12:   instantiated from here
>
> mtl-2.1.2-23/mtl/dense2D.h:548: error: ‘mtl::dimension<long unsigned
> int, 0, 0> mtl::packed_offset<long unsigned int, 0, 0>::dim’ is private
>
> mtl-2.1.2-23/mtl/dense2D.h:1235: error: within this context
>
> mtl-2.1.2-23/mtl/dense2D.h:1236: error: ‘class mtl::packed_offset<long
> unsigned int, 0, 0>’ has no member named ‘ld’
>
> So the packed_offset class has the dim data member declared private.
> Looking at the rect_offset class for which resize actually works, there
> is a suspicious commenting out for the private: scope qualifier ahead of
> the data members.
>
> I could do the same in packed_offset, but this would still leave me with
> the "packed_offset<...> has no member named ld.  It looks like resize
> will only work for rect_offset storage.
>
> Does anyone see a workaround for this?
>
> Peter, does version 4 deal with this?
>
> How do I become an alpha tester of version 4?

Instead of explicitly setting the values of the offset class in the
resize function, I changed the code to call a new resize member function
of the offset class.  The following code implements resize for the
rect_offset class by performing the same functionality that was in the
dense2D class resize function.

   inline void resize(size_type m, size_type n)
   {
     dim = dim_type(m, n);
     ld = n;
   }

Now I need to add a resize function to the packed_offset class.  Here's
my first cut...

   inline void resize(size_type m, size_type n)
   {
     dim = dim_type(m, n);
   }

but the packed_offset class has an addition data member called bw.  Can
anyone explain the purpose of this data member so I can figure out if I
need to alter it in packed_offset::resize?

Pete

_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/

Re: MTL: Symmetric Matrix Resize

by Peter J. Stieber :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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/