Loading ...
Sorry, an error occurred while loading the content.

Fixed size vectors/matrices

Expand Messages
  • pg_fecu
    Hi List-members, I m curious whether there s a possibility to create truly fixed sized vectors/matrices. After checking the code, it seems to me that if I have
    Message 1 of 5 , Jun 22, 2004
    • 0 Attachment
      Hi List-members,

      I'm curious whether there's a possibility to create truly
      fixed sized vectors/matrices. After checking
      the code, it seems to me that if I have a stack based matrix,
      let's say 4x4 then via the assign operator it can be resized to
      eg. 2x3.

      I also did not find a possibility to create fixed sized matrices
      or vectors in the following way (not real code, just an example):

      typedef matrix<2,3,double> dmx2x3;

      Is it intentionally not supported? I think sometimes it would be
      preferable to create fixed size objects (transformation matrices,
      3d points, etc).

      Any comments?

      TIA,
      Fecu
    • Angus Leeming
      ... Try this: typedef boost::numeric::ublas::bounded_matrix matrix2x2; typedef boost::numeric::ublas::bounded_vector coord3d; Regards,
      Message 2 of 5 , Jun 22, 2004
      • 0 Attachment
        pg_fecu wrote:

        > Hi List-members,
        >
        > I'm curious whether there's a possibility to create truly
        > fixed sized vectors/matrices. After checking
        > the code, it seems to me that if I have a stack based matrix,
        > let's say 4x4 then via the assign operator it can be resized to
        > eg. 2x3.
        >
        > I also did not find a possibility to create fixed sized matrices
        > or vectors in the following way (not real code, just an example):
        >
        > typedef matrix<2,3,double> dmx2x3;
        >
        > Is it intentionally not supported? I think sometimes it would be
        > preferable to create fixed size objects (transformation matrices,
        > 3d points, etc).
        >
        > Any comments?

        Try this:

        typedef boost::numeric::ublas::bounded_matrix<double, 2, 2> matrix2x2;
        typedef boost::numeric::ublas::bounded_vector<double, 3> coord3d;

        Regards,
        Angus
      • Michael Stevens
        Hi Fecu, ... Agreed. It is always possible to change the algebraic size of a uBLAS vectors/matrices either by assignment or the resize function. ... Have a
        Message 3 of 5 , Jun 22, 2004
        • 0 Attachment
          Hi Fecu,

          On Tuesday 22 June 2004 14:16, pg_fecu wrote:
          > Hi List-members,
          >
          > I'm curious whether there's a possibility to create truly
          > fixed sized vectors/matrices. After checking
          > the code, it seems to me that if I have a stack based matrix,
          > let's say 4x4 then via the assign operator it can be resized to
          > eg. 2x3.
          Agreed. It is always possible to change the algebraic size of a uBLAS
          vectors/matrices either by assignment or the resize function.
          >
          > I also did not find a possibility to create fixed sized matrices
          > or vectors in the following way (not real code, just an example):
          >
          > typedef matrix<2,3,double> dmx2x3;
          Have a look at
          // Bounded matrix class
          template<class T, std::size_t M, std::size_t N, class F>
          class bounded_matrix:
          This is in matrix.hpp but not yet documented.
          It is however simply a wrapper for the existing matrix of a bounded_array.
          Therefore the algebraic size of the matrices can still be changed. M and N are
          simply use to compute the storage size for the bounded_array.

          > Any comments?
          These two properties can be treated independently I think.
          1. Making the algebraic size of vector/matrix unchangeable once constructed. I
          have often wanted to use this as it would make some code easier. The
          difficulty is that it would make need an extra matrix/vector template
          parameter and a fair bit of complexity.
          2. Compile time fixed sizes. I think this is already pretty well covered by
          the 'bounded' types. They could be a little more efficient in the case 1.
          also applied.

          Michael
        • Gunter Winkler
          ... try typedef bounded_vector VEC; typedef bounded_matrix MAT; these types have a default contructor that
          Message 4 of 5 , Jun 22, 2004
          • 0 Attachment
            On Tuesday 22 June 2004 14:16, pg_fecu wrote:
            > Hi List-members,
            >
            > I'm curious whether there's a possibility to create truly
            > fixed sized vectors/matrices. After checking
            > the code, it seems to me that if I have a stack based matrix,
            > let's say 4x4 then via the assign operator it can be resized to
            > eg. 2x3.
            >
            > I also did not find a possibility to create fixed sized matrices
            > or vectors in the following way (not real code, just an example):
            >
            > typedef matrix<2,3,double> dmx2x3;
            >
            > Is it intentionally not supported? I think sometimes it would be
            > preferable to create fixed size objects (transformation matrices,
            > 3d points, etc).

            try

            typedef bounded_vector<double,3,row_major> VEC;
            typedef bounded_matrix<double,2,3,row_major> MAT;

            these types have a default contructor that initializes the vector/matrix to
            have the given size. It can still be resized to any smaller vector or matrix.

            mfg
            Gunter
          • Patrick Kowalzick
            Dear Fecu, Here you can find a piece of code how I implemented a bounded type http://groups.yahoo.com/group/ublas-dev/message/1040 (see as well reply from
            Message 5 of 5 , Jun 22, 2004
            • 0 Attachment
              Dear Fecu,

              Here you can find a piece of code how I implemented a bounded type
              http://groups.yahoo.com/group/ublas-dev/message/1040
              (see as well reply from Gunter, because I did some copy paste errors with M
              and N). More or less it is a direct copy of the bounded_matrix type).

              With this class you have the possibility to create Instances with

              bounded< matrix<double> , 3 , 2 > dummy1;
              bounded< symmetric_matrix<double> , 3 > dummy2;

              The storage is the same like the one for the matrix type, so maybe stack or
              heap (the example should be heap on most platforms).

              Whilst I want to have a real fixed type as well and not a bounded I wanted
              to continue here ( but I did not do it ). I thought about just hiding the
              resize ( make it private ) function in a class "fixed".

              What do you all think about that approach ?

              Patrick
            Your message has been successfully submitted and would be delivered to recipients shortly.