|
23 | 23 |
|
24 | 24 | class PrettyPrintingTensorVariable(TensorVariable):
|
25 | 25 | def _str_repr(self, formatting="plain"):
|
26 |
| - print_name = self.name if self.name is not None else "<unnamed>" |
27 |
| - dist_name = self.owner.op._print_name[0] |
28 |
| - |
29 |
| - if "latex" in formatting: |
30 |
| - print_name = r"\text{" + _latex_escape(print_name) + "}" |
31 |
| - dist_name = self.owner.op._print_name[1] |
32 |
| - |
33 |
| - # first 3 args are always (rng, size, dtype), rest is relevant for distribution |
34 |
| - dist_args = [_str_for_input_var(x, formatting=formatting) for x in self.owner.inputs[3:]] |
35 |
| - |
36 |
| - if "latex" in formatting: |
37 |
| - return r"${} \sim {}({})$".format(print_name, dist_name, ",~".join(dist_args)) |
38 |
| - else: |
39 |
| - return r"{} ~ {}({})".format(print_name, dist_name, ", ".join(dist_args)) |
| 26 | + try: |
| 27 | + print_name = self.name if self.name is not None else "<unnamed>" |
| 28 | + dist_name = self.owner.op._print_name[0] |
| 29 | + |
| 30 | + if "latex" in formatting: |
| 31 | + print_name = r"\text{" + _latex_escape(print_name) + "}" |
| 32 | + dist_name = self.owner.op._print_name[1] |
| 33 | + |
| 34 | + # first 3 args are always (rng, size, dtype), rest is relevant for distribution |
| 35 | + dist_args = [ |
| 36 | + _str_for_input_var(x, formatting=formatting) for x in self.owner.inputs[3:] |
| 37 | + ] |
| 38 | + |
| 39 | + if "latex" in formatting: |
| 40 | + return r"${} \sim {}({})$".format(print_name, dist_name, ",~".join(dist_args)) |
| 41 | + else: |
| 42 | + return r"{} ~ {}({})".format(print_name, dist_name, ", ".join(dist_args)) |
| 43 | + except: |
| 44 | + # we wrap the above in a try-block because Aesara can do some type juggling |
| 45 | + # during e.g. computation of test values which makes self.owner is None |
| 46 | + return super().__str__() |
40 | 47 |
|
41 | 48 | def __latex__(self, formatting="latex", **kwargs):
|
42 | 49 | return self._str_repr(formatting=formatting)
|
|
0 commit comments