Function Differences with torch.blackman_window

View Source On Gitee

torch.blackman_window

torch.blackman_window(
    window_length,
    periodic=True,
    *,
    dtype=None,
    layout=torch.strided,
    device=None,
    requires_grad=False
) -> Tensor

For more information, see torch.blackman_window.

mindspore.ops.blackman_window

mindspore.ops.blackman_window(
    window_length,
    periodic=True,
    *,
    dtype=mstype.float32
) -> Tensor

For more information, see mindspore.ops.blackman_window.

Differences

PyTorch: Return a Blackman window with the same size as window_length. The periodic parameter determines whether the returned window will remove the last duplicate value of the symmetric window.

MindSpore: MindSpore API basically implements the same function as PyTorch, and the precision varies slightly.

Categories

Subcategories

PyTorch

MindSpore

Differences

Parameters

Parameter 1

window_length

window_length

An int in PyTorch and a Tensor in MindSpore

Parameter 2

periodic

periodic

-

Parameter 3

dtype

dtype

-

Parameter 4

layout

-

Not involved

Parameter 5

device

-

Not involved

Parameter 6

requires_grad

-

MindSpore does not have this parameter and supports reverse derivation by default

Code Example 1

# PyTorch
import torch

torch_output = torch.blackman_window(12, periodic=True)
print(torch_output.numpy())
# [-2.9802322e-08  2.6987284e-02  1.3000000e-01  3.4000000e-01
#   6.3000000e-01  8.9301264e-01  1.0000000e+00  8.9301258e-01
#   6.2999994e-01  3.3999997e-01  1.3000003e-01  2.6987225e-02]

# MindSpore
import mindspore
from mindspore import Tensor

window_length = Tensor(12, mindspore.int32)
ms_output = mindspore.ops.blackman_window(window_length, periodic=True)
print(ms_output.asnumpy())
# [-2.9802322e-08  2.6987284e-02  1.3000000e-01  3.4000000e-01
#   6.3000000e-01  8.9301276e-01  1.0000000e+00  8.9301258e-01
#   6.2999994e-01  3.3999997e-01  1.2999988e-01  2.6987255e-02]