commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: (MATH-608) Remove methods from RealMatrix Interface
Date Fri, 01 Jul 2011 23:39:29 GMT
One concrete example where second argument runtime type dispatching is
helpful is the case of multiplying a dense matrix (of any kind) by a sparse
vector.  It is preferable to put the smarts for how to do this on in the
sparse vector rather than in the dense matrix, but object oriented dispatch
gives us the option to put the method on the matrix.

On Fri, Jul 1, 2011 at 4:26 PM, Gilles Sadowski <
gilles@harfang.homelinux.org> wrote:

> ...
> The idea of separating the algorithms from the storage layout sounds nice
> but why would a class implementing "MatrixOpsIface" be more performant, or
> simpler, than adding specialized "mutliply" methods within the RealMatrix
> implementations themselves?
> E.g.
> ---CUT---
> public class Array2DRowRealMatrix {
>  public Array2DRowRealMatrix multiply(Array2DRowRealMatrix m) { /* ... */ }
>  public Array2DRowRealMatrix multiply(DiagonalRealMatrix m) { /* ... */ }
>  /* ... */
> }
> ---CUT---
>
> Also, there seems to be the problem of exposing the internals (storage
> layout) so that the implementations of "MatrixOpsIface" can actually make
> use of them. This would break encapsulation: The layout would becomes part
> of the interface.
>
> Still, publicizing the operators might be interesting. With generics:
> ---CUT---
> interface Multiply<M extends RealMatrix,
>                   O extends RealMatrix> {
>    public O multiply(M m);
> }
> ---CUT---
>
> Hence, we advertise which operations are type-optimized:
> ---CUT---
> public class Array2DRowRealMatrix
>    implements Multiply<Array2DRowRealMatrix, Array2DRowRealMatrix>,
>               Multiply<Array2DRowRealMatrix, DiagonalRealMatrix> {
>    // ...
> }
>
> Sorry, if this is all besides the point; without a concrete example, it's
> difficult to figure what must be improved.
>
> Also, you could have a look at
>  http://www.ojalgo.org
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message