import torch
from plyfile import PlyData
from torch_geometric.data import Data


def read_ply(path):
    with open(path, 'rb') as f:
        data = PlyData.read(f)

    pos = ([torch.tensor(data['vertex'][axis]) for axis in ['x', 'y', 'z']])
    pos = torch.stack(pos, dim=-1)

    face = None
    if 'face' in data:
        faces = data['face']['vertex_indices']
        faces = [torch.tensor(face, dtype=torch.long) for face in faces]
        face = torch.stack(faces, dim=-1)

    data = Data(pos=pos)
    data.face = face

    return data

[((252, 276), 'torch.stack', 'torch.stack', (['pos'], {'dim': '(-1)'}), '(pos, dim=-1)\n', (263, 276), False, 'import torch\n'), ((491, 504), 'torch_geometric.data.Data', 'Data', ([], {'pos': 'pos'}), '(pos=pos)\n', (495, 504), False, 'from torch_geometric.data import Data\n'), ((148, 163), 'plyfile.PlyData.read', 'PlyData.read', (['f'], {}), '(f)\n', (160, 163), False, 'from plyfile import PlyData\n'), ((177, 211), 'torch.tensor', 'torch.tensor', (["data['vertex'][axis]"], {}), "(data['vertex'][axis])\n", (189, 211), False, 'import torch\n'), ((452, 478), 'torch.stack', 'torch.stack', (['faces'], {'dim': '(-1)'}), '(faces, dim=-1)\n', (463, 478), False, 'import torch\n'), ((381, 417), 'torch.tensor', 'torch.tensor', (['face'], {'dtype': 'torch.long'}), '(face, dtype=torch.long)\n', (393, 417), False, 'import torch\n')]