当前位置: 首页>>代码示例>>Python>>正文


Python torch_sparse.spmm方法代码示例

本文整理汇总了Python中torch_sparse.spmm方法的典型用法代码示例。如果您正苦于以下问题:Python torch_sparse.spmm方法的具体用法?Python torch_sparse.spmm怎么用?Python torch_sparse.spmm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torch_sparse的用法示例。


在下文中一共展示了torch_sparse.spmm方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: forward

# 需要导入模块: import torch_sparse [as 别名]
# 或者: from torch_sparse import spmm [as 别名]
def forward(self, normalized_adjacency_matrix, features):
        """
        Doing a forward pass.
        :param normalized_adjacency_matrix: Normalized adjacency matrix.
        :param features: Feature matrix.
        :return base_features: Convolved features.
        """
        base_features = torch.mm(features, self.weight_matrix)
        base_features = torch.nn.functional.dropout(base_features,
                                                    p=self.dropout_rate,
                                                    training=self.training)
        for _ in range(self.iterations-1):
            base_features = spmm(normalized_adjacency_matrix["indices"],
                                 normalized_adjacency_matrix["values"],
                                 base_features.shape[0],
                                 base_features.shape[0],
                                 base_features)
        base_features = base_features + self.bias
        return base_features 
开发者ID:benedekrozemberczki,项目名称:MixHop-and-N-GCN,代码行数:21,代码来源:layers.py

示例2: forward

# 需要导入模块: import torch_sparse [as 别名]
# 或者: from torch_sparse import spmm [as 别名]
def forward(self, feature_indices, feature_values):
        """
        Making a forward pass.
        :param feature_indices: Non zero value indices.
        :param feature_values: Matrix values.
        :return filtered_features: Output features.
        """
        number_of_nodes = torch.max(feature_indices[0]).item()+1
        number_of_features = torch.max(feature_indices[1]).item()+1
        filtered_features = spmm(index = feature_indices,
                                 value = feature_values,
                                 m = number_of_nodes,
                                 n = number_of_features,
                                 matrix = self.weight_matrix)
        filtered_features = filtered_features + self.bias
        return filtered_features 
开发者ID:benedekrozemberczki,项目名称:APPNP,代码行数:18,代码来源:appnp_layer.py

示例3: get_feat

# 需要导入模块: import torch_sparse [as 别名]
# 或者: from torch_sparse import spmm [as 别名]
def get_feat(self, graph_list):        
        if self.feat_mode == 'dense':
            dense_feat = self.get_fp(graph_list)
        else:
            sp_indices, vals = self.get_fp(graph_list)
            w = self.input_linear.weight
            b = self.input_linear.bias
            dense_feat = spmm(sp_indices, vals, len(graph_list), w.transpose(0, 1)) + b

        return self.mlp(dense_feat), None 
开发者ID:Hanjun-Dai,项目名称:GLN,代码行数:12,代码来源:morganfp.py

示例4: forward

# 需要导入模块: import torch_sparse [as 别名]
# 或者: from torch_sparse import spmm [as 别名]
def forward(self, phi_indices, phi_values, phi_inverse_indices, phi_inverse_values, features):
        """
        Forward propagation pass.
        :param phi_indices: Sparse wavelet matrix index pairs.
        :param phi_values: Sparse wavelet matrix values.
        :param phi_inverse_indices: Inverse wavelet matrix index pairs.
        :param phi_inverse_values: Inverse wavelet matrix values.
        :param features: Feature matrix.
        :return localized_features: Filtered feature matrix extracted.
        """
        rescaled_phi_indices, rescaled_phi_values = spspmm(phi_indices,
                                                           phi_values,
                                                           self.diagonal_weight_indices,
                                                           self.diagonal_weight_filter.view(-1),
                                                           self.ncount,
                                                           self.ncount,
                                                           self.ncount)

        phi_product_indices, phi_product_values = spspmm(rescaled_phi_indices,
                                                         rescaled_phi_values,
                                                         phi_inverse_indices,
                                                         phi_inverse_values,
                                                         self.ncount,
                                                         self.ncount,
                                                         self.ncount)

        filtered_features = torch.mm(features, self.weight_matrix)

        localized_features = spmm(phi_product_indices,
                                  phi_product_values,
                                  self.ncount,
                                  self.ncount,
                                  filtered_features)

        return localized_features 
开发者ID:benedekrozemberczki,项目名称:GraphWaveletNeuralNetwork,代码行数:37,代码来源:gwnn_layer.py

示例5: test_spmm

# 需要导入模块: import torch_sparse [as 别名]
# 或者: from torch_sparse import spmm [as 别名]
def test_spmm(dtype, device):
    row = torch.tensor([0, 0, 1, 2, 2], device=device)
    col = torch.tensor([0, 2, 1, 0, 1], device=device)
    index = torch.stack([row, col], dim=0)
    value = tensor([1, 2, 4, 1, 3], dtype, device)
    x = tensor([[1, 4], [2, 5], [3, 6]], dtype, device)

    out = spmm(index, value, 3, 3, x)
    assert out.tolist() == [[7, 16], [8, 20], [7, 19]] 
开发者ID:rusty1s,项目名称:pytorch_sparse,代码行数:11,代码来源:test_spmm.py


注:本文中的torch_sparse.spmm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。