Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
gnn_graph.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Matteo Caldana <matteo.caldana@polimi.it>
22// Author: Pedro Peixoto <ppeixoto@usp.br>
23
24#ifndef VULPES_GEOMETRY_AGGLOMERATION_GNN_GRAPH_HPP_
25#define VULPES_GEOMETRY_AGGLOMERATION_GNN_GRAPH_HPP_
26
27#include <torch/torch.h>
28
29#include <algorithm>
30#include <vector>
31
34
35namespace vulpes {
36namespace geometry {
37
46class GNNGraph {
47 public:
48 // SAGEconv models assume the following datatypes
49 using float_t = float;
50 using index_t = int64_t;
51 static inline constexpr auto tensor_index_t = torch::kInt64;
52 static inline constexpr auto tensor_float_t = torch::kFloat32;
53
54 using IndVec = std::vector<index_t>;
56
57 GNNGraph() = default;
58
73 template <typename IndexType>
75 const torch::Tensor& feature_tensor,
77 : m_dual_map(internal::cast<index_t>(dual_map)),
78 m_feature_tensor(feature_tensor),
80 assert(m_n_nodes == m_dual_map.size());
81 assert(feature_tensor.dtype() == tensor_float_t);
83 }
84
96
97 GNNGraph getSubGraph(const IndVec& subset_idxs);
98
99 const auto& getFeatureTensor() const { return m_feature_tensor; }
100 const auto& getEdgeIndexTensor() const { return m_edge_index; }
101 const auto& getDualMap() const { return m_dual_map; }
102
103 private:
111
112 void buildEdgeTensor();
113
115 torch::Tensor m_feature_tensor;
118 torch::Tensor m_edge_index;
119
120 std::vector<IndVec> m_connected_components;
121};
122
123} // namespace geometry
124} // namespace vulpes
125
126#endif // VULPES_GEOMETRY_AGGLOMERATION_GNN_GRAPH_HPP_
Definition crs_map.hpp:72
Graph wrapper with Torch tensors for features and edges.
Definition gnn_graph.hpp:46
torch::Tensor m_edge_index
Edge list [2, nnz] (COO, int64).
Definition gnn_graph.hpp:118
torch::Tensor m_feature_tensor
Node features [N, F].
Definition gnn_graph.hpp:115
int64_t index_t
Definition gnn_graph.hpp:50
void buildEdgeTensor()
Build the Torch COO edge tensor from the CRS map.
Definition gnn_graph.cpp:39
GNNGraph(const torch::Tensor &feature_tensor, const datastructure::CrsMap< IndexType, IndexType > &dual_map)
Construct from feature tensor and (typed) dual graph.
Definition gnn_graph.hpp:74
float float_t
Definition gnn_graph.hpp:49
std::vector< IndVec > m_connected_components
Definition gnn_graph.hpp:120
const auto & getFeatureTensor() const
Definition gnn_graph.hpp:99
static constexpr auto tensor_float_t
Definition gnn_graph.hpp:52
index_t m_n_nodes
Number of nodes.
Definition gnn_graph.hpp:116
index_t m_n_features
Number of features per node.
Definition gnn_graph.hpp:117
IndMap m_dual_map
Dual-graph adjacency (CRS).
Definition gnn_graph.hpp:114
const auto & getDualMap() const
Definition gnn_graph.hpp:101
std::vector< index_t > IndVec
Definition gnn_graph.hpp:54
datastructure::CrsMap< index_t, index_t > IndMap
Definition gnn_graph.hpp:55
static constexpr auto tensor_index_t
Definition gnn_graph.hpp:51
const auto & getEdgeIndexTensor() const
Definition gnn_graph.hpp:100
GNNGraph getSubGraph(const IndVec &subset_idxs)
Induced subgraph on a set of node indices.
Definition gnn_graph.cpp:28
Helpers implementing VulPoly's Voronoi construction and cleanup.
Definition abs_agg_model.cpp:42
Definition abs_agg_model.cpp:40
Definition cell_manager.hpp:38