def test_toBlocksBySlices(self): narys = 3 arys, sh, sz = _generate_test_arrays(narys) imagedata = ImagesLoader(self.sc).fromArrays(arys) test_params = [ (1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 3, 1), (1, 3, 2), (1, 3, 3), (2, 1, 1), (2, 1, 2), (2, 1, 3), (2, 2, 1), (2, 2, 2), (2, 2, 3), (2, 3, 1), (2, 3, 2), (2, 3, 3)] for bpd in test_params: blocks = imagedata._toBlocksBySplits(bpd).collect() expectednuniquekeys = reduce(mul, bpd) expectedvalsperkey = narys keystocounts = Counter([kv[0] for kv in blocks]) assert_equals(expectednuniquekeys, len(keystocounts)) assert_equals([expectedvalsperkey] * expectednuniquekeys, keystocounts.values()) gatheredary = None for _, block in blocks: if gatheredary is None: gatheredary = zeros(block.origshape, dtype='int16') gatheredary[block.origslices] = block.values for i in xrange(narys): assert_true(array_equal(arys[i], gatheredary[i]))
def test_toBlocksBySlices(self): narys = 3 arys, sh, sz = _generate_test_arrays(narys) imagedata = ImagesLoader(self.sc).fromArrays(arys) test_params = [(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 3, 1), (1, 3, 2), (1, 3, 3), (2, 1, 1), (2, 1, 2), (2, 1, 3), (2, 2, 1), (2, 2, 2), (2, 2, 3), (2, 3, 1), (2, 3, 2), (2, 3, 3)] for bpd in test_params: blocks = imagedata._toBlocksBySplits(bpd).collect() expectednuniquekeys = reduce(mul, bpd) expectedvalsperkey = narys keystocounts = Counter([kv[0] for kv in blocks]) assert_equals(expectednuniquekeys, len(keystocounts)) assert_equals([expectedvalsperkey] * expectednuniquekeys, keystocounts.values()) gatheredary = None for _, block in blocks: if gatheredary is None: gatheredary = zeros(block.origshape, dtype='int16') gatheredary[block.origslices] = block.values for i in xrange(narys): assert_true(array_equal(arys[i], gatheredary[i]))