Repository: systemml Updated Branches: refs/heads/master 70c7952b9 -> 47e50af3f
[SYSTEMML-2043] New abstraction for large dense row blocks This patch introduces a new abstraction for dense row blocks, which is the basis for supporting both small and large (>16GB) dense blocks, while enabling memory-efficient linearized representations and efficient operations for entire dense blocks. Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/ead46f72 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/ead46f72 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/ead46f72 Branch: refs/heads/master Commit: ead46f728a0f94237ecb63f95e02a757d7c216d1 Parents: 70c7952 Author: Matthias Boehm <[email protected]> Authored: Fri Dec 8 20:27:58 2017 -0800 Committer: Matthias Boehm <[email protected]> Committed: Tue Dec 12 18:56:01 2017 -0800 ---------------------------------------------------------------------- .../sysml/runtime/matrix/data/DenseBlock.java | 155 +++++++++++++++++++ 1 file changed, 155 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/ead46f72/src/main/java/org/apache/sysml/runtime/matrix/data/DenseBlock.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/DenseBlock.java b/src/main/java/org/apache/sysml/runtime/matrix/data/DenseBlock.java new file mode 100644 index 0000000..54d34fb --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/DenseBlock.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +package org.apache.sysml.runtime.matrix.data; + +import java.io.Serializable; + +/** + * This DenseBlock is an abstraction for different dense, row-major + * matrix formats. For efficient dense operations, this API does not + * expose a row but a row-block abstraction, where a block can contain + * one or many contiguous rows. + * + */ +public abstract class DenseBlock implements Serializable +{ + private static final long serialVersionUID = 7517220490270237832L; + + public enum Type { + DRB, //dense row block + LDBR, //large dense row block + } + + /** + * Resets the dense block by deleting non-zero values. After this + * call all countNonZeros() calls are guaranteed to return 0. + */ + public abstract void reset(); + + /** + * Resets the dense block by deleting non-zero values. After this + * call all countNonZeros() calls are guaranteed to return 0. If + * the new dimensions exceed the current capacity, the underlying + * storage is extended accordingly. + * + * @param rlen number of rows + * @param clen number of columns + */ + public abstract void reset(int rlen, int clen); + + /** + * Get the number of rows. + * + * @return number of rows + */ + public abstract int numRows(); + + /** + * Get the number of allocated blocks. + * + * @return number of blocks + */ + public abstract int numBlocks(); + + /** + * Get the length of the dense block as the product + * of row and column dimensions. + * + * @return length + */ + public abstract long size(); + + /** + * Get the total length of allocated blocks. + * + * @return capacity + */ + public abstract long capacity(); + + /** + * Compute the number of non-zero values, which potentially + * makes a full pass over the underlying blocks. + * + * @return number of non-zeros + */ + public abstract long countNonZeros(); + + /** + * Get the allocated blocks. + * + * @return blocks + */ + public abstract double[][] values(); + + + /** + * Get an allocated block. + * + * @param bix block index + * @return block + */ + public abstract double[] values(int bix); + + /** + * Get the block index for a given row. + * + * @param r row index + * @return block index + */ + public abstract int index(int r); + + /** + * Get the position for a given row within + * its associated block. + * + * @param r row index + * @return block position + */ + public abstract int pos(int r); + + /** + * Get the position for a given row and column + * within the associated block. + * + * @param r row index + * @param c column index + * @return block position + */ + public abstract int pos(int r, int c); + + /** + * Set the given value for a given row and column. + * + * @param r row index + * @param c column index + * @param v value + */ + public abstract void set(int r, int c, double v); + + /** + * Get the value for a given row and column. + * + * @param r row index + * @param c column index + * @return value + */ + public abstract double get(int r, int c); +}
