diff --git a/docs/api/api_python/ops/mindspore.ops.func_cov.rst b/docs/api/api_python/ops/mindspore.ops.func_cov.rst index 6f3c8b94d1f..80834f358cc 100644 --- a/docs/api/api_python/ops/mindspore.ops.func_cov.rst +++ b/docs/api/api_python/ops/mindspore.ops.func_cov.rst @@ -24,6 +24,9 @@ mindspore.ops.cov .. warning:: `fweights` 和 `aweights` 的值不能为负数,负数权重场景结果未定义。 + .. note:: + 当前暂不支持复数。 + 参数: - **x** (Tensor) - 一个二维矩阵,或单个变量的标量或一维向量。 diff --git a/mindspore/python/mindspore/ops/function/math_func.py b/mindspore/python/mindspore/ops/function/math_func.py index 1e676a478bf..c7f1d80674d 100644 --- a/mindspore/python/mindspore/ops/function/math_func.py +++ b/mindspore/python/mindspore/ops/function/math_func.py @@ -1953,6 +1953,9 @@ def cov(x, *, correction=1, fweights=None, aweights=None): .. warning:: The values of `fweights` and `aweights` cannot be negative, and the negative weight scene result is undefined. + .. note:: + Currently, complex number is not supported. + Args: x (Tensor): A 2D matrix, or a scalar or 1D vector of a single variable @@ -2028,10 +2031,10 @@ def cov(x, *, correction=1, fweights=None, aweights=None): w = None if w is not None: - w_sum = w.sum().astype(mstype.float32) + w_sum = w.sum() avg = (input_x * w).sum(1) / w_sum else: - w_sum = Tensor(num_observations, dtype=mstype.float32) + w_sum = Tensor(num_observations, dtype=mstype.int64) avg = input_x.sum(1) / w_sum if w is not None and aweights is not None and correction != 0: diff --git a/tests/st/ops/test_func_cov.py b/tests/st/ops/test_func_cov.py index f1cc5737532..5f1c26a0a9f 100644 --- a/tests/st/ops/test_func_cov.py +++ b/tests/st/ops/test_func_cov.py @@ -43,7 +43,7 @@ def test_cov_normal(mode): """ ms.set_context(mode=mode) net = Net() - x = ms.Tensor([[0, 2], [1, 1], [2, 0]]).T + x = ms.Tensor([[0., 2.], [1., 1.], [2., 0.]]).T output1 = net(x) expect_output1 = np.array([[1., -1.], [-1., 1.]]) diff --git a/tests/st/tensor/test_cov.py b/tests/st/tensor/test_cov.py index b6fc4fcac96..e3aadf49574 100644 --- a/tests/st/tensor/test_cov.py +++ b/tests/st/tensor/test_cov.py @@ -42,7 +42,7 @@ def test_cov_normal(mode): """ ms.set_context(mode=mode) net = Net() - x = ms.Tensor([[0, 2], [1, 1], [2, 0]]).T + x = ms.Tensor([[0., 2.], [1., 1.], [2., 0.]]).T output1 = net(x) expect_output1 = np.array([[1., -1.], [-1., 1.]])