test_add.py 482 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
from nose.tools import assert_equal

import torch
rusty1s's avatar
rename  
rusty1s committed
4
from torch_scatter._ext import ffi
rusty1s's avatar
rusty1s committed
5
6
7


def test_scatter_add():
rusty1s's avatar
rusty1s committed
8
9
10
11
12
13
14
    input = [[2, 0, 1, 4, 3], [0, 2, 1, 3, 4]]
    index = [[4, 5, 4, 2, 3], [0, 0, 2, 2, 1]]
    input = torch.FloatTensor(input)
    index = torch.LongTensor(index)
    output = input.new(2, 6).fill_(0)
    expected_output = [[0, 0, 4, 3, 3, 0], [2, 4, 4, 0, 0, 0]]

rusty1s's avatar
rename  
rusty1s committed
15
    ffi.scatter_add_Float(output, index, input, 1)
rusty1s's avatar
rusty1s committed
16
    assert_equal(output.tolist(), expected_output)