From 713e8842036872198407f54c499f6afb93d0599b Mon Sep 17 00:00:00 2001
From: Manuel Guenther <manuel.guenther@idiap.ch>
Date: Mon, 1 Sep 2014 20:59:26 +0200
Subject: [PATCH] Fixed newly introduced bob.core.random bindings

---
 bob/learn/misc/old/ivector_trainer.cc |  2 +-
 bob/learn/misc/old/jfa_trainer.cc     |  4 ++--
 bob/learn/misc/old/kmeans_trainer.cc  |  4 ++--
 bob/learn/misc/old/plda_trainer.cc    |  2 +-
 bob/learn/misc/test_jfa_trainer.py    | 11 ++++++-----
 bob/learn/misc/test_kmeans_trainer.py |  5 ++---
 6 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/bob/learn/misc/old/ivector_trainer.cc b/bob/learn/misc/old/ivector_trainer.cc
index d98ed50..8b964a8 100644
--- a/bob/learn/misc/old/ivector_trainer.cc
+++ b/bob/learn/misc/old/ivector_trainer.cc
@@ -88,7 +88,7 @@ static boost::python::object ITB_getRng(EMTrainerIVectorBase& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 
 #include <boost/make_shared.hpp>
diff --git a/bob/learn/misc/old/jfa_trainer.cc b/bob/learn/misc/old/jfa_trainer.cc
index 18d0299..a5966e2 100644
--- a/bob/learn/misc/old/jfa_trainer.cc
+++ b/bob/learn/misc/old/jfa_trainer.cc
@@ -316,13 +316,13 @@ static boost::python::object isv_getRng(bob::learn::misc::ISVTrainer& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 static boost::python::object jfa_getRng(bob::learn::misc::JFATrainer& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 
 #include <boost/make_shared.hpp>
diff --git a/bob/learn/misc/old/kmeans_trainer.cc b/bob/learn/misc/old/kmeans_trainer.cc
index 3a5838a..4ef008b 100644
--- a/bob/learn/misc/old/kmeans_trainer.cc
+++ b/bob/learn/misc/old/kmeans_trainer.cc
@@ -62,13 +62,13 @@ static boost::python::object KMTB_getRng(EMTrainerKMeansBase& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 static boost::python::object KMT_getRng(bob::learn::misc::KMeansTrainer& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 
 #include <boost/make_shared.hpp>
diff --git a/bob/learn/misc/old/plda_trainer.cc b/bob/learn/misc/old/plda_trainer.cc
index 1c31059..a9a9de3 100644
--- a/bob/learn/misc/old/plda_trainer.cc
+++ b/bob/learn/misc/old/plda_trainer.cc
@@ -98,7 +98,7 @@ static boost::python::object TB_getRng(EMTrainerPLDA& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 
 #include <boost/make_shared.hpp>
diff --git a/bob/learn/misc/test_jfa_trainer.py b/bob/learn/misc/test_jfa_trainer.py
index 5de6a46..7c3f4d4 100644
--- a/bob/learn/misc/test_jfa_trainer.py
+++ b/bob/learn/misc/test_jfa_trainer.py
@@ -11,10 +11,11 @@
 import numpy
 import numpy.linalg
 
+import bob.core.random
+
 from . import GMMStats, GMMMachine, JFABase, JFAMachine, ISVBase, ISVMachine, \
     JFATrainer, ISVTrainer
 
-from . import mt19937 as old_mt19937
 
 def equals(x, y, epsilon):
   return (abs(x - y) < epsilon).all()
@@ -266,7 +267,7 @@ def test_JFATrainInitialize():
   ## JFA
   jb = JFABase(ubm, 2, 2)
   # first round
-  rng = old_mt19937(0)
+  rng = bob.core.random.mt19937(0)
   jt = JFATrainer(10)
   jt.rng = rng
   jt.initialize(jb, TRAINING_STATS)
@@ -275,7 +276,7 @@ def test_JFATrainInitialize():
   d1 = jb.d
 
   # second round
-  rng = old_mt19937(0)
+  rng = bob.core.random.mt19937(0)
   jt.rng = rng
   jt.initialize(jb, TRAINING_STATS)
   u2 = jb.u
@@ -299,7 +300,7 @@ def test_ISVTrainInitialize():
   ## ISV
   ib = ISVBase(ubm, 2)
   # first round
-  rng = old_mt19937(0)
+  rng = bob.core.random.mt19937(0)
   it = ISVTrainer(10)
   it.rng = rng
   it.initialize(ib, TRAINING_STATS)
@@ -307,7 +308,7 @@ def test_ISVTrainInitialize():
   d1 = ib.d
 
   # second round
-  rng = old_mt19937(0)
+  rng = bob.core.random.mt19937(0)
   it.rng = rng
   it.initialize(ib, TRAINING_STATS)
   u2 = ib.u
diff --git a/bob/learn/misc/test_kmeans_trainer.py b/bob/learn/misc/test_kmeans_trainer.py
index 8d47cf0..9cf2ad3 100644
--- a/bob/learn/misc/test_kmeans_trainer.py
+++ b/bob/learn/misc/test_kmeans_trainer.py
@@ -15,7 +15,6 @@ from bob.io.base.test_utils import datafile
 
 from . import KMeansMachine, KMeansTrainer
 
-from . import mt19937 as old_mt19937
 
 def equals(x, y, epsilon):
   return (abs(x - y) < epsilon).all()
@@ -74,7 +73,7 @@ if hasattr(KMeansTrainer, 'KMEANS_PLUS_PLUS'):
     # C++ implementation
     machine = KMeansMachine(dim_c, dim_d)
     trainer = KMeansTrainer()
-    trainer.rng = old_mt19937(seed)
+    trainer.rng = bob.core.random.mt19937(seed)
     trainer.initialization_method = KMeansTrainer.KMEANS_PLUS_PLUS
     trainer.initialize(machine, data)
 
@@ -92,7 +91,7 @@ def test_kmeans_noduplicate():
   # Defines machine and trainer
   machine = KMeansMachine(dim_c, dim_d)
   trainer = KMeansTrainer()
-  trainer.rng = old_mt19937(seed)
+  trainer.rng = bob.core.random.mt19937(seed)
   trainer.initialization_method = KMeansTrainer.RANDOM_NO_DUPLICATE
   trainer.initialize(machine, data)
   # Makes sure that the two initial mean vectors selected are different
-- 
GitLab