| @@ 86-148 (lines=63) @@ | ||
| 83 | self._ip_iteration += 1 |
|
| 84 | self.__finalise_datasets() |
|
| 85 | ||
| 86 | def __set_datasets(self): |
|
| 87 | ''' |
|
| 88 | Set the input and output datasets such that |
|
| 89 | - the output dataset from the previous iteration is the input dataset of |
|
| 90 | the current iteration that is about to be performed |
|
| 91 | - the input dataset from the previous iteration is used to write the |
|
| 92 | output of the urrent iteration that is about to be performed |
|
| 93 | ''' |
|
| 94 | params = self.parameters |
|
| 95 | # Only the 0th and 1st iterations are set in _ip_data_dicts, there is |
|
| 96 | # NOT a key for every iteration in _ip_data_dict, hence this if/elif |
|
| 97 | # block |
|
| 98 | if self._ip_iteration in list(self._ip_data_dict.keys()): |
|
| 99 | # If on the 0th or 1st iteration, set the in_datasets and |
|
| 100 | # out_datasets according to the structure defined in _ip_data_dict |
|
| 101 | # |
|
| 102 | # The body of this if statement is essentially a way to "set up" the |
|
| 103 | # input and ouput datasets so that for iterations after the 0th and |
|
| 104 | # 1st, the two datasets that are swapped between being used for |
|
| 105 | # input or output (depending on the particular iteration) can be |
|
| 106 | # swapped WITHOUT having to define a key-value pair in |
|
| 107 | # _ip_data_dict for EVERY SINGLE ITERATION |
|
| 108 | ||
| 109 | # this line isn't changing anything about the input datasets for |
|
| 110 | # iteration 0, but it is setting the input dataset for iteration 1 |
|
| 111 | # to be the output dataset from iteration 0 |
|
| 112 | params['in_datasets'] = [self._ip_data_dict[self._ip_iteration][0][-1]] |
|
| 113 | params['out_datasets'] = self._ip_data_dict[self._ip_iteration][1] |
|
| 114 | elif self._ip_iteration > 0: |
|
| 115 | # If on an iteration greater than 1 (since the if statement catches |
|
| 116 | # both iteration 0 and 1), then there is some (fiddly...) logic |
|
| 117 | # here to essentially SWAP the out dataset from the previous |
|
| 118 | # iteration with the in dataset of the previous iteration |
|
| 119 | # |
|
| 120 | # Practically speaking, this means that: |
|
| 121 | # - the out dataset from the previous iteration is used as the input |
|
| 122 | # for the current iteration that is about to be performed |
|
| 123 | # - the in dataset from the previous iteration is free to be used to |
|
| 124 | # write the output of the current iteration that is about to be |
|
| 125 | # performed |
|
| 126 | p = [params['in_datasets'], params['out_datasets']] |
|
| 127 | for original, clone in self._ip_data_dict['iterating'].items(): |
|
| 128 | # The definition of a is based on if the "original" dataset was |
|
| 129 | # an input or output dataset for the previous iteration. |
|
| 130 | # |
|
| 131 | # - the if branch is used when the "original" was the input |
|
| 132 | # dataset for the previous iteration |
|
| 133 | # - the else branch is used when the "original" was the output |
|
| 134 | # dataset for the previous iteration |
|
| 135 | a = [0, p[0].index(original)] if original in p[0] else \ |
|
| 136 | [1, p[1].index(original)] |
|
| 137 | # The definition of b is based on if the "clone" dataset was |
|
| 138 | # an input or output dataset for the previous iteration |
|
| 139 | # |
|
| 140 | # Similarly to the definition of a: |
|
| 141 | # - the if branch is used when the "clone" was the input |
|
| 142 | # dataset for the previous iteration |
|
| 143 | # - the else branch is used when the "clone" was the output |
|
| 144 | # dataset for the previous iteration |
|
| 145 | b = [0, p[0].index(clone)] if clone in p[0] else \ |
|
| 146 | [1, p[1].index(clone)] |
|
| 147 | # this is swapping the input and output datasets |
|
| 148 | p[a[0]][a[1]], p[b[0]][b[1]] = p[b[0]][b[1]], p[a[0]][a[1]] |
|
| 149 | ||
| 150 | # def __set_patterns(self): |
|
| 151 | # # The pattern dict key |
|
| @@ 183-226 (lines=44) @@ | ||
| 180 | # alternate a dataset with its clone |
|
| 181 | self.set_alternating_datasets(data, clone) |
|
| 182 | ||
| 183 | def __set_datasets(self): |
|
| 184 | ''' |
|
| 185 | Set the input and output datasets such that |
|
| 186 | - the output dataset from the previous iteration is the input dataset of |
|
| 187 | the current iteration that is about to be performed |
|
| 188 | - the input dataset from the previous iteration is used to write the |
|
| 189 | output of the current iteration that is about to be performed |
|
| 190 | ''' |
|
| 191 | # TODO: perhaps the pattern should be changed here, to make use of |
|
| 192 | # the same logic that is being used to switch the original & cloned |
|
| 193 | # data? |
|
| 194 | params = self.parameters |
|
| 195 | # Only the 0th and 1st iterations are set in _ip_data_dicts, there is |
|
| 196 | # NOT a key for every iteration in _ip_data_dict, hence this if/elif |
|
| 197 | # block |
|
| 198 | if self._ip_iteration in list(self._ip_data_dict.keys()): |
|
| 199 | # If on the 0th or 1st iteration, set the in_datasets and |
|
| 200 | # out_datasets according to the structure defined in _ip_data_dict |
|
| 201 | # |
|
| 202 | # The body of this if statement is essentially a way to "set up" the |
|
| 203 | # input and ouput datasets so that for iterations after the 0th and |
|
| 204 | # 1st, the two datasets that are swapped between being used for |
|
| 205 | # input or output (depending on the particular iteration) can be |
|
| 206 | # swapped WITHOUT having to define a key-value pair in |
|
| 207 | # _ip_data_dict for EVERY SINGLE ITERATION |
|
| 208 | params['in_datasets'] = self._ip_data_dict[self._ip_iteration][0] |
|
| 209 | params['out_datasets'] = self._ip_data_dict[self._ip_iteration][1] |
|
| 210 | elif self._ip_iteration > 0: |
|
| 211 | # If on an iteration greater than 1 (since the if statement catches |
|
| 212 | # both iteration 0 and 1), then there is some (fiddly...) logic |
|
| 213 | # here to essentially SWAP the out dataset from the previous |
|
| 214 | # iteration with the in dataset of the previous iteration |
|
| 215 | # |
|
| 216 | # Practically speaking, this means that: |
|
| 217 | # - the out dataset from the previous iteration is used as the input |
|
| 218 | # for the current iteration that is about to be performed |
|
| 219 | # - the in dataset from the previous iteration is free to be used to |
|
| 220 | # write the output of the current iteration that is about to be |
|
| 221 | # performed |
|
| 222 | p = [params['in_datasets'], params['out_datasets']] |
|
| 223 | for s1, s2 in self._ip_data_dict['iterating'].items(): |
|
| 224 | a = [0, p[0].index(s1)] if s1 in p[0] else [1, p[1].index(s1)] |
|
| 225 | b = [0, p[0].index(s2)] if s2 in p[0] else [1, p[1].index(s2)] |
|
| 226 | p[a[0]][a[1]], p[b[0]][b[1]] = p[b[0]][b[1]], p[a[0]][a[1]] |
|
| 227 | ||
| 228 | def set_alternating_datasets(self, d1, d2): |
|
| 229 | names = [d1.get_name(), d2.get_name()] |
|