From 817bb3192635ac5eb3c4a4c2825a2fdbc529d25a Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Tue, 23 Jun 2020 16:12:17 +0200
Subject: [PATCH] In ContextModule : left-most and right-most child features
 are only taken into account if they are respectively to the left or to the
 right of their parents

---
 torch_modules/src/ContextModule.cpp | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/torch_modules/src/ContextModule.cpp b/torch_modules/src/ContextModule.cpp
index 364f2cb..2e13833 100644
--- a/torch_modules/src/ContextModule.cpp
+++ b/torch_modules/src/ContextModule.cpp
@@ -85,12 +85,22 @@ void ContextModuleImpl::addToContext(std::vector<std::vector<long>> & context, c
       {
         int childIndex = *std::get<2>(target);
         auto childs = util::split(config.getAsFeature(Config::childsColName, baseIndex).get(), '|');
+        int candidate = -1;
+
         if (childIndex >= 0 and childIndex < (int)childs.size())
-          contextIndexes.emplace_back(std::stoi(childs[childIndex]));
+        {
+          candidate = std::stoi(childs[childIndex]);
+          if (candidate > baseIndex)
+            candidate = -1;
+        }
         else if (childIndex < 0 and ((int)childs.size())+childIndex >= 0)
-          contextIndexes.emplace_back(std::stoi(childs[childs.size()+childIndex]));
-        else
-          contextIndexes.emplace_back(-1);
+        {
+          candidate = std::stoi(childs[childs.size()+childIndex]);
+          if (candidate < baseIndex)
+            candidate = -1;
+        }
+
+        contextIndexes.emplace_back(candidate);
       }
     }
     else
-- 
GitLab