commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sébastien Brisard <>
Subject Re: [math] visitor pattern for vectors
Date Fri, 25 May 2012 03:16:08 GMT
Hello again,

> MATH-765 turns out to be too ambitious [1], but one of the points I
> raised was deemed worth implementing.
> {quote}
> My first suggestion would be on the visitor design pattern vs.
> map(UnivariateFunction). The former is specified in the RealMatrix
> interface, the latter is specified in the RealVector abstract class. I
> think both concepts are similar, and both are useful:
>  - visitors know about the cell they are visiting,
>  - map() doesn't.
> Maybe it would be nice as a first step to unify these concepts. Two
> options there
> 1. Specify both in both interfaces,
> 2. Specify only the visitor design pattern, and create a factory which
> would return a visitor from a UnivariateFunction (ignoring the indices
> of the current cell).
> {quote}
> Gilles wrote that he liked this proposal, and favored option #2. What
> do others think?
> Best regards,
> Sébastien
> [1]
On second thoughts, I think that option #2 is preferrable for sparse
vectors. Indeed, in the case of map(), the function to be mapped needs
only be called once for the default value of the entries which are not
stored. For the visitor pattern, as the index of the entry might
affect the behavior of the visitor, this optimization cannot be done.
BTW, I see that the value of the unstored entries in sparse
vectors/matrices is zero. This might be a bit restrictive. For
example, if x is a sparse vector, then should also (in my
opinion) be a sparse vector. Maybe we should think about this

Best regards,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message