Changeset 14244 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/DllImporter.cs
- Timestamp:
- 08/08/16 20:48:54 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/DllImporter.cs
r14234 r14244 23 23 using System.Runtime.InteropServices; 24 24 25 namespace HeuristicLab. igraph {25 namespace HeuristicLab.IGraph { 26 26 internal static class DllImporter { 27 27 private const string X86Dll = "igraph-0.8.0-pre-x86.dll"; 28 28 private const string X64Dll = "igraph-0.8.0-pre-x64.dll"; 29 private readonly static bool X 64= false;29 private readonly static bool X86 = false; 30 30 31 31 static DllImporter() { 32 X 64 =Environment.Is64BitProcess;32 X86 = !Environment.Is64BitProcess; 33 33 } 34 34 … … 36 36 #region igraph init/finalize 37 37 internal static void igraph_empty(igraph_t graph, int n, bool directed) { 38 if (X 64) igraph_empty_x64(graph, n, directed);39 else igraph_empty_x 86(graph, n, directed);38 if (X86) igraph_empty_x86(graph, n, directed); 39 else igraph_empty_x64(graph, n, directed); 40 40 } 41 41 internal static int igraph_destroy(igraph_t graph) { 42 return X 64 ? igraph_destroy_x64(graph) : igraph_destroy_x86(graph);42 return X86 ? igraph_destroy_x86(graph) : igraph_destroy_x64(graph); 43 43 } 44 44 #endregion … … 46 46 #region igraph query 47 47 internal static int igraph_vcount(igraph_t graph) { 48 return X64 ? igraph_vcount_x64(graph) : igraph_vcount_x86(graph); 48 return X86 ? igraph_vcount_x86(graph) : igraph_vcount_x64(graph); 49 } 50 #endregion 51 52 #region igraph characteristics 53 internal static int igraph_density(igraph_t graph, out double density, bool loops) { 54 density = double.NaN; 55 return X86 ? igraph_density_x86(graph, ref density, loops) : igraph_density_x64(graph, ref density, loops); 56 } 57 58 internal static int igraph_pagerank(igraph_t graph, igraph_pagerank_algo_t algo, igraph_vector_t vector, out double value, igraph_vs_t vids, bool directed, double damping, igraph_vector_t weights) { 59 value = 1; 60 var options = IntPtr.Zero; 61 if (algo == igraph_pagerank_algo_t.IGRAPH_PAGERANK_ALGO_ARPACK) { 62 var arpackoptions = GetDefaultArpackOptions(); 63 options = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(igraph_arpack_options_t))); 64 Marshal.StructureToPtr(arpackoptions, options, false); 65 } else if (algo == igraph_pagerank_algo_t.IGRAPH_PAGERANK_ALGO_POWER) { 66 var poweroptions = GetDefaultPowerOptions(); 67 options = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(igraph_pagerank_power_options_t))); 68 Marshal.StructureToPtr(poweroptions, options, false); 69 } 70 try { 71 return X86 ? igraph_pagerank_x86(graph, algo, vector, ref value, vids, directed, damping, weights, options) : igraph_pagerank_x64(graph, algo, vector, ref value, vids, directed, damping, weights, options); 72 } finally { 73 if (algo == igraph_pagerank_algo_t.IGRAPH_PAGERANK_ALGO_ARPACK) { 74 Marshal.DestroyStructure(options, typeof(igraph_arpack_options_t)); 75 Marshal.FreeHGlobal(options); 76 } else if (algo == igraph_pagerank_algo_t.IGRAPH_PAGERANK_ALGO_POWER) { 77 Marshal.DestroyStructure(options, typeof(igraph_pagerank_power_options_t)); 78 Marshal.FreeHGlobal(options); 79 } 80 } 81 } 82 83 unsafe private static igraph_arpack_options_t GetDefaultArpackOptions() { 84 var arpackoptions = new igraph_arpack_options_t(); 85 arpackoptions.bmat[0] = 'I'; 86 arpackoptions.which[0] = arpackoptions.which[1] = 'X'; 87 arpackoptions.nev = 1; 88 arpackoptions.ishift = 1; 89 arpackoptions.mxiter = 3000; 90 arpackoptions.nb = 1; 91 arpackoptions.mode = 1; 92 arpackoptions.iparam[0] = arpackoptions.ishift; 93 arpackoptions.iparam[1] = arpackoptions.iparam[4] = arpackoptions.iparam[5] = arpackoptions.iparam[7] = arpackoptions.iparam[8] = arpackoptions.iparam[9] = arpackoptions.iparam[10] = 0; 94 arpackoptions.iparam[2] = arpackoptions.mxiter; 95 arpackoptions.iparam[3] = arpackoptions.nb; 96 arpackoptions.iparam[6] = arpackoptions.mode; 97 return arpackoptions; 98 } 99 100 private static igraph_pagerank_power_options_t GetDefaultPowerOptions() { 101 var poweroptions = new igraph_pagerank_power_options_t(); 102 poweroptions.niter = 50; 103 poweroptions.eps = 1e-5; 104 return poweroptions; 49 105 } 50 106 #endregion … … 52 108 #region igraph manipulation 53 109 internal static int igraph_add_edge(igraph_t graph, int from, int to) { 54 return X 64 ? igraph_add_edge_x64(graph, from, to) : igraph_add_edge_x86(graph, from, to);110 return X86 ? igraph_add_edge_x86(graph, from, to) : igraph_add_edge_x64(graph, from, to); 55 111 } 56 112 #endregion … … 73 129 [DllImport(X64Dll, EntryPoint = "igraph_add_edge", CallingConvention = CallingConvention.Cdecl)] 74 130 private static extern int igraph_add_edge_x64([In, Out]igraph_t graph, int from, int to); 131 [DllImport(X86Dll, EntryPoint = "igraph_density", CallingConvention = CallingConvention.Cdecl)] 132 private static extern int igraph_density_x86(igraph_t graph, ref double density, bool loops); 133 [DllImport(X64Dll, EntryPoint = "igraph_density", CallingConvention = CallingConvention.Cdecl)] 134 private static extern int igraph_density_x64(igraph_t graph, ref double density, bool loops); 135 [DllImport(X86Dll, EntryPoint = "igraph_pagerank", CallingConvention = CallingConvention.Cdecl)] 136 private static extern int igraph_pagerank_x86(igraph_t graph, igraph_pagerank_algo_t algo, [In, Out]igraph_vector_t vector, ref double value, igraph_vs_t vids, bool directed, double damping, igraph_vector_t weights, IntPtr options); 137 [DllImport(X64Dll, EntryPoint = "igraph_pagerank", CallingConvention = CallingConvention.Cdecl)] 138 private static extern int igraph_pagerank_x64(igraph_t graph, igraph_pagerank_algo_t algo, [In, Out]igraph_vector_t vector, ref double value, igraph_vs_t vids, bool directed, double damping, igraph_vector_t weights, IntPtr options); 75 139 #endregion 76 140 #endregion … … 78 142 #region igraph_rng 79 143 internal static int igraph_rng_get_integer(int l, int h) { 80 return X 64 ? igraph_rng_get_integer_x64(igraph_rng_default_x64(), l, h) : igraph_rng_get_integer_x86(igraph_rng_default_x86(), l, h);144 return X86 ? igraph_rng_get_integer_x86(igraph_rng_default_x86(), l, h) : igraph_rng_get_integer_x64(igraph_rng_default_x64(), l, h); 81 145 } 82 146 internal static int igraph_rng_seed(uint seed) { 83 return X 64 ? igraph_rng_seed_x64(igraph_rng_default_x64(), seed) : igraph_rng_seed_x86(igraph_rng_default_x86(), seed);147 return X86 ? igraph_rng_seed_x86(igraph_rng_default_x86(), seed) : igraph_rng_seed_x64(igraph_rng_default_x64(), seed); 84 148 } 85 149 … … 100 164 #endregion 101 165 166 #region igraph_vector 167 internal static int igraph_vector_init(igraph_vector_t vector, int length) { 168 return X86 ? igraph_vector_init_x86(vector, length) : igraph_vector_init_x64(vector, length); 169 } 170 internal static void igraph_vector_destroy(igraph_vector_t vector) { 171 if (X86) igraph_vector_destroy_x86(vector); 172 else igraph_vector_destroy_x64(vector); 173 } 174 internal static int igraph_vector_copy(igraph_vector_t to, igraph_vector_t from) { 175 return X86 ? igraph_vector_copy_x86(to, from) : igraph_vector_copy_x64(to, from); 176 } 177 178 internal static int igraph_vector_size(igraph_vector_t vector) { 179 return X86 ? igraph_vector_size_x86(vector) : igraph_vector_size_x64(vector); 180 } 181 182 internal static double igraph_vector_e(igraph_vector_t vector, int index) { 183 return X86 ? igraph_vector_e_x86(vector, index) : igraph_vector_e_x64(vector, index); 184 } 185 186 internal static void igraph_vector_set(igraph_vector_t vector, int index, double value) { 187 if (X86) igraph_vector_set_x86(vector, index, value); 188 else igraph_vector_set_x64(vector, index, value); 189 } 190 191 #region Platform specific DLL imports 192 [DllImport(X86Dll, EntryPoint = "igraph_vector_init", CallingConvention = CallingConvention.Cdecl)] 193 private static extern int igraph_vector_init_x86([In, Out]igraph_vector_t vector, int length); 194 [DllImport(X64Dll, EntryPoint = "igraph_vector_init", CallingConvention = CallingConvention.Cdecl)] 195 private static extern int igraph_vector_init_x64([In, Out]igraph_vector_t vector, int length); 196 [DllImport(X86Dll, EntryPoint = "igraph_vector_destroy", CallingConvention = CallingConvention.Cdecl)] 197 private static extern void igraph_vector_destroy_x86([In, Out]igraph_vector_t vector); 198 [DllImport(X64Dll, EntryPoint = "igraph_vector_destroy", CallingConvention = CallingConvention.Cdecl)] 199 private static extern void igraph_vector_destroy_x64([In, Out]igraph_vector_t vector); 200 [DllImport(X86Dll, EntryPoint = "igraph_vector_size", CallingConvention = CallingConvention.Cdecl)] 201 private static extern int igraph_vector_size_x86(igraph_vector_t vector); 202 [DllImport(X64Dll, EntryPoint = "igraph_vector_size", CallingConvention = CallingConvention.Cdecl)] 203 private static extern int igraph_vector_size_x64(igraph_vector_t vector); 204 [DllImport(X86Dll, EntryPoint = "igraph_vector_e", CallingConvention = CallingConvention.Cdecl)] 205 private static extern double igraph_vector_e_x86(igraph_vector_t vector, int index); 206 [DllImport(X64Dll, EntryPoint = "igraph_vector_e", CallingConvention = CallingConvention.Cdecl)] 207 private static extern double igraph_vector_e_x64(igraph_vector_t vector, int index); 208 [DllImport(X86Dll, EntryPoint = "igraph_vector_set", CallingConvention = CallingConvention.Cdecl)] 209 private static extern double igraph_vector_set_x86([In, Out]igraph_vector_t vector, int index, double value); 210 [DllImport(X64Dll, EntryPoint = "igraph_vector_set", CallingConvention = CallingConvention.Cdecl)] 211 private static extern double igraph_vector_set_x64([In, Out]igraph_vector_t vector, int index, double value); 212 [DllImport(X86Dll, EntryPoint = "igraph_vector_copy", CallingConvention = CallingConvention.Cdecl)] 213 private static extern int igraph_vector_copy_x86([In, Out]igraph_vector_t to, igraph_vector_t from); 214 [DllImport(X64Dll, EntryPoint = "igraph_vector_copy", CallingConvention = CallingConvention.Cdecl)] 215 private static extern int igraph_vector_copy_x64([In, Out]igraph_vector_t to, igraph_vector_t from); 216 #endregion 217 #endregion 218 102 219 #region igraph_matrix 103 220 internal static int igraph_matrix_init(igraph_matrix_t matrix, int nrows, int ncols) { 104 return X 64 ? igraph_matrix_init_x64(matrix, nrows, ncols) : igraph_matrix_init_x86(matrix, nrows, ncols);221 return X86 ? igraph_matrix_init_x86(matrix, nrows, ncols) : igraph_matrix_init_x64(matrix, nrows, ncols); 105 222 } 106 223 internal static void igraph_matrix_destroy(igraph_matrix_t matrix) { 107 if (X64) igraph_matrix_destroy_x64(matrix); 108 else igraph_matrix_destroy_x86(matrix); 224 if (X86) igraph_matrix_destroy_x86(matrix); 225 else igraph_matrix_destroy_x64(matrix); 226 } 227 internal static int igraph_matrix_copy(igraph_matrix_t to, igraph_matrix_t from) { 228 return X86 ? igraph_matrix_copy_x86(to, from) : igraph_matrix_copy_x64(to, from); 109 229 } 110 230 111 231 internal static double igraph_matrix_e(igraph_matrix_t matrix, int row, int col) { 112 return X 64 ? igraph_matrix_e_x64(matrix, row, col) : igraph_matrix_e_x86(matrix, row, col);232 return X86 ? igraph_matrix_e_x86(matrix, row, col) : igraph_matrix_e_x64(matrix, row, col); 113 233 } 114 234 115 235 internal static void igraph_matrix_set(igraph_matrix_t matrix, int row, int col, double value) { 116 if (X 64) igraph_matrix_set_x64(matrix, row, col, value);117 else igraph_matrix_set_x 86(matrix, row, col, value);236 if (X86) igraph_matrix_set_x86(matrix, row, col, value); 237 else igraph_matrix_set_x64(matrix, row, col, value); 118 238 } 119 239 … … 132 252 private static extern double igraph_matrix_e_x64(igraph_matrix_t matrix, int row, int col); 133 253 [DllImport(X86Dll, EntryPoint = "igraph_matrix_set", CallingConvention = CallingConvention.Cdecl)] 134 private static extern double igraph_matrix_set_x86( igraph_matrix_t matrix, int row, int col, double value);254 private static extern double igraph_matrix_set_x86([In, Out]igraph_matrix_t matrix, int row, int col, double value); 135 255 [DllImport(X64Dll, EntryPoint = "igraph_matrix_set", CallingConvention = CallingConvention.Cdecl)] 136 private static extern double igraph_matrix_set_x64(igraph_matrix_t matrix, int row, int col, double value); 256 private static extern double igraph_matrix_set_x64([In, Out]igraph_matrix_t matrix, int row, int col, double value); 257 [DllImport(X86Dll, EntryPoint = "igraph_matrix_copy", CallingConvention = CallingConvention.Cdecl)] 258 private static extern int igraph_matrix_copy_x86([In, Out]igraph_matrix_t to, igraph_matrix_t from); 259 [DllImport(X64Dll, EntryPoint = "igraph_matrix_copy", CallingConvention = CallingConvention.Cdecl)] 260 private static extern int igraph_matrix_copy_x64([In, Out]igraph_matrix_t to, igraph_matrix_t from); 137 261 #endregion 138 262 #endregion … … 140 264 #region igraph_layout 141 265 internal static int igraph_layout_fruchterman_reingold(igraph_t graph, igraph_matrix_t res, bool use_seed, int niter, double start_temp, igraph_layout_grid_t grid, igraph_vector_t weights, igraph_vector_t minx, igraph_vector_t maxx, igraph_vector_t miny, igraph_vector_t maxy) { 142 return X64 ? igraph_layout_fruchterman_reingold_x64(graph, res, use_seed, niter, start_temp, grid, weights, minx, maxx, miny, maxy) : igraph_layout_fruchterman_reingold_x86(graph, res, use_seed, niter, start_temp, grid, weights, minx, maxx, miny, maxy); 266 return X86 ? igraph_layout_fruchterman_reingold_x86(graph, res, use_seed, niter, start_temp, grid, weights, minx, maxx, miny, maxy) : igraph_layout_fruchterman_reingold_x64(graph, res, use_seed, niter, start_temp, grid, weights, minx, maxx, miny, maxy); 267 } 268 internal static int igraph_layout_kamada_kawai(igraph_t graph, igraph_matrix_t res, bool use_seed, int maxiter, double epsilon, double kkconst, igraph_vector_t weights, igraph_vector_t minx, igraph_vector_t maxx, igraph_vector_t miny, igraph_vector_t maxy) { 269 return X86 ? igraph_layout_kamada_kawai_x86(graph, res, use_seed, maxiter, epsilon, kkconst, weights, minx, maxx, miny, maxy) : igraph_layout_kamada_kawai_x64(graph, res, use_seed, maxiter, epsilon, kkconst, weights, minx, maxx, miny, maxy); 270 } 271 internal static int igraph_layout_davidson_harel(igraph_t graph, igraph_matrix_t res, bool use_seed, int maxiter, int fineiter, double cool_fact, double weight_node_dist, double weight_border, double weight_edge_lengths, double weight_edge_crossings, double weight_node_edge_dist) { 272 return X86 ? igraph_layout_davidson_harel_x86(graph, res, use_seed, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist) : igraph_layout_davidson_harel_x64(graph, res, use_seed, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist); 143 273 } 144 274 … … 148 278 [DllImport(X64Dll, EntryPoint = "igraph_layout_fruchterman_reingold", CallingConvention = CallingConvention.Cdecl)] 149 279 private static extern int igraph_layout_fruchterman_reingold_x64(igraph_t graph, [In, Out]igraph_matrix_t res, bool use_seed, int niter, double start_temp, igraph_layout_grid_t grid, igraph_vector_t weights, igraph_vector_t minx, igraph_vector_t maxx, igraph_vector_t miny, igraph_vector_t maxy); 150 #endregion 151 #endregion 152 280 [DllImport(X86Dll, EntryPoint = "igraph_layout_kamada_kawai", CallingConvention = CallingConvention.Cdecl)] 281 private static extern int igraph_layout_kamada_kawai_x86(igraph_t graph, [In, Out]igraph_matrix_t res, bool use_seed, int maxiter, double epsilon, double kkconst, igraph_vector_t weights, igraph_vector_t minx, igraph_vector_t maxx, igraph_vector_t miny, igraph_vector_t maxy); 282 [DllImport(X64Dll, EntryPoint = "igraph_layout_kamada_kawai", CallingConvention = CallingConvention.Cdecl)] 283 private static extern int igraph_layout_kamada_kawai_x64(igraph_t graph, [In, Out]igraph_matrix_t res, bool use_seed, int maxiter, double epsilon, double kkconst, igraph_vector_t weights, igraph_vector_t minx, igraph_vector_t maxx, igraph_vector_t miny, igraph_vector_t maxy); 284 [DllImport(X86Dll, EntryPoint = "igraph_layout_davidson_harel", CallingConvention = CallingConvention.Cdecl)] 285 private static extern int igraph_layout_davidson_harel_x86(igraph_t graph, [In, Out]igraph_matrix_t res, bool use_seed, int maxiter, int fineiter, double cool_fact, double weight_node_dist, double weight_border, double weight_edge_lengths, double weight_edge_crossings, double weight_node_edge_dist); 286 [DllImport(X64Dll, EntryPoint = "igraph_layout_davidson_harel", CallingConvention = CallingConvention.Cdecl)] 287 private static extern int igraph_layout_davidson_harel_x64(igraph_t graph, [In, Out]igraph_matrix_t res, bool use_seed, int maxiter, int fineiter, double cool_fact, double weight_node_dist, double weight_border, double weight_edge_lengths, double weight_edge_crossings, double weight_node_edge_dist); 288 #endregion 289 #endregion 290 291 #region igraph_iterators 292 internal static int igraph_vs_all(ref igraph_vs_t vs) { 293 return X86 ? igraph_vs_all_x86(ref vs) : igraph_vs_all_x64(ref vs); 294 } 295 internal static void igraph_vs_destroy(ref igraph_vs_t vs) { 296 if (X86) igraph_vs_destroy_x86(ref vs); 297 else igraph_vs_destroy_x64(ref vs); 298 } 299 300 #region Platform specific DLL imports 301 [DllImport(X86Dll, EntryPoint = "igraph_vs_all", CallingConvention = CallingConvention.Cdecl)] 302 private static extern int igraph_vs_all_x86([In, Out]ref igraph_vs_t vs); 303 [DllImport(X64Dll, EntryPoint = "igraph_vs_all", CallingConvention = CallingConvention.Cdecl)] 304 private static extern int igraph_vs_all_x64([In, Out]ref igraph_vs_t vs); 305 [DllImport(X86Dll, EntryPoint = "igraph_vs_destroy", CallingConvention = CallingConvention.Cdecl)] 306 private static extern void igraph_vs_destroy_x86([In, Out]ref igraph_vs_t vs); 307 [DllImport(X64Dll, EntryPoint = "igraph_vs_destroy", CallingConvention = CallingConvention.Cdecl)] 308 private static extern void igraph_vs_destroy_x64([In, Out]ref igraph_vs_t vs); 309 #endregion 310 #endregion 153 311 } 154 312 }
Note: See TracChangeset
for help on using the changeset viewer.