# Source code for torch_geometric.nn.dense.dense_gcn_conv

import torch
from torch.nn import Parameter

from torch_geometric.nn.dense.linear import Linear
from torch_geometric.nn.inits import zeros

[docs]class DenseGCNConv(torch.nn.Module):
r"""See :class:torch_geometric.nn.conv.GCNConv.
"""
def __init__(self, in_channels, out_channels, improved=False, bias=True):
super().__init__()

self.in_channels = in_channels
self.out_channels = out_channels
self.improved = improved

self.lin = Linear(in_channels, out_channels, bias=False,
weight_initializer='glorot')

if bias:
self.bias = Parameter(torch.Tensor(out_channels))
else:
self.register_parameter('bias', None)

self.reset_parameters()

[docs]    def reset_parameters(self):
self.lin.reset_parameters()
zeros(self.bias)

r"""
Args:
x (Tensor): Node feature tensor :math:\mathbf{X} \in \mathbb{R}^{B
\times N \times F}, with batch-size :math:B, (maximum)
number of nodes :math:N for each graph, and feature
dimension :math:F.
\times N \times N}. The adjacency tensor is broadcastable in
the batch dimension, resulting in a shared adjacency matrix for
the complete batch.
:math:\mathbf{M} \in {\{ 0, 1 \}}^{B \times N} indicating
the valid nodes for each graph. (default: :obj:None)
add_loop (bool, optional): If set to :obj:False, the layer will
(default: :obj:True)
"""
x = x.unsqueeze(0) if x.dim() == 2 else x

adj[:, idx, idx] = 1 if not self.improved else 2

out = self.lin(x)