File tree Expand file tree Collapse file tree 1 file changed +35
-3
lines changed
Expand file tree Collapse file tree 1 file changed +35
-3
lines changed Original file line number Diff line number Diff line change 235235 {
236236 "cell_type" : " code" ,
237237 "execution_count" : 5 ,
238+ "id" : " sharing-sugar" ,
239+ "metadata" : {
240+ "collapsed" : false ,
241+ "execution" : {
242+ "iopub.execute_input" : " 2021-09-14T13:18:50.317866Z" ,
243+ "iopub.status.busy" : " 2021-09-14T13:18:50.317492Z" ,
244+ "iopub.status.idle" : " 2021-09-14T13:18:50.319354Z" ,
245+ "shell.execute_reply" : " 2021-09-14T13:18:50.318988Z"
246+ },
247+ "pycharm" : {
248+ "name" : " #%%\n "
249+ }
250+ },
251+ "outputs" : [],
252+ "source" : [
253+ " %%cppdef\n " ,
254+ " \n " ,
255+ " // implemented in C++ for efficiency\n " ,
256+ " int avg_width(const ogdf::GraphAttributes &GA) {\n " ,
257+ " int sum = 0;\n " ,
258+ " for (auto n : GA.constGraph().nodes) {\n " ,
259+ " sum += GA.width(n);\n " ,
260+ " }\n " ,
261+ " return sum / GA.constGraph().numberOfNodes();\n " ,
262+ " }"
263+ ]
264+ },
265+ {
266+ "cell_type" : " code" ,
267+ "execution_count" : 6 ,
238268 "id" : " brutal-egyptian" ,
239269 "metadata" : {
240270 "execution" : {
249279 "name" : " stdout" ,
250280 "output_type" : " stream" ,
251281 "text" : [
252- " The node widths are 20 20 20 20 40 20 20 20 20 20 20 20 20 20 20 20\n "
282+ " The node widths are 20 20 20 20 40 20 20 20 20 20 20 20 20 20 20 20\n " ,
283+ " The average width is 22\n "
253284 ]
254285 },
255286 {
273304 ],
274305 "source" : [
275306 " print(\" The node widths are\" , GA.width())\n " ,
307+ " print(\" The average width is\" , cpp.avg_width(GA)) # call your own C++ functions from python\n " ,
276308 " \n " ,
277309 " dict(zip(G.nodes, GA.width()))"
278310 ]
279311 },
280312 {
281313 "cell_type" : " code" ,
282- "execution_count" : 6 ,
314+ "execution_count" : 7 ,
283315 "id" : " covered-effect" ,
284316 "metadata" : {
285317 "execution" : {
411443 },
412444 {
413445 "cell_type" : " code" ,
414- "execution_count" : 7 ,
446+ "execution_count" : 8 ,
415447 "id" : " wrapped-mexican" ,
416448 "metadata" : {
417449 "execution" : {
You can’t perform that action at this time.
0 commit comments