commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz" <p...@steitz.com>
Subject RE: [math] RealMatrixImpl changes was: RE: cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/linear RealMatrixImplTest.java
Date Mon, 11 Oct 2004 19:20:43 GMT
I understand what you are trying to do here and support the basic idea, but I don't know if
this will work in general.  What happens when we want to add a sparse matrix to a RealMatrixImpl?
 J made the point that we can't always require getDataRef to be supported.  Given this, for
the RealMatrixImp x RealMatrixImpl case, why not just cast the RealMatrix operand to a RealMatrixImpl
(since getDataRef is defined there)?  This could be done with the current impl.  I don't fully
see the value of the additional interface. 

	-----Original Message----- 
	From: Mark R. Diggory [mailto:mdiggory@latte.harvard.edu] 
	Sent: Mon 10/11/2004 12:10 PM 
	To: Jakarta Commons Developers List 
	Cc: 
	Subject: Re: [math] RealMatrixImpl changes was: RE: cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/linear
RealMatrixImplTest.java
	
	

	Phil,
	
	Heres a patch that shows the changes which would solve this copying
	issue in the current RealMatrixImpl.
	
	Index: RealMatrixImpl.java
	===================================================================
	RCS file:
	/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java,v
	retrieving revision 1.32
	diff -u -r1.32 RealMatrixImpl.java
	--- RealMatrixImpl.java 10 Oct 2004 18:00:33 -0000      1.32
	+++ RealMatrixImpl.java 11 Oct 2004 19:09:03 -0000
	@@ -48,7 +48,7 @@
	   *
	   * @version $Revision: 1.32 $ $Date: 2004/10/10 18:00:33 $
	   */
	-public class RealMatrixImpl implements RealMatrix, Serializable {
	+public class RealMatrixImpl implements RealMatrix,
	InternalMatrixSupport, Serializable {
	
	      /** Serializable version identifier */
	      static final long serialVersionUID = 4237564493130426188L;
	@@ -160,7 +160,7 @@
	          int rowCount = this.getRowDimension();
	          int columnCount = this.getColumnDimension();
	          double[][] outData = new double[rowCount][columnCount];
	-        double[][] mData = m.getData();
	+        double[][] mData = ((InternalMatrixSupport)m).getDataRef();
	          for (int row = 0; row < rowCount; row++) {
	              for (int col = 0; col < columnCount; col++) {
	                  outData[row][col] = data[row][col] + mData[row][col];
	@@ -184,7 +184,7 @@
	          int rowCount = this.getRowDimension();
	          int columnCount = this.getColumnDimension();
	          double[][] outData = new double[rowCount][columnCount];
	-        double[][] mData = m.getData();
	+        double[][] mData = ((InternalMatrixSupport)m).getDataRef();
	          for (int row = 0; row < rowCount; row++) {
	              for (int col = 0; col < columnCount; col++) {
	                  outData[row][col] = data[row][col] - mData[row][col];
	@@ -242,7 +242,7 @@
	          int nRows = this.getRowDimension();
	          int nCols = m.getColumnDimension();
	          int nSum = this.getColumnDimension();
	-        double[][] mData = m.getData();
	+        double[][] mData = ((InternalMatrixSupport)m).getDataRef();
	          double[][] outData = new double[nRows][nCols];
	          double sum = 0;
	          for (int row = 0; row < nRows; row++) {
	@@ -716,7 +716,7 @@
	          int nRowB = b.getRowDimension();
	
	          // Apply permutations to b
	-        double[][] bv = b.getData();
	+        double[][] bv = ((InternalMatrixSupport)b).getDataRef();
	          double[][] bp = new double[nRowB][nColB];
	          for (int row = 0; row < nRowB; row++) {
	              for (int col = 0; col < nColB; col++) {
	Index: InternalMatrixSupport.java
	===================================================================
	RCS file: InternalMatrixSupport.java
	diff -N InternalMatrixSupport.java
	--- /dev/null   1 Jan 1970 00:00:00 -0000
	+++ InternalMatrixSupport.java  1 Jan 1970 00:00:00 -0000
	@@ -0,0 +1,26 @@
	+/*
	+ * Created on Oct 11, 2004
	+ *
	+ * TODO To change the template for this generated file go to
	+ * Window - Preferences - Java - Code Style - Code Templates
	+ */
	+package org.apache.commons.math.linear;
	+
	+/**
	+ * @author Administrator
	+ *
	+ * TODO To change the template for this generated type comment go to
	+ * Window - Preferences - Java - Code Style - Code Templates
	+ */
	+public interface InternalMatrixSupport {
	+
	+       /**
	+     * Returns a reference to the underlying data array.
	+     * <p>
	+     * Does not make a fresh copy of the underlying data.
	+     *
	+     * @return 2-dimensional array of entries
	+     */
	+    public double[][] getDataRef();
	+
	+}
	
	---------------------------------------------------------------------
	To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
	For additional commands, e-mail: commons-dev-help@jakarta.apache.org
	
	

Mime
View raw message