Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7A0D410789 for ; Wed, 19 Nov 2014 02:32:34 +0000 (UTC) Received: (qmail 24772 invoked by uid 500); 19 Nov 2014 02:32:34 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 24643 invoked by uid 500); 19 Nov 2014 02:32:34 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 24379 invoked by uid 99); 19 Nov 2014 02:32:34 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Nov 2014 02:32:34 +0000 Date: Wed, 19 Nov 2014 02:32:34 +0000 (UTC) From: "Brian (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (MATH-1170) Add more in-place operations to RealMatrix and RealVector MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 Brian created MATH-1170: --------------------------- Summary: 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: 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: 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 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 (v6.3.4#6332)