pub struct GraphDataLoader { /* private fields */ }Expand description
Graph data loader
Implementations§
Source§impl GraphDataLoader
impl GraphDataLoader
Sourcepub fn new(batch_size: usize, shuffle: bool) -> Result<Self, Box<dyn Error>>
pub fn new(batch_size: usize, shuffle: bool) -> Result<Self, Box<dyn Error>>
Create a new graph data loader with validation
§Arguments
batch_size- Size of batches, must be > 0shuffle- Whether to shuffle data
§Returns
Ok(Self)- Successfully created data loaderErr- If batch_size is 0
§Example
use torsh_graph::data::GraphDataLoader;
let loader = GraphDataLoader::new(32, true).unwrap();
assert_eq!(loader.batch_size(), 32);Sourcepub fn with_node_features(self, num_node_features: usize) -> Self
pub fn with_node_features(self, num_node_features: usize) -> Self
Set the number of synthetic node features generated for formats that carry connectivity only (edge lists).
Defaults to DEFAULT_NODE_FEATURES.
Sourcepub fn num_node_features(&self) -> usize
pub fn num_node_features(&self) -> usize
Number of synthetic node features used for feature-less formats
Sourcepub fn batch_size(&self) -> usize
pub fn batch_size(&self) -> usize
Get batch size
Sourcepub fn from_directory(&self, path: &str) -> Result<Vec<GraphData>, TorshError>
pub fn from_directory(&self, path: &str) -> Result<Vec<GraphData>, TorshError>
Load every supported graph file in path into a GraphData list.
Files are dispatched on their extension to the parsers in
crate::datasets:
| Extension | Loader |
|---|---|
edges, edgelist, txt | [EdgeListLoader] |
gml | [GMLLoader] |
json | [JSONLoader] |
Files with any other extension (and sub-directories) are ignored. Entries are visited in sorted order so the returned dataset is deterministic.
§Errors
Returns an error if the directory cannot be read, or if a file with a supported extension fails to parse. A failing file is reported rather than silently skipped, so a mis-typed path can never masquerade as an empty dataset.
§Example
use torsh_graph::data::GraphDataLoader;
let loader = GraphDataLoader::new(4, false).unwrap();
let graphs = loader.from_directory("./my_graphs").unwrap();
println!("loaded {} graphs", graphs.len());Auto Trait Implementations§
impl Freeze for GraphDataLoader
impl RefUnwindSafe for GraphDataLoader
impl Send for GraphDataLoader
impl Sync for GraphDataLoader
impl Unpin for GraphDataLoader
impl UnsafeUnpin for GraphDataLoader
impl UnwindSafe for GraphDataLoader
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> 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