Find duplicate variables in spec and create aliases.
(self)
| 167 | return var |
| 168 | |
| 169 | def _alias_variables(self): |
| 170 | """Find duplicate variables in spec and create aliases.""" |
| 171 | # When a variable is duplicated, keep the version that comes first in |
| 172 | # the alphabetical order and alias the others. |
| 173 | variables = self.variables(ordered=True) |
| 174 | for name, value in reversed(variables): |
| 175 | for other_name, other_value in variables: |
| 176 | if name == other_name: |
| 177 | break |
| 178 | # Because variables can be transformed on load (e.g. transposed), |
| 179 | # we use an element-wise equality check. |
| 180 | scope, attr_name = _parent_scope(name) |
| 181 | if ( |
| 182 | not value.is_scalar() |
| 183 | and value.equal(other_value) |
| 184 | and attr_name not in SKIP_CREATING_ALIAS |
| 185 | ): |
| 186 | # Replace variable value by the alias name. |
| 187 | spec = index_spec(self, scope) |
| 188 | setattr(spec, attr_name, other_name) |
| 189 | break |
| 190 | |
| 191 | def _quantize(self, quantization): |
| 192 | """Possibly quantizes the variable of the layer.""" |
no test coverage detected