Menu

Sparse_Matrix

2004-05-28
2012-09-15
  • Thomas Lemaire

    Thomas Lemaire - 2004-05-28

    Sparse_Matrix is an optimized type for matrix with a lot of zeros... In the future it is possible that other kinds of matrix will be implemented (triangular,...).

    What about a matrix superclass which would define the common interface of such matrices and then one could equally use any type of matrix for its common operations.

    About Sparse_Mat, does it break things to add common operators (+,-,*) between a Mat and a Sparse_Mat (which would return a Mat I think) ?

    thomas

     
    • Tony Ottosson Gadd

      This is a tricky problem. I would be nice to have a common base class, but I think this is difficult. Just as you state, returning Mat from operators (+,+,*) is maybe not good. Adding to sparse matrices the result is probably still sparse, the same often holds for multiplication. However for triangular and diagonal matrices returning Mat is probably OK.

      Anyway, I do not really see a big need for triangular and diagonal matrix types. Saving memory is not a big issue here (only save a factor of 2). Speed may of course be an issue, but I am not sure it is very important. For sparse matrices memory is very important to be able to support large systems. Hence, operations on sparse matrices should probably result in sparse matrices.

      /Tony

       
      • Thomas Lemaire

        Thomas Lemaire - 2004-05-28

        "Speed may of course be an issue, but I am not sure it is very important."
        For me it is an issue since I work with realtime system

        "Hence, operations on sparse matrices should probably result in sparse matrices."
        Yes ! but about operation between a sparse matrix and a full matrix ? a lot of time can be saved here.

        thomas

         
        • Tony Ottosson Gadd

          I believe that it is better to implement separate classes for diagonal and triangular matrices where most operations results in a Mat returned. In the same manner I believe that we should implement separately the operations between sparse and full matrices. If these classes have an implicit conversion to Mat a conversion will be performed if necessary and the full matrix functions and operators will be used. Hence, we could choose to implement only those operators that is crucial for improved speed.

          /Tony

           
    • Thomas Lemaire

      Thomas Lemaire - 2004-06-03

      I totally agree with you on how to implement operators for special matrix types, and "cross-type" operators...

      But, I still think that a matrix super-class can be useful in order to easily write functions that can work with any kind of matrix, avoiding the burden to write a function for each type of matrix. (the same goes for vector of course)

      thomas

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.