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 2009/04/20 22:57:33 UTC
svn commit: r766873 -
/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java
Author: luc
Date: Mon Apr 20 20:57:33 2009
New Revision: 766873
URL: http://svn.apache.org/viewvc?rev=766873&view=rev
Log:
fixed missing dimension checks
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java?rev=766873&r1=766872&r2=766873&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/MatrixUtils.java Mon Apr 20 20:57:33 2009
@@ -23,6 +23,7 @@
import org.apache.commons.math.Field;
import org.apache.commons.math.FieldElement;
+import org.apache.commons.math.MathRuntimeException;
/**
* A collection of static methods that operate on or return matrices.
@@ -315,6 +316,9 @@
public static <T extends FieldElement<T>> FieldMatrix<T>
createRowFieldMatrix(final T[] rowData) {
final int nCols = rowData.length;
+ if (nCols == 0) {
+ throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
+ }
final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols);
for (int i = 0; i < nCols; ++i) {
m.setEntry(0, i, rowData[i]);
@@ -410,6 +414,9 @@
public static <T extends FieldElement<T>> FieldMatrix<T>
createColumnFieldMatrix(final T[] columnData) {
final int nRows = columnData.length;
+ if (nRows == 0) {
+ throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
+ }
final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1);
for (int i = 0; i < nRows; ++i) {
m.setEntry(i, 0, columnData[i]);