forked from mindspore-Ecosystem/mindspore
!49135 算子ScalarToTensor针对bool类型的变量,动静行为不一致,问题修正
Merge pull request !49135 from tangdezhi_123/master
This commit is contained in:
commit
d06dc289bf
|
@ -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, 也不是int,float。
|
|
@ -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``
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue