kopia lustrzana https://github.com/corrscope/corrscope
Fix passing tuples/lists into RendererLayout
rodzic
4cffa8c767
commit
62e8c800f4
|
@ -248,8 +248,10 @@ class RendererLayout:
|
|||
inds = np.arange(nspaces)
|
||||
rows, cols = np.unravel_index(inds, (self.nrows, self.ncols))
|
||||
|
||||
row_col = np.array([rows, cols]).T
|
||||
regions = np.array([region_factory(*rc) for rc in row_col]) # type: np.ndarray[Region]
|
||||
row_col = list(zip(rows, cols))
|
||||
regions = np.empty(len(row_col), dtype=object) # type: np.ndarray[Region]
|
||||
regions[:] = [region_factory(*rc) for rc in row_col]
|
||||
|
||||
regions2d = regions.reshape((self.nrows, self.ncols)) # type: np.ndarray[Region]
|
||||
|
||||
# if column major:
|
||||
|
|
|
@ -31,44 +31,43 @@ def test_config():
|
|||
LayoutConfig(ncols=2),
|
||||
LayoutConfig(nrows=8),
|
||||
])
|
||||
def test_hlayout(lcfg):
|
||||
@pytest.mark.parametrize('region_type', [str, tuple, list])
|
||||
def test_hlayout(lcfg, region_type):
|
||||
nplots = 15
|
||||
layout = RendererLayout(lcfg, nplots)
|
||||
|
||||
assert layout.ncols == 2
|
||||
assert layout.nrows == 8
|
||||
|
||||
# holy shit, passing tuples into a numpy array breaks things spectacularly, and it's
|
||||
# painfully difficult to stuff tuples into 1D array.
|
||||
# http://wesmckinney.com/blog/performance-quirk-making-a-1d-object-ndarray-of-tuples/
|
||||
regions = layout.arrange(lambda row, col: str((row, col)))
|
||||
regions = layout.arrange(lambda row, col: region_type((row, col)))
|
||||
assert len(regions) == nplots
|
||||
|
||||
assert regions[0] == '(0, 0)'
|
||||
assert regions[1] == '(0, 1)'
|
||||
assert regions[2] == '(1, 0)'
|
||||
assert regions[0] == region_type((0, 0))
|
||||
assert regions[1] == region_type((0, 1))
|
||||
assert regions[2] == region_type((1, 0))
|
||||
m = nplots - 1
|
||||
assert regions[m] == str((m // 2, m % 2))
|
||||
assert regions[m] == region_type((m // 2, m % 2))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('lcfg', [
|
||||
LayoutConfig(ncols=3, orientation='v'),
|
||||
LayoutConfig(nrows=3, orientation='v'),
|
||||
])
|
||||
def test_vlayout(lcfg):
|
||||
@pytest.mark.parametrize('region_type', [str, tuple, list])
|
||||
def test_vlayout(lcfg, region_type):
|
||||
nplots = 7
|
||||
layout = RendererLayout(lcfg, nplots)
|
||||
|
||||
assert layout.ncols == 3
|
||||
assert layout.nrows == 3
|
||||
|
||||
regions = layout.arrange(lambda row, col: str((row, col)))
|
||||
regions = layout.arrange(lambda row, col: region_type((row, col)))
|
||||
assert len(regions) == nplots
|
||||
|
||||
assert regions[0] == '(0, 0)'
|
||||
assert regions[2] == '(2, 0)'
|
||||
assert regions[3] == '(0, 1)'
|
||||
assert regions[6] == '(0, 2)'
|
||||
assert regions[0] == region_type((0, 0))
|
||||
assert regions[2] == region_type((2, 0))
|
||||
assert regions[3] == region_type((0, 1))
|
||||
assert regions[6] == region_type((0, 2))
|
||||
|
||||
|
||||
def test_renderer():
|
||||
|
|
Ładowanie…
Reference in New Issue