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

M.filled() vs M.non_zeros()

Expand Messages
  • ralfdenzer
    Hi, could anyone explain me the difference between sparse_matrix.filled() and sparse_matrix.non_zeros()? I m using ublas::generalized_vector_of_vector
    Message 1 of 5 , Jan 20, 2004
    • 0 Attachment
      Hi,

      could anyone explain me the difference between
      sparse_matrix.filled() and sparse_matrix.non_zeros()?

      I'm using
      ublas::generalized_vector_of_vector< double, ublas::column_major,
      ublas::vector<ublas::compressed_vector<double> > > MY_SPARSE;
      for assembly of a larger sparse matrix, but for this type
      there exists no M.filled();



      typedef ublas::compressed_matrix<double > MY_COMPRESSED;

      typedef ublas::generalized_vector_of_vector< double,
      ublas::column_major, ublas::vector<ublas::compressed_vector<double> >
      > MY_SPARSE;

      MY_COMPRESSED Mc(5,5,0);
      MY_SPARSE Mvv(5,5,0);

      cout << "Mc.filled()=" << Mc.filled() << endl;
      cout << "Mc.non_zeros()=" << Mc.non_zeros() << endl;
      //cout << "Mvv.filled()=" << Mvv.filled() << endl; // doesn't exists
      cout << "Mvv.non_zeros()=" << Mvv.non_zeros() << endl;

      Mc(2,2) = 1.0;
      Mvv(2,2) = 1.0;

      cout << "Mc.filled()=" << Mc.filled() << endl;
      cout << "Mc.non_zeros()=" << Mc.non_zeros() << endl;
      //cout << "Mvv.filled()=" << Mvv.filled() << endl; // doesn't exists
      cout << "Mvv.non_zeros()=" << Mvv.non_zeros() << endl;

      produces the following output:

      Mc.filled()=0
      Mc.non_zeros()=5
      Mvv.non_zeros()=25

      Mc.filled()=1
      Mc.non_zeros()=5
      Mvv.non_zeros()=25

      Regards

      Ralf
    • Gunter Winkler
      ... filled() returns the number of used non zeros. non_zeros() returns the number of allocated (memory for) non zeros. That means filled()
      Message 2 of 5 , Jan 21, 2004
      • 0 Attachment
        Zitat von ralfdenzer <denzer@...-kl.de>:

        > could anyone explain me the difference between
        > sparse_matrix.filled() and sparse_matrix.non_zeros()?

        filled() returns the number of used non zeros.
        non_zeros() returns the number of allocated (memory for) non zeros.

        That means filled() <= non_zeros() and each new matrix entry increases
        filled().
        non_zeros() can be read as capacity, but is automatically increased if
        necessary.

        mfg
        Gunter
      • Paul C. Leopardi
        ... Gunter, do you know if this also applies to compressed matrices? Thanks
        Message 3 of 5 , Jan 21, 2004
        • 0 Attachment
          On Wed, 21 Jan 2004 19:26, Gunter Winkler wrote:
          > Zitat von ralfdenzer <denzer@...-kl.de>:
          >
          > > could anyone explain me the difference between
          > > sparse_matrix.filled() and sparse_matrix.non_zeros()?
          >
          > filled() returns the number of used non zeros.
          > non_zeros() returns the number of allocated (memory for) non zeros.
          >
          > That means filled() <= non_zeros() and each new matrix entry increases
          > filled().
          > non_zeros() can be read as capacity, but is automatically increased if
          > necessary.

          Gunter, do you know if this also applies to compressed matrices?
          Thanks
        • Gunter Winkler
          ... AFAIK, yes. I cannot look at the code right now. But I am fairly sure. It has the same meaning for all sparse matrix types. (See .insert(i,j,value) for
          Message 4 of 5 , Jan 21, 2004
          • 0 Attachment
            Zitat von "Paul C. Leopardi" <leopardi@...>:
            > Gunter, do you know if this also applies to compressed matrices?

            AFAIK, yes. I cannot look at the code right now. But I am fairly sure. It has
            the same meaning for all sparse matrix types. (See .insert(i,j,value) for
            details.)

            regards
            Gunter
          • ralfdenzer
            ... sure. It has ... .insert(i,j,value) for ... Yes, definitely. My example uses compressed_matrix and as Gunter explained M.filled()
            Message 5 of 5 , Jan 21, 2004
            • 0 Attachment
              --- In ublas-dev@yahoogroups.com, Gunter Winkler <guwi17@g...> wrote:
              > Zitat von "Paul C. Leopardi" <leopardi@b...>:
              > > Gunter, do you know if this also applies to compressed matrices?
              >
              > AFAIK, yes. I cannot look at the code right now. But I am fairly
              sure. It has
              > the same meaning for all sparse matrix types. (See
              .insert(i,j,value) for
              > details.)

              Yes, definitely. My example uses compressed_matrix and as Gunter
              explained M.filled() <= M.non_zeros() for M sparse and M compressed.

              But how do I calculate M.filled() for a vector of compressed_vector's,
              i.e.

              generalized_vector_of_vector< double, column_major,
              vector<compressed_vector<double> > > M(n,n);
              M.filled(); // ???? doesn't exists ????

              They are much faster for 'random' matrix assembly as Gunter pointed
              out on his homepage.

              Regards

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