The Colt package used a functional style to implement what you suggest. This approach has been inherited by Mahout.
The basic idea is that there is an assign method that takes other arguments and a function for combining the arguments. The function allows great amounts of flexibility and promotes compositional style. A small amount of special case code for common operations and the JVM's very impressive ability to in-line code result in pretty fast operations. The problem with this kind of approach is that users have a very hard time understanding how to write code (where is the plus method, they say. where is the element-wise max of two vectors?) On Thu, Jul 7, 2011 at 7:14 AM, Gilles Sadowski < gil...@harfang.homelinux.org> wrote: > Hello. > > > in Blas, the method DAXPY can lead to very compact code. As far as I > know, it > > has no equivalent in RealVector. There are a few method called > xxxxToSelf, > > which modify the calling vector, instead of returning a new one, but > these are > > restricted to scalars operating on vectors. > > In other words, there are no in-place vector-vector operations. > > Would you think it useful to add at least one method, say > > combineToSelf(double s, double t, RealVector v) > > which would replace the components of this by the components of (s * this > + t > > * v). This would be a slight generalization of DAXPY. > > You should open an issue on JIRA to keep track of this feature request. > [Not sure about the "combineToSelf" name: "combine" is used in > "FunctionUtils" but not exactly with the same meaning...] > > > It would be fairly easy to implement for ArrayRealVector, not sure about > > OpenMapRealVector. > > A default implementation would be implemented in "AbstractRealVector", > (where a "SparseEntryIterator" is defined and the method "mapToSelf" is an > example of how it is used). > > > Thanks, > Gilles > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > >