You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2011/05/11 21:57:42 UTC
svn commit: r1102057 -
/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java
Author: luc
Date: Wed May 11 19:57:42 2011
New Revision: 1102057
URL: http://svn.apache.org/viewvc?rev=1102057&view=rev
Log:
Added field parameter on various constructors in Array2DRowFieldMatrix.
JIRA: MATH-573
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java?rev=1102057&r1=1102056&r2=1102057&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java Wed May 11 19:57:42 2011
@@ -84,7 +84,26 @@ public class Array2DRowFieldMatrix<T ext
* @see #Array2DRowFieldMatrix(FieldElement[][], boolean)
*/
public Array2DRowFieldMatrix(final T[][] d) {
- super(extractField(d));
+ this(extractField(d), d);
+ }
+
+ /**
+ * Create a new {@code FieldMatrix<T>} using the input array as the underlying
+ * data array.
+ * <p>The input array is copied, not referenced. This constructor has
+ * the same effect as calling {@link #Array2DRowFieldMatrix(FieldElement[][], boolean)}
+ * with the second argument set to {@code true}.</p>
+ *
+ * @param field Field to which the elements belong.
+ * @param d Data for the new matrix.
+ * @throws DimensionMismatchException if {@code d} is not rectangular.
+ * @throws org.apache.commons.math.exception.NullArgumentException if
+ * {@code d} is {@code null}.
+ * @throws NoDataException if there are not at least one row and one column.
+ * @see #Array2DRowFieldMatrix(FieldElement[][], boolean)
+ */
+ public Array2DRowFieldMatrix(final Field<T> field, final T[][] d) {
+ super(field);
copyIn(d);
}
@@ -105,7 +124,28 @@ public class Array2DRowFieldMatrix<T ext
* @see #Array2DRowFieldMatrix(FieldElement[][])
*/
public Array2DRowFieldMatrix(final T[][] d, final boolean copyArray) {
- super(extractField(d));
+ this(extractField(d), d, copyArray);
+ }
+
+ /**
+ * Create a new {@code FieldMatrix<T>} using the input array as the underlying
+ * data array.
+ * <p>If an array is built specially in order to be embedded in a
+ * {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be
+ * set to {@code false}. This will prevent the copying and improve
+ * performance as no new array will be built and no data will be copied.</p>
+ *
+ * @param field Field to which the elements belong.
+ * @param d Data for the new matrix.
+ * @param copyArray Whether to copy or reference the input array.
+ * @throws DimensionMismatchException if {@code d} is not rectangular.
+ * @throws NoDataException if there are not at least one row and one column.
+ * @throws org.apache.commons.math.exception.NullArgumentException
+ * if {@code d} is {@code null}.
+ * @see #Array2DRowFieldMatrix(FieldElement[][])
+ */
+ public Array2DRowFieldMatrix(final Field<T> field, final T[][] d, final boolean copyArray) {
+ super(field);
if (copyArray) {
copyIn(d);
} else {
@@ -137,7 +177,19 @@ public class Array2DRowFieldMatrix<T ext
* @param v Column vector holding data for new matrix.
*/
public Array2DRowFieldMatrix(final T[] v) {
- super(extractField(v));
+ this(extractField(v), v);
+ }
+
+ /**
+ * Create a new (column) {@code FieldMatrix<T>} using {@code v} as the
+ * data for the unique column of the created matrix.
+ * The input array is copied.
+ *
+ * @param field Field to which the elements belong.
+ * @param v Column vector holding data for new matrix.
+ */
+ public Array2DRowFieldMatrix(final Field<T> field, final T[] v) {
+ super(field);
final int nRows = v.length;
data = buildArray(getField(), nRows, 1);
for (int row = 0; row < nRows; row++) {
@@ -154,7 +206,7 @@ public class Array2DRowFieldMatrix<T ext
/** {@inheritDoc} */
@Override
public FieldMatrix<T> copy() {
- return new Array2DRowFieldMatrix<T>(copyOut(), false);
+ return new Array2DRowFieldMatrix<T>(getField(), copyOut(), false);
}
/**
@@ -181,7 +233,7 @@ public class Array2DRowFieldMatrix<T ext
}
}
- return new Array2DRowFieldMatrix<T>(outData, false);
+ return new Array2DRowFieldMatrix<T>(getField(), outData, false);
}
/**