On 2/28/08 8:44 AM, "Jeff Eastman" <[EMAIL PROTECTED]> wrote:

> 1. While I find the notation awkward and tedious, I think making the
> Matrix interfaces use generics is the best solution for supporting a
> family of efficient implementations: from Boolean through Integer to
> Double. 

I am not at all convinced on this.  But we should see.

> I note that boxed types would need to replace the primitives but
> also that the sparse implementations already use them so the main impact
> would be on the dense implementations.

These sparse implementations are place-holders, really.

> 2. I've flip-flopped on the name question and am now leaning towards
> renaming Matrix1D to Vector. It is more intuitive, easier to type and
> imposing the name uniformity because someday we might add Matrix3D/4D
> seems to be premature abstraction. I am less fervent on renaming
> Matrix2D to be just Matrix, but lean the same way there too. I think the
> commonest terms make the most sense.

What the heck.  Let's go with Matrix and Vector and strike a blow for
clarity.  It isn't like anybody will be confused even after Matrix21d
exists.

> 
> 3. I'm going to make an educated guess that these are the intent:
> 
> public interface DoubleFunction {
>   public double apply(double arg1);
> }
> 
> public interface DoubleDoubleFunction {
>   public double apply(double arg1, double arg2);
> }
> 
> ... and that Matrix1D assign(DoubleFunction function) has the effect of
> applying the function to the elements of the vector in a destructive
> manner; and that Matrix1D assign(Matrix1D y, DoubleDoubleFunction
> function) has the effect of applying the function to each element of the
> argument and receiver, also destructively.

Yes.

Here are some (semi-realistic) sample uses:

- increment every element of a matrix:

   A.assign(Functions.plus(3.0))  // plus is a higher order function that
                                  // returns (roughly) lambda(x) {x+3}

- square the diagonal elements of a row of a matrix:

   A.viewRow(i).assign(new DoubleFunction {double apply(double x) {return
x*x;}})

- set the diagonal elements of a matrix to be the same as a vector

  A.viewDiagonal().assign(y, new DoubleDoubleFunction {
      double apply(double a_ii, y) {return y}  // note that a_ii is ignored
  });

- compute the dot product of two vectors x and y without mutating either,

  x.aggregate(y, DoubleDoubleFunction.plusMult).zSum()

Some common DoubleFunctions include Functions.plus(double x),
Functions.multiply(double x), Functions.log and so on.  Many of these are
curried forms of DoubleDoubleFunctions.  Others are common single argument
math functions.

Some commonly used DoubleDoubleFunctions include Functions.plus(double x,
double y), Functions.max(double x, double y).

Eventually, it will probably be a good idea to in-line some special cases
such as adding vectors if the JIT can't figure
> Ted, how am I doing<grin>?

Awesomely.

Reply via email to