forked from igraph/python-igraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.h
More file actions
147 lines (125 loc) · 7.37 KB
/
Copy pathconvert.h
File metadata and controls
147 lines (125 loc) · 7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* -*- mode: C -*- */
/*
IGraph library.
Copyright (C) 2006-2012 Tamas Nepusz <ntamas@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/************************ Miscellaneous functions *************************/
/** \defgroup python_interface_conversion Converting between Python and igraph data types
* \ingroup python_interface */
#ifndef PYTHON_CONVERT_H
#define PYTHON_CONVERT_H
#include <Python.h>
#include <igraph_constants.h>
#include <igraph_types.h>
#include "graphobject.h"
typedef enum { IGRAPHMODULE_TYPE_INT=0, IGRAPHMODULE_TYPE_FLOAT }
igraphmodule_conv_t;
typedef struct {
const char* name;
int value;
} igraphmodule_enum_translation_table_entry_t;
int PyInt_AsInt(PyObject* obj, int* result);
int PyLong_AsInt(PyObject* obj, int* result);
/* Conversion from PyObject to enum types */
int igraphmodule_PyObject_to_enum(PyObject *o,
igraphmodule_enum_translation_table_entry_t *table, int *result);
int igraphmodule_PyObject_to_add_weights_t(PyObject *o, igraph_add_weights_t *result);
int igraphmodule_PyObject_to_adjacency_t(PyObject *o, igraph_adjacency_t *result);
int igraphmodule_PyObject_to_attribute_combination_type_t(PyObject* o,
igraph_attribute_combination_type_t *type);
int igraphmodule_PyObject_to_barabasi_algorithm_t(PyObject *o,
igraph_barabasi_algorithm_t *result);
int igraphmodule_PyObject_to_bliss_sh_t(PyObject *o, igraph_bliss_sh_t *result);
int igraphmodule_PyObject_to_community_comparison_t(PyObject *obj,
igraph_community_comparison_t *result);
int igraphmodule_PyObject_to_connectedness_t(PyObject *o, igraph_connectedness_t *result);
int igraphmodule_PyObject_to_degseq_t(PyObject *o, igraph_degseq_t *result);
int igraphmodule_PyObject_to_fas_algorithm_t(PyObject *o, igraph_fas_algorithm_t *result);
int igraphmodule_PyObject_to_layout_grid_t(PyObject *o, igraph_layout_grid_t *result);
int igraphmodule_PyObject_to_neimode_t(PyObject *o, igraph_neimode_t *result);
int igraphmodule_PyObject_to_pagerank_algo_t(PyObject *o, igraph_pagerank_algo_t *result);
int igraphmodule_PyObject_to_random_walk_stuck_t(PyObject *o, igraph_random_walk_stuck_t *result);
int igraphmodule_PyObject_to_reciprocity_t(PyObject *o, igraph_reciprocity_t *result);
int igraphmodule_PyObject_to_rewiring_t(PyObject *o, igraph_rewiring_t *result);
int igraphmodule_PyObject_to_spinglass_implementation_t(PyObject *o, igraph_spinglass_implementation_t *result);
int igraphmodule_PyObject_to_spincomm_update_t(PyObject *o, igraph_spincomm_update_t *result);
int igraphmodule_PyObject_to_star_mode_t(PyObject *o, igraph_star_mode_t *result);
int igraphmodule_PyObject_to_subgraph_implementation_t(PyObject *o, igraph_subgraph_implementation_t *result);
int igraphmodule_PyObject_to_to_undirected_t(PyObject *o, igraph_to_undirected_t *result);
int igraphmodule_PyObject_to_transitivity_mode_t(PyObject *o, igraph_transitivity_mode_t *result);
int igraphmodule_PyObject_to_tree_mode_t(PyObject *o, igraph_tree_mode_t *result);
int igraphmodule_PyObject_to_vconn_nei_t(PyObject *o, igraph_vconn_nei_t *result);
/* Conversion from PyObject to igraph types */
int igraphmodule_PyObject_to_integer_t(PyObject *object, igraph_integer_t *v);
int igraphmodule_PyObject_to_real_t(PyObject *object, igraph_real_t *v);
int igraphmodule_PyObject_to_igraph_t(PyObject *o, igraph_t **result);
int igraphmodule_PyObject_to_vector_t(PyObject *list, igraph_vector_t *v,
igraph_bool_t need_non_negative);
int igraphmodule_PyObject_float_to_vector_t(PyObject *list, igraph_vector_t *v);
int igraphmodule_PyObject_to_vector_int_t(PyObject *list, igraph_vector_int_t *v);
int igraphmodule_PyObject_to_vector_long_t(PyObject *list, igraph_vector_long_t *v);
int igraphmodule_PyObject_to_vector_bool_t(PyObject *list, igraph_vector_bool_t *v);
int igraphmodule_PyObject_to_vector_ptr_t(PyObject *list, igraph_vector_ptr_t *v,
igraph_bool_t need_non_negative);
int igraphmodule_PyObject_to_edgelist(PyObject *list, igraph_vector_t *v, igraph_t *graph);
int igraphmodule_PyList_to_matrix_t(PyObject *o, igraph_matrix_t *m);
PyObject* igraphmodule_strvector_t_to_PyList(igraph_strvector_t *v);
int igraphmodule_PyList_to_strvector_t(PyObject* v, igraph_strvector_t *result);
int igraphmodule_append_PyIter_of_graphs_to_vector_ptr_t(PyObject *it,
igraph_vector_ptr_t *v);
int igraphmodule_PyObject_to_vid(PyObject *o, igraph_integer_t *vid, igraph_t *graph);
int igraphmodule_PyObject_to_vs_t(PyObject *o, igraph_vs_t *vs,
igraph_t *graph, igraph_bool_t *return_single,
igraph_integer_t *single_vid);
int igraphmodule_PyObject_to_eid(PyObject *o, igraph_integer_t *eid, igraph_t *graph);
int igraphmodule_PyObject_to_es_t(PyObject *o, igraph_es_t *es, igraph_t *graph,
igraph_bool_t *return_single);
int igraphmodule_PyObject_to_attribute_values(PyObject *o,
igraph_vector_t *v,
igraphmodule_GraphObject* g,
int type,
igraph_real_t def);
int igraphmodule_PyObject_to_drl_options_t(PyObject *obj,
igraph_layout_drl_options_t *options);
int igraphmodule_PyObject_to_attribute_combination_t(PyObject* object,
igraph_attribute_combination_t *type);
int igraphmodule_PyObject_to_eigen_algorithm_t(PyObject *object,
igraph_eigen_algorithm_t *a);
int igraphmodule_PyObject_to_eigen_which_t(PyObject *object,
igraph_eigen_which_t *w);
/* Conversion from attributes to igraph types */
int igraphmodule_attrib_to_vector_t(PyObject *o, igraphmodule_GraphObject *self,
igraph_vector_t **vptr, int attr_type);
int igraphmodule_attrib_to_vector_int_t(PyObject *o, igraphmodule_GraphObject *self,
igraph_vector_int_t **vptr, int attr_type);
int igraphmodule_attrib_to_vector_long_t(PyObject *o, igraphmodule_GraphObject *self,
igraph_vector_long_t **vptr, int attr_type);
int igraphmodule_attrib_to_vector_bool_t(PyObject *o, igraphmodule_GraphObject *self,
igraph_vector_bool_t **vptr, int attr_type);
/* Conversion from igraph types to PyObjects */
PyObject* igraphmodule_vector_bool_t_to_PyList(const igraph_vector_bool_t *v);
PyObject* igraphmodule_vector_t_to_PyList(const igraph_vector_t *v,
igraphmodule_conv_t type);
PyObject* igraphmodule_vector_t_to_PyTuple(const igraph_vector_t *v);
PyObject* igraphmodule_vector_t_pair_to_PyList(const igraph_vector_t *v1,
const igraph_vector_t *v2);
PyObject* igraphmodule_vector_t_to_PyList_pairs(const igraph_vector_t *v);
PyObject* igraphmodule_vector_ptr_t_to_PyList(const igraph_vector_ptr_t *v,
igraphmodule_conv_t type);
PyObject* igraphmodule_vector_int_t_to_PyList(const igraph_vector_int_t *v);
PyObject* igraphmodule_vector_long_t_to_PyList(const igraph_vector_long_t *v);
PyObject* igraphmodule_matrix_t_to_PyList(const igraph_matrix_t *m,
igraphmodule_conv_t type);
#endif