Skip to main content

node_feature_matrix

Function node_feature_matrix 

Source
pub fn node_feature_matrix<N, E, F>(
    graph: &AttributedGraph<N, E>,
    feature_fn: F,
) -> Result<Array2<f64>>
where F: Fn(&N) -> Vec<f64>,
Expand description

Construct a dense node-feature matrix from an attributed graph.

feature_fn is called for each node in insertion order and must return a Vec<f64> of the same length for every node. The resulting matrix has shape (node_count, feature_dim).

§Errors

Returns GraphError::InvalidParameter if the node count is zero or if feature_fn returns vectors of inconsistent length.

§Example

use scirs2_graph::attributed_graph::{AttributedGraph, node_feature_matrix};

let mut g = AttributedGraph::<[f64; 2], ()>::new();
g.add_node([1.0, 0.5]);
g.add_node([0.0, 1.0]);
let mat = node_feature_matrix(&g, |n| n.to_vec()).unwrap();
assert_eq!(mat.shape(), &[2, 2]);