def test_split_nonuniform2(self): """Test splitNonUniform - not starting at coordinate 0""" # # Create the fiber to be split # c = [0, 1, 9, 10, 12, 31, 41] p = [0, 10, 20, 100, 120, 310, 410] f = Fiber(c, p) # # Create list of reference fibers after the split # css = [[9, 10], [12], [31, 41]] pss = [[20, 100], [120], [310, 410]] split_ref = [] for (cs, ps) in zip(css, pss): split_ref.append(Fiber(cs, ps)) # # Do the split # splits = [8, 12, 31] split = f.splitNonUniform(splits) # # Check the split # for i, (sc, sp) in enumerate(split): self.assertEqual(sc, splits[i]) self.assertEqual(sp, split_ref[i])
def test_split_nonuniform_empty(self): """Test splitNonUniform on empty fiber""" empty = Fiber() split = empty.splitNonUniform([1, 5, 17]) # After we split, we need to make sure that we have actually added # another level to the empty fiber self.assertIsInstance(split.getDefault(), Fiber)
def test_split_nonuniform_below(self): """Test splitNonUniformBelow""" c0 = [0, 1, 9, 10, 12, 31, 41] p0 = [ 0, 10, 20, 100, 120, 310, 410 ] f0 = Fiber(c0, p0) c1 = [1, 2, 10, 11, 13, 32, 42] p1 = [ 1, 11, 21, 101, 121, 311, 411 ] f1 = Fiber(c1, p1) c = [2, 4] f = Fiber(c, [f0, f1]) f.splitNonUniformBelow([0, 20,45, 50], depth=0) f0_split = f0.splitNonUniform([0, 20, 45, 50]) f1_split = f1.splitNonUniform([0, 20, 45, 50]) f_ref = Fiber(c, [f0_split, f1_split]) self.assertEqual(f, f_ref)
def test_split_nonuniform_then_flatten(self): """Test that flattenRanks can undo splitNonUniform""" # # Create the fiber to be split # c = [0, 1, 9, 10, 12, 31, 41] p = [0, 10, 20, 100, 120, 310, 410] f = Fiber(c, p) # # Do the split # splits = [0, 12, 31] split = f.splitNonUniform(splits) # # Check the split # self.assertEqual(split.flattenRanks(style="absolute"), f)
# coords = 10 print("Uniform coordinate split (groups of %s coordinates)\n" % coords) fibers = f.splitUniform(coords) for c, s in fibers: s.print() # # Non-unform coordiate-based split # splits = [0, 12, 31] print(f"NonUniform coordinate split (splits at {splits})\n") fibers = f.splitNonUniform(splits) for c, s in fibers: s.print() # # Equal position-based split # size = 2 print(f"Equal position split (groups of {size})\n") fibers = f.splitEqual(size) for c, s in fibers: s.print()