| @@ -27,12 +27,12 @@ from .._c_expression import Tensor as Tensor_ | |||||
| from .._c_expression.typing import Float | from .._c_expression.typing import Float | ||||
| from .utils import _check_input_for_asarray, _deep_list, _deep_tensor_to_nparray, \ | from .utils import _check_input_for_asarray, _deep_list, _deep_tensor_to_nparray, \ | ||||
| _expand, _broadcast_to_shape, _check_input_tensor, _convert_64_to_32, _get_dtype_from_scalar | |||||
| _broadcast_to_shape, _check_input_tensor, _convert_64_to_32, _get_dtype_from_scalar | |||||
| from .utils_const import _raise_value_error, _empty, _check_axis_valid, _max, _min, \ | from .utils_const import _raise_value_error, _empty, _check_axis_valid, _max, _min, \ | ||||
| _check_same_type, _is_shape_empty, _check_shape, _check_dtype, _tile_size, _abs, \ | _check_same_type, _is_shape_empty, _check_shape, _check_dtype, _tile_size, _abs, \ | ||||
| _raise_type_error, _expanded_shape, _check_is_float, _iota, \ | _raise_type_error, _expanded_shape, _check_is_float, _iota, \ | ||||
| _type_convert, _canonicalize_axis, _list_comprehensions, _ceil | _type_convert, _canonicalize_axis, _list_comprehensions, _ceil | ||||
| from .array_ops import transpose, ravel, concatenate, broadcast_arrays, reshape | |||||
| from .array_ops import transpose, ravel, concatenate, broadcast_arrays, reshape, broadcast_to | |||||
| from .dtypes import nan | from .dtypes import nan | ||||
| # According to official numpy reference, the dimension of a numpy array must be less | # According to official numpy reference, the dimension of a numpy array must be less | ||||
| @@ -355,9 +355,7 @@ def full(shape, fill_value, dtype=None): | |||||
| return F.fill(dtype, shape, fill_value) | return F.fill(dtype, shape, fill_value) | ||||
| if isinstance(fill_value, (list, tuple)): | if isinstance(fill_value, (list, tuple)): | ||||
| fill_value = asarray_const(fill_value) | fill_value = asarray_const(fill_value) | ||||
| if isinstance(fill_value, Tensor): | |||||
| fill_value = _expand(fill_value, len(shape)) | |||||
| return F.tile(fill_value, _tile_size(fill_value.shape, shape, len(shape))) | |||||
| return broadcast_to(fill_value, shape) | |||||
| # if shape contains zero, use c.Tensor() | # if shape contains zero, use c.Tensor() | ||||
| return _convert_64_to_32(empty_compile(dtype, shape)) | return _convert_64_to_32(empty_compile(dtype, shape)) | ||||
| @@ -366,9 +364,6 @@ def arange(start, stop=None, step=None, dtype=None): | |||||
| """ | """ | ||||
| Returns evenly spaced values within a given interval. | Returns evenly spaced values within a given interval. | ||||
| Returns `num` evenly spaced samples, calculated over the interval :math:`[start, stop]`. | |||||
| The endpoint of the interval can optionally be excluded. | |||||
| Args: | Args: | ||||
| start(Union[int, float]): Start of interval. The interval includes this value. | start(Union[int, float]): Start of interval. The interval includes this value. | ||||
| When `stop` is provided as a position argument, `start` must be given, when `stop` | When `stop` is provided as a position argument, `start` must be given, when `stop` | ||||
| @@ -92,7 +92,7 @@ def expand_dims(a, axis): | |||||
| the new axis is placed, | the new axis is placed, | ||||
| Returns: | Returns: | ||||
| View of `a` with the number of dimensions increased. | |||||
| Tensor, with the number of dimensions increased at specified axis. | |||||
| Raises: | Raises: | ||||
| TypeError: If input arguments have types not specified above. | TypeError: If input arguments have types not specified above. | ||||
| @@ -822,7 +822,7 @@ def atleast_1d(*arys): | |||||
| def atleast_2d(*arys): | def atleast_2d(*arys): | ||||
| """ | """ | ||||
| Views inputs as arrays with at least two dimensions. | |||||
| Reshapes inputs as arrays with at least two dimensions. | |||||
| Note: | Note: | ||||
| In graph mode, returns a tuple of tensor instead of a list of | In graph mode, returns a tuple of tensor instead of a list of | ||||
| @@ -859,7 +859,7 @@ def atleast_2d(*arys): | |||||
| def atleast_3d(*arys): | def atleast_3d(*arys): | ||||
| """ | """ | ||||
| Views inputs as arrays with at least three dimensions. | |||||
| Reshapes inputs as arrays with at least three dimensions. | |||||
| Note: | Note: | ||||
| In graph mode, returns a tuple of tensor instead of a list of | In graph mode, returns a tuple of tensor instead of a list of | ||||
| @@ -870,8 +870,8 @@ def atleast_3d(*arys): | |||||
| Returns: | Returns: | ||||
| Tensor, or list of tensors, each with ``a.ndim >= 3``. For example, | Tensor, or list of tensors, each with ``a.ndim >= 3``. For example, | ||||
| a 1-D array of shape `(N,)` becomes a view of shape `(1, N, 1)`, and | |||||
| a 2-D array of shape `(M, N)` becomes a view of shape `(M, N, 1)`. | |||||
| a 1-D array of shape `(N,)` becomes a tensor of shape `(1, N, 1)`, and | |||||
| a 2-D array of shape `(M, N)` becomes a tensor of shape `(M, N, 1)`. | |||||
| Raises: | Raises: | ||||
| TypeError: if the input is not a tensor. | TypeError: if the input is not a tensor. | ||||
| @@ -1591,7 +1591,7 @@ def flip(m, axis=None): | |||||
| all of the axes specified in the tuple. | all of the axes specified in the tuple. | ||||
| Returns: | Returns: | ||||
| Tensor, a view of `m` with the entries of `axis` reversed. | |||||
| Tensor, with the entries of `axis` reversed. | |||||
| Raises: | Raises: | ||||
| TypeError: if the input is not a tensor. | TypeError: if the input is not a tensor. | ||||
| @@ -95,7 +95,7 @@ def less_equal(x1, x2, out=None, where=True, dtype=None): | |||||
| Returns: | Returns: | ||||
| Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | ||||
| bool, unless ``dtype=object`` is passed. This is a scalar if both `x1` and `x2` are | |||||
| bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are | |||||
| scalars. | scalars. | ||||
| Raises: | Raises: | ||||
| @@ -142,7 +142,7 @@ def less(x1, x2, out=None, where=True, dtype=None): | |||||
| Returns: | Returns: | ||||
| Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | ||||
| bool, unless ``dtype=object`` is passed. This is a scalar if both `x1` and `x2` are | |||||
| bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are | |||||
| scalars. | scalars. | ||||
| Raises: | Raises: | ||||
| @@ -188,7 +188,7 @@ def greater_equal(x1, x2, out=None, where=True, dtype=None): | |||||
| Returns: | Returns: | ||||
| Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | ||||
| bool, unless ``dtype=object`` is passed. This is a scalar if both `x1` and `x2` are | |||||
| bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are | |||||
| scalars. | scalars. | ||||
| Raises: | Raises: | ||||
| @@ -234,7 +234,7 @@ def greater(x1, x2, out=None, where=True, dtype=None): | |||||
| Returns: | Returns: | ||||
| Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | ||||
| bool, unless ``dtype=object`` is passed. This is a scalar if both `x1` and `x2` are | |||||
| bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are | |||||
| scalars. | scalars. | ||||
| Raises: | Raises: | ||||
| @@ -280,7 +280,7 @@ def equal(x1, x2, out=None, where=True, dtype=None): | |||||
| Returns: | Returns: | ||||
| Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type | ||||
| bool, unless ``dtype=object`` is passed. This is a scalar if both `x1` and `x2` are | |||||
| bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are | |||||
| scalars. | scalars. | ||||
| Raises: | Raises: | ||||
| @@ -1692,7 +1692,7 @@ def amin(a, axis=None, keepdims=False, initial=None, where=True): | |||||
| a (Tensor): Input data. | a (Tensor): Input data. | ||||
| axis (None or int or tuple of ints, optional): defaults to None. Axis or | axis (None or int or tuple of ints, optional): defaults to None. Axis or | ||||
| axes along which to operate. By default, flattened input is used. If | axes along which to operate. By default, flattened input is used. If | ||||
| this is a tuple of ints, the maximum is selected over multiple axes, | |||||
| this is a tuple of ints, the minimum is selected over multiple axes, | |||||
| instead of a single axis or all the axes as before. | instead of a single axis or all the axes as before. | ||||
| keepdims (boolean, optional): defaults to False. | keepdims (boolean, optional): defaults to False. | ||||
| If this is set to True, the axes which are reduced are left in the | If this is set to True, the axes which are reduced are left in the | ||||
| @@ -58,7 +58,7 @@ def count_nonzero(x, axis=(), keep_dims=False, dtype=mstype.int32): | |||||
| Tensor, number of nonzero element. The data type is dtype. | Tensor, number of nonzero element. The data type is dtype. | ||||
| Supported Platforms: | Supported Platforms: | ||||
| ``Ascend`` ``GPU`` | |||||
| ``Ascend`` ``GPU`` ``CPU`` | |||||
| Examples: | Examples: | ||||
| >>> input_x = Tensor(np.array([[0, 1, 0], [1, 1, 0]]).astype(np.float32)) | >>> input_x = Tensor(np.array([[0, 1, 0], [1, 1, 0]]).astype(np.float32)) | ||||
| @@ -77,7 +77,7 @@ def count_nonzero(x, axis=(), keep_dims=False, dtype=mstype.int32): | |||||
| reduce_sum = P.ReduceSum(keep_dims) | reduce_sum = P.ReduceSum(keep_dims) | ||||
| nonzero_bool = not_equal(x, 0) | nonzero_bool = not_equal(x, 0) | ||||
| # ReduceSum only support float16 or float32 tensor. | # ReduceSum only support float16 or float32 tensor. | ||||
| nonzero_val = cast(nonzero_bool, mstype.float16) | |||||
| nonzero_val = cast(nonzero_bool, mstype.float32) | |||||
| nonzero_num = cast(reduce_sum(nonzero_val, axis), dtype) | nonzero_num = cast(reduce_sum(nonzero_val, axis), dtype) | ||||
| return nonzero_num | return nonzero_num | ||||