Skip to content

[Question] How to perform reduction on 4D tensor #431

@mh-nguyen712

Description

@mh-nguyen712

Hi and Thanks for creating this library!
I have a problem and pykeops seems to be a good frame work.
I have 2 tensors x of shape B, M, D and y of shape B, N, D and I want to compute the distance matrix between these two tensors, resulting in a tensor of shape B, M, N.
The usual code in pytorch is

import torch 
B = 128
M = 1024
N = 1024
D = 1024

x = torch.randn(B, M, D, device='cuda')
y = torch.randn(B, N, D, device='cuda')

dist = (x.unsqueeze(2) - y.unsqueeze(1)).pow(2).sum(dim = -1) 

I've tried using pykeops:

a_i = LazyTensor(x.unsqueeze(1))          # shape (7, 1, 5, 3)
b_j = LazyTensor(y.unsqueeze(2))          # shape (7, 5, 1, 3)
c = (a_i - b_j).sum(dim=-1)

but c is still a LazyTensor. How could I perform the computation?
Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions