> [...]
> 
> >>
> >> > Maybe that we could also impose that it is forbidden to divide by a 
> >> > sparse
> >> > vector whose default value is zero. This will avoid a check on all 
> >> > entries
> >> > (at the expense of forbidding legitimate divisions, when all the entries
> >> > have a non-default value; but then one would wonder why using a sparse
> >> > vector...).
> >
> > [...]
> 
> Gilles, I have the feeling that your prefered option is to store the
> sign of the default value.

Not really; if there are no obvious drawbacks, I'd prefer the above option.
I.e. something like

  public OpenMapRealVector ebeDivide(OpenMapRealVector v) {
    if (v.getDefaultEntry() == 0) {
      throw new ZeroException();
    }

    // ...
  }

> In theory, that would solve the problem. I
> see two objections
> 1. sparse vectors would be less sparse (most users do not care about
> the sign of the zero entries!)

I agree; division by zero is in most (all?) cases a bug. So thoses users
won't care about the above solution (or will be happy that their code fails
early instead of propagating NaNs).

> 2. there is a threshold to decided whether or not an entry is actually
> zero. So the current implementation already assumes the sign is lost.

That's why the unit test fails. I think that it is more robust to make it
explicit (by throwing an exception) that division by zero is not supported.

> I'm really confused about the best solution to adopt.

So am I.
But my preference is to be more robust even if less efficient and not
supporting corner cases.


Best,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to