improve I/F of ggnn_update test
@@ -10,6 +10,7 @@ from chainer_chemistry.links.update.ggnn_update import GGNNUpdate
from chainer_chemistry.utils.permutation import permute_adj
from chainer_chemistry.utils.permutation import permute_node
from chainer_chemistry.utils.sparse_utils import _convert_to_sparse
+from chainer_chemistry.utils.sparse_utils import convert_sparse_with_edge_type
atom_size = 5
hidden_dim = 4
@@ -40,6 +41,13 @@ def data():
return embed_atom_data, adj_data, y_grad
+def convert_to_sparse(dense_adj):
+ # auxiliary function
+ data, row, col, edge_type = _convert_to_sparse(dense_adj)
+ return convert_sparse_with_edge_type(data, row, col, atom_size,
+ edge_type, num_edge_type)
+
+
def check_forward(update, atom_data, adj_data):
update.reset_state()
y_actual = cuda.to_cpu(update(atom_data, adj_data).data)
@@ -52,7 +60,7 @@ def test_forward_cpu(update, data):
atom_data, adj_data = data[:2]
y_dense = check_forward(update, atom_data, adj_data)
- sparse_adj = _convert_to_sparse(adj_data)
+ sparse_adj = convert_to_sparse(adj_data)
y_sparse = check_forward(update, atom_data, sparse_adj)
# results for dense matrix and sparse matrix must be same
@@ -66,7 +74,7 @@ def test_forward_gpu(update, data):
update.to_gpu()
y_dense = check_forward(update, atom_data, adj_data)
- sparse_adj = _convert_to_sparse(adj_data)
+ sparse_adj = convert_to_sparse(adj_data)
y_sparse = check_forward(update, atom_data, sparse_adj)
numpy.testing.assert_allclose(
@@ -106,7 +114,7 @@ def test_backward_cpu(update, data):
atom_data, adj_data, y_grad = data
gx_dense = check_backward(update, atom_data, adj_data, y_grad)
- sparse_adj = _convert_to_sparse(adj_data)
+ sparse_adj = convert_to_sparse(adj_data)
gx_sparse = check_backward(update, atom_data, sparse_adj, y_grad)
numpy.testing.assert_allclose(
@@ -119,7 +127,7 @@ def test_backward_gpu(update, data):
atom_data, adj_data, y_grad = map(cuda.to_gpu, data)
gx_dense = check_backward(update, atom_data, adj_data, y_grad)
- sparse_adj = _convert_to_sparse(adj_data)
+ sparse_adj = convert_to_sparse(adj_data)
gx_sparse = check_backward(update, atom_data, sparse_adj, y_grad)
numpy.testing.assert_allclose(
