[opengm] 47/386: setting initial values from numpy array works
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:35:03 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/master
in repository opengm.
commit fb985d78e6146716d0ba8de315f2713eba77f9b8
Author: DerThorsten <thorsten.beier at iwr.uni-heidelberg.de>
Date: Mon Dec 15 15:28:58 2014 +0100
setting initial values from numpy array works
---
fubar/python_stuff.py | 5 ++---
src/interfaces/python/opengm/opengmcore/opengmcore.cpp | 13 +++++++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/fubar/python_stuff.py b/fubar/python_stuff.py
index 4d7525b..bda65b3 100644
--- a/fubar/python_stuff.py
+++ b/fubar/python_stuff.py
@@ -12,10 +12,9 @@ gm = opengm.gm(space)
+weightVals = numpy.ones(4)*4.0
+weights = opengm.Weights(weightVals)
-weights = opengm.Weights(4)
-for i in range(4):
- weights[i] = 1.0
diff --git a/src/interfaces/python/opengm/opengmcore/opengmcore.cpp b/src/interfaces/python/opengm/opengmcore/opengmcore.cpp
index af7af84..9cb6235 100644
--- a/src/interfaces/python/opengm/opengmcore/opengmcore.cpp
+++ b/src/interfaces/python/opengm/opengmcore/opengmcore.cpp
@@ -165,6 +165,17 @@ typename D::value_type dequePushBack(
}
+template<class V>
+opengm::learning::Weights<V> * pyWeightsConstructor(
+ opengm::python::NumpyView<V, 1> values
+){
+ opengm::learning::Weights<V> * f = new opengm::learning::Weights<V> (values.shape(0));
+ for(size_t i=0; i<values.shape(i); ++i){
+ f->setWeight(i, values(i));
+ }
+ return f;
+}
+
template<class V>
@@ -173,6 +184,8 @@ void pyExportWeights(const std::string & clsName){
typedef opengm::learning::Weights<V> Weights;
boost::python::class_<Weights>(clsName.c_str(),boost::python::init<const size_t >())
+
+ .def("__init__", make_constructor(&pyWeightsConstructor<V> ,boost::python::default_call_policies()))
.def("__getitem__", &Weights::getWeight)
.def("__setitem__", &Weights::setWeight)
;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opengm.git
More information about the debian-science-commits
mailing list