pub struct SparseGraph {
pub edge_list: Vec<(usize, usize)>,
pub node_features: Option<Tensor>,
pub edge_weights: Option<Vec<f32>>,
pub num_nodes: usize,
pub num_edges: usize,
}Expand description
Sparse coordinate (COO) representation of a graph or graph operator.
Each stored entry is a (row, col) coordinate together with an associated
weight. This is used both for sparsified adjacency matrices (see
SparseGraph::from_dense) and for sparse operators such as the graph
Laplacian (see sparse_laplacian).
Fields§
§edge_list: Vec<(usize, usize)>Stored (row, col) coordinates of non-zero entries.
node_features: Option<Tensor>Optional dense node-feature matrix associated with the graph.
edge_weights: Option<Vec<f32>>Weight associated with each coordinate in edge_list (same length).
num_nodes: usizeNumber of nodes the operator is defined over.
num_edges: usizeNumber of stored entries (edge_list.len()).
Implementations§
Source§impl SparseGraph
impl SparseGraph
Sourcepub fn from_dense(adjacency: &Tensor, threshold: f32) -> Result<Self>
pub fn from_dense(adjacency: &Tensor, threshold: f32) -> Result<Self>
Build a sparse graph from a dense adjacency matrix, keeping only entries
whose magnitude strictly exceeds threshold.
The matrix is interpreted as a rows x cols tensor; num_nodes is taken
from the number of rows. Entries are scanned in row-major order so the
resulting edge_list is sorted by (row, col).
Sourcepub fn to_edge_index(&self) -> Result<Tensor>
pub fn to_edge_index(&self) -> Result<Tensor>
Convert the stored coordinates into a [2, num_edges] edge-index tensor.
The first row holds source indices and the second holds destinations,
matching the convention used by GraphData. An empty graph yields a
[2, 0] tensor.
Sourcepub fn memory_footprint(&self) -> usize
pub fn memory_footprint(&self) -> usize
Total memory occupied by this representation, in bytes.
This counts the inline size of the struct itself plus all heap allocations it owns (the coordinate list, the optional node-feature tensor, and the optional weight vector). The value is therefore always strictly positive, even for a graph with no stored edges, because the structure’s own fields still occupy memory.
Trait Implementations§
Source§impl Clone for SparseGraph
impl Clone for SparseGraph
Source§fn clone(&self) -> SparseGraph
fn clone(&self) -> SparseGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for SparseGraph
impl RefUnwindSafe for SparseGraph
impl Send for SparseGraph
impl Sync for SparseGraph
impl Unpin for SparseGraph
impl UnsafeUnpin for SparseGraph
impl UnwindSafe for SparseGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more