Skip to content

Commit ac17781

Browse files
committed
Fix issues with separated pybind functionality.
1 parent 4e058b7 commit ac17781

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

core/pythoncdb/py_algorithms.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "py_algorithms.hh"
2+
3+
#include <pybind11/stl.h>
4+
25
#include "../Algorithm.hh"
36

47
#include "../algorithms/canonicalise.hh"
@@ -93,9 +96,9 @@ namespace cadabra
9396
def_algo<sort_sum>(m, "sort_sum", true, false, 0);
9497
def_algo<tabdimension>(m, "tab_dimension", true, false, 0);
9598
def_algo<young_project_product>(m, "young_project_product", true, false, 0);
99+
def_algo<drop_weight, Ex>(m, "drop_weight", false, false, 0, py::arg("condition") = Ex{});
96100
def_algo<complete, Ex>(m, "complete", false, false, 0, py::arg("add"));
97101
def_algo<decompose, Ex>(m, "decompose", false, false, 0, py::arg("basis"));
98-
def_algo<drop_weight, Ex>(m, "drop_weight", false, false, 0, py::arg("condition"));
99102
def_algo<eliminate_metric, Ex>(m, "eliminate_metric", true, false, 0, py::arg("preferred") = Ex{});
100103
def_algo<keep_weight, Ex>(m, "keep_weight", false, false, 0, py::arg("condition"));
101104
def_algo<lower_free_indices, bool>(m, "lower_free_indices", true, false, 0, py::arg("lower") = true);
@@ -126,6 +129,5 @@ namespace cadabra
126129
def_algo<split_gamma, bool>(m, "split_gamma", true, false, 0, py::arg("on_back"));
127130
def_algo<split_index, Ex>(m, "split_index", true, false, 0, py::arg("rules"));
128131
def_algo<unwrap, Ex>(m, "unwrap", true, false, 0, py::arg("wrapper") = Ex{});
129-
130132
}
131133
}

core/pythoncdb/py_algorithms.hh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace cadabra
1010
{
1111
template <class Algo, typename... Args>
12-
Ex_ptr apply_algo(Ex_ptr ex, bool deep, bool repeat, unsigned int depth, Args... args)
12+
Ex_ptr apply_algo(Ex_ptr ex, Args... args, bool deep, bool repeat, unsigned int depth)
1313
{
1414
Algo algo(*get_kernel_from_scope(), *ex, args...);
1515

@@ -25,21 +25,21 @@ namespace cadabra
2525
}
2626

2727
template<class Algo, typename... Args, typename... PyArgs>
28-
void def_algo(pybind11::module& m, const char* name, bool deep, bool repeat, unsigned int depth, PyArgs... args)
28+
void def_algo(pybind11::module& m, const char* name, bool deep, bool repeat, unsigned int depth, PyArgs... pyargs)
2929
{
3030
m.def(name,
31-
&apply_algo<Algo, Args...>,
31+
&apply_algo<Algo, Args...>,
3232
pybind11::arg("ex"),
33+
std::forward<PyArgs>(pyargs)...,
3334
pybind11::arg("deep") = deep,
3435
pybind11::arg("repeat") = repeat,
3536
pybind11::arg("depth") = depth,
36-
std::forward<PyArgs>(args)...,
3737
pybind11::doc(read_manual("algorithms", name).c_str()),
3838
pybind11::return_value_policy::reference_internal);
3939
}
4040

4141
template <class Algo, typename... Args>
42-
Ex_ptr apply_algo_preorder(Ex_ptr ex, bool deep, bool repeat, unsigned int depth, Args... args)
42+
Ex_ptr apply_algo_preorder(Ex_ptr ex, Args... args, bool deep, bool repeat, unsigned int depth)
4343
{
4444
Algo algo(*get_kernel_from_scope(), *ex, args...);
4545

@@ -55,15 +55,15 @@ namespace cadabra
5555
}
5656

5757
template<class Algo, typename... Args, typename... PyArgs>
58-
void def_algo_preorder(pybind11::module& m, const char* name, bool deep, bool repeat, unsigned int depth, PyArgs... args)
58+
void def_algo_preorder(pybind11::module& m, const char* name, bool deep, bool repeat, unsigned int depth, PyArgs... pyargs)
5959
{
6060
m.def(name,
6161
&apply_algo_preorder<Algo, Args...>,
6262
pybind11::arg("ex"),
63+
std::forward<PyArgs>(pyargs)...,
6364
pybind11::arg("deep") = deep,
6465
pybind11::arg("repeat") = repeat,
6566
pybind11::arg("depth") = depth,
66-
std::forward<PyArgs>(args)...,
6767
pybind11::doc(read_manual("algorithms", name).c_str()),
6868
pybind11::return_value_policy::reference_internal);
6969
}

core/pythoncdb/py_ex.cc

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
#include "Config.hh"
3+
14
#include "py_ex.hh"
25
#include "py_helpers.hh"
36
#include "py_globals.hh"
@@ -502,18 +505,9 @@ namespace cadabra
502505
std::vector<std::string> av;
503506
for (auto& arg : args)
504507
av.push_back(arg.cast<std::string>());
505-
return apply_algo_preorder<map_sympy, std::string, std::vector<std::string>>(ex, true, false, 0, head, av);
508+
return apply_algo_preorder<map_sympy, std::string, std::vector<std::string>>(ex, head, av, true, false, 0);
506509
}
507510

508-
#ifdef MATHEMATICA_FOUND
509-
Ex_ptr map_mma_wrapper(Ex_ptr ex, std::string head)
510-
{
511-
map_mma algo(*get_kernel_from_scope(), *ex, head);
512-
return dispatch_base(ex, algo, true, false, 0, true);
513-
}
514-
#endif
515-
516-
517511
void init_ex(py::module& m)
518512
{
519513
pybind11::enum_<str_node::parent_rel_t>(m, "parent_rel_t")
@@ -589,12 +583,9 @@ namespace cadabra
589583
pybind11::arg("ex"),
590584
pybind11::arg("function") = "",
591585
pybind11::return_value_policy::reference_internal);
592-
#ifdef MATHEMATICA_FOUND
593-
m.def("map_mma", &map_mma_wrapper,
594-
pybind11::arg("ex"),
595-
pybind11::arg("function") = "",
596-
pybind11::return_value_policy::reference_internal);
597-
#endif
586+
#ifdef MATHEMATICA_FOUND
587+
def_algo<map_mma, std::string>(m, "map_mma", false, false, 0, pybind11::arg("function") = "");
588+
#endif
598589

599590
m.def("terms", &terms);
600591

0 commit comments

Comments
 (0)