Skip to content

Commit

Permalink
Require positive definite shape for split_blocks.
Browse files Browse the repository at this point in the history
Make an assertion about the space shape. Namely require it to contain
only positive values. There should be no 0 values or the shape is
trivial and thus doesn't need to be divided into blocks. Further
negative values have no meaning in this context as they are not relative
to anything.
  • Loading branch information
jakirkham committed Mar 3, 2017
1 parent 0d2b567 commit 079888a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kenjutsu/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def split_blocks(space_shape, block_shape, block_halo=None):

uneven_block_division = tuple(vec_mod(space_shape, block_shape))

if not all(imap(lambda e: e > 0, space_shape)):
raise ValueError(
"Shape of the space must be positive definite."
"Instead got: %s." % str(space_shape)
)

if any(uneven_block_division):
uneven_block_division_str = vec_nonzero(uneven_block_division)
uneven_block_division_str = vec_str(uneven_block_division_str)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def test_split_blocks(self):
" same."
)

with self.assertRaises(ValueError) as e:
blocks.split_blocks((1, 0), (1, -1))

self.assertEqual(
str(e.exception),
"Shape of the space must be positive definite."
"Instead got: (1, 0)."
)

result = blocks.split_blocks((2,), (1,))
self.assertEqual(
result,
Expand Down

0 comments on commit 079888a

Please sign in to comment.