Repository: systemml Updated Branches: refs/heads/master 11e460573 -> aa45de98b
[MINOR] Refactor MatrixMetadata/FrameMetadata methods to Metadata Move common methods from MatrixMetadata and FrameMetadata classes to abstract parent Metadata class. Closes #641. Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/aa45de98 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/aa45de98 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/aa45de98 Branch: refs/heads/master Commit: aa45de98b87300919669ae3ec64dfd44a0b54b21 Parents: 11e4605 Author: Deron Eriksson <[email protected]> Authored: Mon Aug 28 10:24:04 2017 -0700 Committer: Deron Eriksson <[email protected]> Committed: Mon Aug 28 10:24:04 2017 -0700 ---------------------------------------------------------------------- .../sysml/api/mlcontext/FrameMetadata.java | 139 ----------------- .../sysml/api/mlcontext/MatrixMetadata.java | 152 ------------------ .../apache/sysml/api/mlcontext/Metadata.java | 155 +++++++++++++++++++ 3 files changed, 155 insertions(+), 291 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/aa45de98/src/main/java/org/apache/sysml/api/mlcontext/FrameMetadata.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/mlcontext/FrameMetadata.java b/src/main/java/org/apache/sysml/api/mlcontext/FrameMetadata.java index 6b0e68c..67d7ab9 100644 --- a/src/main/java/org/apache/sysml/api/mlcontext/FrameMetadata.java +++ b/src/main/java/org/apache/sysml/api/mlcontext/FrameMetadata.java @@ -19,7 +19,6 @@ package org.apache.sysml.api.mlcontext; -import org.apache.sysml.conf.ConfigurationManager; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; /** @@ -30,11 +29,6 @@ import org.apache.sysml.runtime.matrix.MatrixCharacteristics; */ public class FrameMetadata extends Metadata { - private Long numRows = null; - private Long numColumns = null; - private Long numNonZeros = null; - private Integer numRowsPerBlock = null; - private Integer numColumnsPerBlock = null; private FrameFormat frameFormat; private FrameSchema frameSchema; @@ -523,139 +517,6 @@ public class FrameMetadata extends Metadata { } /** - * Obtain the number of rows - * - * @return the number of rows - */ - public Long getNumRows() { - return numRows; - } - - /** - * Set the number of rows - * - * @param numRows - * the number of rows - */ - public void setNumRows(Long numRows) { - this.numRows = numRows; - } - - /** - * Obtain the number of columns - * - * @return the number of columns - */ - public Long getNumColumns() { - return numColumns; - } - - /** - * Set the number of columns - * - * @param numColumns - * the number of columns - */ - public void setNumColumns(Long numColumns) { - this.numColumns = numColumns; - } - - /** - * Obtain the number of non-zero values - * - * @return the number of non-zero values - */ - public Long getNumNonZeros() { - return numNonZeros; - } - - /** - * Set the number of non-zero values - * - * @param numNonZeros - * the number of non-zero values - */ - public void setNumNonZeros(Long numNonZeros) { - this.numNonZeros = numNonZeros; - } - - /** - * Obtain the number of rows per block - * - * @return the number of rows per block - */ - public Integer getNumRowsPerBlock() { - return numRowsPerBlock; - } - - /** - * Set the number of rows per block - * - * @param numRowsPerBlock - * the number of rows per block - */ - public void setNumRowsPerBlock(Integer numRowsPerBlock) { - this.numRowsPerBlock = numRowsPerBlock; - } - - /** - * Obtain the number of columns per block - * - * @return the number of columns per block - */ - public Integer getNumColumnsPerBlock() { - return numColumnsPerBlock; - } - - /** - * Set the number of columns per block - * - * @param numColumnsPerBlock - * the number of columns per block - */ - public void setNumColumnsPerBlock(Integer numColumnsPerBlock) { - this.numColumnsPerBlock = numColumnsPerBlock; - } - - /** - * Convert the frame metadata to a MatrixCharacteristics object. If all - * field values are {@code null}, {@code null} is returned. - * - * @return the frame metadata as a MatrixCharacteristics object, or - * {@code null} if all field values are null - */ - public MatrixCharacteristics asMatrixCharacteristics() { - - if ((numRows == null) && (numColumns == null) && (numRowsPerBlock == null) && (numColumnsPerBlock == null) - && (numNonZeros == null)) { - return null; - } - - long nr = (numRows == null) ? -1 : numRows; - long nc = (numColumns == null) ? -1 : numColumns; - int nrpb = (numRowsPerBlock == null) ? ConfigurationManager.getBlocksize() : numRowsPerBlock; - int ncpb = (numColumnsPerBlock == null) ? ConfigurationManager.getBlocksize() : numColumnsPerBlock; - long nnz = (numNonZeros == null) ? -1 : numNonZeros; - MatrixCharacteristics mc = new MatrixCharacteristics(nr, nc, nrpb, ncpb, nnz); - return mc; - } - - @Override - public String toString() { - return "rows: " + fieldDisplay(numRows) + ", columns: " + fieldDisplay(numColumns) + ", non-zeros: " - + fieldDisplay(numNonZeros) + ", rows per block: " + fieldDisplay(numRowsPerBlock) - + ", columns per block: " + fieldDisplay(numColumnsPerBlock); - } - - private String fieldDisplay(Object field) { - if (field == null) { - return "None"; - } else { - return field.toString(); - } - } - - /** * Obtain the frame format * * @return the frame format http://git-wip-us.apache.org/repos/asf/systemml/blob/aa45de98/src/main/java/org/apache/sysml/api/mlcontext/MatrixMetadata.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/mlcontext/MatrixMetadata.java b/src/main/java/org/apache/sysml/api/mlcontext/MatrixMetadata.java index 8f4cad7..4510249 100644 --- a/src/main/java/org/apache/sysml/api/mlcontext/MatrixMetadata.java +++ b/src/main/java/org/apache/sysml/api/mlcontext/MatrixMetadata.java @@ -19,7 +19,6 @@ package org.apache.sysml.api.mlcontext; -import org.apache.sysml.conf.ConfigurationManager; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; /** @@ -30,11 +29,6 @@ import org.apache.sysml.runtime.matrix.MatrixCharacteristics; */ public class MatrixMetadata extends Metadata { - private Long numRows = null; - private Long numColumns = null; - private Long numNonZeros = null; - private Integer numRowsPerBlock = null; - private Integer numColumnsPerBlock = null; private MatrixFormat matrixFormat; public MatrixMetadata() { @@ -355,152 +349,6 @@ public class MatrixMetadata extends Metadata { } /** - * Set the MatrixMetadata fields based on a MatrixCharacteristics object. - * - * @param matrixCharacteristics - * the matrix metadata as a MatrixCharacteristics object - */ - public void setMatrixCharacteristics(MatrixCharacteristics matrixCharacteristics) { - this.numRows = matrixCharacteristics.getRows(); - this.numColumns = matrixCharacteristics.getCols(); - this.numNonZeros = matrixCharacteristics.getNonZeros(); - this.numRowsPerBlock = matrixCharacteristics.getRowsPerBlock(); - this.numColumnsPerBlock = matrixCharacteristics.getColsPerBlock(); - } - - /** - * Obtain the number of rows - * - * @return the number of rows - */ - public Long getNumRows() { - return numRows; - } - - /** - * Set the number of rows - * - * @param numRows - * the number of rows - */ - public void setNumRows(Long numRows) { - this.numRows = numRows; - } - - /** - * Obtain the number of columns - * - * @return the number of columns - */ - public Long getNumColumns() { - return numColumns; - } - - /** - * Set the number of columns - * - * @param numColumns - * the number of columns - */ - public void setNumColumns(Long numColumns) { - this.numColumns = numColumns; - } - - /** - * Obtain the number of non-zero values - * - * @return the number of non-zero values - */ - public Long getNumNonZeros() { - return numNonZeros; - } - - /** - * Set the number of non-zero values - * - * @param numNonZeros - * the number of non-zero values - */ - public void setNumNonZeros(Long numNonZeros) { - this.numNonZeros = numNonZeros; - } - - /** - * Obtain the number of rows per block - * - * @return the number of rows per block - */ - public Integer getNumRowsPerBlock() { - return numRowsPerBlock; - } - - /** - * Set the number of rows per block - * - * @param numRowsPerBlock - * the number of rows per block - */ - public void setNumRowsPerBlock(Integer numRowsPerBlock) { - this.numRowsPerBlock = numRowsPerBlock; - } - - /** - * Obtain the number of columns per block - * - * @return the number of columns per block - */ - public Integer getNumColumnsPerBlock() { - return numColumnsPerBlock; - } - - /** - * Set the number of columns per block - * - * @param numColumnsPerBlock - * the number of columns per block - */ - public void setNumColumnsPerBlock(Integer numColumnsPerBlock) { - this.numColumnsPerBlock = numColumnsPerBlock; - } - - /** - * Convert the matrix metadata to a MatrixCharacteristics object. If all - * field values are {@code null}, {@code null} is returned. - * - * @return the matrix metadata as a MatrixCharacteristics object, or - * {@code null} if all field values are null - */ - public MatrixCharacteristics asMatrixCharacteristics() { - - if ((numRows == null) && (numColumns == null) && (numRowsPerBlock == null) && (numColumnsPerBlock == null) - && (numNonZeros == null)) { - return null; - } - - long nr = (numRows == null) ? -1 : numRows; - long nc = (numColumns == null) ? -1 : numColumns; - int nrpb = (numRowsPerBlock == null) ? ConfigurationManager.getBlocksize() : numRowsPerBlock; - int ncpb = (numColumnsPerBlock == null) ? ConfigurationManager.getBlocksize() : numColumnsPerBlock; - long nnz = (numNonZeros == null) ? -1 : numNonZeros; - return new MatrixCharacteristics(nr, nc, nrpb, ncpb, nnz); - } - - @Override - public String toString() { - return "rows: " + fieldDisplay(numRows) + ", columns: " + fieldDisplay(numColumns) + ", non-zeros: " - + fieldDisplay(numNonZeros) + ", rows per block: " + fieldDisplay(numRowsPerBlock) - + ", columns per block: " + fieldDisplay(numColumnsPerBlock); - } - - private String fieldDisplay(Object field) { - if (field == null) { - return "None"; - } else { - return field.toString(); - } - } - - /** * Obtain the matrix format * * @return the matrix format http://git-wip-us.apache.org/repos/asf/systemml/blob/aa45de98/src/main/java/org/apache/sysml/api/mlcontext/Metadata.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/mlcontext/Metadata.java b/src/main/java/org/apache/sysml/api/mlcontext/Metadata.java index 4061b5c..e7b167e 100644 --- a/src/main/java/org/apache/sysml/api/mlcontext/Metadata.java +++ b/src/main/java/org/apache/sysml/api/mlcontext/Metadata.java @@ -19,6 +19,9 @@ package org.apache.sysml.api.mlcontext; +import org.apache.sysml.conf.ConfigurationManager; +import org.apache.sysml.runtime.matrix.MatrixCharacteristics; + /** * Abstract metadata class for MLContext API. Complex types such as SystemML * matrices and frames typically require metadata, so this abstract class serves @@ -27,4 +30,156 @@ package org.apache.sysml.api.mlcontext; */ public abstract class Metadata { + protected Long numColumns = null; + protected Integer numColumnsPerBlock = null; + protected Long numNonZeros = null; + protected Long numRows = null; + protected Integer numRowsPerBlock = null; + + /** + * Convert the metadata to a MatrixCharacteristics object. If all field + * values are {@code null}, {@code null} is returned. + * + * @return the metadata as a MatrixCharacteristics object, or {@code null} + * if all field values are null + */ + public MatrixCharacteristics asMatrixCharacteristics() { + + if ((numRows == null) && (numColumns == null) && (numRowsPerBlock == null) && (numColumnsPerBlock == null) + && (numNonZeros == null)) { + return null; + } + + long nr = (numRows == null) ? -1 : numRows; + long nc = (numColumns == null) ? -1 : numColumns; + int nrpb = (numRowsPerBlock == null) ? ConfigurationManager.getBlocksize() : numRowsPerBlock; + int ncpb = (numColumnsPerBlock == null) ? ConfigurationManager.getBlocksize() : numColumnsPerBlock; + long nnz = (numNonZeros == null) ? -1 : numNonZeros; + return new MatrixCharacteristics(nr, nc, nrpb, ncpb, nnz); + } + + protected String fieldDisplay(Object field) { + if (field == null) { + return "None"; + } else { + return field.toString(); + } + } + + /** + * Obtain the number of columns + * + * @return the number of columns + */ + public Long getNumColumns() { + return numColumns; + } + + /** + * Obtain the number of columns per block + * + * @return the number of columns per block + */ + public Integer getNumColumnsPerBlock() { + return numColumnsPerBlock; + } + + /** + * Obtain the number of non-zero values + * + * @return the number of non-zero values + */ + public Long getNumNonZeros() { + return numNonZeros; + } + + /** + * Obtain the number of rows + * + * @return the number of rows + */ + public Long getNumRows() { + return numRows; + } + + /** + * Obtain the number of rows per block + * + * @return the number of rows per block + */ + public Integer getNumRowsPerBlock() { + return numRowsPerBlock; + } + + /** + * Set the metadata fields based on a MatrixCharacteristics object. + * + * @param matrixCharacteristics + * the matrix metadata as a MatrixCharacteristics object + */ + public void setMatrixCharacteristics(MatrixCharacteristics matrixCharacteristics) { + this.numRows = matrixCharacteristics.getRows(); + this.numColumns = matrixCharacteristics.getCols(); + this.numNonZeros = matrixCharacteristics.getNonZeros(); + this.numRowsPerBlock = matrixCharacteristics.getRowsPerBlock(); + this.numColumnsPerBlock = matrixCharacteristics.getColsPerBlock(); + } + + /** + * Set the number of columns + * + * @param numColumns + * the number of columns + */ + public void setNumColumns(Long numColumns) { + this.numColumns = numColumns; + } + + /** + * Set the number of columns per block + * + * @param numColumnsPerBlock + * the number of columns per block + */ + public void setNumColumnsPerBlock(Integer numColumnsPerBlock) { + this.numColumnsPerBlock = numColumnsPerBlock; + } + + /** + * Set the number of non-zero values + * + * @param numNonZeros + * the number of non-zero values + */ + public void setNumNonZeros(Long numNonZeros) { + this.numNonZeros = numNonZeros; + } + + /** + * Set the number of rows + * + * @param numRows + * the number of rows + */ + public void setNumRows(Long numRows) { + this.numRows = numRows; + } + + /** + * Set the number of rows per block + * + * @param numRowsPerBlock + * the number of rows per block + */ + public void setNumRowsPerBlock(Integer numRowsPerBlock) { + this.numRowsPerBlock = numRowsPerBlock; + } + + @Override + public String toString() { + return "rows: " + fieldDisplay(numRows) + ", columns: " + fieldDisplay(numColumns) + ", non-zeros: " + + fieldDisplay(numNonZeros) + ", rows per block: " + fieldDisplay(numRowsPerBlock) + + ", columns per block: " + fieldDisplay(numColumnsPerBlock); + } + }
