2323import numpy as np
2424# TODO: define functions to manipulate a tensor
2525from ..fluid .layers import cast #DEFINE_ALIAS
26- from ..fluid .layers import expand_as #DEFINE_ALIAS
2726from ..fluid .layers import slice #DEFINE_ALIAS
2827from ..fluid .layers import strided_slice #DEFINE_ALIAS
2928from ..fluid .layers import transpose #DEFINE_ALIAS
@@ -1100,6 +1099,9 @@ def tile(x, repeat_times, name=None):
11001099 np_out = out.numpy()
11011100 # [[1, 2, 3], [1, 2, 3]]
11021101 """
1102+ if in_dygraph_mode ():
1103+ return core .ops .tile (x , 'repeat_times' , repeat_times )
1104+
11031105 check_variable_and_dtype (
11041106 x , 'x' , ['bool' , 'float32' , 'float64' , 'int32' , 'int64' ], 'tile' )
11051107 check_type (repeat_times , 'repeat_times' , (list , tuple , Variable ), 'tile' )
@@ -1109,9 +1111,6 @@ def tile(x, repeat_times, name=None):
11091111 "must set its stop_gradient to be True by "
11101112 "some_var.stop_gradient == True supporting some_var is the input." )
11111113
1112- if in_dygraph_mode ():
1113- return core .ops .tile (x , 'repeat_times' , repeat_times )
1114-
11151114 helper = LayerHelper ('tile' , ** locals ())
11161115
11171116 inputs = {"X" : [x ]}
@@ -1176,6 +1175,9 @@ def expand_as(x, y, name=None):
11761175 np_out = out.numpy()
11771176 # [[1, 2, 3], [1, 2, 3]]
11781177 """
1178+ if in_dygraph_mode ():
1179+ return core .ops .expand_as_v2 (x , y )
1180+
11791181 check_variable_and_dtype (
11801182 x , 'x' , ['bool' , 'float32' , 'float64' , 'int32' , 'int64' ], 'expand_as' )
11811183 check_type (y , 'y' , Variable , 'expand_as' )
@@ -1188,9 +1190,6 @@ def expand_as(x, y, name=None):
11881190 "some_var as the input 'x'." )
11891191 inputs = {"X" : [x ], "target_tensor" : [y ]}
11901192
1191- if in_dygraph_mode ():
1192- return core .ops .expand_as_v2 (x , y )
1193-
11941193 helper = LayerHelper ('expand_as' , ** locals ())
11951194 dtype = helper .input_dtype (input_param_name = 'x' )
11961195 out = helper .create_variable_for_type_inference (dtype )
@@ -1229,6 +1228,9 @@ def expand(x, shape, name=None):
12291228 out = out.numpy()
12301229 # [[1, 2, 3], [1, 2, 3]]
12311230 """
1231+ if in_dygraph_mode ():
1232+ return core .ops .expand_v2 (x , 'shape' , shape )
1233+
12321234 check_variable_and_dtype (
12331235 x , 'x' , ['bool' , 'float32' , 'float64' , 'int32' , 'int64' ], 'expand' )
12341236 check_type (shape , 'shape' , (list , tuple , Variable ), 'expand' )
@@ -1241,9 +1243,6 @@ def expand(x, shape, name=None):
12411243 "some_var.stop_gradient = True, supporting "
12421244 "some_var as the input." )
12431245
1244- if in_dygraph_mode ():
1245- return core .ops .expand_v2 (x , 'shape' , shape )
1246-
12471246 helper = LayerHelper ('expand' , ** locals ())
12481247
12491248 def get_attr_expand_shape (list_expand_shape ):
0 commit comments