Skip to content

Commit

Permalink
Removed pyamgcl.make_params() function
Browse files Browse the repository at this point in the history
Replaced it with params::params(dict) constructor.
  • Loading branch information
ddemidov committed Sep 25, 2014
1 parent 63b226e commit e64acdd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
40 changes: 18 additions & 22 deletions python/pyamgcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ struct is_builtin_vector< numpy_boost<double,1> > : boost::true_type {};

//---------------------------------------------------------------------------
struct params {
params() {}

params(const boost::python::dict &args) {
using namespace boost::python;

for(stl_input_iterator<tuple> arg(args.items()), end; arg != end; ++arg) {
const char *name = extract<const char*>((*arg)[0]);
const char *type = extract<const char*>((*arg)[1].attr("__class__").attr("__name__"));

if (strcmp(type, "int") == 0)
seti(name, extract<int>((*arg)[1]));
else
setf(name, extract<float>((*arg)[1]));
}
}

void seti(const char *name, int value) {
p.put(name, value);
}
Expand All @@ -53,25 +69,6 @@ struct params {
boost::property_tree::ptree p;
};

//---------------------------------------------------------------------------
params make_params(boost::python::tuple args, boost::python::dict kwargs) {
params p;

using namespace boost::python;

for(stl_input_iterator<tuple> arg(kwargs.items()), end; arg != end; ++arg) {
const char *name = extract<const char*>((*arg)[0]);
const char *type = extract<const char*>((*arg)[1].attr("__class__").attr("__name__"));

if (strcmp(type, "int") == 0)
p.seti(name, extract<int>((*arg)[1]));
else
p.setf(name, extract<float>((*arg)[1]));
}

return p;
}

//---------------------------------------------------------------------------
struct make_solver {
make_solver(
Expand Down Expand Up @@ -166,15 +163,14 @@ BOOST_PYTHON_MODULE(pyamgcl)
{
using namespace boost::python;

class_<params>("params")
class_<params>("params", init<>())
.def(init<const boost::python::dict &>())
.def("__setitem__", &params::seti)
.def("__setitem__", &params::setf)
.def("__str__", &params::str)
.def("__repr__", &params::repr)
;

def("make_params", raw_function(make_params));

enum_<amgcl::runtime::coarsening::type>("coarsening")
.value("ruge_stuben", amgcl::runtime::coarsening::ruge_stuben)
.value("aggregation", amgcl::runtime::coarsening::aggregation)
Expand Down
2 changes: 1 addition & 1 deletion python/test_pyamgcl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestPyAMGCL(unittest.TestCase):
amg.coarsening.smoothed_aggregation,
amg.relaxation.spai0,
amg.solver_type.bicgstab,
amg.make_params(tol = 1e-8),
amg.params({"tol" : 1e-8}),
A.indptr.astype(np.int32),
A.indices.astype(np.int32),
A.data.astype(np.float64)
Expand Down

0 comments on commit e64acdd

Please sign in to comment.