Skip to content

Commit 7736732

Browse files
brandonwillardtwiecki
authored andcommitted
Print type name in theano.graph.basic.__str__
1 parent 808136d commit 7736732

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

tests/scalar/test_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def test_composite_printing(self):
176176
assert str(g) == (
177177
"FunctionGraph(*1 -> Composite{((i0 + i1) + i2),"
178178
" (i0 + (i1 * i2)), (i0 / i1), "
179-
"(i0 // Constant{5}), "
179+
"(i0 // ScalarConstant{5}), "
180180
"(-i0), (i0 - i1), ((i0 ** i1) + (-i2)),"
181-
" (i0 % Constant{3})}(x, y, z), "
181+
" (i0 % ScalarConstant{3})}(x, y, z), "
182182
"*1::1, *1::2, *1::3, *1::4, *1::5, *1::6, *1::7)"
183183
)
184184

tests/test_printing.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,17 @@ def test_scan_debugprint1():
284284
| | | | | | |A [id M]
285285
| | | | | | |InplaceDimShuffle{x} [id N] ''
286286
| | | | | | |TensorConstant{1.0} [id O]
287-
| | | | | |Constant{0} [id P]
287+
| | | | | |ScalarConstant{0} [id P]
288288
| | | | |Subtensor{int64} [id Q] ''
289289
| | | | |Shape [id R] ''
290290
| | | | | |Rebroadcast{0} [id J] ''
291-
| | | | |Constant{1} [id S]
291+
| | | | |ScalarConstant{1} [id S]
292292
| | | |Rebroadcast{0} [id J] ''
293293
| | | |ScalarFromTensor [id T] ''
294294
| | | |Subtensor{int64} [id H] ''
295295
| | |A [id M]
296-
| |Constant{1} [id U]
297-
|Constant{-1} [id V]
296+
| |ScalarConstant{1} [id U]
297+
|ScalarConstant{-1} [id V]
298298
299299
Inner graphs of the scan ops:
300300
@@ -334,17 +334,17 @@ def test_scan_debugprint2():
334334
| | |Shape [id E] ''
335335
| | | |Subtensor{int64::} [id F] 'coefficients[0:]'
336336
| | | |coefficients [id G]
337-
| | | |Constant{0} [id H]
338-
| | |Constant{0} [id I]
337+
| | | |ScalarConstant{0} [id H]
338+
| | |ScalarConstant{0} [id I]
339339
| |Subtensor{int64} [id J] ''
340340
| |Shape [id K] ''
341341
| | |Subtensor{int64::} [id L] ''
342342
| | |ARange{dtype='int64'} [id M] ''
343343
| | | |TensorConstant{0} [id N]
344344
| | | |TensorConstant{10000} [id O]
345345
| | | |TensorConstant{1} [id P]
346-
| | |Constant{0} [id Q]
347-
| |Constant{0} [id R]
346+
| | |ScalarConstant{0} [id Q]
347+
| |ScalarConstant{0} [id R]
348348
|Subtensor{:int64:} [id S] ''
349349
| |Subtensor{int64::} [id F] 'coefficients[0:]'
350350
| |ScalarFromTensor [id T] ''
@@ -413,17 +413,17 @@ def compute_A_k(A, k):
413413
| | |Shape [id E] ''
414414
| | | |Subtensor{int64::} [id F] 'coefficients[0:]'
415415
| | | |coefficients [id G]
416-
| | | |Constant{0} [id H]
417-
| | |Constant{0} [id I]
416+
| | | |ScalarConstant{0} [id H]
417+
| | |ScalarConstant{0} [id I]
418418
| |Subtensor{int64} [id J] ''
419419
| |Shape [id K] ''
420420
| | |Subtensor{int64::} [id L] ''
421421
| | |ARange{dtype='int64'} [id M] ''
422422
| | | |TensorConstant{0} [id N]
423423
| | | |TensorConstant{10} [id O]
424424
| | | |TensorConstant{1} [id P]
425-
| | |Constant{0} [id Q]
426-
| |Constant{0} [id R]
425+
| | |ScalarConstant{0} [id Q]
426+
| |ScalarConstant{0} [id R]
427427
|Subtensor{:int64:} [id S] ''
428428
| |Subtensor{int64::} [id F] 'coefficients[0:]'
429429
| |ScalarFromTensor [id T] ''
@@ -459,17 +459,17 @@ def compute_A_k(A, k):
459459
> | | | | | | | |A_copy [id BO] -> [id W]
460460
> | | | | | | | |InplaceDimShuffle{x} [id BP] ''
461461
> | | | | | | | |TensorConstant{1.0} [id BQ]
462-
> | | | | | | |Constant{0} [id BR]
462+
> | | | | | | |ScalarConstant{0} [id BR]
463463
> | | | | | |Subtensor{int64} [id BS] ''
464464
> | | | | | |Shape [id BT] ''
465465
> | | | | | | |Rebroadcast{0} [id BL] ''
466-
> | | | | | |Constant{1} [id BU]
466+
> | | | | | |ScalarConstant{1} [id BU]
467467
> | | | | |Rebroadcast{0} [id BL] ''
468468
> | | | | |ScalarFromTensor [id BV] ''
469469
> | | | | |Subtensor{int64} [id BJ] ''
470470
> | | | |A_copy [id BO] -> [id W]
471-
> | | |Constant{1} [id BW]
472-
> | |Constant{-1} [id BX]
471+
> | | |ScalarConstant{1} [id BW]
472+
> | |ScalarConstant{-1} [id BX]
473473
> |InplaceDimShuffle{x} [id BY] ''
474474
> |<TensorType(int64, scalar)> [id BZ] -> [id U]
475475
@@ -514,8 +514,8 @@ def fn(a_m2, a_m1, b_m2, b_m1):
514514
| | | | |Shape [id I] ''
515515
| | | | | |Subtensor{:int64:} [id J] ''
516516
| | | | | |<TensorType(int64, vector)> [id K]
517-
| | | | | |Constant{2} [id L]
518-
| | | | |Constant{0} [id M]
517+
| | | | | |ScalarConstant{2} [id L]
518+
| | | | |ScalarConstant{0} [id M]
519519
| | | |Subtensor{:int64:} [id J] ''
520520
| | | |ScalarFromTensor [id N] ''
521521
| | | |Subtensor{int64} [id H] ''
@@ -527,15 +527,15 @@ def fn(a_m2, a_m1, b_m2, b_m1):
527527
| | | |Shape [id S] ''
528528
| | | | |Subtensor{:int64:} [id T] ''
529529
| | | | |<TensorType(int64, vector)> [id U]
530-
| | | | |Constant{2} [id V]
531-
| | | |Constant{0} [id W]
530+
| | | | |ScalarConstant{2} [id V]
531+
| | | |ScalarConstant{0} [id W]
532532
| | |Subtensor{:int64:} [id T] ''
533533
| | |ScalarFromTensor [id X] ''
534534
| | |Subtensor{int64} [id R] ''
535-
| |Constant{2} [id Y]
535+
| |ScalarConstant{2} [id Y]
536536
|Subtensor{int64::} [id Z] ''
537537
|for{cpu,scan_fn}.1 [id C] ''
538-
|Constant{2} [id BA]
538+
|ScalarConstant{2} [id BA]
539539
540540
Inner graphs of the scan ops:
541541
@@ -592,31 +592,31 @@ def test_scan_debugprint5():
592592
| | | | | | | | |A [id P]
593593
| | | | | | | | |InplaceDimShuffle{x} [id Q] ''
594594
| | | | | | | | |TensorConstant{1.0} [id R]
595-
| | | | | | | |Constant{0} [id S]
595+
| | | | | | | |ScalarConstant{0} [id S]
596596
| | | | | | |Subtensor{int64} [id T] ''
597597
| | | | | | |Shape [id U] ''
598598
| | | | | | | |Rebroadcast{0} [id M] ''
599-
| | | | | | |Constant{1} [id V]
599+
| | | | | | |ScalarConstant{1} [id V]
600600
| | | | | |Rebroadcast{0} [id M] ''
601601
| | | | | |ScalarFromTensor [id W] ''
602602
| | | | | |Subtensor{int64} [id K] ''
603603
| | | | |A [id P]
604-
| | | |Constant{0} [id X]
604+
| | | |ScalarConstant{0} [id X]
605605
| | |TensorConstant{1} [id Y]
606606
| |Subtensor{:int64:} [id Z] ''
607607
| | |Subtensor{::int64} [id BA] ''
608608
| | | |Subtensor{:int64:} [id BB] ''
609609
| | | | |for{cpu,scan_fn} [id F] ''
610-
| | | | |Constant{-1} [id BC]
611-
| | | |Constant{-1} [id BD]
610+
| | | | |ScalarConstant{-1} [id BC]
611+
| | | |ScalarConstant{-1} [id BD]
612612
| | |ScalarFromTensor [id BE] ''
613613
| | |Elemwise{sub,no_inplace} [id C] ''
614614
| |Subtensor{:int64:} [id BF] ''
615615
| | |Subtensor{:int64:} [id BG] ''
616616
| | | |Subtensor{::int64} [id BH] ''
617617
| | | | |for{cpu,scan_fn} [id F] ''
618-
| | | | |Constant{-1} [id BI]
619-
| | | |Constant{-1} [id BJ]
618+
| | | | |ScalarConstant{-1} [id BI]
619+
| | | |ScalarConstant{-1} [id BJ]
620620
| | |ScalarFromTensor [id BK] ''
621621
| | |Elemwise{sub,no_inplace} [id C] ''
622622
| |Subtensor{::int64} [id BL] ''
@@ -629,21 +629,21 @@ def test_scan_debugprint5():
629629
| | | | |Elemwise{second,no_inplace} [id BR] ''
630630
| | | | | |Subtensor{int64::} [id BS] ''
631631
| | | | | | |for{cpu,scan_fn} [id F] ''
632-
| | | | | | |Constant{1} [id BT]
632+
| | | | | | |ScalarConstant{1} [id BT]
633633
| | | | | |InplaceDimShuffle{x,x} [id BU] ''
634634
| | | | | |TensorConstant{0.0} [id BV]
635635
| | | | |Elemwise{second} [id BW] ''
636636
| | | | | |Subtensor{int64} [id BX] ''
637637
| | | | | | |Subtensor{int64::} [id BS] ''
638-
| | | | | | |Constant{-1} [id BY]
638+
| | | | | | |ScalarConstant{-1} [id BY]
639639
| | | | | |InplaceDimShuffle{x} [id BZ] ''
640640
| | | | | |Elemwise{second,no_inplace} [id CA] ''
641641
| | | | | |Sum{acc_dtype=float64} [id CB] ''
642642
| | | | | | |Subtensor{int64} [id BX] ''
643643
| | | | | |TensorConstant{1.0} [id CC]
644-
| | | | |Constant{-1} [id BY]
645-
| | | |Constant{1} [id BT]
646-
| | |Constant{-1} [id CD]
644+
| | | | |ScalarConstant{-1} [id BY]
645+
| | | |ScalarConstant{1} [id BT]
646+
| | |ScalarConstant{-1} [id CD]
647647
| |Alloc [id CE] ''
648648
| | |TensorConstant{0.0} [id CF]
649649
| | |Elemwise{add,no_inplace} [id CG] ''
@@ -652,9 +652,9 @@ def test_scan_debugprint5():
652652
| | |Subtensor{int64} [id CI] ''
653653
| | |Shape [id CJ] ''
654654
| | | |A [id P]
655-
| | |Constant{0} [id CK]
655+
| | |ScalarConstant{0} [id CK]
656656
| |A [id P]
657-
|Constant{-1} [id CL]
657+
|ScalarConstant{-1} [id CL]
658658
659659
Inner graphs of the scan ops:
660660
@@ -711,4 +711,4 @@ def f_pow2(x_tm1):
711711
def test_subtensor():
712712
x = dvector()
713713
y = x[1]
714-
assert pp(y) == "<TensorType(float64, vector)>[Constant{1}]"
714+
assert pp(y) == "<TensorType(float64, vector)>[ScalarConstant{1}]"

theano/graph/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ def __str__(self):
630630
name = str(self.data)
631631
if len(name) > 20:
632632
name = name[:10] + "..." + name[-10:]
633-
return "Constant{%s}" % name
633+
return f"{type(self).__name__}{{{name}}}"
634634

635635
def clone(self):
636636
"""

0 commit comments

Comments
 (0)