weibozhao commented on a change in pull request #24: URL: https://github.com/apache/flink-ml/pull/24#discussion_r768457556
########## File path: flink-ml-core/src/main/java/org/apache/flink/ml/linalg/DenseMatrix.java ########## @@ -0,0 +1,69 @@ +package org.apache.flink.ml.linalg; + +import org.apache.flink.api.common.typeinfo.TypeInfo; +import org.apache.flink.ml.linalg.typeinfo.DenseMatrixTypeInfoFactory; +import org.apache.flink.util.Preconditions; + +/** + * Column-major dense matrix. The entry values are stored in a single array of doubles with columns + * listed in sequence. + */ +@TypeInfo(DenseMatrixTypeInfoFactory.class) +public class DenseMatrix implements Matrix { + + /** Row dimension. */ + private final int numRows; + + /** Column dimension. */ + private final int numCols; + + /** + * Array for internal storage of elements. + * + * <p>The matrix data is stored in column major format internally. + */ + public final double[] values; + + /** + * Constructs an m-by-n matrix of zeros. + * + * @param numRows Number of rows. + * @param numCols Number of columns. + */ + public DenseMatrix(int numRows, int numCols) { + this(numRows, numCols, new double[numRows * numCols]); + } + + /** + * Constructs a matrix from a 1-D array. The data in the array should be organized in column + * major. + * + * @param numRows Number of rows. + * @param numCols Number of cols. + * @param values One-dimensional array of doubles. + */ + public DenseMatrix(int numRows, int numCols, double[] values) { + Preconditions.checkArgument(values.length == numRows * numCols); + this.numRows = numRows; + this.numCols = numCols; + this.values = values; + } + + @Override + public int numRows() { + return numRows; + } + + @Override + public int numCols() { + return numCols; + } + + @Override + public double get(int i, int j) { + if (i >= numRows || j >= numCols) { Review comment: OK -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org