renamed Dense{Real/Field}Matrix into Block{Real/Field}Matrix

as suggested by Phil in http://markmail.org/message/iibgiz4bsv6hjjvh

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@783678 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-06-11 08:05:24 +00:00
parent 9d4fb6760b
commit 37ee8dbfe6
23 changed files with 391 additions and 385 deletions

View File

@ -110,7 +110,7 @@
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="org.apache.commons.math.linear.DenseFieldMatrix"/>
<Class name="org.apache.commons.math.linear.BlockFieldMatrix"/>
<Method name="&lt;init>" params="int,int,org.apache.commons.math.FieldElement[][],boolean" returns="void" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
@ -125,7 +125,7 @@
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="org.apache.commons.math.linear.DenseRealMatrix"/>
<Class name="org.apache.commons.math.linear.BlockRealMatrix"/>
<Method name="&lt;init>" params="int,int,double[][],boolean" returns="void" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>

View File

@ -421,7 +421,7 @@ public class MessagesResources_fr
{ "{0}x{1} and {2}x{3} matrices are not multiplication compatible",
"les dimensions {0}x{1} et {2}x{3} sont incompatibles pour la multiplication matricielle" },
// org.apache.commons.math.linear.DenseRealMatrix
// org.apache.commons.math.linear.BlockRealMatrix
{ "wrong array shape (block length = {0}, expected {1})",
"forme de tableau erron\u00e9e (bloc de longueur {0} au lieu des {1} attendus)" },

View File

@ -63,7 +63,7 @@ import org.apache.commons.math.MathRuntimeException;
* @version $Revision$ $Date$
* @since 2.0
*/
public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMatrix<T> implements Serializable {
public class BlockFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMatrix<T> implements Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = -4602336630143123183L;
@ -95,7 +95,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* @throws IllegalArgumentException if row or column dimension is not
* positive
*/
public DenseFieldMatrix(final Field<T> field, final int rows, final int columns)
public BlockFieldMatrix(final Field<T> field, final int rows, final int columns)
throws IllegalArgumentException {
super(field, rows, columns);
@ -115,16 +115,16 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* Create a new dense matrix copying entries from raw layout data.
* <p>The input array <em>must</em> already be in raw layout.</p>
* <p>Calling this constructor is equivalent to call:
* <pre>matrix = new DenseFieldMatrix<T>(getField(), rawData.length, rawData[0].length,
* <pre>matrix = new BlockFieldMatrix<T>(getField(), rawData.length, rawData[0].length,
* toBlocksLayout(rawData), false);</pre>
* </p>
* @param rawData data for new matrix, in raw layout
*
* @exception IllegalArgumentException if <code>blockData</code> shape is
* inconsistent with block layout
* @see #DenseFieldMatrix(int, int, FieldElement[][], boolean)
* @see #BlockFieldMatrix(int, int, FieldElement[][], boolean)
*/
public DenseFieldMatrix(final T[][] rawData)
public BlockFieldMatrix(final T[][] rawData)
throws IllegalArgumentException {
this(rawData.length, rawData[0].length, toBlocksLayout(rawData), false);
}
@ -142,9 +142,9 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* inconsistent with block layout
* @see #createBlocksLayout(Field, int, int)
* @see #toBlocksLayout(FieldElement[][])
* @see #DenseFieldMatrix(FieldElement[][])
* @see #BlockFieldMatrix(FieldElement[][])
*/
public DenseFieldMatrix(final int rows, final int columns,
public BlockFieldMatrix(final int rows, final int columns,
final T[][] blockData, final boolean copyArray)
throws IllegalArgumentException {
@ -186,7 +186,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* <p>
* Raw layout is the straightforward layout where element at row i and
* column j is in array element <code>rawData[i][j]</code>. Blocks layout
* is the layout used in {@link DenseFieldMatrix} instances, where the matrix
* is the layout used in {@link BlockFieldMatrix} instances, where the matrix
* is split in square blocks (except at right and bottom side where blocks may
* be rectangular to fit matrix size) and each block is stored in a flattened
* one-dimensional array.
@ -194,7 +194,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* <p>
* This method creates an array in blocks layout from an input array in raw layout.
* It can be used to provide the array argument of the {@link
* DenseFieldMatrix#DenseFieldMatrix(int, int, FieldElement[][], boolean)}
* BlockFieldMatrix#DenseFieldMatrix(int, int, FieldElement[][], boolean)}
* constructor.
* </p>
* @param <T> the type of the field elements
@ -203,7 +203,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* @exception IllegalArgumentException if <code>rawData</code> is not rectangular
* (not all rows have the same length)
* @see #createBlocksLayout(Field, int, int)
* @see #DenseFieldMatrix(int, int, FieldElement[][], boolean)
* @see #BlockFieldMatrix(int, int, FieldElement[][], boolean)
*/
public static <T extends FieldElement<T>> T[][] toBlocksLayout(final T[][] rawData)
throws IllegalArgumentException {
@ -255,7 +255,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* Create a data array in blocks layout.
* <p>
* This method can be used to create the array argument of the {@link
* DenseFieldMatrix#DenseFieldMatrix(int, int, FieldElement[][], boolean)}
* BlockFieldMatrix#DenseFieldMatrix(int, int, FieldElement[][], boolean)}
* constructor.
* </p>
* @param <T> the type of the field elements
@ -264,7 +264,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* @param columns the number of columns in the new matrix
* @return a new data array in blocks layout
* @see #toBlocksLayout(FieldElement[][])
* @see #DenseFieldMatrix(int, int, FieldElement[][], boolean)
* @see #BlockFieldMatrix(int, int, FieldElement[][], boolean)
*/
public static <T extends FieldElement<T>> T[][] createBlocksLayout(final Field<T> field,
final int rows, final int columns) {
@ -293,7 +293,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
@Override
public FieldMatrix<T> createMatrix(final int rowDimension, final int columnDimension)
throws IllegalArgumentException {
return new DenseFieldMatrix<T>(getField(), rowDimension, columnDimension);
return new BlockFieldMatrix<T>(getField(), rowDimension, columnDimension);
}
/** {@inheritDoc} */
@ -301,7 +301,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
public FieldMatrix<T> copy() {
// create an empty matrix
DenseFieldMatrix<T> copied = new DenseFieldMatrix<T>(getField(), rows, columns);
BlockFieldMatrix<T> copied = new BlockFieldMatrix<T>(getField(), rows, columns);
// copy the blocks
for (int i = 0; i < blocks.length; ++i) {
@ -317,13 +317,13 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
public FieldMatrix<T> add(final FieldMatrix<T> m)
throws IllegalArgumentException {
try {
return add((DenseFieldMatrix<T>) m);
return add((BlockFieldMatrix<T>) m);
} catch (ClassCastException cce) {
// safety check
checkAdditionCompatible(m);
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, columns);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns);
// perform addition block-wise, to ensure good cache behavior
int blockIndex = 0;
@ -361,13 +361,13 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* @return this + m
* @throws IllegalArgumentException if m is not the same size as this
*/
public DenseFieldMatrix<T> add(final DenseFieldMatrix<T> m)
public BlockFieldMatrix<T> add(final BlockFieldMatrix<T> m)
throws IllegalArgumentException {
// safety check
checkAdditionCompatible(m);
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, columns);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns);
// perform addition block-wise, to ensure good cache behavior
for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) {
@ -388,13 +388,13 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
public FieldMatrix<T> subtract(final FieldMatrix<T> m)
throws IllegalArgumentException {
try {
return subtract((DenseFieldMatrix<T>) m);
return subtract((BlockFieldMatrix<T>) m);
} catch (ClassCastException cce) {
// safety check
checkSubtractionCompatible(m);
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, columns);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns);
// perform subtraction block-wise, to ensure good cache behavior
int blockIndex = 0;
@ -432,13 +432,13 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* @return this - m
* @throws IllegalArgumentException if m is not the same size as this
*/
public DenseFieldMatrix<T> subtract(final DenseFieldMatrix<T> m)
public BlockFieldMatrix<T> subtract(final BlockFieldMatrix<T> m)
throws IllegalArgumentException {
// safety check
checkSubtractionCompatible(m);
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, columns);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns);
// perform subtraction block-wise, to ensure good cache behavior
for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) {
@ -459,7 +459,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
public FieldMatrix<T> scalarAdd(final T d)
throws IllegalArgumentException {
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, columns);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns);
// perform subtraction block-wise, to ensure good cache behavior
for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) {
@ -479,7 +479,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
public FieldMatrix<T> scalarMultiply(final T d)
throws IllegalArgumentException {
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, columns);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, columns);
// perform subtraction block-wise, to ensure good cache behavior
for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) {
@ -499,13 +499,13 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
public FieldMatrix<T> multiply(final FieldMatrix<T> m)
throws IllegalArgumentException {
try {
return multiply((DenseFieldMatrix<T>) m);
return multiply((BlockFieldMatrix<T>) m);
} catch (ClassCastException cce) {
// safety check
checkMultiplicationCompatible(m);
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, m.getColumnDimension());
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, m.getColumnDimension());
final T zero = getField().getZero();
// perform multiplication block-wise, to ensure good cache behavior
@ -561,12 +561,12 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* @throws IllegalArgumentException
* if columnDimension(this) != rowDimension(m)
*/
public DenseFieldMatrix<T> multiply(DenseFieldMatrix<T> m) throws IllegalArgumentException {
public BlockFieldMatrix<T> multiply(BlockFieldMatrix<T> m) throws IllegalArgumentException {
// safety check
checkMultiplicationCompatible(m);
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, m.columns);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, m.columns);
final T zero = getField().getZero();
// perform multiplication block-wise, to ensure good cache behavior
@ -666,8 +666,8 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
// create the output matrix
final DenseFieldMatrix<T> out =
new DenseFieldMatrix<T>(getField(), endRow - startRow + 1, endColumn - startColumn + 1);
final BlockFieldMatrix<T> out =
new BlockFieldMatrix<T>(getField(), endRow - startRow + 1, endColumn - startColumn + 1);
// compute blocks shifts
final int blockStartRow = startRow / BLOCK_SIZE;
@ -839,7 +839,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
throws MatrixIndexException {
checkRowIndex(row);
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), 1, columns);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), 1, columns);
// perform copy block-wise, to ensure good cache behavior
final int iBlock = row / BLOCK_SIZE;
@ -871,7 +871,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
public void setRowMatrix(final int row, final FieldMatrix<T> matrix)
throws MatrixIndexException, InvalidMatrixException {
try {
setRowMatrix(row, (DenseFieldMatrix<T>) matrix);
setRowMatrix(row, (BlockFieldMatrix<T>) matrix);
} catch (ClassCastException cce) {
super.setRowMatrix(row, matrix);
}
@ -888,7 +888,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* @throws InvalidMatrixException if the matrix dimensions do not match one
* instance row
*/
public void setRowMatrix(final int row, final DenseFieldMatrix<T> matrix)
public void setRowMatrix(final int row, final BlockFieldMatrix<T> matrix)
throws MatrixIndexException, InvalidMatrixException {
checkRowIndex(row);
@ -930,7 +930,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
throws MatrixIndexException {
checkColumnIndex(column);
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), rows, 1);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), rows, 1);
// perform copy block-wise, to ensure good cache behavior
final int jBlock = column / BLOCK_SIZE;
@ -960,7 +960,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
public void setColumnMatrix(final int column, final FieldMatrix<T> matrix)
throws MatrixIndexException, InvalidMatrixException {
try {
setColumnMatrix(column, (DenseFieldMatrix<T>) matrix);
setColumnMatrix(column, (BlockFieldMatrix<T>) matrix);
} catch (ClassCastException cce) {
super.setColumnMatrix(column, matrix);
}
@ -977,7 +977,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
* @throws InvalidMatrixException if the matrix dimensions do not match one
* instance column
*/
void setColumnMatrix(final int column, final DenseFieldMatrix<T> matrix)
void setColumnMatrix(final int column, final BlockFieldMatrix<T> matrix)
throws MatrixIndexException, InvalidMatrixException {
checkColumnIndex(column);
@ -1259,7 +1259,7 @@ public class DenseFieldMatrix<T extends FieldElement<T>> extends AbstractFieldMa
final int nRows = getRowDimension();
final int nCols = getColumnDimension();
final DenseFieldMatrix<T> out = new DenseFieldMatrix<T>(getField(), nCols, nRows);
final BlockFieldMatrix<T> out = new BlockFieldMatrix<T>(getField(), nCols, nRows);
// perform transpose block-wise, to ensure good cache behavior
int blockIndex = 0;

View File

@ -61,7 +61,7 @@ import org.apache.commons.math.MathRuntimeException;
* @version $Revision$ $Date$
* @since 2.0
*/
public class DenseRealMatrix extends AbstractRealMatrix implements Serializable {
public class BlockRealMatrix extends AbstractRealMatrix implements Serializable {
/** Serializable version identifier */
private static final long serialVersionUID = 4991895511313664478L;
@ -92,7 +92,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* @throws IllegalArgumentException if row or column dimension is not
* positive
*/
public DenseRealMatrix(final int rows, final int columns)
public BlockRealMatrix(final int rows, final int columns)
throws IllegalArgumentException {
super(rows, columns);
@ -112,16 +112,16 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* Create a new dense matrix copying entries from raw layout data.
* <p>The input array <em>must</em> already be in raw layout.</p>
* <p>Calling this constructor is equivalent to call:
* <pre>matrix = new DenseRealMatrix(rawData.length, rawData[0].length,
* <pre>matrix = new BlockRealMatrix(rawData.length, rawData[0].length,
* toBlocksLayout(rawData), false);</pre>
* </p>
* @param rawData data for new matrix, in raw layout
*
* @exception IllegalArgumentException if <code>blockData</code> shape is
* inconsistent with block layout
* @see #DenseRealMatrix(int, int, double[][], boolean)
* @see #BlockRealMatrix(int, int, double[][], boolean)
*/
public DenseRealMatrix(final double[][] rawData)
public BlockRealMatrix(final double[][] rawData)
throws IllegalArgumentException {
this(rawData.length, rawData[0].length, toBlocksLayout(rawData), false);
}
@ -139,9 +139,9 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* inconsistent with block layout
* @see #createBlocksLayout(int, int)
* @see #toBlocksLayout(double[][])
* @see #DenseRealMatrix(double[][])
* @see #BlockRealMatrix(double[][])
*/
public DenseRealMatrix(final int rows, final int columns,
public BlockRealMatrix(final int rows, final int columns,
final double[][] blockData, final boolean copyArray)
throws IllegalArgumentException {
@ -183,7 +183,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* <p>
* Raw layout is the straightforward layout where element at row i and
* column j is in array element <code>rawData[i][j]</code>. Blocks layout
* is the layout used in {@link DenseRealMatrix} instances, where the matrix
* is the layout used in {@link BlockRealMatrix} instances, where the matrix
* is split in square blocks (except at right and bottom side where blocks may
* be rectangular to fit matrix size) and each block is stored in a flattened
* one-dimensional array.
@ -191,14 +191,14 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* <p>
* This method creates an array in blocks layout from an input array in raw layout.
* It can be used to provide the array argument of the {@link
* DenseRealMatrix#DenseRealMatrix(int, int, double[][], boolean)} constructor.
* BlockRealMatrix#DenseRealMatrix(int, int, double[][], boolean)} constructor.
* </p>
* @param rawData data array in raw layout
* @return a new data array containing the same entries but in blocks layout
* @exception IllegalArgumentException if <code>rawData</code> is not rectangular
* (not all rows have the same length)
* @see #createBlocksLayout(int, int)
* @see #DenseRealMatrix(int, int, double[][], boolean)
* @see #BlockRealMatrix(int, int, double[][], boolean)
*/
public static double[][] toBlocksLayout(final double[][] rawData)
throws IllegalArgumentException {
@ -249,13 +249,13 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* Create a data array in blocks layout.
* <p>
* This method can be used to create the array argument of the {@link
* DenseRealMatrix#DenseRealMatrix(int, int, double[][], boolean)} constructor.
* BlockRealMatrix#DenseRealMatrix(int, int, double[][], boolean)} constructor.
* </p>
* @param rows the number of rows in the new matrix
* @param columns the number of columns in the new matrix
* @return a new data array in blocks layout
* @see #toBlocksLayout(double[][])
* @see #DenseRealMatrix(int, int, double[][], boolean)
* @see #BlockRealMatrix(int, int, double[][], boolean)
*/
public static double[][] createBlocksLayout(final int rows, final int columns) {
@ -281,17 +281,17 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix createMatrix(final int rowDimension, final int columnDimension)
public BlockRealMatrix createMatrix(final int rowDimension, final int columnDimension)
throws IllegalArgumentException {
return new DenseRealMatrix(rowDimension, columnDimension);
return new BlockRealMatrix(rowDimension, columnDimension);
}
/** {@inheritDoc} */
@Override
public DenseRealMatrix copy() {
public BlockRealMatrix copy() {
// create an empty matrix
DenseRealMatrix copied = new DenseRealMatrix(rows, columns);
BlockRealMatrix copied = new BlockRealMatrix(rows, columns);
// copy the blocks
for (int i = 0; i < blocks.length; ++i) {
@ -304,16 +304,16 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix add(final RealMatrix m)
public BlockRealMatrix add(final RealMatrix m)
throws IllegalArgumentException {
try {
return add((DenseRealMatrix) m);
return add((BlockRealMatrix) m);
} catch (ClassCastException cce) {
// safety check
MatrixUtils.checkAdditionCompatible(this, m);
final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
final BlockRealMatrix out = new BlockRealMatrix(rows, columns);
// perform addition block-wise, to ensure good cache behavior
int blockIndex = 0;
@ -351,13 +351,13 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* @return this + m
* @throws IllegalArgumentException if m is not the same size as this
*/
public DenseRealMatrix add(final DenseRealMatrix m)
public BlockRealMatrix add(final BlockRealMatrix m)
throws IllegalArgumentException {
// safety check
MatrixUtils.checkAdditionCompatible(this, m);
final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
final BlockRealMatrix out = new BlockRealMatrix(rows, columns);
// perform addition block-wise, to ensure good cache behavior
for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) {
@ -375,16 +375,16 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix subtract(final RealMatrix m)
public BlockRealMatrix subtract(final RealMatrix m)
throws IllegalArgumentException {
try {
return subtract((DenseRealMatrix) m);
return subtract((BlockRealMatrix) m);
} catch (ClassCastException cce) {
// safety check
MatrixUtils.checkSubtractionCompatible(this, m);
final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
final BlockRealMatrix out = new BlockRealMatrix(rows, columns);
// perform subtraction block-wise, to ensure good cache behavior
int blockIndex = 0;
@ -422,13 +422,13 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* @return this - m
* @throws IllegalArgumentException if m is not the same size as this
*/
public DenseRealMatrix subtract(final DenseRealMatrix m)
public BlockRealMatrix subtract(final BlockRealMatrix m)
throws IllegalArgumentException {
// safety check
MatrixUtils.checkSubtractionCompatible(this, m);
final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
final BlockRealMatrix out = new BlockRealMatrix(rows, columns);
// perform subtraction block-wise, to ensure good cache behavior
for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) {
@ -446,10 +446,10 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix scalarAdd(final double d)
public BlockRealMatrix scalarAdd(final double d)
throws IllegalArgumentException {
final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
final BlockRealMatrix out = new BlockRealMatrix(rows, columns);
// perform subtraction block-wise, to ensure good cache behavior
for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) {
@ -469,7 +469,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
public RealMatrix scalarMultiply(final double d)
throws IllegalArgumentException {
final DenseRealMatrix out = new DenseRealMatrix(rows, columns);
final BlockRealMatrix out = new BlockRealMatrix(rows, columns);
// perform subtraction block-wise, to ensure good cache behavior
for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) {
@ -486,16 +486,16 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix multiply(final RealMatrix m)
public BlockRealMatrix multiply(final RealMatrix m)
throws IllegalArgumentException {
try {
return multiply((DenseRealMatrix) m);
return multiply((BlockRealMatrix) m);
} catch (ClassCastException cce) {
// safety check
MatrixUtils.checkMultiplicationCompatible(this, m);
final DenseRealMatrix out = new DenseRealMatrix(rows, m.getColumnDimension());
final BlockRealMatrix out = new BlockRealMatrix(rows, m.getColumnDimension());
// perform multiplication block-wise, to ensure good cache behavior
int blockIndex = 0;
@ -549,12 +549,12 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* @throws IllegalArgumentException
* if columnDimension(this) != rowDimension(m)
*/
public DenseRealMatrix multiply(DenseRealMatrix m) throws IllegalArgumentException {
public BlockRealMatrix multiply(BlockRealMatrix m) throws IllegalArgumentException {
// safety check
MatrixUtils.checkMultiplicationCompatible(this, m);
final DenseRealMatrix out = new DenseRealMatrix(rows, m.columns);
final BlockRealMatrix out = new BlockRealMatrix(rows, m.columns);
// perform multiplication block-wise, to ensure good cache behavior
int blockIndex = 0;
@ -681,7 +681,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix getSubMatrix(final int startRow, final int endRow,
public BlockRealMatrix getSubMatrix(final int startRow, final int endRow,
final int startColumn, final int endColumn)
throws MatrixIndexException {
@ -689,8 +689,8 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
// create the output matrix
final DenseRealMatrix out =
new DenseRealMatrix(endRow - startRow + 1, endColumn - startColumn + 1);
final BlockRealMatrix out =
new BlockRealMatrix(endRow - startRow + 1, endColumn - startColumn + 1);
// compute blocks shifts
final int blockStartRow = startRow / BLOCK_SIZE;
@ -858,11 +858,11 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix getRowMatrix(final int row)
public BlockRealMatrix getRowMatrix(final int row)
throws MatrixIndexException {
MatrixUtils.checkRowIndex(this, row);
final DenseRealMatrix out = new DenseRealMatrix(1, columns);
final BlockRealMatrix out = new BlockRealMatrix(1, columns);
// perform copy block-wise, to ensure good cache behavior
final int iBlock = row / BLOCK_SIZE;
@ -894,7 +894,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
public void setRowMatrix(final int row, final RealMatrix matrix)
throws MatrixIndexException, InvalidMatrixException {
try {
setRowMatrix(row, (DenseRealMatrix) matrix);
setRowMatrix(row, (BlockRealMatrix) matrix);
} catch (ClassCastException cce) {
super.setRowMatrix(row, matrix);
}
@ -911,7 +911,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* @throws InvalidMatrixException if the matrix dimensions do not match one
* instance row
*/
public void setRowMatrix(final int row, final DenseRealMatrix matrix)
public void setRowMatrix(final int row, final BlockRealMatrix matrix)
throws MatrixIndexException, InvalidMatrixException {
MatrixUtils.checkRowIndex(this, row);
@ -949,11 +949,11 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix getColumnMatrix(final int column)
public BlockRealMatrix getColumnMatrix(final int column)
throws MatrixIndexException {
MatrixUtils.checkColumnIndex(this, column);
final DenseRealMatrix out = new DenseRealMatrix(rows, 1);
final BlockRealMatrix out = new BlockRealMatrix(rows, 1);
// perform copy block-wise, to ensure good cache behavior
final int jBlock = column / BLOCK_SIZE;
@ -983,7 +983,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
public void setColumnMatrix(final int column, final RealMatrix matrix)
throws MatrixIndexException, InvalidMatrixException {
try {
setColumnMatrix(column, (DenseRealMatrix) matrix);
setColumnMatrix(column, (BlockRealMatrix) matrix);
} catch (ClassCastException cce) {
super.setColumnMatrix(column, matrix);
}
@ -1000,7 +1000,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
* @throws InvalidMatrixException if the matrix dimensions do not match one
* instance column
*/
void setColumnMatrix(final int column, final DenseRealMatrix matrix)
void setColumnMatrix(final int column, final BlockRealMatrix matrix)
throws MatrixIndexException, InvalidMatrixException {
MatrixUtils.checkColumnIndex(this, column);
@ -1276,11 +1276,11 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
/** {@inheritDoc} */
@Override
public DenseRealMatrix transpose() {
public BlockRealMatrix transpose() {
final int nRows = getRowDimension();
final int nCols = getColumnDimension();
final DenseRealMatrix out = new DenseRealMatrix(nCols, nRows);
final BlockRealMatrix out = new BlockRealMatrix(nCols, nRows);
// perform transpose block-wise, to ensure good cache behavior
int blockIndex = 0;

View File

@ -164,7 +164,7 @@ public class OpenMapRealMatrix extends AbstractRealMatrix implements SparseRealM
MatrixUtils.checkMultiplicationCompatible(this, m);
final int outCols = m.getColumnDimension();
final DenseRealMatrix out = new DenseRealMatrix(rowDimension, outCols);
final BlockRealMatrix out = new BlockRealMatrix(rowDimension, outCols);
for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) {
iterator.advance();
final double value = iterator.value();

View File

@ -369,9 +369,9 @@ public class QRDecompositionImpl implements QRDecomposition {
}
final int columns = b.getColumnDimension();
final int blockSize = DenseRealMatrix.BLOCK_SIZE;
final int blockSize = BlockRealMatrix.BLOCK_SIZE;
final int cBlocks = (columns + blockSize - 1) / blockSize;
final double[][] xBlocks = DenseRealMatrix.createBlocksLayout(n, columns);
final double[][] xBlocks = BlockRealMatrix.createBlocksLayout(n, columns);
final double[][] y = new double[b.getRowDimension()][blockSize];
final double[] alpha = new double[blockSize];
@ -435,7 +435,7 @@ public class QRDecompositionImpl implements QRDecomposition {
}
return new DenseRealMatrix(n, columns, xBlocks, false);
return new BlockRealMatrix(n, columns, xBlocks, false);
}

View File

@ -21,7 +21,7 @@ import java.io.Serializable;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.linear.DecompositionSolver;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.InvalidMatrixException;
import org.apache.commons.math.linear.LUDecompositionImpl;
import org.apache.commons.math.linear.QRDecompositionImpl;
@ -109,7 +109,7 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer implemen
try {
// solve the linearized least squares problem
RealMatrix mA = new DenseRealMatrix(a);
RealMatrix mA = new BlockRealMatrix(a);
DecompositionSolver solver = useLU ?
new LUDecompositionImpl(mA).getSolver() :
new QRDecompositionImpl(mA).getSolver();

View File

@ -18,7 +18,7 @@ package org.apache.commons.math.stat.correlation;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.stat.descriptive.moment.Mean;
import org.apache.commons.math.stat.descriptive.moment.Variance;
@ -78,7 +78,7 @@ public class Covariance {
* rectangular with at least two rows and two columns.
*/
public Covariance(double[][] data, boolean biasCorrected) {
this(new DenseRealMatrix(data), biasCorrected);
this(new BlockRealMatrix(data), biasCorrected);
}
/**
@ -159,7 +159,7 @@ public class Covariance {
protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) {
int dimension = matrix.getColumnDimension();
Variance variance = new Variance(biasCorrected);
RealMatrix outMatrix = new DenseRealMatrix(dimension, dimension);
RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension);
for (int i = 0; i < dimension; i++) {
for (int j = 0; j < i; j++) {
double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected);
@ -190,7 +190,7 @@ public class Covariance {
* @return covariance matrix
*/
protected RealMatrix computeCovarianceMatrix(double[][] data, boolean biasCorrected) {
return computeCovarianceMatrix(new DenseRealMatrix(data), biasCorrected);
return computeCovarianceMatrix(new BlockRealMatrix(data), biasCorrected);
}
/**

View File

@ -21,7 +21,7 @@ import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.distribution.TDistribution;
import org.apache.commons.math.distribution.TDistributionImpl;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.stat.regression.SimpleRegression;
/**
@ -65,7 +65,7 @@ public class PearsonsCorrelation {
* rectangular with at least two rows and two columns.
*/
public PearsonsCorrelation(double[][] data) {
this(new DenseRealMatrix(data));
this(new BlockRealMatrix(data));
}
/**
@ -141,7 +141,7 @@ public class PearsonsCorrelation {
out[i][j] = Math.sqrt((1 - r * r) /(nObs - 2));
}
}
return new DenseRealMatrix(out);
return new BlockRealMatrix(out);
}
/**
@ -172,7 +172,7 @@ public class PearsonsCorrelation {
}
}
}
return new DenseRealMatrix(out);
return new BlockRealMatrix(out);
}
@ -185,7 +185,7 @@ public class PearsonsCorrelation {
*/
public RealMatrix computeCorrelationMatrix(RealMatrix matrix) {
int nVars = matrix.getColumnDimension();
RealMatrix outMatrix = new DenseRealMatrix(nVars, nVars);
RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars);
for (int i = 0; i < nVars; i++) {
for (int j = 0; j < i; j++) {
double corr = correlation(matrix.getColumn(i), matrix.getColumn(j));
@ -206,7 +206,7 @@ public class PearsonsCorrelation {
* @return correlation matrix
*/
public RealMatrix computeCorrelationMatrix(double[][] data) {
return computeCorrelationMatrix(new DenseRealMatrix(data));
return computeCorrelationMatrix(new BlockRealMatrix(data));
}
/**
@ -249,7 +249,7 @@ public class PearsonsCorrelation {
*/
public RealMatrix covarianceToCorrelation(RealMatrix covarianceMatrix) {
int nVars = covarianceMatrix.getColumnDimension();
RealMatrix outMatrix = new DenseRealMatrix(nVars, nVars);
RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars);
for (int i = 0; i < nVars; i++) {
double sigma = Math.sqrt(covarianceMatrix.getEntry(i, i));
outMatrix.setEntry(i, i, 1d);

View File

@ -18,7 +18,7 @@
package org.apache.commons.math.stat.correlation;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.stat.ranking.NaturalRanking;
import org.apache.commons.math.stat.ranking.RankingAlgorithm;
@ -128,7 +128,7 @@ public class SpearmansCorrelation {
* @return correlation matrix
*/
public RealMatrix computeCorrelationMatrix(double[][] data) {
return computeCorrelationMatrix(new DenseRealMatrix(data));
return computeCorrelationMatrix(new BlockRealMatrix(data));
}
/**

View File

@ -83,6 +83,9 @@ The <action> type attribute can be add,update,fix,remove.
Added support for any type of field in linear algebra (FielxMatrix, FieldVector,
FieldLUDecomposition)
</action>
<action dev="luc" type="add" >
Added a block-based storage type for dense matrices improving speed for large dimensions
</action>
<action dev="psteitz" type="add" due-to="John Bollinger">
Added AggregateSummaryStatistics class to support aggregation of SummaryStatistics.
</action>

View File

@ -71,9 +71,12 @@ RealMatrix pInverse = new LUDecompositionImpl(p).getSolver().getInverse();
</source>
</p>
<p>
The two main implementations of the interface are <a
The three main implementations of the interface are <a
href="../apidocs/org/apache/commons/math/linear/RealMatrixImpl.html">
RealMatrixImpl</a> for dense matrices and <a
RealMatrixImpl</a> and <a
href="../apidocs/org/apache/commons/math/linear/BlockRealMatrix.html">
BlockRealMatrix</a> for dense matrices (the second one being more suited to
dimensions above 50 or 100) and <a
href="../apidocs/org/apache/commons/math/linear/SparseRealMatrix.html">
SparseRealMatrix</a> for sparse matrices.
</p>

View File

@ -28,7 +28,7 @@ import org.apache.commons.math.fraction.Fraction;
import org.apache.commons.math.fraction.FractionField;
/**
* Test cases for the {@link DenseFieldMatrix} class.
* Test cases for the {@link BlockFieldMatrix} class.
*
* @version $Revision$ $Date$
*/
@ -158,14 +158,14 @@ public final class DenseFieldMatrixTest extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite(DenseFieldMatrixTest.class);
suite.setName("DenseFieldMatrix<Fraction> Tests");
suite.setName("BlockFieldMatrix<Fraction> Tests");
return suite;
}
/** test dimensions */
public void testDimensions() {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
DenseFieldMatrix<Fraction> m2 = new DenseFieldMatrix<Fraction>(testData2);
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> m2 = new BlockFieldMatrix<Fraction>(testData2);
assertEquals("testData row dimension",3,m.getRowDimension());
assertEquals("testData column dimension",3,m.getColumnDimension());
assertTrue("testData is square",m.isSquare());
@ -177,18 +177,18 @@ public final class DenseFieldMatrixTest extends TestCase {
/** test copy functions */
public void testCopyFunctions() {
Random r = new Random(66636328996002l);
DenseFieldMatrix<Fraction> m1 = createRandomMatrix(r, 47, 83);
DenseFieldMatrix<Fraction> m2 = new DenseFieldMatrix<Fraction>(m1.getData());
BlockFieldMatrix<Fraction> m1 = createRandomMatrix(r, 47, 83);
BlockFieldMatrix<Fraction> m2 = new BlockFieldMatrix<Fraction>(m1.getData());
assertEquals(m1, m2);
DenseFieldMatrix<Fraction> m3 = new DenseFieldMatrix<Fraction>(testData);
DenseFieldMatrix<Fraction> m4 = new DenseFieldMatrix<Fraction>(m3.getData());
BlockFieldMatrix<Fraction> m3 = new BlockFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> m4 = new BlockFieldMatrix<Fraction>(m3.getData());
assertEquals(m3, m4);
}
/** test add */
public void testAdd() {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
DenseFieldMatrix<Fraction> mInv = new DenseFieldMatrix<Fraction>(testDataInv);
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> mInv = new BlockFieldMatrix<Fraction>(testDataInv);
FieldMatrix<Fraction> mPlusMInv = m.add(mInv);
Fraction[][] sumEntries = mPlusMInv.getData();
for (int row = 0; row < m.getRowDimension(); row++) {
@ -200,8 +200,8 @@ public final class DenseFieldMatrixTest extends TestCase {
/** test add failure */
public void testAddFail() {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
DenseFieldMatrix<Fraction> m2 = new DenseFieldMatrix<Fraction>(testData2);
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> m2 = new BlockFieldMatrix<Fraction>(testData2);
try {
m.add(m2);
fail("IllegalArgumentException expected");
@ -212,11 +212,11 @@ public final class DenseFieldMatrixTest extends TestCase {
/** test m-n = m + -n */
public void testPlusMinus() {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
DenseFieldMatrix<Fraction> m2 = new DenseFieldMatrix<Fraction>(testDataInv);
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> m2 = new BlockFieldMatrix<Fraction>(testDataInv);
TestUtils.assertEquals(m.subtract(m2), m2.scalarMultiply(new Fraction(-1)).add(m));
try {
m.subtract(new DenseFieldMatrix<Fraction>(testData2));
m.subtract(new BlockFieldMatrix<Fraction>(testData2));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
// ignored
@ -225,17 +225,17 @@ public final class DenseFieldMatrixTest extends TestCase {
/** test multiply */
public void testMultiply() {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
DenseFieldMatrix<Fraction> mInv = new DenseFieldMatrix<Fraction>(testDataInv);
DenseFieldMatrix<Fraction> identity = new DenseFieldMatrix<Fraction>(id);
DenseFieldMatrix<Fraction> m2 = new DenseFieldMatrix<Fraction>(testData2);
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> mInv = new BlockFieldMatrix<Fraction>(testDataInv);
BlockFieldMatrix<Fraction> identity = new BlockFieldMatrix<Fraction>(id);
BlockFieldMatrix<Fraction> m2 = new BlockFieldMatrix<Fraction>(testData2);
TestUtils.assertEquals(m.multiply(mInv), identity);
TestUtils.assertEquals(mInv.multiply(m), identity);
TestUtils.assertEquals(m.multiply(identity), m);
TestUtils.assertEquals(identity.multiply(mInv), mInv);
TestUtils.assertEquals(m2.multiply(identity), m2);
try {
m.multiply(new DenseFieldMatrix<Fraction>(bigSingular));
m.multiply(new BlockFieldMatrix<Fraction>(bigSingular));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
@ -245,7 +245,7 @@ public final class DenseFieldMatrixTest extends TestCase {
public void testSeveralBlocks() {
FieldMatrix<Fraction> m =
new DenseFieldMatrix<Fraction>(FractionField.getInstance(), 37, 41);
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), 37, 41);
for (int i = 0; i < m.getRowDimension(); ++i) {
for (int j = 0; j < m.getColumnDimension(); ++j) {
m.setEntry(i, j, new Fraction(i * 11 + j, 11));
@ -327,7 +327,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
//Additional Test for DenseFieldMatrix<Fraction>Test.testMultiply
//Additional Test for BlockFieldMatrix<Fraction>Test.testMultiply
private Fraction[][] d3 = new Fraction[][] {
{new Fraction(1),new Fraction(2),new Fraction(3),new Fraction(4)},
@ -342,17 +342,17 @@ public final class DenseFieldMatrixTest extends TestCase {
private Fraction[][] d5 = new Fraction[][] {{new Fraction(30)},{new Fraction(70)}};
public void testMultiply2() {
FieldMatrix<Fraction> m3 = new DenseFieldMatrix<Fraction>(d3);
FieldMatrix<Fraction> m4 = new DenseFieldMatrix<Fraction>(d4);
FieldMatrix<Fraction> m5 = new DenseFieldMatrix<Fraction>(d5);
FieldMatrix<Fraction> m3 = new BlockFieldMatrix<Fraction>(d3);
FieldMatrix<Fraction> m4 = new BlockFieldMatrix<Fraction>(d4);
FieldMatrix<Fraction> m5 = new BlockFieldMatrix<Fraction>(d5);
TestUtils.assertEquals(m3.multiply(m4), m5);
}
/** test trace */
public void testTrace() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(id);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(id);
assertEquals(new Fraction(3),m.getTrace());
m = new DenseFieldMatrix<Fraction>(testData2);
m = new BlockFieldMatrix<Fraction>(testData2);
try {
m.getTrace();
fail("Expecting NonSquareMatrixException");
@ -363,17 +363,17 @@ public final class DenseFieldMatrixTest extends TestCase {
/** test scalarAdd */
public void testScalarAdd() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
TestUtils.assertEquals(new DenseFieldMatrix<Fraction>(testDataPlus2),
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
TestUtils.assertEquals(new BlockFieldMatrix<Fraction>(testDataPlus2),
m.scalarAdd(new Fraction(2)));
}
/** test operate */
public void testOperate() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(id);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(id);
TestUtils.assertEquals(testVector, m.operate(testVector));
TestUtils.assertEquals(testVector, m.operate(new FieldVectorImpl<Fraction>(testVector)).getData());
m = new DenseFieldMatrix<Fraction>(bigSingular);
m = new BlockFieldMatrix<Fraction>(bigSingular);
try {
m.operate(testVector);
fail("Expecting illegalArgumentException");
@ -383,9 +383,9 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testOperateLarge() {
int p = (11 * DenseFieldMatrix.BLOCK_SIZE) / 10;
int q = (11 * DenseFieldMatrix.BLOCK_SIZE) / 10;
int r = DenseFieldMatrix.BLOCK_SIZE / 2;
int p = (11 * BlockFieldMatrix.BLOCK_SIZE) / 10;
int q = (11 * BlockFieldMatrix.BLOCK_SIZE) / 10;
int r = BlockFieldMatrix.BLOCK_SIZE / 2;
Random random = new Random(111007463902334l);
FieldMatrix<Fraction> m1 = createRandomMatrix(random, p, q);
FieldMatrix<Fraction> m2 = createRandomMatrix(random, q, r);
@ -396,9 +396,9 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testOperatePremultiplyLarge() {
int p = (11 * DenseFieldMatrix.BLOCK_SIZE) / 10;
int q = (11 * DenseFieldMatrix.BLOCK_SIZE) / 10;
int r = DenseFieldMatrix.BLOCK_SIZE / 2;
int p = (11 * BlockFieldMatrix.BLOCK_SIZE) / 10;
int q = (11 * BlockFieldMatrix.BLOCK_SIZE) / 10;
int r = BlockFieldMatrix.BLOCK_SIZE / 2;
Random random = new Random(111007463902334l);
FieldMatrix<Fraction> m1 = createRandomMatrix(random, p, q);
FieldMatrix<Fraction> m2 = createRandomMatrix(random, q, r);
@ -410,7 +410,7 @@ public final class DenseFieldMatrixTest extends TestCase {
/** test issue MATH-209 */
public void testMath209() {
FieldMatrix<Fraction> a = new DenseFieldMatrix<Fraction>(new Fraction[][] {
FieldMatrix<Fraction> a = new BlockFieldMatrix<Fraction>(new Fraction[][] {
{ new Fraction(1), new Fraction(2) },
{ new Fraction(3), new Fraction(4) },
{ new Fraction(5), new Fraction(6) }
@ -424,22 +424,22 @@ public final class DenseFieldMatrixTest extends TestCase {
/** test transpose */
public void testTranspose() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
FieldMatrix<Fraction> mIT = new FieldLUDecompositionImpl<Fraction>(m).getSolver().getInverse().transpose();
FieldMatrix<Fraction> mTI = new FieldLUDecompositionImpl<Fraction>(m.transpose()).getSolver().getInverse();
TestUtils.assertEquals(mIT, mTI);
m = new DenseFieldMatrix<Fraction>(testData2);
FieldMatrix<Fraction> mt = new DenseFieldMatrix<Fraction>(testData2T);
m = new BlockFieldMatrix<Fraction>(testData2);
FieldMatrix<Fraction> mt = new BlockFieldMatrix<Fraction>(testData2T);
TestUtils.assertEquals(mt, m.transpose());
}
/** test preMultiply by vector */
public void testPremultiplyVector() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
TestUtils.assertEquals(m.preMultiply(testVector), preMultTest);
TestUtils.assertEquals(m.preMultiply(new FieldVectorImpl<Fraction>(testVector).getData()),
preMultTest);
m = new DenseFieldMatrix<Fraction>(bigSingular);
m = new BlockFieldMatrix<Fraction>(bigSingular);
try {
m.preMultiply(testVector);
fail("expecting IllegalArgumentException");
@ -449,20 +449,20 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testPremultiply() {
FieldMatrix<Fraction> m3 = new DenseFieldMatrix<Fraction>(d3);
FieldMatrix<Fraction> m4 = new DenseFieldMatrix<Fraction>(d4);
FieldMatrix<Fraction> m5 = new DenseFieldMatrix<Fraction>(d5);
FieldMatrix<Fraction> m3 = new BlockFieldMatrix<Fraction>(d3);
FieldMatrix<Fraction> m4 = new BlockFieldMatrix<Fraction>(d4);
FieldMatrix<Fraction> m5 = new BlockFieldMatrix<Fraction>(d5);
TestUtils.assertEquals(m4.preMultiply(m3), m5);
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
DenseFieldMatrix<Fraction> mInv = new DenseFieldMatrix<Fraction>(testDataInv);
DenseFieldMatrix<Fraction> identity = new DenseFieldMatrix<Fraction>(id);
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> mInv = new BlockFieldMatrix<Fraction>(testDataInv);
BlockFieldMatrix<Fraction> identity = new BlockFieldMatrix<Fraction>(id);
TestUtils.assertEquals(m.preMultiply(mInv), identity);
TestUtils.assertEquals(mInv.preMultiply(m), identity);
TestUtils.assertEquals(m.preMultiply(identity), m);
TestUtils.assertEquals(identity.preMultiply(mInv), mInv);
try {
m.preMultiply(new DenseFieldMatrix<Fraction>(bigSingular));
m.preMultiply(new BlockFieldMatrix<Fraction>(bigSingular));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
// ignored
@ -470,7 +470,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetVectors() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
TestUtils.assertEquals(m.getRow(0), testDataRow1);
TestUtils.assertEquals(m.getColumn(2), testDataCol3);
try {
@ -488,7 +488,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetEntry() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
assertEquals(m.getEntry(0,1),new Fraction(2));
try {
m.getEntry(10, 4);
@ -505,14 +505,14 @@ public final class DenseFieldMatrixTest extends TestCase {
{new Fraction(1),new Fraction(2),new Fraction(3)},
{new Fraction(2),new Fraction(5),new Fraction(3)}
};
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(matrixData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(matrixData);
// One more with three rows, two columns
Fraction[][] matrixData2 = {
{new Fraction(1),new Fraction(2)},
{new Fraction(2),new Fraction(5)},
{new Fraction(1), new Fraction(7)}
};
FieldMatrix<Fraction> n = new DenseFieldMatrix<Fraction>(matrixData2);
FieldMatrix<Fraction> n = new BlockFieldMatrix<Fraction>(matrixData2);
// Now multiply m by n
FieldMatrix<Fraction> p = m.multiply(n);
assertEquals(2, p.getRowDimension());
@ -528,7 +528,7 @@ public final class DenseFieldMatrixTest extends TestCase {
{new Fraction(-1), new Fraction(7), new Fraction(6)},
{new Fraction(4), new Fraction(-3), new Fraction(-5)}
};
FieldMatrix<Fraction> coefficients = new DenseFieldMatrix<Fraction>(coefficientsData);
FieldMatrix<Fraction> coefficients = new BlockFieldMatrix<Fraction>(coefficientsData);
Fraction[] constants = {new Fraction(1), new Fraction(-2), new Fraction(1)};
Fraction[] solution = new FieldLUDecompositionImpl<Fraction>(coefficients).getSolver().solve(constants);
assertEquals(new Fraction(2).multiply(solution[0]).
@ -548,7 +548,7 @@ public final class DenseFieldMatrixTest extends TestCase {
// test submatrix accessors
public void testGetSubMatrix() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false);
checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false);
checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false);
@ -571,7 +571,7 @@ public final class DenseFieldMatrixTest extends TestCase {
boolean mustFail) {
try {
FieldMatrix<Fraction> sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
assertEquals(new DenseFieldMatrix<Fraction>(reference), sub);
assertEquals(new BlockFieldMatrix<Fraction>(reference), sub);
if (mustFail) {
fail("Expecting MatrixIndexException");
}
@ -587,7 +587,7 @@ public final class DenseFieldMatrixTest extends TestCase {
boolean mustFail) {
try {
FieldMatrix<Fraction> sub = m.getSubMatrix(selectedRows, selectedColumns);
assertEquals(new DenseFieldMatrix<Fraction>(reference), sub);
assertEquals(new BlockFieldMatrix<Fraction>(reference), sub);
if (mustFail) {
fail("Expecting MatrixIndexException");
}
@ -599,11 +599,11 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetSetMatrixLarge() {
int n = 3 * DenseFieldMatrix.BLOCK_SIZE;
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m =
new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
FieldMatrix<Fraction> sub =
new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n - 4, n - 4).scalarAdd(new Fraction(1));
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n - 4, n - 4).scalarAdd(new Fraction(1));
m.setSubMatrix(sub.getData(), 2, 2);
for (int i = 0; i < n; ++i) {
@ -620,7 +620,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testCopySubMatrix() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false);
checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false);
checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false);
@ -647,7 +647,7 @@ public final class DenseFieldMatrixTest extends TestCase {
new Fraction[1][1] :
new Fraction[reference.length][reference[0].length];
m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
assertEquals(new DenseFieldMatrix<Fraction>(reference), new DenseFieldMatrix<Fraction>(sub));
assertEquals(new BlockFieldMatrix<Fraction>(reference), new BlockFieldMatrix<Fraction>(sub));
if (mustFail) {
fail("Expecting MatrixIndexException");
}
@ -666,7 +666,7 @@ public final class DenseFieldMatrixTest extends TestCase {
new Fraction[1][1] :
new Fraction[reference.length][reference[0].length];
m.copySubMatrix(selectedRows, selectedColumns, sub);
assertEquals(new DenseFieldMatrix<Fraction>(reference), new DenseFieldMatrix<Fraction>(sub));
assertEquals(new BlockFieldMatrix<Fraction>(reference), new BlockFieldMatrix<Fraction>(sub));
if (mustFail) {
fail("Expecting MatrixIndexException");
}
@ -678,9 +678,9 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetRowMatrix() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> mRow0 = new DenseFieldMatrix<Fraction>(subRow0);
FieldMatrix<Fraction> mRow3 = new DenseFieldMatrix<Fraction>(subRow3);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> mRow0 = new BlockFieldMatrix<Fraction>(subRow0);
FieldMatrix<Fraction> mRow3 = new BlockFieldMatrix<Fraction>(subRow3);
assertEquals("Row0", mRow0, m.getRowMatrix(0));
assertEquals("Row3", mRow3, m.getRowMatrix(3));
try {
@ -698,8 +698,8 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testSetRowMatrix() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> mRow3 = new DenseFieldMatrix<Fraction>(subRow3);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> mRow3 = new BlockFieldMatrix<Fraction>(subRow3);
assertNotSame(mRow3, m.getRowMatrix(0));
m.setRowMatrix(0, mRow3);
assertEquals(mRow3, m.getRowMatrix(0));
@ -718,11 +718,11 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetSetRowMatrixLarge() {
int n = 3 * DenseFieldMatrix.BLOCK_SIZE;
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m =
new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
FieldMatrix<Fraction> sub =
new DenseFieldMatrix<Fraction>(FractionField.getInstance(), 1, n).scalarAdd(new Fraction(1));
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), 1, n).scalarAdd(new Fraction(1));
m.setRowMatrix(2, sub);
for (int i = 0; i < n; ++i) {
@ -739,9 +739,9 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetColumnMatrix() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> mColumn1 = new DenseFieldMatrix<Fraction>(subColumn1);
FieldMatrix<Fraction> mColumn3 = new DenseFieldMatrix<Fraction>(subColumn3);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> mColumn1 = new BlockFieldMatrix<Fraction>(subColumn1);
FieldMatrix<Fraction> mColumn3 = new BlockFieldMatrix<Fraction>(subColumn3);
assertEquals(mColumn1, m.getColumnMatrix(1));
assertEquals(mColumn3, m.getColumnMatrix(3));
try {
@ -759,8 +759,8 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testSetColumnMatrix() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> mColumn3 = new DenseFieldMatrix<Fraction>(subColumn3);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> mColumn3 = new BlockFieldMatrix<Fraction>(subColumn3);
assertNotSame(mColumn3, m.getColumnMatrix(1));
m.setColumnMatrix(1, mColumn3);
assertEquals(mColumn3, m.getColumnMatrix(1));
@ -779,11 +779,11 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetSetColumnMatrixLarge() {
int n = 3 * DenseFieldMatrix.BLOCK_SIZE;
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m =
new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
FieldMatrix<Fraction> sub =
new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n, 1).scalarAdd(new Fraction(1));
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n, 1).scalarAdd(new Fraction(1));
m.setColumnMatrix(2, sub);
for (int i = 0; i < n; ++i) {
@ -800,7 +800,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetRowVector() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
FieldVector<Fraction> mRow0 = new FieldVectorImpl<Fraction>(subRow0[0]);
FieldVector<Fraction> mRow3 = new FieldVectorImpl<Fraction>(subRow3[0]);
assertEquals(mRow0, m.getRowVector(0));
@ -820,7 +820,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testSetRowVector() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
FieldVector<Fraction> mRow3 = new FieldVectorImpl<Fraction>(subRow3[0]);
assertNotSame(mRow3, m.getRowMatrix(0));
m.setRowVector(0, mRow3);
@ -840,8 +840,8 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetSetRowVectorLarge() {
int n = 3 * DenseFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
FieldVector<Fraction> sub = new FieldVectorImpl<Fraction>(n, new Fraction(1));
m.setRowVector(2, sub);
@ -859,7 +859,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetColumnVector() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
FieldVector<Fraction> mColumn1 = columnToVector(subColumn1);
FieldVector<Fraction> mColumn3 = columnToVector(subColumn3);
assertEquals(mColumn1, m.getColumnVector(1));
@ -879,7 +879,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testSetColumnVector() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
FieldVector<Fraction> mColumn3 = columnToVector(subColumn3);
assertNotSame(mColumn3, m.getColumnVector(1));
m.setColumnVector(1, mColumn3);
@ -899,8 +899,8 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetSetColumnVectorLarge() {
int n = 3 * DenseFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
FieldVector<Fraction> sub = new FieldVectorImpl<Fraction>(n, new Fraction(1));
m.setColumnVector(2, sub);
@ -926,7 +926,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetRow() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
checkArrays(subRow0[0], m.getRow(0));
checkArrays(subRow3[0], m.getRow(3));
try {
@ -944,7 +944,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testSetRow() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
assertTrue(subRow3[0][0] != m.getRow(0)[0]);
m.setRow(0, subRow3[0]);
checkArrays(subRow3[0], m.getRow(0));
@ -963,8 +963,8 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetSetRowLarge() {
int n = 3 * DenseFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
Fraction[] sub = new Fraction[n];
Arrays.fill(sub, new Fraction(1));
@ -983,7 +983,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetColumn() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
Fraction[] mColumn1 = columnToArray(subColumn1);
Fraction[] mColumn3 = columnToArray(subColumn3);
checkArrays(mColumn1, m.getColumn(1));
@ -1003,7 +1003,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testSetColumn() {
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(subTestData);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(subTestData);
Fraction[] mColumn3 = columnToArray(subColumn3);
assertTrue(mColumn3[0] != m.getColumn(1)[0]);
m.setColumn(1, mColumn3);
@ -1023,8 +1023,8 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testGetSetColumnLarge() {
int n = 3 * DenseFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), n, n);
Fraction[] sub = new Fraction[n];
Arrays.fill(sub, new Fraction(1));
@ -1058,43 +1058,43 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testEqualsAndHashCode() {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
DenseFieldMatrix<Fraction> m1 = (DenseFieldMatrix<Fraction>) m.copy();
DenseFieldMatrix<Fraction> mt = (DenseFieldMatrix<Fraction>) m.transpose();
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> m1 = (BlockFieldMatrix<Fraction>) m.copy();
BlockFieldMatrix<Fraction> mt = (BlockFieldMatrix<Fraction>) m.transpose();
assertTrue(m.hashCode() != mt.hashCode());
assertEquals(m.hashCode(), m1.hashCode());
assertEquals(m, m);
assertEquals(m, m1);
assertFalse(m.equals(null));
assertFalse(m.equals(mt));
assertFalse(m.equals(new DenseFieldMatrix<Fraction>(bigSingular)));
assertFalse(m.equals(new BlockFieldMatrix<Fraction>(bigSingular)));
}
public void testToString() {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
assertEquals("DenseFieldMatrix{{1,2,3},{2,5,3},{1,0,8}}", m.toString());
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
assertEquals("BlockFieldMatrix{{1,2,3},{2,5,3},{1,0,8}}", m.toString());
}
public void testSetSubMatrix() throws Exception {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
m.setSubMatrix(detData2,1,1);
FieldMatrix<Fraction> expected = new DenseFieldMatrix<Fraction>
FieldMatrix<Fraction> expected = new BlockFieldMatrix<Fraction>
(new Fraction[][] {{new Fraction(1),new Fraction(2),new Fraction(3)},{new Fraction(2),new Fraction(1),new Fraction(3)},{new Fraction(1),new Fraction(2),new Fraction(4)}});
assertEquals(expected, m);
m.setSubMatrix(detData2,0,0);
expected = new DenseFieldMatrix<Fraction>
expected = new BlockFieldMatrix<Fraction>
(new Fraction[][] {{new Fraction(1),new Fraction(3),new Fraction(3)},{new Fraction(2),new Fraction(4),new Fraction(3)},{new Fraction(1),new Fraction(2),new Fraction(4)}});
assertEquals(expected, m);
m.setSubMatrix(testDataPlus2,0,0);
expected = new DenseFieldMatrix<Fraction>
expected = new BlockFieldMatrix<Fraction>
(new Fraction[][] {{new Fraction(3),new Fraction(4),new Fraction(5)},{new Fraction(4),new Fraction(7),new Fraction(5)},{new Fraction(3),new Fraction(2),new Fraction(10)}});
assertEquals(expected, m);
// javadoc example
DenseFieldMatrix<Fraction> matrix =
new DenseFieldMatrix<Fraction>(new Fraction[][] {
BlockFieldMatrix<Fraction> matrix =
new BlockFieldMatrix<Fraction>(new Fraction[][] {
{new Fraction(1), new Fraction(2), new Fraction(3), new Fraction(4)},
{new Fraction(5), new Fraction(6), new Fraction(7), new Fraction(8)},
{new Fraction(9), new Fraction(0), new Fraction(1) , new Fraction(2)}
@ -1104,7 +1104,7 @@ public final class DenseFieldMatrixTest extends TestCase {
{new Fraction(5), new Fraction(6)}
}, 1, 1);
expected =
new DenseFieldMatrix<Fraction>(new Fraction[][] {
new BlockFieldMatrix<Fraction>(new Fraction[][] {
{new Fraction(1), new Fraction(2), new Fraction(3),new Fraction(4)},
{new Fraction(5), new Fraction(3), new Fraction(4), new Fraction(8)},
{new Fraction(9), new Fraction(5) ,new Fraction(6), new Fraction(2)}
@ -1162,13 +1162,13 @@ public final class DenseFieldMatrixTest extends TestCase {
int rows = 150;
int columns = 75;
FieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
FieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m.walkInRowOrder(new SetVisitor());
GetVisitor getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor);
assertEquals(rows * columns, getVisitor.getCount());
m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m.walkInRowOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
@ -1182,13 +1182,13 @@ public final class DenseFieldMatrixTest extends TestCase {
assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
}
m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m.walkInColumnOrder(new SetVisitor());
getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor);
assertEquals(rows * columns, getVisitor.getCount());
m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m.walkInColumnOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
@ -1202,13 +1202,13 @@ public final class DenseFieldMatrixTest extends TestCase {
assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
}
m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m.walkInOptimizedOrder(new SetVisitor());
getVisitor = new GetVisitor();
m.walkInRowOrder(getVisitor);
assertEquals(rows * columns, getVisitor.getCount());
m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
getVisitor = new GetVisitor();
m.walkInRowOrder(getVisitor, 1, rows - 2, 1, columns - 2);
@ -1222,13 +1222,13 @@ public final class DenseFieldMatrixTest extends TestCase {
assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
}
m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m.walkInOptimizedOrder(new SetVisitor());
getVisitor = new GetVisitor();
m.walkInColumnOrder(getVisitor);
assertEquals(rows * columns, getVisitor.getCount());
m = new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m = new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
getVisitor = new GetVisitor();
m.walkInColumnOrder(getVisitor, 1, rows - 2, 1, columns - 2);
@ -1245,7 +1245,7 @@ public final class DenseFieldMatrixTest extends TestCase {
}
public void testSerial() {
DenseFieldMatrix<Fraction> m = new DenseFieldMatrix<Fraction>(testData);
BlockFieldMatrix<Fraction> m = new BlockFieldMatrix<Fraction>(testData);
assertEquals(m,TestUtils.serializeAndRecover(m));
}
@ -1275,9 +1275,9 @@ public final class DenseFieldMatrixTest extends TestCase {
}
}
private DenseFieldMatrix<Fraction> createRandomMatrix(Random r, int rows, int columns) {
DenseFieldMatrix<Fraction> m =
new DenseFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
private BlockFieldMatrix<Fraction> createRandomMatrix(Random r, int rows, int columns) {
BlockFieldMatrix<Fraction> m =
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), rows, columns);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
int p = r.nextInt(20) - 10;

View File

@ -26,7 +26,7 @@ import junit.framework.TestSuite;
import org.apache.commons.math.TestUtils;
/**
* Test cases for the {@link DenseRealMatrix} class.
* Test cases for the {@link BlockRealMatrix} class.
*
* @version $Revision$ $Date$
*/
@ -99,14 +99,14 @@ public final class DenseRealMatrixTest extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite(DenseRealMatrixTest.class);
suite.setName("DenseRealMatrix Tests");
suite.setName("BlockRealMatrix Tests");
return suite;
}
/** test dimensions */
public void testDimensions() {
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix m2 = new DenseRealMatrix(testData2);
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(testData2);
assertEquals("testData row dimension",3,m.getRowDimension());
assertEquals("testData column dimension",3,m.getColumnDimension());
assertTrue("testData is square",m.isSquare());
@ -118,18 +118,18 @@ public final class DenseRealMatrixTest extends TestCase {
/** test copy functions */
public void testCopyFunctions() {
Random r = new Random(66636328996002l);
DenseRealMatrix m1 = createRandomMatrix(r, 47, 83);
DenseRealMatrix m2 = new DenseRealMatrix(m1.getData());
BlockRealMatrix m1 = createRandomMatrix(r, 47, 83);
BlockRealMatrix m2 = new BlockRealMatrix(m1.getData());
assertEquals(m1, m2);
DenseRealMatrix m3 = new DenseRealMatrix(testData);
DenseRealMatrix m4 = new DenseRealMatrix(m3.getData());
BlockRealMatrix m3 = new BlockRealMatrix(testData);
BlockRealMatrix m4 = new BlockRealMatrix(m3.getData());
assertEquals(m3, m4);
}
/** test add */
public void testAdd() {
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix mInv = new DenseRealMatrix(testDataInv);
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix mInv = new BlockRealMatrix(testDataInv);
RealMatrix mPlusMInv = m.add(mInv);
double[][] sumEntries = mPlusMInv.getData();
for (int row = 0; row < m.getRowDimension(); row++) {
@ -143,8 +143,8 @@ public final class DenseRealMatrixTest extends TestCase {
/** test add failure */
public void testAddFail() {
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix m2 = new DenseRealMatrix(testData2);
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(testData2);
try {
m.add(m2);
fail("IllegalArgumentException expected");
@ -155,27 +155,27 @@ public final class DenseRealMatrixTest extends TestCase {
/** test norm */
public void testNorm() {
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix m2 = new DenseRealMatrix(testData2);
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(testData2);
assertEquals("testData norm",14d,m.getNorm(),entryTolerance);
assertEquals("testData2 norm",7d,m2.getNorm(),entryTolerance);
}
/** test Frobenius norm */
public void testFrobeniusNorm() {
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix m2 = new DenseRealMatrix(testData2);
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(testData2);
assertEquals("testData Frobenius norm", Math.sqrt(117.0), m.getFrobeniusNorm(), entryTolerance);
assertEquals("testData2 Frobenius norm", Math.sqrt(52.0), m2.getFrobeniusNorm(), entryTolerance);
}
/** test m-n = m + -n */
public void testPlusMinus() {
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix m2 = new DenseRealMatrix(testDataInv);
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(testDataInv);
assertClose(m.subtract(m2), m2.scalarMultiply(-1d).add(m), entryTolerance);
try {
m.subtract(new DenseRealMatrix(testData2));
m.subtract(new BlockRealMatrix(testData2));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
// ignored
@ -184,17 +184,17 @@ public final class DenseRealMatrixTest extends TestCase {
/** test multiply */
public void testMultiply() {
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix mInv = new DenseRealMatrix(testDataInv);
DenseRealMatrix identity = new DenseRealMatrix(id);
DenseRealMatrix m2 = new DenseRealMatrix(testData2);
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix mInv = new BlockRealMatrix(testDataInv);
BlockRealMatrix identity = new BlockRealMatrix(id);
BlockRealMatrix m2 = new BlockRealMatrix(testData2);
assertClose(m.multiply(mInv), identity, entryTolerance);
assertClose(mInv.multiply(m), identity, entryTolerance);
assertClose(m.multiply(identity), m, entryTolerance);
assertClose(identity.multiply(mInv), mInv, entryTolerance);
assertClose(m2.multiply(identity), m2, entryTolerance);
try {
m.multiply(new DenseRealMatrix(bigSingular));
m.multiply(new BlockRealMatrix(bigSingular));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
@ -203,7 +203,7 @@ public final class DenseRealMatrixTest extends TestCase {
public void testSeveralBlocks() {
RealMatrix m = new DenseRealMatrix(35, 71);
RealMatrix m = new BlockRealMatrix(35, 71);
for (int i = 0; i < m.getRowDimension(); ++i) {
for (int j = 0; j < m.getColumnDimension(); ++j) {
m.setEntry(i, j, i + j / 1024.0);
@ -292,17 +292,17 @@ public final class DenseRealMatrixTest extends TestCase {
private double[][] d5 = new double[][] {{30},{70}};
public void testMultiply2() {
RealMatrix m3 = new DenseRealMatrix(d3);
RealMatrix m4 = new DenseRealMatrix(d4);
RealMatrix m5 = new DenseRealMatrix(d5);
RealMatrix m3 = new BlockRealMatrix(d3);
RealMatrix m4 = new BlockRealMatrix(d4);
RealMatrix m5 = new BlockRealMatrix(d5);
assertClose(m3.multiply(m4), m5, entryTolerance);
}
/** test trace */
public void testTrace() {
RealMatrix m = new DenseRealMatrix(id);
RealMatrix m = new BlockRealMatrix(id);
assertEquals("identity trace",3d,m.getTrace(),entryTolerance);
m = new DenseRealMatrix(testData2);
m = new BlockRealMatrix(testData2);
try {
m.getTrace();
fail("Expecting NonSquareMatrixException");
@ -313,16 +313,16 @@ public final class DenseRealMatrixTest extends TestCase {
/** test scalarAdd */
public void testScalarAdd() {
RealMatrix m = new DenseRealMatrix(testData);
assertClose(new DenseRealMatrix(testDataPlus2), m.scalarAdd(2d), entryTolerance);
RealMatrix m = new BlockRealMatrix(testData);
assertClose(new BlockRealMatrix(testDataPlus2), m.scalarAdd(2d), entryTolerance);
}
/** test operate */
public void testOperate() {
RealMatrix m = new DenseRealMatrix(id);
RealMatrix m = new BlockRealMatrix(id);
assertClose(testVector, m.operate(testVector), entryTolerance);
assertClose(testVector, m.operate(new RealVectorImpl(testVector)).getData(), entryTolerance);
m = new DenseRealMatrix(bigSingular);
m = new BlockRealMatrix(bigSingular);
try {
m.operate(testVector);
fail("Expecting illegalArgumentException");
@ -332,9 +332,9 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testOperateLarge() {
int p = (7 * DenseRealMatrix.BLOCK_SIZE) / 2;
int q = (5 * DenseRealMatrix.BLOCK_SIZE) / 2;
int r = 3 * DenseRealMatrix.BLOCK_SIZE;
int p = (7 * BlockRealMatrix.BLOCK_SIZE) / 2;
int q = (5 * BlockRealMatrix.BLOCK_SIZE) / 2;
int r = 3 * BlockRealMatrix.BLOCK_SIZE;
Random random = new Random(111007463902334l);
RealMatrix m1 = createRandomMatrix(random, p, q);
RealMatrix m2 = createRandomMatrix(random, q, r);
@ -345,9 +345,9 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testOperatePremultiplyLarge() {
int p = (7 * DenseRealMatrix.BLOCK_SIZE) / 2;
int q = (5 * DenseRealMatrix.BLOCK_SIZE) / 2;
int r = 3 * DenseRealMatrix.BLOCK_SIZE;
int p = (7 * BlockRealMatrix.BLOCK_SIZE) / 2;
int q = (5 * BlockRealMatrix.BLOCK_SIZE) / 2;
int r = 3 * BlockRealMatrix.BLOCK_SIZE;
Random random = new Random(111007463902334l);
RealMatrix m1 = createRandomMatrix(random, p, q);
RealMatrix m2 = createRandomMatrix(random, q, r);
@ -359,7 +359,7 @@ public final class DenseRealMatrixTest extends TestCase {
/** test issue MATH-209 */
public void testMath209() {
RealMatrix a = new DenseRealMatrix(new double[][] {
RealMatrix a = new BlockRealMatrix(new double[][] {
{ 1, 2 }, { 3, 4 }, { 5, 6 }
});
double[] b = a.operate(new double[] { 1, 1 });
@ -371,22 +371,22 @@ public final class DenseRealMatrixTest extends TestCase {
/** test transpose */
public void testTranspose() {
RealMatrix m = new DenseRealMatrix(testData);
RealMatrix m = new BlockRealMatrix(testData);
RealMatrix mIT = new LUDecompositionImpl(m).getSolver().getInverse().transpose();
RealMatrix mTI = new LUDecompositionImpl(m.transpose()).getSolver().getInverse();
assertClose(mIT, mTI, normTolerance);
m = new DenseRealMatrix(testData2);
RealMatrix mt = new DenseRealMatrix(testData2T);
m = new BlockRealMatrix(testData2);
RealMatrix mt = new BlockRealMatrix(testData2T);
assertClose(mt, m.transpose(), normTolerance);
}
/** test preMultiply by vector */
public void testPremultiplyVector() {
RealMatrix m = new DenseRealMatrix(testData);
RealMatrix m = new BlockRealMatrix(testData);
assertClose(m.preMultiply(testVector), preMultTest, normTolerance);
assertClose(m.preMultiply(new RealVectorImpl(testVector).getData()),
preMultTest, normTolerance);
m = new DenseRealMatrix(bigSingular);
m = new BlockRealMatrix(bigSingular);
try {
m.preMultiply(testVector);
fail("expecting IllegalArgumentException");
@ -396,20 +396,20 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testPremultiply() {
RealMatrix m3 = new DenseRealMatrix(d3);
RealMatrix m4 = new DenseRealMatrix(d4);
RealMatrix m5 = new DenseRealMatrix(d5);
RealMatrix m3 = new BlockRealMatrix(d3);
RealMatrix m4 = new BlockRealMatrix(d4);
RealMatrix m5 = new BlockRealMatrix(d5);
assertClose(m4.preMultiply(m3), m5, entryTolerance);
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix mInv = new DenseRealMatrix(testDataInv);
DenseRealMatrix identity = new DenseRealMatrix(id);
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix mInv = new BlockRealMatrix(testDataInv);
BlockRealMatrix identity = new BlockRealMatrix(id);
assertClose(m.preMultiply(mInv), identity, entryTolerance);
assertClose(mInv.preMultiply(m), identity, entryTolerance);
assertClose(m.preMultiply(identity), m, entryTolerance);
assertClose(identity.preMultiply(mInv), mInv, entryTolerance);
try {
m.preMultiply(new DenseRealMatrix(bigSingular));
m.preMultiply(new BlockRealMatrix(bigSingular));
fail("Expecting illegalArgumentException");
} catch (IllegalArgumentException ex) {
// ignored
@ -417,7 +417,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetVectors() {
RealMatrix m = new DenseRealMatrix(testData);
RealMatrix m = new BlockRealMatrix(testData);
assertClose(m.getRow(0), testDataRow1, entryTolerance);
assertClose(m.getColumn(2), testDataCol3, entryTolerance);
try {
@ -435,7 +435,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetEntry() {
RealMatrix m = new DenseRealMatrix(testData);
RealMatrix m = new BlockRealMatrix(testData);
assertEquals("get entry",m.getEntry(0,1),2d,entryTolerance);
try {
m.getEntry(10, 4);
@ -449,10 +449,10 @@ public final class DenseRealMatrixTest extends TestCase {
public void testExamples() {
// Create a real matrix with two rows and three columns
double[][] matrixData = { {1d,2d,3d}, {2d,5d,3d}};
RealMatrix m = new DenseRealMatrix(matrixData);
RealMatrix m = new BlockRealMatrix(matrixData);
// One more with three rows, two columns
double[][] matrixData2 = { {1d,2d}, {2d,5d}, {1d, 7d}};
RealMatrix n = new DenseRealMatrix(matrixData2);
RealMatrix n = new BlockRealMatrix(matrixData2);
// Now multiply m by n
RealMatrix p = m.multiply(n);
assertEquals(2, p.getRowDimension());
@ -464,7 +464,7 @@ public final class DenseRealMatrixTest extends TestCase {
// Solve example
double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
RealMatrix coefficients = new DenseRealMatrix(coefficientsData);
RealMatrix coefficients = new BlockRealMatrix(coefficientsData);
double[] constants = {1, -2, 1};
double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0], 1E-12);
@ -475,7 +475,7 @@ public final class DenseRealMatrixTest extends TestCase {
// test submatrix accessors
public void testGetSubMatrix() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false);
checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false);
checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false);
@ -498,7 +498,7 @@ public final class DenseRealMatrixTest extends TestCase {
boolean mustFail) {
try {
RealMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
assertEquals(new DenseRealMatrix(reference), sub);
assertEquals(new BlockRealMatrix(reference), sub);
if (mustFail) {
fail("Expecting MatrixIndexException");
}
@ -514,7 +514,7 @@ public final class DenseRealMatrixTest extends TestCase {
boolean mustFail) {
try {
RealMatrix sub = m.getSubMatrix(selectedRows, selectedColumns);
assertEquals(new DenseRealMatrix(reference), sub);
assertEquals(new BlockRealMatrix(reference), sub);
if (mustFail) {
fail("Expecting MatrixIndexException");
}
@ -526,9 +526,9 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetSetMatrixLarge() {
int n = 3 * DenseRealMatrix.BLOCK_SIZE;
RealMatrix m = new DenseRealMatrix(n, n);
RealMatrix sub = new DenseRealMatrix(n - 4, n - 4).scalarAdd(1);
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
RealMatrix sub = new BlockRealMatrix(n - 4, n - 4).scalarAdd(1);
m.setSubMatrix(sub.getData(), 2, 2);
for (int i = 0; i < n; ++i) {
@ -545,7 +545,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testCopySubMatrix() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false);
checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false);
checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false);
@ -572,7 +572,7 @@ public final class DenseRealMatrixTest extends TestCase {
new double[1][1] :
new double[reference.length][reference[0].length];
m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
assertEquals(new DenseRealMatrix(reference), new DenseRealMatrix(sub));
assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
if (mustFail) {
fail("Expecting MatrixIndexException");
}
@ -591,7 +591,7 @@ public final class DenseRealMatrixTest extends TestCase {
new double[1][1] :
new double[reference.length][reference[0].length];
m.copySubMatrix(selectedRows, selectedColumns, sub);
assertEquals(new DenseRealMatrix(reference), new DenseRealMatrix(sub));
assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
if (mustFail) {
fail("Expecting MatrixIndexException");
}
@ -603,9 +603,9 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetRowMatrix() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix mRow0 = new DenseRealMatrix(subRow0);
RealMatrix mRow3 = new DenseRealMatrix(subRow3);
RealMatrix m = new BlockRealMatrix(subTestData);
RealMatrix mRow0 = new BlockRealMatrix(subRow0);
RealMatrix mRow3 = new BlockRealMatrix(subRow3);
assertEquals("Row0", mRow0, m.getRowMatrix(0));
assertEquals("Row3", mRow3, m.getRowMatrix(3));
try {
@ -623,8 +623,8 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testSetRowMatrix() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix mRow3 = new DenseRealMatrix(subRow3);
RealMatrix m = new BlockRealMatrix(subTestData);
RealMatrix mRow3 = new BlockRealMatrix(subRow3);
assertNotSame(mRow3, m.getRowMatrix(0));
m.setRowMatrix(0, mRow3);
assertEquals(mRow3, m.getRowMatrix(0));
@ -643,9 +643,9 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetSetRowMatrixLarge() {
int n = 3 * DenseRealMatrix.BLOCK_SIZE;
RealMatrix m = new DenseRealMatrix(n, n);
RealMatrix sub = new DenseRealMatrix(1, n).scalarAdd(1);
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
RealMatrix sub = new BlockRealMatrix(1, n).scalarAdd(1);
m.setRowMatrix(2, sub);
for (int i = 0; i < n; ++i) {
@ -662,9 +662,9 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetColumnMatrix() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix mColumn1 = new DenseRealMatrix(subColumn1);
RealMatrix mColumn3 = new DenseRealMatrix(subColumn3);
RealMatrix m = new BlockRealMatrix(subTestData);
RealMatrix mColumn1 = new BlockRealMatrix(subColumn1);
RealMatrix mColumn3 = new BlockRealMatrix(subColumn3);
assertEquals(mColumn1, m.getColumnMatrix(1));
assertEquals(mColumn3, m.getColumnMatrix(3));
try {
@ -682,8 +682,8 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testSetColumnMatrix() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix mColumn3 = new DenseRealMatrix(subColumn3);
RealMatrix m = new BlockRealMatrix(subTestData);
RealMatrix mColumn3 = new BlockRealMatrix(subColumn3);
assertNotSame(mColumn3, m.getColumnMatrix(1));
m.setColumnMatrix(1, mColumn3);
assertEquals(mColumn3, m.getColumnMatrix(1));
@ -702,9 +702,9 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetSetColumnMatrixLarge() {
int n = 3 * DenseRealMatrix.BLOCK_SIZE;
RealMatrix m = new DenseRealMatrix(n, n);
RealMatrix sub = new DenseRealMatrix(n, 1).scalarAdd(1);
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
RealMatrix sub = new BlockRealMatrix(n, 1).scalarAdd(1);
m.setColumnMatrix(2, sub);
for (int i = 0; i < n; ++i) {
@ -721,7 +721,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetRowVector() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
RealVector mRow0 = new RealVectorImpl(subRow0[0]);
RealVector mRow3 = new RealVectorImpl(subRow3[0]);
assertEquals(mRow0, m.getRowVector(0));
@ -741,7 +741,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testSetRowVector() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
RealVector mRow3 = new RealVectorImpl(subRow3[0]);
assertNotSame(mRow3, m.getRowMatrix(0));
m.setRowVector(0, mRow3);
@ -761,8 +761,8 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetSetRowVectorLarge() {
int n = 3 * DenseRealMatrix.BLOCK_SIZE;
RealMatrix m = new DenseRealMatrix(n, n);
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
RealVector sub = new RealVectorImpl(n, 1.0);
m.setRowVector(2, sub);
@ -780,7 +780,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetColumnVector() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
RealVector mColumn1 = columnToVector(subColumn1);
RealVector mColumn3 = columnToVector(subColumn3);
assertEquals(mColumn1, m.getColumnVector(1));
@ -800,7 +800,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testSetColumnVector() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
RealVector mColumn3 = columnToVector(subColumn3);
assertNotSame(mColumn3, m.getColumnVector(1));
m.setColumnVector(1, mColumn3);
@ -820,8 +820,8 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetSetColumnVectorLarge() {
int n = 3 * DenseRealMatrix.BLOCK_SIZE;
RealMatrix m = new DenseRealMatrix(n, n);
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
RealVector sub = new RealVectorImpl(n, 1.0);
m.setColumnVector(2, sub);
@ -847,7 +847,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetRow() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
checkArrays(subRow0[0], m.getRow(0));
checkArrays(subRow3[0], m.getRow(3));
try {
@ -865,7 +865,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testSetRow() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
assertTrue(subRow3[0][0] != m.getRow(0)[0]);
m.setRow(0, subRow3[0]);
checkArrays(subRow3[0], m.getRow(0));
@ -884,8 +884,8 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetSetRowLarge() {
int n = 3 * DenseRealMatrix.BLOCK_SIZE;
RealMatrix m = new DenseRealMatrix(n, n);
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
double[] sub = new double[n];
Arrays.fill(sub, 1.0);
@ -904,7 +904,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetColumn() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
double[] mColumn1 = columnToArray(subColumn1);
double[] mColumn3 = columnToArray(subColumn3);
checkArrays(mColumn1, m.getColumn(1));
@ -924,7 +924,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testSetColumn() {
RealMatrix m = new DenseRealMatrix(subTestData);
RealMatrix m = new BlockRealMatrix(subTestData);
double[] mColumn3 = columnToArray(subColumn3);
assertTrue(mColumn3[0] != m.getColumn(1)[0]);
m.setColumn(1, mColumn3);
@ -944,8 +944,8 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testGetSetColumnLarge() {
int n = 3 * DenseRealMatrix.BLOCK_SIZE;
RealMatrix m = new DenseRealMatrix(n, n);
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
double[] sub = new double[n];
Arrays.fill(sub, 1.0);
@ -979,46 +979,46 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testEqualsAndHashCode() {
DenseRealMatrix m = new DenseRealMatrix(testData);
DenseRealMatrix m1 = (DenseRealMatrix) m.copy();
DenseRealMatrix mt = (DenseRealMatrix) m.transpose();
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m1 = (BlockRealMatrix) m.copy();
BlockRealMatrix mt = (BlockRealMatrix) m.transpose();
assertTrue(m.hashCode() != mt.hashCode());
assertEquals(m.hashCode(), m1.hashCode());
assertEquals(m, m);
assertEquals(m, m1);
assertFalse(m.equals(null));
assertFalse(m.equals(mt));
assertFalse(m.equals(new DenseRealMatrix(bigSingular)));
assertFalse(m.equals(new BlockRealMatrix(bigSingular)));
}
public void testToString() {
DenseRealMatrix m = new DenseRealMatrix(testData);
assertEquals("DenseRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
BlockRealMatrix m = new BlockRealMatrix(testData);
assertEquals("BlockRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
m.toString());
}
public void testSetSubMatrix() throws Exception {
DenseRealMatrix m = new DenseRealMatrix(testData);
BlockRealMatrix m = new BlockRealMatrix(testData);
m.setSubMatrix(detData2,1,1);
RealMatrix expected = new DenseRealMatrix
RealMatrix expected = new BlockRealMatrix
(new double[][] {{1.0,2.0,3.0},{2.0,1.0,3.0},{1.0,2.0,4.0}});
assertEquals(expected, m);
m.setSubMatrix(detData2,0,0);
expected = new DenseRealMatrix
expected = new BlockRealMatrix
(new double[][] {{1.0,3.0,3.0},{2.0,4.0,3.0},{1.0,2.0,4.0}});
assertEquals(expected, m);
m.setSubMatrix(testDataPlus2,0,0);
expected = new DenseRealMatrix
expected = new BlockRealMatrix
(new double[][] {{3.0,4.0,5.0},{4.0,7.0,5.0},{3.0,2.0,10.0}});
assertEquals(expected, m);
// javadoc example
DenseRealMatrix matrix = new DenseRealMatrix
BlockRealMatrix matrix = new BlockRealMatrix
(new double[][] {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 0, 1 , 2}});
matrix.setSubMatrix(new double[][] {{3, 4}, {5, 6}}, 1, 1);
expected = new DenseRealMatrix
expected = new BlockRealMatrix
(new double[][] {{1, 2, 3, 4}, {5, 3, 4, 8}, {9, 5 ,6, 2}});
assertEquals(expected, matrix);
@ -1073,13 +1073,13 @@ public final class DenseRealMatrixTest extends TestCase {
int rows = 150;
int columns = 75;
RealMatrix m = new DenseRealMatrix(rows, columns);
RealMatrix m = new BlockRealMatrix(rows, columns);
m.walkInRowOrder(new SetVisitor());
GetVisitor getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor);
assertEquals(rows * columns, getVisitor.getCount());
m = new DenseRealMatrix(rows, columns);
m = new BlockRealMatrix(rows, columns);
m.walkInRowOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
@ -1093,13 +1093,13 @@ public final class DenseRealMatrixTest extends TestCase {
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
}
m = new DenseRealMatrix(rows, columns);
m = new BlockRealMatrix(rows, columns);
m.walkInColumnOrder(new SetVisitor());
getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor);
assertEquals(rows * columns, getVisitor.getCount());
m = new DenseRealMatrix(rows, columns);
m = new BlockRealMatrix(rows, columns);
m.walkInColumnOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
@ -1113,13 +1113,13 @@ public final class DenseRealMatrixTest extends TestCase {
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
}
m = new DenseRealMatrix(rows, columns);
m = new BlockRealMatrix(rows, columns);
m.walkInOptimizedOrder(new SetVisitor());
getVisitor = new GetVisitor();
m.walkInRowOrder(getVisitor);
assertEquals(rows * columns, getVisitor.getCount());
m = new DenseRealMatrix(rows, columns);
m = new BlockRealMatrix(rows, columns);
m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
getVisitor = new GetVisitor();
m.walkInRowOrder(getVisitor, 1, rows - 2, 1, columns - 2);
@ -1133,13 +1133,13 @@ public final class DenseRealMatrixTest extends TestCase {
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
}
m = new DenseRealMatrix(rows, columns);
m = new BlockRealMatrix(rows, columns);
m.walkInOptimizedOrder(new SetVisitor());
getVisitor = new GetVisitor();
m.walkInColumnOrder(getVisitor);
assertEquals(rows * columns, getVisitor.getCount());
m = new DenseRealMatrix(rows, columns);
m = new BlockRealMatrix(rows, columns);
m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
getVisitor = new GetVisitor();
m.walkInColumnOrder(getVisitor, 1, rows - 2, 1, columns - 2);
@ -1156,7 +1156,7 @@ public final class DenseRealMatrixTest extends TestCase {
}
public void testSerial() {
DenseRealMatrix m = new DenseRealMatrix(testData);
BlockRealMatrix m = new BlockRealMatrix(testData);
assertEquals(m,TestUtils.serializeAndRecover(m));
}
@ -1196,8 +1196,8 @@ public final class DenseRealMatrixTest extends TestCase {
}
}
private DenseRealMatrix createRandomMatrix(Random r, int rows, int columns) {
DenseRealMatrix m = new DenseRealMatrix(rows, columns);
private BlockRealMatrix createRandomMatrix(Random r, int rows, int columns) {
BlockRealMatrix m = new BlockRealMatrix(rows, columns);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
m.setEntry(i, j, 200 * r.nextDouble() - 100);

View File

@ -74,7 +74,7 @@ public final class MatrixUtilsTest extends TestCase {
}
public void testCreateRealMatrix() {
assertEquals(new DenseRealMatrix(testData),
assertEquals(new BlockRealMatrix(testData),
MatrixUtils.createRealMatrix(testData));
try {
MatrixUtils.createRealMatrix(new double[][] {{1}, {1,2}}); // ragged
@ -155,7 +155,7 @@ public final class MatrixUtilsTest extends TestCase {
public void testCreateRowRealMatrix() {
assertEquals(MatrixUtils.createRowRealMatrix(row),
new DenseRealMatrix(rowMatrix));
new BlockRealMatrix(rowMatrix));
try {
MatrixUtils.createRowRealMatrix(new double[] {}); // empty
fail("Expecting IllegalArgumentException");
@ -213,7 +213,7 @@ public final class MatrixUtilsTest extends TestCase {
public void testCreateColumnRealMatrix() {
assertEquals(MatrixUtils.createColumnRealMatrix(col),
new DenseRealMatrix(colMatrix));
new BlockRealMatrix(colMatrix));
try {
MatrixUtils.createColumnRealMatrix(new double[] {}); // empty
fail("Expecting IllegalArgumentException");

View File

@ -21,7 +21,7 @@ import java.util.Random;
import org.apache.commons.math.linear.DefaultRealMatrixChangingVisitor;
import org.apache.commons.math.linear.DefaultRealMatrixPreservingVisitor;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.MatrixVisitorException;
import org.apache.commons.math.linear.QRDecomposition;
@ -77,8 +77,8 @@ public class QRDecompositionImplTest extends TestCase {
checkDimension(MatrixUtils.createRealMatrix(testData3x4));
Random r = new Random(643895747384642l);
int p = (5 * DenseRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * DenseRealMatrix.BLOCK_SIZE) / 4;
int p = (5 * BlockRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * BlockRealMatrix.BLOCK_SIZE) / 4;
checkDimension(createTestMatrix(r, p, q));
checkDimension(createTestMatrix(r, q, p));
@ -105,8 +105,8 @@ public class QRDecompositionImplTest extends TestCase {
checkAEqualQR(MatrixUtils.createRealMatrix(testData4x3));
Random r = new Random(643895747384642l);
int p = (5 * DenseRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * DenseRealMatrix.BLOCK_SIZE) / 4;
int p = (5 * BlockRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * BlockRealMatrix.BLOCK_SIZE) / 4;
checkAEqualQR(createTestMatrix(r, p, q));
checkAEqualQR(createTestMatrix(r, q, p));
@ -130,8 +130,8 @@ public class QRDecompositionImplTest extends TestCase {
checkQOrthogonal(MatrixUtils.createRealMatrix(testData4x3));
Random r = new Random(643895747384642l);
int p = (5 * DenseRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * DenseRealMatrix.BLOCK_SIZE) / 4;
int p = (5 * BlockRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * BlockRealMatrix.BLOCK_SIZE) / 4;
checkQOrthogonal(createTestMatrix(r, p, q));
checkQOrthogonal(createTestMatrix(r, q, p));
@ -160,8 +160,8 @@ public class QRDecompositionImplTest extends TestCase {
checkUpperTriangular(new QRDecompositionImpl(matrix).getR());
Random r = new Random(643895747384642l);
int p = (5 * DenseRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * DenseRealMatrix.BLOCK_SIZE) / 4;
int p = (5 * BlockRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * BlockRealMatrix.BLOCK_SIZE) / 4;
matrix = createTestMatrix(r, p, q);
checkUpperTriangular(new QRDecompositionImpl(matrix).getR());
@ -196,8 +196,8 @@ public class QRDecompositionImplTest extends TestCase {
checkTrapezoidal(new QRDecompositionImpl(matrix).getH());
Random r = new Random(643895747384642l);
int p = (5 * DenseRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * DenseRealMatrix.BLOCK_SIZE) / 4;
int p = (5 * BlockRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * BlockRealMatrix.BLOCK_SIZE) / 4;
matrix = createTestMatrix(r, p, q);
checkTrapezoidal(new QRDecompositionImpl(matrix).getH());

View File

@ -25,7 +25,7 @@ import junit.framework.TestSuite;
import org.apache.commons.math.linear.DecompositionSolver;
import org.apache.commons.math.linear.DefaultRealMatrixChangingVisitor;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.InvalidMatrixException;
import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.MatrixVisitorException;
@ -192,10 +192,10 @@ public class QRSolverTest extends TestCase {
public void testOverdetermined() {
final Random r = new Random(5559252868205245l);
int p = (7 * DenseRealMatrix.BLOCK_SIZE) / 4;
int q = (5 * DenseRealMatrix.BLOCK_SIZE) / 4;
int p = (7 * BlockRealMatrix.BLOCK_SIZE) / 4;
int q = (5 * BlockRealMatrix.BLOCK_SIZE) / 4;
RealMatrix a = createTestMatrix(r, p, q);
RealMatrix xRef = createTestMatrix(r, q, DenseRealMatrix.BLOCK_SIZE + 3);
RealMatrix xRef = createTestMatrix(r, q, BlockRealMatrix.BLOCK_SIZE + 3);
// build a perturbed system: A.X + noise = B
RealMatrix b = a.multiply(xRef);
@ -215,10 +215,10 @@ public class QRSolverTest extends TestCase {
public void testUnderdetermined() {
final Random r = new Random(42185006424567123l);
int p = (5 * DenseRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * DenseRealMatrix.BLOCK_SIZE) / 4;
int p = (5 * BlockRealMatrix.BLOCK_SIZE) / 4;
int q = (7 * BlockRealMatrix.BLOCK_SIZE) / 4;
RealMatrix a = createTestMatrix(r, p, q);
RealMatrix xRef = createTestMatrix(r, q, DenseRealMatrix.BLOCK_SIZE + 3);
RealMatrix xRef = createTestMatrix(r, q, BlockRealMatrix.BLOCK_SIZE + 3);
RealMatrix b = a.multiply(xRef);
RealMatrix x = new QRDecompositionImpl(a).getSolver().solve(b);

View File

@ -195,7 +195,7 @@ public final class SparseRealMatrixTest extends TestCase {
OpenMapRealMatrix m2 = createSparseMatrix(testData2);
assertClose("inverse multiply", m.multiply(mInv), identity,
entryTolerance);
assertClose("inverse multiply", m.multiply(new DenseRealMatrix(testDataInv)), identity,
assertClose("inverse multiply", m.multiply(new BlockRealMatrix(testDataInv)), identity,
entryTolerance);
assertClose("inverse multiply", mInv.multiply(m), identity,
entryTolerance);

View File

@ -29,7 +29,7 @@ import junit.framework.TestSuite;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction;
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.optimization.OptimizationException;
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
@ -485,7 +485,7 @@ extends TestCase {
final RealMatrix factors;
final double[] target;
public LinearProblem(double[][] factors, double[] target) {
this.factors = new DenseRealMatrix(factors);
this.factors = new BlockRealMatrix(factors);
this.target = target;
}

View File

@ -30,7 +30,7 @@ import junit.framework.TestSuite;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction;
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.optimization.OptimizationException;
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
@ -525,7 +525,7 @@ public class LevenbergMarquardtOptimizerTest
final RealMatrix factors;
final double[] target;
public LinearProblem(double[][] factors, double[] target) {
this.factors = new DenseRealMatrix(factors);
this.factors = new BlockRealMatrix(factors);
this.target = target;
}

View File

@ -30,7 +30,7 @@ import org.apache.commons.math.analysis.DifferentiableMultivariateRealFunction;
import org.apache.commons.math.analysis.MultivariateRealFunction;
import org.apache.commons.math.analysis.MultivariateVectorialFunction;
import org.apache.commons.math.analysis.solvers.BrentSolver;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.optimization.GoalType;
import org.apache.commons.math.optimization.OptimizationException;
@ -369,7 +369,7 @@ extends TestCase {
final RealMatrix factors;
final double[] target;
public LinearProblem(double[][] factors, double[] target) {
this.factors = new DenseRealMatrix(factors);
this.factors = new BlockRealMatrix(factors);
this.target = target;
}

View File

@ -20,7 +20,7 @@ import org.apache.commons.math.TestUtils;
import org.apache.commons.math.distribution.TDistribution;
import org.apache.commons.math.distribution.TDistributionImpl;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import junit.framework.TestCase;
@ -184,7 +184,7 @@ public class PearsonsCorrelationTest extends TestCase {
} catch (IllegalArgumentException ex) {
// Expected
}
RealMatrix matrix = new DenseRealMatrix(new double[][] {{0},{1}});
RealMatrix matrix = new BlockRealMatrix(new double[][] {{0},{1}});
try {
new PearsonsCorrelation(matrix);
fail("Expecting IllegalArgumentException");
@ -259,12 +259,12 @@ public class PearsonsCorrelationTest extends TestCase {
System.arraycopy(data, ptr, matrixData[i], 0, nCols);
ptr += nCols;
}
return new DenseRealMatrix(matrixData);
return new BlockRealMatrix(matrixData);
}
protected RealMatrix createLowerTriangularRealMatrix(double[] data, int dimension) {
int ptr = 0;
RealMatrix result = new DenseRealMatrix(dimension, dimension);
RealMatrix result = new BlockRealMatrix(dimension, dimension);
for (int i = 1; i < dimension; i++) {
for (int j = 0; j < i; j++) {
result.setEntry(i, j, data[ptr]);

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.stat.correlation;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.linear.DenseRealMatrix;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.RealMatrix;
/**
@ -99,7 +99,7 @@ public class SpearmansRankCorrelationTest extends PearsonsCorrelationTest {
} catch (IllegalArgumentException ex) {
// Expected
}
RealMatrix matrix = new DenseRealMatrix(new double[][] {{0},{1}});
RealMatrix matrix = new BlockRealMatrix(new double[][] {{0},{1}});
try {
new SpearmansCorrelation(matrix);
fail("Expecting IllegalArgumentException");