!49135 算子ScalarToTensor针对bool类型的变量,动静行为不一致,问题修正

Merge pull request !49135 from tangdezhi_123/master
This commit is contained in:
i-robot 2023-02-21 11:08:27 +00:00 committed by Gitee
commit d06dc289bf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 5 additions and 5 deletions

View File

@ -6,11 +6,11 @@ mindspore.ops.scalar_to_tensor
将Scalar转换为指定数据类型的Tensor。
参数:
- **input_x** (Union[int, float]) - 输入是Scalar。只能是常量值。
- **input_x** (Union[bool, int, float]) - 输入是Scalar。只能是常量值。
- **dtype** (mindspore.dtype) - 指定输出的数据类型。只能是常量值。默认值mindspore.float32。
返回:
Tensor零维Tensor其值和输入一致。
异常:
- **TypeError** - `input_x` 既不是int也不是float。
- **TypeError** - `input_x` 既不是bool, 也不是intfloat。

View File

@ -4702,7 +4702,7 @@ def scalar_to_tensor(input_x, dtype=mstype.float32):
Converts a scalar to a `Tensor`, and converts the data type to the specified type.
Args:
input_x (Union[int, float]): The input is a scalar. Only constant value is allowed.
input_x (Union[bool, int, float]): The input is a scalar. Only constant value is allowed.
dtype (mindspore.dtype): The target data type. Default: mindspore.float32. Only
constant value is allowed.
@ -4710,7 +4710,7 @@ def scalar_to_tensor(input_x, dtype=mstype.float32):
Tensor. 0-D Tensor and the content is the input.
Raises:
TypeError: If `input_x` is neither int nor float.
TypeError: If `input_x` is neither bool nor int nor float.
Supported Platforms:
``Ascend`` ``GPU`` ``CPU``

View File

@ -1762,7 +1762,7 @@ class ScalarToTensor(PrimitiveWithInfer):
self.init_prim_io_names(inputs=['input_scalar', 'dtype'], outputs=['output_data'])
def __call__(self, x, dtype=mstype.float32):
validator.check_value_type("x", x, [int, float], self.name)
validator.check_value_type("x", x, [bool, int, float], self.name)
validator.check_subclass("dtype", dtype, mstype.number, self.name)
data_type = mstype.dtype_to_nptype(dtype)
return Tensor(np.array(x, data_type))