ch.javasoft.smx.impl
Class DefaultIntMatrix

java.lang.Object
  extended by ch.javasoft.smx.impl.DefaultIntMatrix
All Implemented Interfaces:
IntMatrix, MatrixBase<Integer>, ReadableBigIntegerMatrix<Integer>, ReadableBigIntegerRationalMatrix<Integer>, ReadableDoubleMatrix<Integer>, ReadableIntMatrix<Integer>, ReadableIntRationalMatrix<Integer>, ReadableLongMatrix<Integer>, ReadableLongRationalMatrix<Integer>, ReadableMatrix<Integer>, WritableIntMatrix<Integer>, WritableMatrix<Integer>, Cloneable

public class DefaultIntMatrix
extends Object
implements IntMatrix

The DefaultIntMatrix is the default implementation of IntMatrix. It contains a 1-dimensional array with all the matrix values.


Constructor Summary
DefaultIntMatrix(int[][] values, boolean rowsInDim1)
          Initializes the matrix from a 2-dim int array.
DefaultIntMatrix(int[] values, int rowCount, int columnCount)
           
DefaultIntMatrix(Integer[][] values, boolean rowsInDim1)
          Initializes the matrix from a 2-dim int array.
DefaultIntMatrix(int rowCount, int colCount)
           
DefaultIntMatrix(ReadableIntMatrix mx)
           
 
Method Summary
 void add(int row, int col, int value)
           
 void addRowToOtherRow(int srcRow, int srcFactor, int dstRow, int dstFactor)
           
 DefaultIntMatrix clone()
           
static DefaultIntMatrix diag(int[] values)
           
static DefaultIntMatrix diag(int value, int len)
           
 boolean equals(Object obj)
           
 BigFraction getBigFractionValueAt(int row, int col)
           
 BigInteger[] getBigIntegerColumn(int col)
           
 BigInteger[][] getBigIntegerColumns()
           
 BigInteger getBigIntegerDenominatorAt(int row, int col)
           
 BigInteger getBigIntegerNumeratorAt(int row, int col)
           
 BigInteger[] getBigIntegerRow(int row)
           
 BigInteger[][] getBigIntegerRows()
           
 BigInteger getBigIntegerValueAt(int row, int col)
           
 int getColumnCount()
           
 double[] getDoubleColumn(int col)
           
 double[][] getDoubleColumns()
           
 double[] getDoubleRow(int row)
           
 double[][] getDoubleRows()
           
 double getDoubleValueAt(int row, int col)
           
 int[] getIntColumn(int col)
           
static int[] getIntColumn(ReadableIntMatrix mx, int col)
           
 int[][] getIntColumns()
           
static int[][] getIntColumns(ReadableIntMatrix mx)
           
 int getIntDenominatorAt(int row, int col)
           
 int getIntNumeratorAt(int row, int col)
           
 int[] getIntRow(int row)
           
static int[] getIntRow(ReadableIntMatrix mx, int row)
           
 int[][] getIntRows()
           
static int[][] getIntRows(ReadableIntMatrix mx)
           
 int getIntValueAt(int row, int col)
           
 long[] getLongColumn(int col)
           
 long[][] getLongColumns()
           
 long getLongDenominatorAt(int row, int col)
           
 long getLongNumeratorAt(int row, int col)
           
 long[] getLongRow(int row)
           
 long[][] getLongRows()
           
 long getLongValueAt(int row, int col)
           
 MatrixOperations<Integer> getMatrixOperations()
           
 IntegerOperations getNumberOperations()
           
 Integer[][] getNumberRows()
           
static Integer[][] getNumberRows(ReadableIntMatrix<Integer> mx)
           
 Integer getNumberValueAt(int row, int col)
           
 int getRowCount()
           
 int getSignumAt(int row, int col)
           
 int hashCode()
           
static DefaultIntMatrix identity(int len)
           
 void multiply(int row, int col, int factor)
           
 void multiplyRow(int row, int factor)
           
 void negate(int row, int col)
           
 DefaultIntMatrix newInstance(Integer[][] data, boolean rowsInDim1)
           
 DefaultIntMatrix newInstance(int rows, int cols)
           
 void setValueAt(int row, int col, int value)
           
 void setValueAt(int row, int col, Integer value)
           
 ReadableBigIntegerMatrix subBigIntegerMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
           
 BigIntegerRationalMatrix subBigIntegerRationalMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
           
 DoubleMatrix subDoubleMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
           
 IntMatrix subIntMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
           
 IntRationalMatrix subIntRationalMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
           
 ReadableLongMatrix subLongMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
           
 LongRationalMatrix subLongRationalMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
           
 void swapColumns(int colA, int colB)
           
 void swapRows(int rowA, int rowB)
           
 void toArray(BigInteger[] array)
           
 void toArray(double[] array)
           
 void toArray(int[] array)
           
 void toArray(long[] array)
           
 BigInteger[] toBigIntegerArray()
           
 BigIntegerMatrix toBigIntegerMatrix(boolean enforceNewInstance)
           
 BigIntegerRationalMatrix toBigIntegerRationalMatrix(boolean enforceNewInstance)
           
 double[] toDoubleArray()
           
 DoubleMatrix toDoubleMatrix(boolean enforceNewInstance)
           
 int[] toIntArray()
           
 IntMatrix toIntMatrix(boolean enforceNewInstance)
           
 IntRationalMatrix toIntRationalMatrix(boolean enforceNewInstance)
           
 long[] toLongArray()
           
 LongMatrix toLongMatrix(boolean enforceNewInstance)
           
 LongRationalMatrix toLongRationalMatrix(boolean enforceNewInstance)
           
 String toMultilineString()
           
static String toMultilineString(ReadableIntMatrix mx)
           
 IntMatrix toReadableMatrix(boolean enforceNewInstance)
           
 String toString()
           
static String toString(ReadableIntMatrix mx)
           
protected static String toString(ReadableIntMatrix mx, String prefix, String postfix, String rowPrefix, String rowPostfix, String rowSeparator, String colPrefix, String colPostfix, String colSeparator)
           
 IntMatrix toWritableMatrix(boolean enforceNewInstance)
           
 DefaultIntMatrix transpose()
           
 void writeTo(OutputStream out)
           
static void writeTo(OutputStream out, ReadableIntMatrix mx)
           
protected static void writeTo(PrintWriter writer, ReadableIntMatrix mx, String prefix, String postfix, String rowPrefix, String rowPostfix, String rowSeparator, String colPrefix, String colPostfix, String colSeparator)
           
 void writeTo(Writer writer)
           
static void writeTo(Writer writer, ReadableIntMatrix mx)
           
 void writeToMultiline(OutputStream out)
           
static void writeToMultiline(OutputStream out, ReadableIntMatrix mx)
           
 void writeToMultiline(Writer writer)
           
static void writeToMultiline(Writer writer, ReadableIntMatrix mx)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultIntMatrix

public DefaultIntMatrix(int rowCount,
                        int colCount)

DefaultIntMatrix

public DefaultIntMatrix(int[] values,
                        int rowCount,
                        int columnCount)

DefaultIntMatrix

public DefaultIntMatrix(int[][] values,
                        boolean rowsInDim1)
Initializes the matrix from a 2-dim int array. The resulting rows relate to the first dimension if rowsInDim1 is true, or to the second dimension otherwise. If the second dimension has different lengths, the maximum value is taken, missing values are initialized with 0.

Parameters:
values - The 2-dim int array with the source values
rowsInDim1 - If true, the 1st dimension will become rows in the resulting DefaultDoubleMatrix, the columns relate to the 2nd dimension. If false, it is vice versa.

DefaultIntMatrix

public DefaultIntMatrix(Integer[][] values,
                        boolean rowsInDim1)
Initializes the matrix from a 2-dim int array. The resulting rows relate to the first dimension if rowsInDim1 is true, or to the second dimension otherwise. If the second dimension has different lengths, the maximum value is taken, missing values are initialized with 0.

Parameters:
values - The 2-dim int array with the source values
rowsInDim1 - If true, the 1st dimension will become rows in the resulting DefaultDoubleMatrix, the columns relate to the 2nd dimension. If false, it is vice versa.

DefaultIntMatrix

public DefaultIntMatrix(ReadableIntMatrix mx)
Method Detail

diag

public static DefaultIntMatrix diag(int[] values)

diag

public static DefaultIntMatrix diag(int value,
                                    int len)

identity

public static DefaultIntMatrix identity(int len)

getNumberOperations

public IntegerOperations getNumberOperations()
Specified by:
getNumberOperations in interface MatrixBase<Integer>

getMatrixOperations

public MatrixOperations<Integer> getMatrixOperations()
Specified by:
getMatrixOperations in interface MatrixBase<Integer>

getIntValueAt

public int getIntValueAt(int row,
                         int col)
Specified by:
getIntValueAt in interface ReadableIntMatrix<Integer>

getLongValueAt

public long getLongValueAt(int row,
                           int col)
Specified by:
getLongValueAt in interface ReadableLongMatrix<Integer>

getSignumAt

public int getSignumAt(int row,
                       int col)
Specified by:
getSignumAt in interface ReadableMatrix<Integer>

getIntNumeratorAt

public int getIntNumeratorAt(int row,
                             int col)
Specified by:
getIntNumeratorAt in interface ReadableIntRationalMatrix<Integer>

getIntDenominatorAt

public int getIntDenominatorAt(int row,
                               int col)
Specified by:
getIntDenominatorAt in interface ReadableIntRationalMatrix<Integer>

getLongNumeratorAt

public long getLongNumeratorAt(int row,
                               int col)
Specified by:
getLongNumeratorAt in interface ReadableLongRationalMatrix<Integer>

getLongDenominatorAt

public long getLongDenominatorAt(int row,
                                 int col)
Specified by:
getLongDenominatorAt in interface ReadableLongRationalMatrix<Integer>

getBigIntegerNumeratorAt

public BigInteger getBigIntegerNumeratorAt(int row,
                                           int col)
Specified by:
getBigIntegerNumeratorAt in interface ReadableBigIntegerRationalMatrix<Integer>

getBigIntegerDenominatorAt

public BigInteger getBigIntegerDenominatorAt(int row,
                                             int col)
Specified by:
getBigIntegerDenominatorAt in interface ReadableBigIntegerRationalMatrix<Integer>

getDoubleValueAt

public double getDoubleValueAt(int row,
                               int col)
Specified by:
getDoubleValueAt in interface ReadableDoubleMatrix<Integer>

getBigFractionValueAt

public BigFraction getBigFractionValueAt(int row,
                                         int col)
Specified by:
getBigFractionValueAt in interface ReadableBigIntegerRationalMatrix<Integer>

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface MatrixBase<Integer>

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface MatrixBase<Integer>

setValueAt

public void setValueAt(int row,
                       int col,
                       int value)
Specified by:
setValueAt in interface WritableIntMatrix<Integer>

setValueAt

public void setValueAt(int row,
                       int col,
                       Integer value)
Specified by:
setValueAt in interface WritableMatrix<Integer>

swapRows

public void swapRows(int rowA,
                     int rowB)
Specified by:
swapRows in interface WritableMatrix<Integer>

swapColumns

public void swapColumns(int colA,
                        int colB)
Specified by:
swapColumns in interface WritableMatrix<Integer>

getNumberValueAt

public Integer getNumberValueAt(int row,
                                int col)
Specified by:
getNumberValueAt in interface ReadableMatrix<Integer>

toIntArray

public int[] toIntArray()
Specified by:
toIntArray in interface ReadableIntMatrix<Integer>

toArray

public void toArray(int[] array)
Specified by:
toArray in interface ReadableIntMatrix<Integer>

toDoubleArray

public double[] toDoubleArray()
Specified by:
toDoubleArray in interface ReadableDoubleMatrix<Integer>

toLongArray

public long[] toLongArray()
Specified by:
toLongArray in interface ReadableLongMatrix<Integer>

toArray

public void toArray(double[] array)
Specified by:
toArray in interface ReadableDoubleMatrix<Integer>

toArray

public void toArray(long[] array)
Specified by:
toArray in interface ReadableLongMatrix<Integer>

getDoubleColumn

public double[] getDoubleColumn(int col)
Specified by:
getDoubleColumn in interface ReadableDoubleMatrix<Integer>

getDoubleColumns

public double[][] getDoubleColumns()
Specified by:
getDoubleColumns in interface ReadableDoubleMatrix<Integer>

getDoubleRow

public double[] getDoubleRow(int row)
Specified by:
getDoubleRow in interface ReadableDoubleMatrix<Integer>

getDoubleRows

public double[][] getDoubleRows()
Specified by:
getDoubleRows in interface ReadableDoubleMatrix<Integer>

getIntColumn

public int[] getIntColumn(int col)
Specified by:
getIntColumn in interface ReadableIntMatrix<Integer>

getIntColumn

public static int[] getIntColumn(ReadableIntMatrix mx,
                                 int col)

getLongColumn

public long[] getLongColumn(int col)
Specified by:
getLongColumn in interface ReadableLongMatrix<Integer>

getIntRow

public int[] getIntRow(int row)
Specified by:
getIntRow in interface ReadableIntMatrix<Integer>

getIntRow

public static int[] getIntRow(ReadableIntMatrix mx,
                              int row)

getLongRow

public long[] getLongRow(int row)
Specified by:
getLongRow in interface ReadableLongMatrix<Integer>

getIntColumns

public int[][] getIntColumns()
Specified by:
getIntColumns in interface ReadableIntMatrix<Integer>

getIntColumns

public static int[][] getIntColumns(ReadableIntMatrix mx)

getLongColumns

public long[][] getLongColumns()
Specified by:
getLongColumns in interface ReadableLongMatrix<Integer>

getNumberRows

public Integer[][] getNumberRows()
Specified by:
getNumberRows in interface ReadableMatrix<Integer>

getNumberRows

public static Integer[][] getNumberRows(ReadableIntMatrix<Integer> mx)

getIntRows

public int[][] getIntRows()
Specified by:
getIntRows in interface ReadableIntMatrix<Integer>

getIntRows

public static int[][] getIntRows(ReadableIntMatrix mx)

getLongRows

public long[][] getLongRows()
Specified by:
getLongRows in interface ReadableLongMatrix<Integer>

toString

public String toString()
Specified by:
toString in interface MatrixBase<Integer>
Overrides:
toString in class Object

writeTo

public void writeTo(Writer writer)
Specified by:
writeTo in interface MatrixBase<Integer>

writeTo

public void writeTo(OutputStream out)
Specified by:
writeTo in interface MatrixBase<Integer>

toString

public static String toString(ReadableIntMatrix mx)

writeTo

public static void writeTo(Writer writer,
                           ReadableIntMatrix mx)

writeTo

public static void writeTo(OutputStream out,
                           ReadableIntMatrix mx)

toMultilineString

public String toMultilineString()
Specified by:
toMultilineString in interface MatrixBase<Integer>

writeToMultiline

public void writeToMultiline(Writer writer)
Specified by:
writeToMultiline in interface MatrixBase<Integer>

writeToMultiline

public void writeToMultiline(OutputStream out)
Specified by:
writeToMultiline in interface MatrixBase<Integer>

toMultilineString

public static String toMultilineString(ReadableIntMatrix mx)

writeToMultiline

public static void writeToMultiline(Writer writer,
                                    ReadableIntMatrix mx)

writeToMultiline

public static void writeToMultiline(OutputStream out,
                                    ReadableIntMatrix mx)

toString

protected static String toString(ReadableIntMatrix mx,
                                 String prefix,
                                 String postfix,
                                 String rowPrefix,
                                 String rowPostfix,
                                 String rowSeparator,
                                 String colPrefix,
                                 String colPostfix,
                                 String colSeparator)

writeTo

protected static void writeTo(PrintWriter writer,
                              ReadableIntMatrix mx,
                              String prefix,
                              String postfix,
                              String rowPrefix,
                              String rowPostfix,
                              String rowSeparator,
                              String colPrefix,
                              String colPostfix,
                              String colSeparator)

clone

public DefaultIntMatrix clone()
Specified by:
clone in interface IntMatrix
Specified by:
clone in interface MatrixBase<Integer>
Specified by:
clone in interface ReadableMatrix<Integer>
Specified by:
clone in interface WritableMatrix<Integer>
Overrides:
clone in class Object

newInstance

public DefaultIntMatrix newInstance(int rows,
                                    int cols)
Specified by:
newInstance in interface IntMatrix
Specified by:
newInstance in interface MatrixBase<Integer>
Specified by:
newInstance in interface ReadableMatrix<Integer>
Specified by:
newInstance in interface WritableMatrix<Integer>

newInstance

public DefaultIntMatrix newInstance(Integer[][] data,
                                    boolean rowsInDim1)
Specified by:
newInstance in interface IntMatrix
Specified by:
newInstance in interface MatrixBase<Integer>
Specified by:
newInstance in interface ReadableMatrix<Integer>
Specified by:
newInstance in interface WritableMatrix<Integer>

toIntMatrix

public IntMatrix toIntMatrix(boolean enforceNewInstance)
Specified by:
toIntMatrix in interface ReadableIntMatrix<Integer>

toWritableMatrix

public IntMatrix toWritableMatrix(boolean enforceNewInstance)
Specified by:
toWritableMatrix in interface ReadableMatrix<Integer>

toReadableMatrix

public IntMatrix toReadableMatrix(boolean enforceNewInstance)
Specified by:
toReadableMatrix in interface WritableMatrix<Integer>

toLongMatrix

public LongMatrix toLongMatrix(boolean enforceNewInstance)
Specified by:
toLongMatrix in interface ReadableLongMatrix<Integer>

toIntRationalMatrix

public IntRationalMatrix toIntRationalMatrix(boolean enforceNewInstance)
Specified by:
toIntRationalMatrix in interface ReadableIntRationalMatrix<Integer>

toLongRationalMatrix

public LongRationalMatrix toLongRationalMatrix(boolean enforceNewInstance)
Specified by:
toLongRationalMatrix in interface ReadableLongRationalMatrix<Integer>

toBigIntegerRationalMatrix

public BigIntegerRationalMatrix toBigIntegerRationalMatrix(boolean enforceNewInstance)
Specified by:
toBigIntegerRationalMatrix in interface ReadableBigIntegerRationalMatrix<Integer>

toDoubleMatrix

public DoubleMatrix toDoubleMatrix(boolean enforceNewInstance)
Specified by:
toDoubleMatrix in interface ReadableDoubleMatrix<Integer>

addRowToOtherRow

public void addRowToOtherRow(int srcRow,
                             int srcFactor,
                             int dstRow,
                             int dstFactor)
Specified by:
addRowToOtherRow in interface WritableIntMatrix<Integer>

add

public void add(int row,
                int col,
                int value)
Specified by:
add in interface WritableIntMatrix<Integer>

multiply

public void multiply(int row,
                     int col,
                     int factor)
Specified by:
multiply in interface WritableIntMatrix<Integer>

multiplyRow

public void multiplyRow(int row,
                        int factor)
Specified by:
multiplyRow in interface WritableIntMatrix<Integer>

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

subIntMatrix

public IntMatrix subIntMatrix(int rowStart,
                              int rowEnd,
                              int colStart,
                              int colEnd)
Specified by:
subIntMatrix in interface ReadableIntMatrix<Integer>

subLongMatrix

public ReadableLongMatrix subLongMatrix(int rowStart,
                                        int rowEnd,
                                        int colStart,
                                        int colEnd)
Specified by:
subLongMatrix in interface ReadableLongMatrix<Integer>

subIntRationalMatrix

public IntRationalMatrix subIntRationalMatrix(int rowStart,
                                              int rowEnd,
                                              int colStart,
                                              int colEnd)
Specified by:
subIntRationalMatrix in interface ReadableIntRationalMatrix<Integer>

subLongRationalMatrix

public LongRationalMatrix subLongRationalMatrix(int rowStart,
                                                int rowEnd,
                                                int colStart,
                                                int colEnd)
Specified by:
subLongRationalMatrix in interface ReadableLongRationalMatrix<Integer>

subBigIntegerMatrix

public ReadableBigIntegerMatrix subBigIntegerMatrix(int rowStart,
                                                    int rowEnd,
                                                    int colStart,
                                                    int colEnd)
Specified by:
subBigIntegerMatrix in interface ReadableBigIntegerMatrix<Integer>

subBigIntegerRationalMatrix

public BigIntegerRationalMatrix subBigIntegerRationalMatrix(int rowStart,
                                                            int rowEnd,
                                                            int colStart,
                                                            int colEnd)
Specified by:
subBigIntegerRationalMatrix in interface ReadableBigIntegerRationalMatrix<Integer>

subDoubleMatrix

public DoubleMatrix subDoubleMatrix(int rowStart,
                                    int rowEnd,
                                    int colStart,
                                    int colEnd)
Specified by:
subDoubleMatrix in interface ReadableDoubleMatrix<Integer>

transpose

public DefaultIntMatrix transpose()
Specified by:
transpose in interface IntMatrix
Specified by:
transpose in interface MatrixBase<Integer>
Specified by:
transpose in interface ReadableMatrix<Integer>
Specified by:
transpose in interface WritableMatrix<Integer>

getBigIntegerValueAt

public BigInteger getBigIntegerValueAt(int row,
                                       int col)
Specified by:
getBigIntegerValueAt in interface ReadableBigIntegerMatrix<Integer>

toArray

public void toArray(BigInteger[] array)
Specified by:
toArray in interface ReadableBigIntegerMatrix<Integer>

toBigIntegerArray

public BigInteger[] toBigIntegerArray()
Specified by:
toBigIntegerArray in interface ReadableBigIntegerMatrix<Integer>

toBigIntegerMatrix

public BigIntegerMatrix toBigIntegerMatrix(boolean enforceNewInstance)
Specified by:
toBigIntegerMatrix in interface ReadableBigIntegerMatrix<Integer>

getBigIntegerColumn

public BigInteger[] getBigIntegerColumn(int col)
Specified by:
getBigIntegerColumn in interface ReadableBigIntegerMatrix<Integer>

getBigIntegerColumns

public BigInteger[][] getBigIntegerColumns()
Specified by:
getBigIntegerColumns in interface ReadableBigIntegerMatrix<Integer>

getBigIntegerRow

public BigInteger[] getBigIntegerRow(int row)
Specified by:
getBigIntegerRow in interface ReadableBigIntegerMatrix<Integer>

getBigIntegerRows

public BigInteger[][] getBigIntegerRows()
Specified by:
getBigIntegerRows in interface ReadableBigIntegerMatrix<Integer>

negate

public void negate(int row,
                   int col)
Specified by:
negate in interface WritableMatrix<Integer>