Compose/mem_fun/confusion
Hello,
I'm trying to explore the compose, bind, and mem_fn libraries. I
used a "real" problem I'm having. Given a vector<Trade>, I want to
gather a sum of the return values of Trade::volume().
I wound up writing "accumulate_with_op" thusly:
template
Hi, I found the following problems when I run examples programs in the libs/graph/examples (I run and tested the running all example program.): In few cases I didn't find problem just the program run many time (more than 1 minutes, maybe problem..) therefore I also reported. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 boost_web_graph.cpp 2 [thorin] {...libs/graph/example:1812} a.out /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0/boost/graph/detail/adjacency_list.hpp:843: failed assertion `u != v' Abort (core dumped) Exit 134 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dag_shortest_paths.cpp 2 [thorin] {...libs/graph/example:1837} a.out 0: 2147483647 1: 0 2: 2 3: 6 4: 5 5: 3 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dave.cpp 2 [thorin] {...libs/graph/example:1840} a.out a --> c d b --> a d c --> f d --> c e f e --> b g f --> e g g --> Starting graph: a 2147483647 (a,c) (a,d) c 2147483647 (c,f) d 2147483647 (d,c) (d,e) (d,f) f 2147483647 (f,e) (f,g) e 2147483647 (e,b) (e,g) g 2147483647 b 2147483647 (b,a) (b,d) infinite loop.............. ^CSegmentation fault (core dumped) Exit 139 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dijkstra-example.cpp infinite loop... ^CSegmentation fault (core dumped) Exit 139 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 edge-function.cpp edge-function.cpp:137: failed assertion `exists == true' Abort (core dumped) Exit 134 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 edmunds-karp-eg.cpp a.out (many time run.) g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 johnson-eg.cpp a.out Segmentation fault Exit 139 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 max_flow.cpp a.out ^C ^C (many time run) g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 min_max_paths.cpp a.out Segmentation fault Exit 139 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 minimum_degree_ordering.cpp /tmp/ccuZOrPG.o: In function `harwell_boeing::harwell_boeing(char *)': /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x3d): undefined reference to `readHB_info' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x71): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xa6): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xe5): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x126): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x13b): undefined reference to `readHB_mat_double' collect2: ld returned 1 exit status Exit 1 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 minimum_degree_ordering.cpp /tmp/ccSQnK6n.o: In function `harwell_boeing::harwell_boeing(char *)': /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x3d): undefined reference to `readHB_info' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x71): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xa6): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xe5): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x126): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x13b): undefined reference to `readHB_mat_double' collect2: ld returned 1 exit status Exit 1 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 prim-example.cpp a.out /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0/boost/graph/detail/adjacency_list.hpp:843: failed assertion `u != v' Abort (core dumped) Exit 134 g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 push-relabel-eg.cpp a.out ^C (many time run) Janos
Hi Janos, Here's the replies to all the issues you listed. I've checked in all the bug fixes to CVS at boost sourceforge, so you can get an update from there, or wait until the next boost release, which may not be for a while. Cheers, Jeremy g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 boost_web_graph.cpp 2 [thorin] {...libs/graph/example:1812} a.out /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0/boost/graph/detail/adjacency_list.hpp:843: failed assertion `u != v' Abort (core dumped) Exit 134 Fixed. The example was using an undirected graph when it should have been using a directed graph. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dag_shortest_paths.cpp 2 [thorin] {...libs/graph/example:1837} a.out 0: 2147483647 1: 0 2: 2 3: 6 4: 5 5: 3 The above is the correct output. The large number represents infinity. There is no path from the source to vertex 0. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dave.cpp 2 [thorin] {...libs/graph/example:1840} a.out a --> c d b --> a d c --> f d --> c e f e --> b g f --> e g g --> Starting graph: a 2147483647 (a,c) (a,d) c 2147483647 (c,f) d 2147483647 (d,c) (d,e) (d,f) f 2147483647 (f,e) (f,g) e 2147483647 (e,b) (e,g) g 2147483647 b 2147483647 (b,a) (b,d) infinite loop.............. ^CSegmentation fault (core dumped) Exit 139 Fixed. There was a typo in a recent change to dijkstra_shortest_paths. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dijkstra-example.cpp infinite loop... ^CSegmentation fault (core dumped) Exit 139 Fixed. Same bug as with dave.cpp. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 edge-function.cpp edge-function.cpp:137: failed assertion `exists == true' Abort (core dumped) Exit 134 Fixed. Needed to update the example to match a change that was made to the graph data file. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 edmunds-karp-eg.cpp a.out (many time run.) The program was waiting for input. You have to pass the input graph through stdin. e.g.: edmunds-karp-eg < max_flow.dat g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 johnson-eg.cpp a.out Segmentation fault Exit 139 I could not reproduce the error. Probably fixed by the previous fix to dijkstra's. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 max_flow.cpp a.out ^C ^C (many time run) The program was waiting for input. You have to pass the input graph through stdin. e.g.: max_flow < max_flow.dat g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 min_max_paths.cpp a.out Segmentation fault Exit 139 I could not reproduce the error. Probably fixed by the previous fix to dijkstra's. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 minimum_degree_ordering.cpp /tmp/ccuZOrPG.o: In function `harwell_boeing::harwell_boeing(char *)': /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x3d): undefined reference to `readHB_info' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x71): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xa6): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xe5): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x126): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x13b): undefined reference to `readHB_mat_double' collect2: ld returned 1 exit status Exit 1 You also need to compile and link in the iohb.c file. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 minimum_degree_ordering.cpp /tmp/ccSQnK6n.o: In function `harwell_boeing::harwell_boeing(char *)': /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x3d): undefined reference to `readHB_info' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x71): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xa6): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xe5): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x126): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x13b): undefined reference to `readHB_mat_double' collect2: ld returned 1 exit status Exit 1 You also need to compile and link in the iohb.c file. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 prim-example.cpp a.out /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0/boost/graph/detail/adjacency_list.hpp:843: failed assertion `u != v' Abort (core dumped) Exit 134 Fixed. Example tried to added a self edge to an undirected graph. I took out the self edge. g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 push-relabel-eg.cpp a.out ^C (many time run) The program was waiting for input. You have to pass the input graph through stdin. e.g.: push-relabel-eg < max_flow.dat ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------
Hi Jeremy,
Here's the replies to all the issues you listed. I've checked in all the bug fixes to CVS at boost sourceforge, so you can get an update from there, or wait until the next boost release, which may not be for a while.
Thank you very much the fast answer. I looked through the list I'll probably download the update from sourceforge in January. Merry Christmas! Cheers, Janos
Cheers, Jeremy
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 boost_web_graph.cpp 2 [thorin] {...libs/graph/example:1812} a.out /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0/boost/graph/detail/adjacency_list.hpp:843: failed assertion `u != v' Abort (core dumped) Exit 134
Fixed. The example was using an undirected graph when it should have been using a directed graph.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dag_shortest_paths.cpp 2 [thorin] {...libs/graph/example:1837} a.out 0: 2147483647 1: 0 2: 2 3: 6 4: 5 5: 3
The above is the correct output. The large number represents infinity. There is no path from the source to vertex 0.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dave.cpp 2 [thorin] {...libs/graph/example:1840} a.out a --> c d b --> a d c --> f d --> c e f e --> b g f --> e g g --> Starting graph: a 2147483647 (a,c) (a,d) c 2147483647 (c,f) d 2147483647 (d,c) (d,e) (d,f) f 2147483647 (f,e) (f,g) e 2147483647 (e,b) (e,g) g 2147483647 b 2147483647 (b,a) (b,d) infinite loop.............. ^CSegmentation fault (core dumped) Exit 139
Fixed. There was a typo in a recent change to dijkstra_shortest_paths.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 dijkstra-example.cpp infinite loop... ^CSegmentation fault (core dumped) Exit 139
Fixed. Same bug as with dave.cpp.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 edge-function.cpp edge-function.cpp:137: failed assertion `exists == true' Abort (core dumped) Exit 134
Fixed. Needed to update the example to match a change that was made to the graph data file.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 edmunds-karp-eg.cpp a.out (many time run.)
The program was waiting for input. You have to pass the input graph through stdin. e.g.:
edmunds-karp-eg < max_flow.dat
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 johnson-eg.cpp a.out Segmentation fault Exit 139
I could not reproduce the error. Probably fixed by the previous fix to dijkstra's.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 max_flow.cpp a.out ^C ^C (many time run)
The program was waiting for input. You have to pass the input graph through stdin. e.g.:
max_flow < max_flow.dat
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 min_max_paths.cpp a.out Segmentation fault Exit 139
I could not reproduce the error. Probably fixed by the previous fix to dijkstra's.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 minimum_degree_ordering.cpp /tmp/ccuZOrPG.o: In function `harwell_boeing::harwell_boeing(char *)': /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x3d): undefined reference to `readHB_info' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x71): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xa6): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xe5): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x126): undefined reference to `IOHBTerminate' /tmp/ccuZOrPG.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x13b): undefined reference to `readHB_mat_double' collect2: ld returned 1 exit status Exit 1
You also need to compile and link in the iohb.c file.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 minimum_degree_ordering.cpp /tmp/ccSQnK6n.o: In function `harwell_boeing::harwell_boeing(char *)': /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x3d): undefined reference to `readHB_info' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x71): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xa6): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0xe5): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x126): undefined reference to `IOHBTerminate' /tmp/ccSQnK6n.o(.harwell_boeing::gnu.linkonce.t.(char *)+0x13b): undefined reference to `readHB_mat_double' collect2: ld returned 1 exit status Exit 1
You also need to compile and link in the iohb.c file.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 prim-example.cpp a.out /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0/boost/graph/detail/adjacency_list.hpp:843: failed assertion `u != v' Abort (core dumped) Exit 134
Fixed. Example tried to added a self edge to an undirected graph. I took out the self edge.
g++ -ftemplate-depth-30 -I /net/cooler/vol/export/proteome/murvai/CC/BOOST/boost_1_26_0 push-relabel-eg.cpp a.out ^C (many time run)
The program was waiting for input. You have to pass the input graph through stdin. e.g.:
push-relabel-eg < max_flow.dat
---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
On Friday 14 December 2001 03:06 pm, you wrote:
Hello,
I'm trying to explore the compose, bind, and mem_fn libraries. I used a "real" problem I'm having. Given a vector<Trade>, I want to gather a sum of the return values of Trade::volume(). [...] vector<Trade> li; // ..... sum = accumulate_with_op(li.begin(),li.end(),0,mem_fun_ref (&Trade::volume))
This gives me my sum pretty nicely, so I'm sort of happy... BUT...
Here are two ways to compute the sum without defining your own functions or classes. Both methods use std::accumulate (which, of course, is what you're trying to do), but the difference is in the way that Trade::volume() is called. The first code snippet uses Boost.Bind only. We essentially create a function object that takes two arguments, x and y, and then performs the operation x + y.Volume(). We get '+' by using the standard library's plus<int>, and we use the fact that bind is composable to call Volume on the second argument. The code is thus: std::accumulate(li.begin(), li.end(), 0, boost::bind<int>( std::plus<int>(), _1, boost::bind(&Trade::Volume, _2))); The other option is philosophically different. Instead of transforming he values as we add them, we instead transform the sequence we are adding using the Boost Iterator Adaptors library. The transform_iterator adapts an iterator by applying a function object to each element as it is dereferenced. Therefore, the sequence that accumulate "sees" is the result of calling Trade::Volume on each member of the underlying sequence. Here's the code: std::accumulate( boost::make_transform_iterator(li.begin(), boost::mem_fn(&Trade::Volume)), boost::make_transform_iterator(li.end(), boost::mem_fn(&Trade::Volume)), 0); I consider this version better (philosphically) because the accumulation is over things we can actually accumulate - integers. The transform_iterator version is also more reusable code, because now you have the ability to transform a sequence of Trade objects (or Trade object pointers - see the documentation of mem_fn) into their corresponding trade volumes, and other operations become simpler. Code was tested under GCC 2.95.3, but I expect it will work for MSVC5. Doug
From: "dmoore99atwork"
Hello,
I'm trying to explore the compose, bind, and mem_fn libraries. I used a "real" problem I'm having. Given a vector<Trade>, I want to gather a sum of the return values of Trade::volume().
I wound up writing "accumulate_with_op" thusly: [...]
As Douglas already pointed out, std::accumulate has a version that takes a binary function object that can be used to do the job. However, I've found that the easiest way to solve these problems is to simply use for_each, like this: void add(double & a, double b) { a += b; } double sum = 0.0; std::for_each(trades.begin(), trades.end(), bind(add, ref(sum), bind(&Trade::volume, _1))); As you can see from the above, bind can compose, so you don't need compose_f_gx.
I tried for a long time to use combinations of for_each, compose_f_gx, and mem_fn to be able to do the Sum (to lead to other things like mean, stddev) into a stateful function object. Something like this:
/* broken code, trying to convery my intentions */ MeanValue m1; m1 = for_each(l.begin(), l.end(),compose_f_gx(MeanValue(),mem_fun_ref (&Trade::volume)); cout << m1.result();
I'm not sure that I understand correctly your intent, but this might be what
you want:
#include
participants (5)
-
dmoore99atwork
-
Douglas Gregor
-
Janos Murvai
-
Jeremy Siek
-
Peter Dimov