commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian (JIRA)" <>
Subject [jira] [Created] (MATH-1170) Add more in-place operations to RealMatrix and RealVector
Date Wed, 19 Nov 2014 02:32:34 GMT
Brian created MATH-1170:

             Summary: Add more in-place operations to RealMatrix and RealVector
                 Key: MATH-1170
             Project: Commons Math
          Issue Type: Improvement
            Reporter: Brian
            Priority: Minor

It would be nice if for many methods of RealMatrix and RealVector there were in-place versions
of the methods - that would use the existing structures rather than creating new ones.  There
are certain situations where this is preferable.  For example, a series of matrices all of
which will operate on the same vector, after transforming the result each time.  This could
be done very frequently and the vector can be very large.  In some situations it is significantly
more efficient to use the same vector instead of creating many temporary ones each time which
then have to be garbage collected.

An example of two methods that could benefit from in-place versions: the RealMatrix.operate
and RealVector.add.  E.g., RealMatrix.operatInPlace, would transform its input vector/double
array without creating a new one.

There was also a question on stack overflow about this:

There is also a lot of precedents for this kind of behavior, in other languages.

In other languages, this is sometimes handled behind the scenes - when a self-assignment is
found, a new variable is not created - in order to improve performance.  E.g., some functional
languages perform such optimizations behind the scenes, and it is used in MATLAB:

In some ways directly providing the option for in-place operations is preferable because then
we could control when it is applied.  It could be used where appropriate within the internals
of other methods as well.

Similarly there is also a convention in Ruby to have a special version of a method, marked
with a "!" to indicate it is "dangerous" - usually meaning it changes its input - so-called
"bang methods".  Many of these are built into the core Ruby, e.g., sort/sort! for arrays,
upcase/upcase!, chomp/chomp!, and reverse/reverse! for strings.  

This message was sent by Atlassian JIRA

View raw message