|
|
@ -18,7 +18,7 @@ from ..layer_helper import LayerHelper
|
|
|
|
from ..param_attr import ParamAttr
|
|
|
|
from ..param_attr import ParamAttr
|
|
|
|
from ..framework import convert_np_dtype_to_dtype_, in_dygraph_mode, _varbase_creator
|
|
|
|
from ..framework import convert_np_dtype_to_dtype_, in_dygraph_mode, _varbase_creator
|
|
|
|
from ..framework import Variable
|
|
|
|
from ..framework import Variable
|
|
|
|
from ..initializer import Constant, force_init_on_cpu
|
|
|
|
from ..initializer import Constant
|
|
|
|
from ..core import VarDesc
|
|
|
|
from ..core import VarDesc
|
|
|
|
from .. import core
|
|
|
|
from .. import core
|
|
|
|
from .layer_function_generator import templatedoc
|
|
|
|
from .layer_function_generator import templatedoc
|
|
|
@ -569,10 +569,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
|
|
|
|
shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2]
|
|
|
|
shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2]
|
|
|
|
data4 = fluid.layers.fill_constant(shape=shape, dtype='bool', value=True) # data4=[[True,True],[True,True]]
|
|
|
|
data4 = fluid.layers.fill_constant(shape=shape, dtype='bool', value=True) # data4=[[True,True],[True,True]]
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
attrs = {
|
|
|
|
attrs = {'value': float(value), 'force_cpu': force_cpu}
|
|
|
|
'value': float(value),
|
|
|
|
|
|
|
|
'force_cpu': force_cpu or force_init_on_cpu()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if convert_dtype(dtype) in ['int64', 'int32']:
|
|
|
|
if convert_dtype(dtype) in ['int64', 'int32']:
|
|
|
|
attrs['str_value'] = str(int(value))
|
|
|
|
attrs['str_value'] = str(int(value))
|
|
|
@ -601,10 +598,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
|
|
|
|
'fill_constant')
|
|
|
|
'fill_constant')
|
|
|
|
check_type(shape, 'shape', (Variable, list, tuple), 'fill_constant')
|
|
|
|
check_type(shape, 'shape', (Variable, list, tuple), 'fill_constant')
|
|
|
|
inputs = {}
|
|
|
|
inputs = {}
|
|
|
|
attrs = {
|
|
|
|
attrs = {'value': float(value), 'force_cpu': force_cpu}
|
|
|
|
'value': float(value),
|
|
|
|
|
|
|
|
'force_cpu': force_cpu or force_init_on_cpu()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if convert_dtype(dtype) in ['int64', 'int32']:
|
|
|
|
if convert_dtype(dtype) in ['int64', 'int32']:
|
|
|
|
attrs['str_value'] = str(int(value))
|
|
|
|
attrs['str_value'] = str(int(value))
|
|
|
@ -722,7 +716,7 @@ def fill_constant_batch_size_like(input,
|
|
|
|
'value': float(value),
|
|
|
|
'value': float(value),
|
|
|
|
'input_dim_idx': input_dim_idx,
|
|
|
|
'input_dim_idx': input_dim_idx,
|
|
|
|
'output_dim_idx': output_dim_idx,
|
|
|
|
'output_dim_idx': output_dim_idx,
|
|
|
|
'force_cpu': force_cpu or force_init_on_cpu()
|
|
|
|
'force_cpu': force_cpu
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if convert_dtype(dtype) in ['int64', 'int32']:
|
|
|
|
if convert_dtype(dtype) in ['int64', 'int32']:
|
|
|
|
attrs['str_value'] = str(int(value))
|
|
|
|
attrs['str_value'] = str(int(value))
|
|
|
|