Skip to content

Conversation

ooooo-create
Copy link
Contributor

@ooooo-create ooooo-create commented Aug 22, 2025

paddle.unique 在 axis=None,return_inverse = True时,返回的 inverse 是被 flatten 之后的,但是 numpy 和 torch 会保持原来输入的形状

import paddle
import torch
import numpy as np

# 构造一个二维张量
x_np = np.array([[1, 2, 1], [3, 2, 1]])
x_pd = paddle.to_tensor(x_np)
x_th = torch.tensor(x_np)

# paddle.unique
out_pd, inverse_pd = paddle.unique(x_pd, return_inverse=True)
print("Paddle unique output:", out_pd.numpy())
print("Paddle inverse:", inverse_pd.numpy(), "shape:", inverse_pd.shape)

# torch.unique
out_th, inverse_th = torch.unique(x_th, return_inverse=True)
print("Torch unique output:", out_th.numpy())
print("Torch inverse:", inverse_th.numpy(), "shape:", inverse_th.shape)

"""
Paddle unique output: [1 2 3]
Paddle inverse: [0 1 0 2 1 0] shape: [6]
Torch unique output: [1 2 3]
Torch inverse: [[0 1 0]
 [2 1 0]] shape: torch.Size([2, 3])
"""

Copy link

paddle-bot bot commented Aug 22, 2025

Thanks for your contribution!

@ooooo-create ooooo-create changed the title 【Hackathon 9th No.13】Fix accuracy for paddle.unique 【Hackathon 9th No.13、9】Fix accuracy for paddle.unique Aug 22, 2025
@ooooo-create ooooo-create changed the title 【Hackathon 9th No.13、9】Fix accuracy for paddle.unique 【Hackathon 9th No.13】Fix accuracy for paddle.unique Aug 22, 2025
@cangtianhuang cangtianhuang self-assigned this Sep 1, 2025
Copy link
Collaborator

@cangtianhuang cangtianhuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cangtianhuang cangtianhuang merged commit 4e79a76 into PFCCLab:main Sep 1, 2025
@ooooo-create ooooo-create deleted the accuracy_unique branch September 29, 2025 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants