def testUnstack(self): # flat lists remain flat lists. self.assertEqualArrays(unstack([1, 2, 3]), [1, 2, 3]) # lists of lists get unstacked. self.assertEqualArrays(unstack([[1, 2], [3, 4]]), [[1, 3], [2, 4]]) # matrices stay matrices, e.g. each r, g, b # components is split into grayscale images. self.assertEqualArrays( unstack([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]), [[[1, 4], [7, 10]], [[2, 5], [8, 11]], [[3, 6], [9, 12]]])
def testStackUnstackIdentity(self): a = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]] b = [1, 2, 3] c = [[1, 2], [3, 4]] for m in (a, b, c): self.assertEqualArrays(stack(*unstack(m)), m)
def testUnstack(self): # flat lists remain flat lists. self.assertEqualArrays( unstack([1, 2, 3]), [1, 2, 3]) # lists of lists get unstacked. self.assertEqualArrays( unstack([[1, 2], [3, 4]]), [[1, 3], [2, 4]]) # matrices stay matrices, e.g. each r, g, b # components is split into grayscale images. self.assertEqualArrays( unstack([ [[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]] ]), [ [[1, 4], [7, 10]], [[2, 5], [8, 11]], [[3, 6], [9, 12]] ])
def rgb_to_xyz(r, g, b, *rest): r, g, b = map(_inverse_compand_srgb, (r, g, b)) x, y, z = unstack(_clip1(dot_t(stack(r, g, b), _xyz_from_rgb))) return map(_clip1, (x, y, z) + rest)
def xyz_to_rgb(x, y, z, *rest): x, y, z = map(_clip1, (x, y, z)) r, g, b = unstack(dot_t(stack(x, y, z), _rgb_from_xyz)) r, g, b = map(_clip1, (r, g, b)) r, g, b = map(_compand_srgb, (r, g, b)) return map(_clip1, (r, g, b) + rest)