From c4da4ceadd4836a1947d0d100b252000018fc0d1 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Thu, 16 Feb 2023 14:56:20 +0100 Subject: [PATCH 1/3] Added `get_adj_matrix()` --- reCTBN/src/process.rs | 2 ++ reCTBN/src/process/ctbn.rs | 5 +++++ reCTBN/src/process/ctmp.rs | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/reCTBN/src/process.rs b/reCTBN/src/process.rs index 45c5e0a..f554af4 100644 --- a/reCTBN/src/process.rs +++ b/reCTBN/src/process.rs @@ -5,6 +5,7 @@ pub mod ctmp; use std::collections::BTreeSet; +use ndarray::Array2; use thiserror::Error; use crate::params; @@ -117,4 +118,5 @@ pub trait NetworkProcess: Sync { /// /// * The **children set** of the selected node. fn get_children_set(&self, node: usize) -> BTreeSet; + fn get_adj_matrix(&self) -> Option>; } diff --git a/reCTBN/src/process/ctbn.rs b/reCTBN/src/process/ctbn.rs index 162345e..9784776 100644 --- a/reCTBN/src/process/ctbn.rs +++ b/reCTBN/src/process/ctbn.rs @@ -240,4 +240,9 @@ impl process::NetworkProcess for CtbnNetwork { .filter_map(|(idx, x)| if x > &0 { Some(idx) } else { None }) .collect() } + + /// Get the Adjacency Matrix. + fn get_adj_matrix(&self) -> Option> { + self.adj_matrix.clone() + } } diff --git a/reCTBN/src/process/ctmp.rs b/reCTBN/src/process/ctmp.rs index 41b8db6..4a346e7 100644 --- a/reCTBN/src/process/ctmp.rs +++ b/reCTBN/src/process/ctmp.rs @@ -1,5 +1,7 @@ use std::collections::BTreeSet; +use ndarray::Array2; + use crate::{ params::{Params, StateType}, process, @@ -111,4 +113,7 @@ impl NetworkProcess for CtmpProcess { None => panic!("Uninitialized CtmpProcess"), } } + fn get_adj_matrix(&self) -> Option> { + unimplemented!("CtmpProcess has only one node") + } } From 4fd0ee040734c3b78227f3bbc8002842083be829 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Thu, 16 Feb 2023 15:12:32 +0100 Subject: [PATCH 2/3] Function `get_adj_matrix()` is now specific to `CtbnNetwork` only --- reCTBN/src/process.rs | 2 -- reCTBN/src/process/ctbn.rs | 9 ++++----- reCTBN/src/process/ctmp.rs | 5 ----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/reCTBN/src/process.rs b/reCTBN/src/process.rs index f554af4..45c5e0a 100644 --- a/reCTBN/src/process.rs +++ b/reCTBN/src/process.rs @@ -5,7 +5,6 @@ pub mod ctmp; use std::collections::BTreeSet; -use ndarray::Array2; use thiserror::Error; use crate::params; @@ -118,5 +117,4 @@ pub trait NetworkProcess: Sync { /// /// * The **children set** of the selected node. fn get_children_set(&self, node: usize) -> BTreeSet; - fn get_adj_matrix(&self) -> Option>; } diff --git a/reCTBN/src/process/ctbn.rs b/reCTBN/src/process/ctbn.rs index 9784776..6956ea0 100644 --- a/reCTBN/src/process/ctbn.rs +++ b/reCTBN/src/process/ctbn.rs @@ -138,6 +138,10 @@ impl CtbnNetwork { return array_state; } + /// Get the Adjacency Matrix. + pub fn get_adj_matrix(&self) -> Option> { + self.adj_matrix.clone() + } } impl process::NetworkProcess for CtbnNetwork { @@ -240,9 +244,4 @@ impl process::NetworkProcess for CtbnNetwork { .filter_map(|(idx, x)| if x > &0 { Some(idx) } else { None }) .collect() } - - /// Get the Adjacency Matrix. - fn get_adj_matrix(&self) -> Option> { - self.adj_matrix.clone() - } } diff --git a/reCTBN/src/process/ctmp.rs b/reCTBN/src/process/ctmp.rs index 4a346e7..41b8db6 100644 --- a/reCTBN/src/process/ctmp.rs +++ b/reCTBN/src/process/ctmp.rs @@ -1,7 +1,5 @@ use std::collections::BTreeSet; -use ndarray::Array2; - use crate::{ params::{Params, StateType}, process, @@ -113,7 +111,4 @@ impl NetworkProcess for CtmpProcess { None => panic!("Uninitialized CtmpProcess"), } } - fn get_adj_matrix(&self) -> Option> { - unimplemented!("CtmpProcess has only one node") - } } From 7a3ac6c9abd364dfc62d2a45717c95c32f78476f Mon Sep 17 00:00:00 2001 From: meliurwen Date: Thu, 16 Feb 2023 16:36:07 +0100 Subject: [PATCH 3/3] Using `as_ref()` instead of `clone()` in `get_adj_matrix()` --- reCTBN/src/process/ctbn.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reCTBN/src/process/ctbn.rs b/reCTBN/src/process/ctbn.rs index 6956ea0..d93400d 100644 --- a/reCTBN/src/process/ctbn.rs +++ b/reCTBN/src/process/ctbn.rs @@ -139,8 +139,8 @@ impl CtbnNetwork { return array_state; } /// Get the Adjacency Matrix. - pub fn get_adj_matrix(&self) -> Option> { - self.adj_matrix.clone() + pub fn get_adj_matrix(&self) -> Option<&Array2> { + self.adj_matrix.as_ref() } }