Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix blockmatrix sparse sum bug #4888

Merged
merged 1 commit into from Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions hail/python/test/hail/linalg/test_linalg.py
Expand Up @@ -425,12 +425,18 @@ def sums_agree(bm, nd):
nd2[3, 5] = 4.0
bm2 = BlockMatrix.from_numpy(nd2, block_size=2).sparsify_rectangles([[2, 4, 4, 6]])

nd3 = np.zeros(shape=(5, 7))
bm3 = BlockMatrix.fill(5, 7, value=0.0, block_size=2).sparsify_rectangles([])
bm3 = BlockMatrix.from_numpy(nd2, block_size=2).sparsify_rectangles([[2, 4, 4, 6], [0, 5, 0, 1]])

bm4 = BlockMatrix.from_numpy(nd2, block_size=2).sparsify_rectangles([[2, 4, 4, 6], [0, 1, 0, 7]])

nd5 = np.zeros(shape=(5, 7))
bm5 = BlockMatrix.fill(5, 7, value=0.0, block_size=2).sparsify_rectangles([])

sums_agree(bm, nd)
sums_agree(bm2, nd2)
sums_agree(bm3, nd3)
sums_agree(bm3, nd2)
sums_agree(bm4, nd2)
sums_agree(bm5, nd5)

def test_slicing(self):
nd = np.array(np.arange(0, 80, dtype=float)).reshape(8, 10)
Expand Down
16 changes: 14 additions & 2 deletions hail/src/main/scala/is/hail/linalg/GridPartitioner.scala
Expand Up @@ -123,9 +123,21 @@ case class GridPartitioner(blockSize: Int, nRows: Long, nCols: Long, maybeBlocks
v(firstCol until firstCol + blockColNCols(j))
}

def maybeBlockRows(): Option[Array[Int]] = maybeBlocks.map(_.map(blockBlockRow).distinct)
def maybeBlockRows(): Option[Array[Int]] =
maybeBlocks match {
case Some(bis) =>
val bisRow = bis.map(blockBlockRow).distinct
if (bisRow.length < nBlockRows) Some(bisRow) else None
case None => None
}

def maybeBlockCols(): Option[Array[Int]] = maybeBlocks.map(_.map(blockBlockCol).distinct)
def maybeBlockCols(): Option[Array[Int]] =
maybeBlocks match {
case Some(bis) =>
val bisCol = bis.map(blockBlockCol).distinct
if (bisCol.length < nBlockCols) Some(bisCol) else None
case None => None
}

// returns increasing array of all blocks intersecting the diagonal band consisting of
// all elements with lower <= jj - ii <= upper
Expand Down