88
99namespace cadabra
1010 {
11- template <class Algo , typename ... Args >
12- Ex_ptr apply_algo (Ex_ptr ex, Args... args , bool deep, bool repeat, unsigned int depth)
11+ template <class Algo >
12+ Ex_ptr apply_algo_base (Algo& algo, Ex_ptr ex , bool deep, bool repeat, unsigned int depth, bool pre_order= false )
1313 {
14- Algo algo (*get_kernel_from_scope (), *ex, args...);
15-
1614 Ex::iterator it = ex->begin ();
1715 if (ex->is_valid (it)) {
1816 ProgressMonitor* pm = get_progress_monitor ();
1917 algo.set_progress_monitor (pm);
20- ex->update_state (algo.apply_generic (it, deep, repeat, depth));
18+ if (pre_order)
19+ ex->update_state (algo.apply_pre_order (repeat));
20+ else
21+ ex->update_state (algo.apply_generic (it, deep, repeat, depth));
2122 call_post_process (*get_kernel_from_scope (), ex);
2223 }
2324
2425 return ex;
2526 }
27+
28+ template <class Algo >
29+ Ex_ptr apply_algo (Ex_ptr ex, bool deep, bool repeat, unsigned int depth)
30+ {
31+ Algo algo (*get_kernel_from_scope (), *ex);
32+ return apply_algo_base (algo, ex, deep, repeat, depth, false );
33+ }
34+
35+ template <class Algo , typename Arg1>
36+ Ex_ptr apply_algo (Ex_ptr ex, Arg1 arg1, bool deep, bool repeat, unsigned int depth)
37+ {
38+ Algo algo (*get_kernel_from_scope (), *ex, arg1);
39+ return apply_algo_base (algo, ex, deep, repeat, depth, false );
40+ }
41+
42+ template <class Algo , typename Arg1, typename Arg2>
43+ Ex_ptr apply_algo (Ex_ptr ex, Arg1 arg1, Arg2 arg2, bool deep, bool repeat, unsigned int depth)
44+ {
45+ Algo algo (*get_kernel_from_scope (), *ex, arg1, arg2);
46+ return apply_algo_base (algo, ex, deep, repeat, depth, false );
47+ }
48+
49+ template <class Algo , typename Arg1, typename Arg2, typename Arg3>
50+ Ex_ptr apply_algo (Ex_ptr ex, Arg1 arg1, Arg2 arg2, Arg3 arg3, bool deep, bool repeat, unsigned int depth)
51+ {
52+ Algo algo (*get_kernel_from_scope (), *ex, arg1, arg2, arg3);
53+ return apply_algo_base (algo, ex, deep, repeat, depth, false );
54+ }
55+
2656
2757 template <class Algo , typename ... Args, typename ... PyArgs>
2858 void def_algo (pybind11::module & m, const char * name, bool deep, bool repeat, unsigned int depth, PyArgs... pyargs)
@@ -38,20 +68,18 @@ namespace cadabra
3868 pybind11::return_value_policy::reference_internal);
3969 }
4070
41- template <class Algo , typename ... Args >
42- Ex_ptr apply_algo_preorder (Ex_ptr ex, Args... args , bool deep, bool repeat, unsigned int depth)
71+ template <class Algo , typename Arg1 >
72+ Ex_ptr apply_algo_preorder (Ex_ptr ex, Arg1 arg1 , bool deep, bool repeat, unsigned int depth)
4373 {
44- Algo algo (*get_kernel_from_scope (), *ex, args...);
45-
46- Ex::iterator it = ex->begin ();
47- if (ex->is_valid (it)) {
48- ProgressMonitor* pm = get_progress_monitor ();
49- algo.set_progress_monitor (pm);
50- ex->update_state (algo.apply_pre_order (repeat));
51- call_post_process (*get_kernel_from_scope (), ex);
52- }
74+ Algo algo (*get_kernel_from_scope (), *ex, arg1);
75+ return apply_algo_base (algo, ex, deep, repeat, depth, true );
76+ }
5377
54- return ex;
78+ template <class Algo , typename Arg1, typename Arg2>
79+ Ex_ptr apply_algo_preorder (Ex_ptr ex, Arg1 arg1, Arg2 arg2, bool deep, bool repeat, unsigned int depth)
80+ {
81+ Algo algo (*get_kernel_from_scope (), *ex, arg1, arg2);
82+ return apply_algo_base (algo, ex, deep, repeat, depth, true );
5583 }
5684
5785 template <class Algo , typename ... Args, typename ... PyArgs>
0 commit comments