def test_split_into_groups(self): lst = [1, 2, 3, 4, 5, 6] g1 = split_into_groups(lst[:5], 3) self.assertEqual(g1, [[1, 2], [3, 4], [5]]) g2 = split_into_groups(lst, 7) self.assertEqual(g2, [[1], [2], [3], [4], [5], [6]]) g3 = split_into_groups(lst[0:1], 7) self.assertEqual(g3, [[1]]) g4 = split_into_groups(lst, 3) self.assertEqual(g4, [[1, 2], [3, 4], [5, 6]])
def split(self, num_parts): commands = [] for i, l in enumerate(split_into_groups(self.scenes, num_parts)): c = self.to_builder() \ .with_scenes(l) \ .with_split_id(i) \ .build() commands.append(c) return commands
def split(self, num_parts): split_on = self.command_options.split_on if split_on: commands = [] for i, split_elements in enumerate( split_into_groups(self.config[split_on], num_parts)): split_config = deepcopy(self.config) split_config[split_on] = split_elements c = self.to_builder() \ .with_config(**split_config) \ .with_split_id(i) \ .build() commands.append(c) return commands else: return [self]
def split(self, num_parts): commands = [] t_scenes = list(map(lambda x: (0, x), self.train_scenes)) v_scenes = list(map(lambda x: (1, x), self.val_scenes)) for i, l in enumerate(split_into_groups(t_scenes + v_scenes, num_parts)): split_t_scenes = list( map(lambda x: x[1], filter(lambda x: x[0] == 0, l))) split_v_scenes = list( map(lambda x: x[1], filter(lambda x: x[0] == 1, l))) c = self.to_builder() \ .with_train_scenes(split_t_scenes) \ .with_val_scenes(split_v_scenes) \ .with_split_id(i) \ .build() commands.append(c) return commands