提交 1a530729 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Simplify TensorType.shape format in str output

上级 b3a69117
...@@ -386,7 +386,18 @@ class TensorType(CType[np.ndarray], HasDataType, HasShape): ...@@ -386,7 +386,18 @@ class TensorType(CType[np.ndarray], HasDataType, HasShape):
if self.name: if self.name:
return self.name return self.name
else: else:
return f"TensorType({self.dtype}, {self.shape})"
def shape_str(s):
if s is None:
return "?"
else:
return str(s)
formatted_shape = ", ".join([shape_str(s) for s in self.shape])
if len(self.shape) == 1:
formatted_shape += ","
return f"TensorType({self.dtype}, ({formatted_shape}))"
def __repr__(self): def __repr__(self):
return str(self) return str(self)
......
...@@ -217,7 +217,7 @@ For example, :ref:`aesara.tensor.irow <libdoc_tensor_creation>` is an instance o ...@@ -217,7 +217,7 @@ For example, :ref:`aesara.tensor.irow <libdoc_tensor_creation>` is an instance o
>>> from aesara.tensor import irow >>> from aesara.tensor import irow
>>> irow() >>> irow()
<TensorType(int32, (1, None))> <TensorType(int32, (1, ?))>
As the string print-out shows, `irow` specifies the following information about As the string print-out shows, `irow` specifies the following information about
the :class:`Variable`\s it constructs: the :class:`Variable`\s it constructs:
......
...@@ -90,7 +90,7 @@ For example, let's say we have two :class:`Variable`\s with the following ...@@ -90,7 +90,7 @@ For example, let's say we have two :class:`Variable`\s with the following
>>> from aesara.tensor.type import TensorType >>> from aesara.tensor.type import TensorType
>>> v1 = TensorType("float64", (2, None))() >>> v1 = TensorType("float64", (2, None))()
>>> v1.type >>> v1.type
TensorType(float64, (2, None)) TensorType(float64, (2, ?))
>>> v2 = TensorType("float64", (2, 1))() >>> v2 = TensorType("float64", (2, 1))()
>>> v2.type >>> v2.type
TensorType(float64, (2, 1)) TensorType(float64, (2, 1))
...@@ -145,7 +145,7 @@ SpecifyShape.0 ...@@ -145,7 +145,7 @@ SpecifyShape.0
>>> import aesara >>> import aesara
>>> aesara.dprint(v3, print_type=True) >>> aesara.dprint(v3, print_type=True)
SpecifyShape [id A] <TensorType(float64, (2, 1))> SpecifyShape [id A] <TensorType(float64, (2, 1))>
|<TensorType(float64, (2, None))> [id B] <TensorType(float64, (2, None))> |<TensorType(float64, (2, ?))> [id B] <TensorType(float64, (2, ?))>
|TensorConstant{2} [id C] <TensorType(int8, ())> |TensorConstant{2} [id C] <TensorType(int8, ())>
|TensorConstant{1} [id D] <TensorType(int8, ())> |TensorConstant{1} [id D] <TensorType(int8, ())>
......
...@@ -406,7 +406,7 @@ Using the original Gibbs sampling example, with ``strict=True`` added to the ...@@ -406,7 +406,7 @@ Using the original Gibbs sampling example, with ``strict=True`` added to the
Traceback (most recent call last): Traceback (most recent call last):
... ...
MissingInputError: An input of the graph, used to compute MissingInputError: An input of the graph, used to compute
DimShuffle{1,0}(<TensorType(float64, (None, None))>), was not provided and DimShuffle{1,0}(<TensorType(float64, (?, ?))>), was not provided and
not given a value.Use the Aesara flag exception_verbosity='high',for not given a value.Use the Aesara flag exception_verbosity='high',for
more information on this error. more information on this error.
......
...@@ -44,8 +44,8 @@ Running the code above we see: ...@@ -44,8 +44,8 @@ Running the code above we see:
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Input dimension mismatch. (input[0].shape[0] = 3, input[1].shape[0] = 2) ValueError: Input dimension mismatch. (input[0].shape[0] = 3, input[1].shape[0] = 2)
Apply node that caused the error: Elemwise{add,no_inplace}(<TensorType(float64, (None,))>, <TensorType(float64, (None,))>, <TensorType(float64, (None,))>) Apply node that caused the error: Elemwise{add,no_inplace}(<TensorType(float64, (?,))>, <TensorType(float64, (?,))>, <TensorType(float64, (?,))>)
Inputs types: [TensorType(float64, (None,)), TensorType(float64, (None,)), TensorType(float64, (None,))] Inputs types: [TensorType(float64, (?,)), TensorType(float64, (?,)), TensorType(float64, (?,))]
Inputs shapes: [(3,), (2,), (2,)] Inputs shapes: [(3,), (2,), (2,)]
Inputs strides: [(8,), (8,), (8,)] Inputs strides: [(8,), (8,), (8,)]
Inputs scalar values: ['not scalar', 'not scalar', 'not scalar'] Inputs scalar values: ['not scalar', 'not scalar', 'not scalar']
...@@ -73,11 +73,11 @@ message becomes : ...@@ -73,11 +73,11 @@ message becomes :
z = z + y z = z + y
Debugprint of the apply node: Debugprint of the apply node:
Elemwise{add,no_inplace} [id A] <TensorType(float64, (None,))> '' Elemwise{add,no_inplace} [id A] <TensorType(float64, (?,))> ''
|Elemwise{add,no_inplace} [id B] <TensorType(float64, (None,))> '' |Elemwise{add,no_inplace} [id B] <TensorType(float64, (?,))> ''
| |<TensorType(float64, (None,))> [id C] <TensorType(float64, (None,))> | |<TensorType(float64, (?,))> [id C] <TensorType(float64, (?,))>
| |<TensorType(float64, (None,))> [id C] <TensorType(float64, (None,))> | |<TensorType(float64, (?,))> [id C] <TensorType(float64, (?,))>
|<TensorType(float64, (None,))> [id D] <TensorType(float64, (None,))> |<TensorType(float64, (?,))> [id D] <TensorType(float64, (?,))>
We can here see that the error can be traced back to the line ``z = z + y``. We can here see that the error can be traced back to the line ``z = z + y``.
For this example, using ``optimizer=fast_compile`` worked. If it did not, For this example, using ``optimizer=fast_compile`` worked. If it did not,
...@@ -145,18 +145,18 @@ Running the above code generates the following error message: ...@@ -145,18 +145,18 @@ Running the above code generates the following error message:
outputs = self.vm() outputs = self.vm()
ValueError: Shape mismatch: x has 10 cols (and 5 rows) but y has 20 rows (and 10 cols) ValueError: Shape mismatch: x has 10 cols (and 5 rows) but y has 20 rows (and 10 cols)
Apply node that caused the error: Dot22(x, DimShuffle{1,0}.0) Apply node that caused the error: Dot22(x, DimShuffle{1,0}.0)
Inputs types: [TensorType(float64, (None, None)), TensorType(float64, (None, None))] Inputs types: [TensorType(float64, (?, ?)), TensorType(float64, (?, ?))]
Inputs shapes: [(5, 10), (20, 10)] Inputs shapes: [(5, 10), (20, 10)]
Inputs strides: [(80, 8), (8, 160)] Inputs strides: [(80, 8), (8, 160)]
Inputs scalar values: ['not scalar', 'not scalar'] Inputs scalar values: ['not scalar', 'not scalar']
Debugprint of the apply node: Debugprint of the apply node:
Dot22 [id A] <TensorType(float64, (None, None))> '' Dot22 [id A] <TensorType(float64, (?, ?))> ''
|x [id B] <TensorType(float64, (None, None))> |x [id B] <TensorType(float64, (?, ?))>
|DimShuffle{1,0} [id C] <TensorType(float64, (None, None))> '' |DimShuffle{1,0} [id C] <TensorType(float64, (?, ?))> ''
|Flatten{2} [id D] <TensorType(float64, (None, None))> '' |Flatten{2} [id D] <TensorType(float64, (?, ?))> ''
|DimShuffle{2,0,1} [id E] <TensorType(float64, (None, None, None))> '' |DimShuffle{2,0,1} [id E] <TensorType(float64, (?, ?, ?))> ''
|W1 [id F] <TensorType(float64, (None, None, None))> |W1 [id F] <TensorType(float64, (?, ?, ?))>
HINT: Re-running with most Aesara optimization disabled could give you a back-traces when this node was created. This can be done with by setting the Aesara flags 'optimizer=fast_compile'. If that does not work, Aesara optimization can be disabled with 'optimizer=None'. HINT: Re-running with most Aesara optimization disabled could give you a back-traces when this node was created. This can be done with by setting the Aesara flags 'optimizer=fast_compile'. If that does not work, Aesara optimization can be disabled with 'optimizer=None'.
...@@ -483,7 +483,7 @@ Consider this example script (``ex.py``): ...@@ -483,7 +483,7 @@ Consider this example script (``ex.py``):
ValueError: Input dimension mismatch. (input[0].shape[0] = 3, input[1].shape[0] = 5) ValueError: Input dimension mismatch. (input[0].shape[0] = 3, input[1].shape[0] = 5)
Apply node that caused the error: Elemwise{mul,no_inplace}(a, b) Apply node that caused the error: Elemwise{mul,no_inplace}(a, b)
Toposort index: 0 Toposort index: 0
Inputs types: [TensorType(float64, (None, None)), TensorType(float64, (None, None))] Inputs types: [TensorType(float64, (?, ?)), TensorType(float64, (?, ?))]
Inputs shapes: [(3, 4), (5, 5)] Inputs shapes: [(3, 4), (5, 5)]
Inputs strides: [(32, 8), (40, 8)] Inputs strides: [(32, 8), (40, 8)]
Inputs values: ['not shown', 'not shown'] Inputs values: ['not shown', 'not shown']
......
...@@ -580,10 +580,10 @@ Inner graphs: ...@@ -580,10 +580,10 @@ Inner graphs:
OpFromGraph{inline=False} [id A] OpFromGraph{inline=False} [id A]
>Elemwise{add,no_inplace} [id E] >Elemwise{add,no_inplace} [id E]
> |*0-<TensorType(float64, (None, None))> [id F] > |*0-<TensorType(float64, (?, ?))> [id F]
> |Elemwise{mul,no_inplace} [id G] > |Elemwise{mul,no_inplace} [id G]
> |*1-<TensorType(float64, (None, None))> [id H] > |*1-<TensorType(float64, (?, ?))> [id H]
> |*2-<TensorType(float64, (None, None))> [id I] > |*2-<TensorType(float64, (?, ?))> [id I]
""" """
for truth, out in zip(exp_res.split("\n"), lines): for truth, out in zip(exp_res.split("\n"), lines):
......
...@@ -58,8 +58,8 @@ def test_debugprint_sitsot(): ...@@ -58,8 +58,8 @@ def test_debugprint_sitsot():
for{cpu,scan_fn} [id C] (outer_out_sit_sot-0) for{cpu,scan_fn} [id C] (outer_out_sit_sot-0)
>Elemwise{mul,no_inplace} [id W] (inner_out_sit_sot-0) >Elemwise{mul,no_inplace} [id W] (inner_out_sit_sot-0)
> |*0-<TensorType(float64, (None,))> [id X] -> [id E] (inner_in_sit_sot-0) > |*0-<TensorType(float64, (?,))> [id X] -> [id E] (inner_in_sit_sot-0)
> |*1-<TensorType(float64, (None,))> [id Y] -> [id M] (inner_in_non_seqs-0)""" > |*1-<TensorType(float64, (?,))> [id Y] -> [id M] (inner_in_non_seqs-0)"""
for truth, out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
...@@ -113,8 +113,8 @@ def test_debugprint_sitsot_no_extra_info(): ...@@ -113,8 +113,8 @@ def test_debugprint_sitsot_no_extra_info():
for{cpu,scan_fn} [id C] for{cpu,scan_fn} [id C]
>Elemwise{mul,no_inplace} [id W] >Elemwise{mul,no_inplace} [id W]
> |*0-<TensorType(float64, (None,))> [id X] -> [id E] > |*0-<TensorType(float64, (?,))> [id X] -> [id E]
> |*1-<TensorType(float64, (None,))> [id Y] -> [id M]""" > |*1-<TensorType(float64, (?,))> [id Y] -> [id M]"""
for truth, out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
...@@ -264,7 +264,7 @@ def test_debugprint_nested_scans(): ...@@ -264,7 +264,7 @@ def test_debugprint_nested_scans():
> | | | | | | | |Unbroadcast{0} [id BL] > | | | | | | | |Unbroadcast{0} [id BL]
> | | | | | | | |InplaceDimShuffle{x,0} [id BM] > | | | | | | | |InplaceDimShuffle{x,0} [id BM]
> | | | | | | | |Elemwise{second,no_inplace} [id BN] > | | | | | | | |Elemwise{second,no_inplace} [id BN]
> | | | | | | | |*2-<TensorType(float64, (None,))> [id BO] -> [id W] (inner_in_non_seqs-0) > | | | | | | | |*2-<TensorType(float64, (?,))> [id BO] -> [id W] (inner_in_non_seqs-0)
> | | | | | | | |InplaceDimShuffle{x} [id BP] > | | | | | | | |InplaceDimShuffle{x} [id BP]
> | | | | | | | |TensorConstant{1.0} [id BQ] > | | | | | | | |TensorConstant{1.0} [id BQ]
> | | | | | | |ScalarConstant{0} [id BR] > | | | | | | |ScalarConstant{0} [id BR]
...@@ -275,7 +275,7 @@ def test_debugprint_nested_scans(): ...@@ -275,7 +275,7 @@ def test_debugprint_nested_scans():
> | | | | |Unbroadcast{0} [id BL] > | | | | |Unbroadcast{0} [id BL]
> | | | | |ScalarFromTensor [id BV] > | | | | |ScalarFromTensor [id BV]
> | | | | |Subtensor{int64} [id BJ] > | | | | |Subtensor{int64} [id BJ]
> | | | |*2-<TensorType(float64, (None,))> [id BO] -> [id W] (inner_in_non_seqs-0) (outer_in_non_seqs-0) > | | | |*2-<TensorType(float64, (?,))> [id BO] -> [id W] (inner_in_non_seqs-0) (outer_in_non_seqs-0)
> | | |ScalarConstant{1} [id BW] > | | |ScalarConstant{1} [id BW]
> | |ScalarConstant{-1} [id BX] > | |ScalarConstant{-1} [id BX]
> |InplaceDimShuffle{x} [id BY] > |InplaceDimShuffle{x} [id BY]
...@@ -283,8 +283,8 @@ def test_debugprint_nested_scans(): ...@@ -283,8 +283,8 @@ def test_debugprint_nested_scans():
for{cpu,scan_fn} [id BE] (outer_out_sit_sot-0) for{cpu,scan_fn} [id BE] (outer_out_sit_sot-0)
>Elemwise{mul,no_inplace} [id CA] (inner_out_sit_sot-0) >Elemwise{mul,no_inplace} [id CA] (inner_out_sit_sot-0)
> |*0-<TensorType(float64, (None,))> [id CB] -> [id BG] (inner_in_sit_sot-0) > |*0-<TensorType(float64, (?,))> [id CB] -> [id BG] (inner_in_sit_sot-0)
> |*1-<TensorType(float64, (None,))> [id CC] -> [id BO] (inner_in_non_seqs-0)""" > |*1-<TensorType(float64, (?,))> [id CC] -> [id BO] (inner_in_non_seqs-0)"""
for truth, out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
...@@ -334,7 +334,7 @@ def test_debugprint_nested_scans(): ...@@ -334,7 +334,7 @@ def test_debugprint_nested_scans():
for{cpu,scan_fn} [id E] (outer_out_nit_sot-0) for{cpu,scan_fn} [id E] (outer_out_nit_sot-0)
-*0-<TensorType(float64, ())> [id Y] -> [id U] (inner_in_seqs-0) -*0-<TensorType(float64, ())> [id Y] -> [id U] (inner_in_seqs-0)
-*1-<TensorType(int64, ())> [id Z] -> [id W] (inner_in_seqs-1) -*1-<TensorType(int64, ())> [id Z] -> [id W] (inner_in_seqs-1)
-*2-<TensorType(float64, (None,))> [id BA] -> [id C] (inner_in_non_seqs-0) -*2-<TensorType(float64, (?,))> [id BA] -> [id C] (inner_in_non_seqs-0)
-*3-<TensorType(int32, ())> [id BB] -> [id B] (inner_in_non_seqs-1) -*3-<TensorType(int32, ())> [id BB] -> [id B] (inner_in_non_seqs-1)
>Elemwise{mul,no_inplace} [id BC] (inner_out_nit_sot-0) >Elemwise{mul,no_inplace} [id BC] (inner_out_nit_sot-0)
> |InplaceDimShuffle{x} [id BD] > |InplaceDimShuffle{x} [id BD]
...@@ -353,7 +353,7 @@ def test_debugprint_nested_scans(): ...@@ -353,7 +353,7 @@ def test_debugprint_nested_scans():
> | | | | | | | |Unbroadcast{0} [id BN] > | | | | | | | |Unbroadcast{0} [id BN]
> | | | | | | | |InplaceDimShuffle{x,0} [id BO] > | | | | | | | |InplaceDimShuffle{x,0} [id BO]
> | | | | | | | |Elemwise{second,no_inplace} [id BP] > | | | | | | | |Elemwise{second,no_inplace} [id BP]
> | | | | | | | |*2-<TensorType(float64, (None,))> [id BA] (inner_in_non_seqs-0) > | | | | | | | |*2-<TensorType(float64, (?,))> [id BA] (inner_in_non_seqs-0)
> | | | | | | | |InplaceDimShuffle{x} [id BQ] > | | | | | | | |InplaceDimShuffle{x} [id BQ]
> | | | | | | | |TensorConstant{1.0} [id BR] > | | | | | | | |TensorConstant{1.0} [id BR]
> | | | | | | |ScalarConstant{0} [id BS] > | | | | | | |ScalarConstant{0} [id BS]
...@@ -364,18 +364,18 @@ def test_debugprint_nested_scans(): ...@@ -364,18 +364,18 @@ def test_debugprint_nested_scans():
> | | | | |Unbroadcast{0} [id BN] > | | | | |Unbroadcast{0} [id BN]
> | | | | |ScalarFromTensor [id BW] > | | | | |ScalarFromTensor [id BW]
> | | | | |Subtensor{int64} [id BL] > | | | | |Subtensor{int64} [id BL]
> | | | |*2-<TensorType(float64, (None,))> [id BA] (inner_in_non_seqs-0) (outer_in_non_seqs-0) > | | | |*2-<TensorType(float64, (?,))> [id BA] (inner_in_non_seqs-0) (outer_in_non_seqs-0)
> | | |ScalarConstant{1} [id BX] > | | |ScalarConstant{1} [id BX]
> | |ScalarConstant{-1} [id BY] > | |ScalarConstant{-1} [id BY]
> |InplaceDimShuffle{x} [id BZ] > |InplaceDimShuffle{x} [id BZ]
> |*1-<TensorType(int64, ())> [id Z] (inner_in_seqs-1) > |*1-<TensorType(int64, ())> [id Z] (inner_in_seqs-1)
for{cpu,scan_fn} [id BH] (outer_out_sit_sot-0) for{cpu,scan_fn} [id BH] (outer_out_sit_sot-0)
-*0-<TensorType(float64, (None,))> [id CA] -> [id BI] (inner_in_sit_sot-0) -*0-<TensorType(float64, (?,))> [id CA] -> [id BI] (inner_in_sit_sot-0)
-*1-<TensorType(float64, (None,))> [id CB] -> [id BA] (inner_in_non_seqs-0) -*1-<TensorType(float64, (?,))> [id CB] -> [id BA] (inner_in_non_seqs-0)
>Elemwise{mul,no_inplace} [id CC] (inner_out_sit_sot-0) >Elemwise{mul,no_inplace} [id CC] (inner_out_sit_sot-0)
> |*0-<TensorType(float64, (None,))> [id CA] (inner_in_sit_sot-0) > |*0-<TensorType(float64, (?,))> [id CA] (inner_in_sit_sot-0)
> |*1-<TensorType(float64, (None,))> [id CB] (inner_in_non_seqs-0)""" > |*1-<TensorType(float64, (?,))> [id CB] (inner_in_non_seqs-0)"""
for truth, out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
...@@ -413,7 +413,7 @@ def test_debugprint_mitsot(): ...@@ -413,7 +413,7 @@ def test_debugprint_mitsot():
| | | | |Subtensor{int64} [id H] | | | | |Subtensor{int64} [id H]
| | | | |Shape [id I] | | | | |Shape [id I]
| | | | | |Subtensor{:int64:} [id J] | | | | | |Subtensor{:int64:} [id J]
| | | | | |<TensorType(int64, (None,))> [id K] | | | | | |<TensorType(int64, (?,))> [id K]
| | | | | |ScalarConstant{2} [id L] | | | | | |ScalarConstant{2} [id L]
| | | | |ScalarConstant{0} [id M] | | | | |ScalarConstant{0} [id M]
| | | |Subtensor{:int64:} [id J] | | | |Subtensor{:int64:} [id J]
...@@ -426,7 +426,7 @@ def test_debugprint_mitsot(): ...@@ -426,7 +426,7 @@ def test_debugprint_mitsot():
| | | |Subtensor{int64} [id R] | | | |Subtensor{int64} [id R]
| | | |Shape [id S] | | | |Shape [id S]
| | | | |Subtensor{:int64:} [id T] | | | | |Subtensor{:int64:} [id T]
| | | | |<TensorType(int64, (None,))> [id U] | | | | |<TensorType(int64, (?,))> [id U]
| | | | |ScalarConstant{2} [id V] | | | | |ScalarConstant{2} [id V]
| | | |ScalarConstant{0} [id W] | | | |ScalarConstant{0} [id W]
| | |Subtensor{:int64:} [id T] | | |Subtensor{:int64:} [id T]
...@@ -562,19 +562,19 @@ def test_debugprint_mitmot(): ...@@ -562,19 +562,19 @@ def test_debugprint_mitmot():
for{cpu,grad_of_scan_fn}.1 [id B] (outer_out_sit_sot-0) for{cpu,grad_of_scan_fn}.1 [id B] (outer_out_sit_sot-0)
>Elemwise{add,no_inplace} [id CM] (inner_out_mit_mot-0-0) >Elemwise{add,no_inplace} [id CM] (inner_out_mit_mot-0-0)
> |Elemwise{mul} [id CN] > |Elemwise{mul} [id CN]
> | |*2-<TensorType(float64, (None,))> [id CO] -> [id BL] (inner_in_mit_mot-0-0) > | |*2-<TensorType(float64, (?,))> [id CO] -> [id BL] (inner_in_mit_mot-0-0)
> | |*5-<TensorType(float64, (None,))> [id CP] -> [id P] (inner_in_non_seqs-0) > | |*5-<TensorType(float64, (?,))> [id CP] -> [id P] (inner_in_non_seqs-0)
> |*3-<TensorType(float64, (None,))> [id CQ] -> [id BL] (inner_in_mit_mot-0-1) > |*3-<TensorType(float64, (?,))> [id CQ] -> [id BL] (inner_in_mit_mot-0-1)
>Elemwise{add,no_inplace} [id CR] (inner_out_sit_sot-0) >Elemwise{add,no_inplace} [id CR] (inner_out_sit_sot-0)
> |Elemwise{mul} [id CS] > |Elemwise{mul} [id CS]
> | |*2-<TensorType(float64, (None,))> [id CO] -> [id BL] (inner_in_mit_mot-0-0) > | |*2-<TensorType(float64, (?,))> [id CO] -> [id BL] (inner_in_mit_mot-0-0)
> | |*0-<TensorType(float64, (None,))> [id CT] -> [id Z] (inner_in_seqs-0) > | |*0-<TensorType(float64, (?,))> [id CT] -> [id Z] (inner_in_seqs-0)
> |*4-<TensorType(float64, (None,))> [id CU] -> [id CE] (inner_in_sit_sot-0) > |*4-<TensorType(float64, (?,))> [id CU] -> [id CE] (inner_in_sit_sot-0)
for{cpu,scan_fn} [id F] (outer_out_sit_sot-0) for{cpu,scan_fn} [id F] (outer_out_sit_sot-0)
>Elemwise{mul,no_inplace} [id CV] (inner_out_sit_sot-0) >Elemwise{mul,no_inplace} [id CV] (inner_out_sit_sot-0)
> |*0-<TensorType(float64, (None,))> [id CT] -> [id H] (inner_in_sit_sot-0) > |*0-<TensorType(float64, (?,))> [id CT] -> [id H] (inner_in_sit_sot-0)
> |*1-<TensorType(float64, (None,))> [id CW] -> [id P] (inner_in_non_seqs-0)""" > |*1-<TensorType(float64, (?,))> [id CW] -> [id P] (inner_in_non_seqs-0)"""
for truth, out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
......
...@@ -614,8 +614,8 @@ class TestUselessElemwise: ...@@ -614,8 +614,8 @@ class TestUselessElemwise:
f2 = function([x], eq(x, x), mode=self.mode) f2 = function([x], eq(x, x), mode=self.mode)
assert np.all(f2(vx) == np.ones((5, 4))) assert np.all(f2(vx) == np.ones((5, 4)))
topo2 = f2.maker.fgraph.toposort() topo2 = f2.maker.fgraph.toposort()
# Shape_i{1}(<TensorType(float64, (None, None))>), # Shape_i{1}(<TensorType(float64, (?, ?))>),
# Shape_i{0}(<TensorType(float64, (None, None))>), Alloc([[1]], Shape_i{0}.0, # Shape_i{0}(<TensorType(float64, (?, ?))>), Alloc([[1]], Shape_i{0}.0,
# Shape_i{1}.0 # Shape_i{1}.0
assert len(topo2) == 3 assert len(topo2) == 3
assert isinstance(topo2[-1].op, Alloc) assert isinstance(topo2[-1].op, Alloc)
......
...@@ -82,6 +82,7 @@ class TestDimshuffleLift: ...@@ -82,6 +82,7 @@ class TestDimshuffleLift:
x, y, z = inputs() x, y, z = inputs()
e = ds(ds(x, (1, 0)), (1, 0)) e = ds(ds(x, (1, 0)), (1, 0))
g = FunctionGraph([x], [e]) g = FunctionGraph([x], [e])
# TODO FIXME: Construct these graphs and compare them.
assert ( assert (
str(g) == "FunctionGraph(InplaceDimShuffle{1,0}(InplaceDimShuffle{1,0}(x)))" str(g) == "FunctionGraph(InplaceDimShuffle{1,0}(InplaceDimShuffle{1,0}(x)))"
) )
...@@ -93,6 +94,7 @@ class TestDimshuffleLift: ...@@ -93,6 +94,7 @@ class TestDimshuffleLift:
x, y, z = inputs() x, y, z = inputs()
e = ds(ds(x, (1, "x", 0)), (2, 0, "x", 1)) e = ds(ds(x, (1, "x", 0)), (2, 0, "x", 1))
g = FunctionGraph([x], [e]) g = FunctionGraph([x], [e])
# TODO FIXME: Construct these graphs and compare them.
assert ( assert (
str(g) str(g)
== "FunctionGraph(InplaceDimShuffle{2,0,x,1}(InplaceDimShuffle{1,x,0}(x)))" == "FunctionGraph(InplaceDimShuffle{2,0,x,1}(InplaceDimShuffle{1,x,0}(x)))"
...@@ -106,6 +108,7 @@ class TestDimshuffleLift: ...@@ -106,6 +108,7 @@ class TestDimshuffleLift:
x, y, z = inputs() x, y, z = inputs()
e = ds(ds(ds(x, (0, "x", 1)), (2, 0, "x", 1)), (1, 0)) e = ds(ds(ds(x, (0, "x", 1)), (2, 0, "x", 1)), (1, 0))
g = FunctionGraph([x], [e]) g = FunctionGraph([x], [e])
# TODO FIXME: Construct these graphs and compare them.
assert str(g) == ( assert str(g) == (
"FunctionGraph(InplaceDimShuffle{1,0}(InplaceDimShuffle{2,0,x,1}" "FunctionGraph(InplaceDimShuffle{1,0}(InplaceDimShuffle{2,0,x,1}"
"(InplaceDimShuffle{0,x,1}(x))))" "(InplaceDimShuffle{0,x,1}(x))))"
...@@ -119,6 +122,7 @@ class TestDimshuffleLift: ...@@ -119,6 +122,7 @@ class TestDimshuffleLift:
e = x + y + z e = x + y + z
g = FunctionGraph([x, y, z], [e]) g = FunctionGraph([x, y, z], [e])
# TODO FIXME: Construct these graphs and compare them.
# It does not really matter if the DimShuffles are inplace # It does not really matter if the DimShuffles are inplace
# or not. # or not.
init_str_g_inplace = ( init_str_g_inplace = (
...@@ -149,13 +153,14 @@ class TestDimshuffleLift: ...@@ -149,13 +153,14 @@ class TestDimshuffleLift:
m = matrix(dtype="float64") m = matrix(dtype="float64")
out = ((v + 42) * (m + 84)).T out = ((v + 42) * (m + 84)).T
g = FunctionGraph([v, m], [out]) g = FunctionGraph([v, m], [out])
# TODO FIXME: Construct these graphs and compare them.
init_str_g = ( init_str_g = (
"FunctionGraph(InplaceDimShuffle{1,0}(Elemwise{mul,no_inplace}" "FunctionGraph(InplaceDimShuffle{1,0}(Elemwise{mul,no_inplace}"
"(InplaceDimShuffle{x,0}(Elemwise{add,no_inplace}" "(InplaceDimShuffle{x,0}(Elemwise{add,no_inplace}"
"(<TensorType(float64, (None,))>, " "(<TensorType(float64, (?,))>, "
"InplaceDimShuffle{x}(TensorConstant{42}))), " "InplaceDimShuffle{x}(TensorConstant{42}))), "
"Elemwise{add,no_inplace}" "Elemwise{add,no_inplace}"
"(<TensorType(float64, (None, None))>, " "(<TensorType(float64, (?, ?))>, "
"InplaceDimShuffle{x,x}(TensorConstant{84})))))" "InplaceDimShuffle{x,x}(TensorConstant{84})))))"
) )
assert str(g) == init_str_g assert str(g) == init_str_g
...@@ -163,10 +168,10 @@ class TestDimshuffleLift: ...@@ -163,10 +168,10 @@ class TestDimshuffleLift:
new_g = FunctionGraph(g.inputs, [new_out]) new_g = FunctionGraph(g.inputs, [new_out])
rewrite_str_g = ( rewrite_str_g = (
"FunctionGraph(Elemwise{mul,no_inplace}(Elemwise{add,no_inplace}" "FunctionGraph(Elemwise{mul,no_inplace}(Elemwise{add,no_inplace}"
"(InplaceDimShuffle{0,x}(<TensorType(float64, (None,))>), " "(InplaceDimShuffle{0,x}(<TensorType(float64, (?,))>), "
"InplaceDimShuffle{x,x}(TensorConstant{42})), " "InplaceDimShuffle{x,x}(TensorConstant{42})), "
"Elemwise{add,no_inplace}(InplaceDimShuffle{1,0}" "Elemwise{add,no_inplace}(InplaceDimShuffle{1,0}"
"(<TensorType(float64, (None, None))>), " "(<TensorType(float64, (?, ?))>), "
"InplaceDimShuffle{x,x}(TensorConstant{84}))))" "InplaceDimShuffle{x,x}(TensorConstant{84}))))"
) )
assert str(new_g) == rewrite_str_g assert str(new_g) == rewrite_str_g
...@@ -177,6 +182,7 @@ class TestDimshuffleLift: ...@@ -177,6 +182,7 @@ class TestDimshuffleLift:
x, _, _ = inputs() x, _, _ = inputs()
e = ds(x, (0, 1)) e = ds(x, (0, 1))
g = FunctionGraph([x], [e]) g = FunctionGraph([x], [e])
# TODO FIXME: Construct these graphs and compare them.
assert str(g) == "FunctionGraph(InplaceDimShuffle{0,1}(x))" assert str(g) == "FunctionGraph(InplaceDimShuffle{0,1}(x))"
dimshuffle_lift.rewrite(g) dimshuffle_lift.rewrite(g)
assert str(g) == "FunctionGraph(x)" assert str(g) == "FunctionGraph(x)"
...@@ -191,6 +197,7 @@ class TestDimshuffleLift: ...@@ -191,6 +197,7 @@ class TestDimshuffleLift:
ds_z = ds(z, (2, 1, 0)) # useful ds_z = ds(z, (2, 1, 0)) # useful
ds_u = ds(u, ("x")) # useful ds_u = ds(u, ("x")) # useful
g = FunctionGraph([x, y, z, u], [ds_x, ds_y, ds_z, ds_u]) g = FunctionGraph([x, y, z, u], [ds_x, ds_y, ds_z, ds_u])
# TODO FIXME: Construct these graphs and compare them.
assert ( assert (
str(g) str(g)
== "FunctionGraph(InplaceDimShuffle{0,x}(x), InplaceDimShuffle{2,1,0}(y), InplaceDimShuffle{2,1,0}(z), InplaceDimShuffle{x}(TensorConstant{1}))" == "FunctionGraph(InplaceDimShuffle{0,x}(x), InplaceDimShuffle{2,1,0}(y), InplaceDimShuffle{2,1,0}(z), InplaceDimShuffle{x}(TensorConstant{1}))"
...@@ -225,6 +232,7 @@ def test_local_useless_dimshuffle_in_reshape(): ...@@ -225,6 +232,7 @@ def test_local_useless_dimshuffle_in_reshape():
], ],
) )
# TODO FIXME: Construct these graphs and compare them.
assert str(g) == ( assert str(g) == (
"FunctionGraph(Reshape{1}(InplaceDimShuffle{x,0}(vector), Shape(vector)), " "FunctionGraph(Reshape{1}(InplaceDimShuffle{x,0}(vector), Shape(vector)), "
"Reshape{2}(InplaceDimShuffle{x,0,x,1}(mat), Shape(mat)), " "Reshape{2}(InplaceDimShuffle{x,0,x,1}(mat), Shape(mat)), "
......
...@@ -513,7 +513,7 @@ def makeSharedTester( ...@@ -513,7 +513,7 @@ def makeSharedTester(
) )
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
f() f()
# [Gemm{inplace}(<TensorType(float64, (None, None))>, 0.01, <TensorType(float64, (None, None))>, <TensorType(float64, (None, None))>, 2e-06)] # [Gemm{inplace}(<TensorType(float64, (?, ?))>, 0.01, <TensorType(float64, (?, ?))>, <TensorType(float64, (?, ?))>, 2e-06)]
if aesara.config.mode != "FAST_COMPILE": if aesara.config.mode != "FAST_COMPILE":
assert ( assert (
sum( sum(
......
...@@ -282,7 +282,7 @@ def test_debugprint(): ...@@ -282,7 +282,7 @@ def test_debugprint():
| | |B | | |B
| |TensorConstant{1.0} | |TensorConstant{1.0}
| |B | |B
| |<TensorType(float64, (None,))> | |<TensorType(float64, (?,))>
| |TensorConstant{0.0} | |TensorConstant{0.0}
|D |D
""" """
...@@ -306,9 +306,9 @@ def test_debugprint_id_type(): ...@@ -306,9 +306,9 @@ def test_debugprint_id_type():
exp_res = f"""Elemwise{{add,no_inplace}} [id {e_at.auto_name}] exp_res = f"""Elemwise{{add,no_inplace}} [id {e_at.auto_name}]
|dot [id {d_at.auto_name}] |dot [id {d_at.auto_name}]
| |<TensorType(float64, (None, None))> [id {b_at.auto_name}] | |<TensorType(float64, (?, ?))> [id {b_at.auto_name}]
| |<TensorType(float64, (None,))> [id {a_at.auto_name}] | |<TensorType(float64, (?,))> [id {a_at.auto_name}]
|<TensorType(float64, (None,))> [id {a_at.auto_name}] |<TensorType(float64, (?,))> [id {a_at.auto_name}]
""" """
assert [l.strip() for l in s.split("\n")] == [ assert [l.strip() for l in s.split("\n")] == [
...@@ -319,7 +319,7 @@ def test_debugprint_id_type(): ...@@ -319,7 +319,7 @@ def test_debugprint_id_type():
def test_pprint(): def test_pprint():
x = dvector() x = dvector()
y = x[1] y = x[1]
assert pp(y) == "<TensorType(float64, (None,))>[1]" assert pp(y) == "<TensorType(float64, (?,))>[1]"
def test_debugprint_inner_graph(): def test_debugprint_inner_graph():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论