Skip to content

Commit 87b424e

Browse files
committed
Follow comments
1 parent 9f731a6 commit 87b424e

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

python/paddle/v2/fluid/layers/math_op_patch.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
def monkey_patch_variable():
22-
def new_name():
22+
def unique_tmp_name():
2323
return unique_name("tmp")
2424

2525
def safe_get_dtype(var):
@@ -29,21 +29,9 @@ def safe_get_dtype(var):
2929
raise ValueError("Cannot get data type from %s", var.name)
3030
return dtype
3131

32-
def create_scalar(block, value, dtype):
33-
value = float(value)
34-
tmp_name = new_name()
35-
var = block.create_var(name=tmp_name, shape=[1], dtype=dtype)
36-
block.append_op(
37-
type="fill",
38-
outputs={"Out": [var]},
39-
attrs={"value": [value],
40-
"shape": [1],
41-
"dtype": dtype})
42-
return var
43-
4432
def create_tensor(block, value, dtype, shape):
4533
value = float(value)
46-
tmp_name = new_name()
34+
tmp_name = unique_tmp_name()
4735
var = block.create_var(name=tmp_name, shape=shape, dtype=dtype)
4836
block.append_op(
4937
type="fill_constant",
@@ -53,10 +41,13 @@ def create_tensor(block, value, dtype, shape):
5341
'value': value})
5442
return var
5543

44+
def create_scalar(block, value, dtype):
45+
return create_tensor(block, value, dtype, shape=[1])
46+
5647
def create_tensor_with_batchsize(ref_var, value, dtype):
5748
assert isinstance(ref_var, Variable)
5849
value = float(value)
59-
tmp_name = new_name()
50+
tmp_name = unique_tmp_name()
6051
var = ref_var.block.create_var(name=tmp_name, dtype=dtype)
6152
ref_var.block.append_op(
6253
type='fill_constant_batch_size_like',
@@ -68,7 +59,7 @@ def create_tensor_with_batchsize(ref_var, value, dtype):
6859

6960
def astype(self, dtype):
7061
"""
71-
Cast a variable to data type.
62+
Cast a variable to a specified data type.
7263
NOTE: The variable must be a Tensor
7364
Args:
7465
self(Variable): The source variable
@@ -77,7 +68,7 @@ def astype(self, dtype):
7768
Returns:
7869
Variable with new dtype
7970
"""
80-
tmp_name = new_name()
71+
tmp_name = unique_tmp_name()
8172
out = self.block.create_var(name=tmp_name, dtype=dtype)
8273
self.block.append_op(
8374
type="cast",
@@ -120,7 +111,7 @@ def __impl__(self, other_var):
120111
self = other_var
121112
other_var = tmp
122113

123-
tmp_name = new_name()
114+
tmp_name = unique_tmp_name()
124115
out = self.block.create_var(name=tmp_name, dtype=lhs_dtype)
125116
self.block.append_op(
126117
type=op_type,

0 commit comments

Comments
 (0)