You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Rodrigo di Lorenzo Lopes <br...@terra.com.br> on 2005/05/22 06:13:01 UTC

[math] setSubMatrix patch

Index: 
D:/workspace/commons-math/src/java/org/apache/commons/math/linear/RealMatrix.java
===================================================================
--- 
D:/workspace/commons-math/src/java/org/apache/commons/math/linear/RealMatrix.java   
 (revision 170743)
+++ 
D:/workspace/commons-math/src/java/org/apache/commons/math/linear/RealMatrix.java   
 (working copy)
@@ -25,7 +25,6 @@
  * @version $Revision$ $Date$
  */
 public interface RealMatrix {
-
     /**
      * Returns a (deep) copy of this.
      *
@@ -129,6 +128,16 @@
    RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
    throws MatrixIndexException;
    
+    /**
+     * Replace values from row, column by
+     * values of  <a 
href="http://mathworld.wolfram.com/Submatrix.html">submatrix</a>.
+     * @param subMatrix submatrix be copied.
+     * @param row row of initial element will be replace  
+     * @param column column of initial element will be replace
+     */
+    public void setSubMatrix(double subMatrix[][], int row, int column) 
throws MatrixIndexException;
+   
+   
    /**
     * Returns the entries in row number <code>row</code>
     * as a row matrix.  Row indices start at 0.
Index: 
D:/workspace/commons-math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
===================================================================
--- 
D:/workspace/commons-math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java   
 (revision 170743)
+++ 
D:/workspace/commons-math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java   
 (working copy)
@@ -365,7 +365,31 @@
         }
         return subMatrix;
     }
-    
+
+    /**
+     * Replace values from row, column by
+     * values of  <a 
href="http://mathworld.wolfram.com/Submatrix.html">submatrix</a>.
+     * @param subMatrix submatrix be copied.
+     * @param row row of initial element will be replace  
+     * @param column column of initial element will be replace
+     */    
+    public void setSubMatrix(double[][] subMatrix, int row, int column) {
+        int nRows = subMatrix.length;
+        int nCols = subMatrix[0].length;
+
+        if (data == null){
+            data = new double[nRows][nCols];
+            System.arraycopy(subMatrix, 0, data, 0, subMatrix.length);    
+        }
+        
+        for (int i = row; i < row + nRows; i++) {
+            System.arraycopy(subMatrix[i], 0, data[i], column, nCols);
+        }
+        lu = null;    
+    }
+    
+    
+    
     /**
      * Returns the entries in row number <code>row</code>
      * as a row matrix.  Row indices start at 0.
@@ -957,14 +981,7 @@
      * @param in data to copy in
      */
     private void copyIn(double[][] in) {
-        int nRows = in.length;
-        int nCols = in[0].length;
-        data = new double[nRows][nCols];
-        System.arraycopy(in, 0, data, 0, in.length);
-        for (int i = 0; i < nRows; i++) {
-            System.arraycopy(in[i], 0, data[i], 0, nCols);
-        }
-        lu = null;
+        setSubMatrix(in,0,0);
     }
 
     /**

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] setSubMatrix patch

Posted by Phil Steitz <ph...@gmail.com>.
No need to apologize.  Your contributions are most appreciated.  Let
me know if you need help getting set up or anything.  Thanks!

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] setSubMatrix patch

Posted by Rodrigo di Lorenzo Lopes <br...@terra.com.br>.
Phil Steitz wrote:
Oh! I´m sorry Phil .. Yes, I am still learning.
I will send a unit test and BigMatrix versions soon.

Thank for all,
Rodrigo

>Rodrigo,
>
>Thanks for the patch!
>
>It would be great if you could also add some unit tests for this and
>provide an implementation and tests for the BigMatrix versions.
>
>Also, its a little easier to keep things organized if you attach the
>patch to the bugzilla ticket.  Just open the report here
><http://issues.apache.org/bugzilla/show_bug.cgi?id=35007> then use the
>"Create a New Attachment" link to add the patch.
>
>Phil
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] setSubMatrix patch

Posted by Phil Steitz <ph...@gmail.com>.
Rodrigo,

Thanks for the patch!

It would be great if you could also add some unit tests for this and
provide an implementation and tests for the BigMatrix versions.

Also, its a little easier to keep things organized if you attach the
patch to the bugzilla ticket.  Just open the report here
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35007> then use the
"Create a New Attachment" link to add the patch.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org