|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcox.jmatt.java.MathTools.util.MMatrixBuilder
public class MMatrixBuilder
This is a helper method for creating MMatrices. The MMatrix class is deliberately light on constructors to ease the burden of scripting. The methods in this class are designed in pairs: one method to create a double[][] array and another to create a MMatrix from the same signature.
Constructor Summary | |
---|---|
MMatrixBuilder()
|
Method Summary | |
---|---|
static MMatrix |
changeElement(MMatrix pMatrix,
int pRow,
int pCol,
double pVal)
This method replaces one element in a MMatrix with the specified value. |
static double[][] |
createArray(int pRows,
int pCols,
double pFill)
Create a non-ragged double[][] filled with the supplied value. |
static double[][] |
createArray(java.lang.String pArray)
Convenience method for createArray(pArray, null, null). |
static double[][] |
createArray(java.lang.String[] pRows,
java.lang.String pColSplit)
Create a double[][] from a String[] array. |
static double[][] |
createArray(java.lang.String pArray,
java.lang.String pRowSplit,
java.lang.String pColSplit)
This method creates a double[][] from a (single!) String, broken by rows and then columns by pRowSplit and pColSplit respectively. |
static double[][] |
createDiagonalArray(int pDimension,
double pFill,
double pDiagonal)
Create a square double[][] filled with the pFill value and pDiagonal along its main diagonal. |
static MMatrix |
createDiagonalMMatrix(int pDimension,
double pFill,
double pDiagonal)
Create a MMatrix with the specified 'background' pFill and pDiagonal down its main diagonal. |
static int[][] |
createIntArray(int pRows,
int pCols,
int pFill)
Create a non-ragged int[][] filled with the supplied value. |
static MMatrix |
createMMatrix(double[][] pArray)
Use this method to create a MMatrix directly. |
static MMatrix |
createMMatrix(int pRows,
int pCols,
double pFill)
Create a MMatrix filled with a particular constant. |
static MMatrix |
createMMatrix(java.lang.String pArray)
Convenience method for createMMatrix(pArray, null, null). |
static MMatrix |
createMMatrix(java.lang.String[] pRows,
java.lang.String pColSplit)
Create a MMatrix from a String[] array with each String split by pColSplit. |
static MMatrix |
createMMatrix(java.lang.String pArray,
java.lang.String pRowSplit,
java.lang.String pColSplit)
Create a MMatrix from a single String, broken by rows and then columns. |
static double[][] |
createRandArray(int pRows,
int pCols,
int pMin,
int pMax,
boolean pAllowZero)
Create an array of the given dimension filled with random values. |
static MMatrix |
createRandMMatrix(int pRows,
int pCols,
int pMin,
int pMax,
boolean pAllowZero)
Create a MMatrix filled with random values. |
static double[][] |
createSquareArray(int pDimension,
double pFill)
Create a square double[][] filled with the supplied value. |
static MMatrix |
createSquareMMatrix(int pDimension,
double pFill)
Create a MMatrix with the same number of rows and columns, filled with the pFill value. |
static void |
dump(double[] pAry)
Dump a double[] at Debug level. |
static void |
dump(double[][] pAry)
This (debugging!) method prints the contents of a double[][] at Debug level. |
MMatrixBuilder_SCROB |
getSCROB()
Return a SCROB instance of this class. |
static void |
printMMatrix(MMatrix pMatrix)
Print MMatrix information. |
static MMatrix |
replaceColumn(MMatrix pMatrix,
int pCol,
double[] pVals)
Replace some or all of a MMatrix column with new values. |
static MMatrix |
replaceRow(MMatrix pMatrix,
int pRow,
double[] pVals)
Change an entire MMatrix row. |
static double[][] |
smoothCopy(double[][] pAry)
Create a non-ragged copy of the double[][] passed in. |
static MMatrix |
TEST_MATRIX()
This method creates a simple 3x3 MMatrix with the elements '1 2 3/4 5 6/7 8 9.' As implied by its name this MMatrix is useful for testing purposes. |
static java.lang.String[][] |
toStringArray(double[][] pAry,
java.lang.String rowPfx,
java.lang.String rowSfx,
java.lang.String[] elPfx,
java.lang.String[] elSfx)
Convert a double[][] array into a String[][] array. |
static double[][] |
transposeArray(double[][] pAry)
Transpose an array by interchanging its rows and columns. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MMatrixBuilder()
Method Detail |
---|
public static MMatrix TEST_MATRIX()
public static MMatrix createMMatrix(double[][] pArray)
public static MMatrix createMMatrix(int pRows, int pCols, double pFill)
public static double[][] createArray(int pRows, int pCols, double pFill)
pRows
- The number of rows in the returned array.pCols
- The number of columns in the returned array.pFill
- The fill value for the new array.
public static int[][] createIntArray(int pRows, int pCols, int pFill)
pRows
- The number of rows in the returned array.pCols
- The number of columns in the returned array.pFill
- The fill value for the new array.
public static MMatrix createSquareMMatrix(int pDimension, double pFill)
public static double[][] createSquareArray(int pDimension, double pFill)
public static MMatrix createDiagonalMMatrix(int pDimension, double pFill, double pDiagonal)
public static double[][] createDiagonalArray(int pDimension, double pFill, double pDiagonal)
pDimension
- The number of rows and columns in the returned array.pFill
- The fill value ('background') value in the array.pDiagonal
- The diagonal value in the resulting array.
public static MMatrix createRandMMatrix(int pRows, int pCols, int pMin, int pMax, boolean pAllowZero)
public static double[][] createRandArray(int pRows, int pCols, int pMin, int pMax, boolean pAllowZero)
MathEngine.random()
methods to generate values so the
minimum element-value is included and the maximum value is excluded. The 'allowZero' argument determines which method to use. If either dimension is zero
or less an empty array is returned.
pRows
- The number of rows to create.pCols
- The number of columns in each row.pMin
- The minimum value for each element. This is included in the possible values.pMax
- The maximum value for each element. Not included in possible values.pAllowZero
- true to allow zero as a possible value, false to exclude it.public static double[][] smoothCopy(double[][] pAry)
public static MMatrix createMMatrix(java.lang.String[] pRows, java.lang.String pColSplit)
public static double[][] createArray(java.lang.String[] pRows, java.lang.String pColSplit)
public static MMatrix createMMatrix(java.lang.String pArray, java.lang.String pRowSplit, java.lang.String pColSplit)
public static double[][] createArray(java.lang.String pArray, java.lang.String pRowSplit, java.lang.String pColSplit)
This method creates a double[][] from a (single!) String, broken by rows and then columns by pRowSplit and pColSplit respectively. If null, pRowSplit defaults to a newline character and pColSplit defaults to a single space.
NOTE: The row- and column-split defaults are different from the MMatrix.createMMatrix()
method! This method, by default, parses a format
more 'natural' to reading. That is, space-separated element values organized (newline) into visual rows.
public static MMatrix createMMatrix(java.lang.String pArray)
public static double[][] createArray(java.lang.String pArray)
public static MMatrix changeElement(MMatrix pMatrix, int pRow, int pCol, double pVal)
pMatrix
- The MMatrix to 'change.'pRow
- The row of the element to change.pCol
- The column of the element to change.pVal
- The value to insert.
public static MMatrix replaceRow(MMatrix pMatrix, int pRow, double[] pVals)
changeElement()
this copies the MMatrix and works on the copy. The row sent in is copied to its length
or that of the row it replaces. Any elements left in the MMatrix are unalterd, any leftovers in the replacement row are ignored. If pMatrix is null a zero
MMatrix is returned. If the replacement row index is greater than pMatrix.rows() a simple copy is returned. If the replacement row is null or empty a simple
copy is returned.
pMatrix
- The MMatrix to change.pRow
- The row to replace.pVals
- The double[][] array to replace pRow.
public static MMatrix replaceColumn(MMatrix pMatrix, int pCol, double[] pVals)
pMatrix
- The MMatrix to edit.pCol
- The column to replace.pVals
- The column replacement values.
public static java.lang.String[][] toStringArray(double[][] pAry, java.lang.String rowPfx, java.lang.String rowSfx, java.lang.String[] elPfx, java.lang.String[] elSfx)
Convert a double[][] array into a String[][] array. The row prefix is prepended to each row and the row suffix is appended. An element prefix and suffix can be specified for each element by index. If the element array runs out before the row does any remaining elements are left unadorned. If the element prefix or suffix arrays have leftovers they are ignored. Null prefixes and suffixes are ignored but blanks are not.
This method makes no assumption about the size or smoothness of the array. If pAry is ragged so will be the returned array. If pAry is null or empty an empty array is returned.
pAry
- The double[][] array to convert to String[][].rowPfx
- The prefix added to each row. Ignored if null.rowSfx
- The suffix appended after each row. Ignored if null.elPfx
- The array of prefixes to prepend to row elements. Ignored if null, individual elemenents also ignored if null.elSfx
- The array of element suffixes appended. Ignored if null as are individual elements.
public static void dump(double[][] pAry)
public static void dump(double[] pAry)
public static void printMMatrix(MMatrix pMatrix)
CapCom.println()
.
public static double[][] transposeArray(double[][] pAry)
pAry
- A M x N array.
public MMatrixBuilder_SCROB getSCROB()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |