Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-1170

Add more in-place operations to RealMatrix and RealVector

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Resolved
    • Minor
    • Resolution: Incomplete
    • None
    • None
    • None
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              brian44 Brian
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: