test.py 860 Bytes
Newer Older
Hang Zhang's avatar
init  
Hang Zhang committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## Created by: Hang Zhang
## ECE Department, Rutgers University
## Email: zhang.hang@rutgers.edu
## Copyright (c) 2017
##
## This source code is licensed under the MIT-style license found in the
## LICENSE file in the root directory of this source tree 
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import torch
import torch.nn as nn
from torch.autograd import Variable
from encoding import Aggregate
Hang Zhang's avatar
Hang Zhang committed
15
from torch.autograd import gradcheck
Hang Zhang's avatar
init  
Hang Zhang committed
16

Hang Zhang's avatar
Hang Zhang committed
17
# declare dims and variables 
Hang Zhang's avatar
init  
Hang Zhang committed
18
B, N, K, D = 1, 2, 3, 4
Hang Zhang's avatar
Hang Zhang committed
19
20
21
22
23
24
25
A = Variable(torch.randn(B,N,K).cuda(), requires_grad=True)
R = Variable(torch.randn(B,N,K,D).cuda(), requires_grad=True)

# check Aggregate operation
test = gradcheck(Aggregate(),(A, R), eps=1e-4, atol=1e-3)
print('Gradcheck of Aggreate() returns ', test)

Hang Zhang's avatar
init  
Hang Zhang committed
26