[ 
https://issues.apache.org/jira/browse/MATH-1170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14217780#comment-14217780
 ] 

Gilles commented on MATH-1170:
------------------------------

There has been numerous discussions about how to improve the matrix API:
* https://issues.apache.org/jira/browse/MATH-765
* https://issues.apache.org/jira/browse/MATH-870
* https://issues.apache.org/jira/browse/MATH-928
* https://issues.apache.org/jira/browse/MATH-1003

It should also be taken into account that the current interface requires the 
implementation of _many_ methods; this has been raised as a problem for some 
usage.  Adding more methods would make it worse (and less likely that alternate 
implementations are going to be worked on, as the current situation shows).
But you are of course right that in-place operations could be better in some 
circumstances (e.g. very large matrices)...
In others, developers might prefer the less "dangerous" approach.

You are welcome to revive the discussion on the "dev" ML.


> Add more in-place operations to RealMatrix and RealVector
> ---------------------------------------------------------
>
>                 Key: MATH-1170
>                 URL: https://issues.apache.org/jira/browse/MATH-1170
>             Project: Commons Math
>          Issue Type: Wish
>            Reporter: Brian
>            Priority: Minor
>
> It would be nice if for some methods of RealMatrix and RealVector there were 
> in-place versions of the methods - that would use the existing structures 
> rather than creating new ones.  In some situations it might be more efficient 
> to use the same vector instead of creating many temporary ones each time 
> which then have to be garbage collected, so it would be nice to provide the 
> option.
> An example of a method that could benefit from in-place versions:  
> RealVector.add.  
> There was also a question on stack overflow about this for matrix operations:
> http://stackoverflow.com/questions/20529484/performing-in-place-calculations-with-commons-maths-realmatrix
> 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:
> http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/
> http://undocumentedmatlab.com/blog/internal-matlab-memory-optimizations
> 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 an exclamation point 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
(v6.3.4#6332)

Reply via email to