On Fri, Jul 1, 2011 at 2:35 PM, Greg Sterijevski <gsterijevski@gmail.com>wrote:
> My request stems from attempting to build a SymmetricRealMatrix which
> stores
> its contents in a packed format. I began implementing multiply and so forth
> and did not relish having a bunch of case statements. This lead me to the
> idea of removing all operations involving other matrices to a separate
> class.
>
Fair. I have been approximately the same place.
> I am not clear about why using java's type system is such a bad thing. A
> diagonal is different from a symmetric. Both fall under the "is a"
> condition. Each is an example of a matrixbut different enough to merit its
> own class.
>
Diagonal is different from symmetric, but diagonal is sparse and so is a row
based hashed representation as is a tridiagonal matrix. A single
implementation can be used to get decent performance on diagonal,
banddiagonal, random sparse and sequentially accessible sparse
representations. On the other hand, symmetric matrices can be sparse or
not, but allow separate optimizations.
It is this multiple inheritance that makes the type system unsatisfactory.
Even worse, the type system dispatches based on the compiletime
declaration, not the runtime type. Thus, if I have a Matrix which happens
to be a diagonal matrix, Java will pick the general case, not the special
case.
Sadly, a case statement won't even work for this. All that works, really is
a sequence of if (x instanceof Y) statements.
I will look at Mahout's solution for this. I guess a better question to the
> list would have been: "What is the best way to implement a symmetric matrix
> where only the lower (or upper) triangular portion is kept?"
>
Wow. Now you are asking a hard question!
(my preference is fancy stride indexing into a single indexed double array
to get a triangular matrix and then a layer to get symmetry. The triangular
matrix can actually be just an instance of a general dense matrix if you
have sufficiently general striding).
