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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
"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
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
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