From 931c01d3e4ef41bdbb7d9fed42c34b0cbf527e1b Mon Sep 17 00:00:00 2001 From: Milan Boers Date: Thu, 30 Nov 2023 16:58:04 +0100 Subject: [PATCH] Fix some compilation, clippy, fmt issues --- src/dqn.rs | 4 ++-- src/examples/eucdist_dqn.rs | 26 +++++++++++++------------- src/lib.rs | 5 +---- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/dqn.rs b/src/dqn.rs index 931a923..d668cf0 100644 --- a/src/dqn.rs +++ b/src/dqn.rs @@ -28,9 +28,9 @@ type QNetworkDevice for MyState { - fn into(self) -> [f32; 6] { +impl From for [f32; 6] { + fn from(val: MyState) -> Self { [ - self.tx as f32, - self.ty as f32, - self.x as f32, - self.y as f32, - self.maxx as f32, - self.maxy as f32, + val.tx as f32, + val.ty as f32, + val.x as f32, + val.y as f32, + val.maxx as f32, + val.maxy as f32, ] } } // From float array has to be implemented for the DQN state -impl From<[f32; 4]> for MyState { - fn from(v: [f32; 4]) -> Self { +impl From<[f32; 6]> for MyState { + fn from(v: [f32; 6]) -> Self { MyState { tx: v[0] as i32, ty: v[1] as i32, @@ -54,9 +54,9 @@ enum MyAction { // Into float array has to be implemented for the action, // so that the DQN can use it. -impl Into<[f32; 4]> for MyAction { - fn into(self) -> [f32; 4] { - match self { +impl From for [f32; 4] { + fn from(val: MyAction) -> Self { + match val { MyAction::Move { dx: -1, dy: 0 } => [1.0, 0.0, 0.0, 0.0], MyAction::Move { dx: 1, dy: 0 } => [0.0, 1.0, 0.0, 0.0], MyAction::Move { dx: 0, dy: -1 } => [0.0, 0.0, 1.0, 0.0], diff --git a/src/lib.rs b/src/lib.rs index 11b876f..4bcea06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,10 +173,7 @@ where learning_strategy.value(&self.q.get(s_t_next), &old_value, r_t_next) }; - self.q - .entry(s_t) - .or_insert_with(HashMap::new) - .insert(action, v); + self.q.entry(s_t).or_default().insert(action, v); if termination_strategy.should_stop(s_t_next) { break;