Changeset 15130 for stable/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0pre/HeuristicLab.Igraph0.8.0pre/DllImporter.cs
 Timestamp:
 07/06/17 10:09:53 (2 years ago)
 Location:
 stable/HeuristicLab.ExtLibs/HeuristicLab.Igraph
 Files:

 1 edited
 1 copied
Legend:
 Unmodified
 Added
 Removed

stable/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0pre/HeuristicLab.Igraph0.8.0pre/DllImporter.cs
r14234 r15130 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 = "igraph0.8.0prex86.dll"; 28 28 private const string X64Dll = "igraph0.8.0prex64.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 = 1000; 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 = 1e5; 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 X64 ? 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); 111 } 112 #endregion 113 114 #region igraph visits 115 internal static int igraph_bfs(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, igraph_vector_t order, igraph_vector_t rank, igraph_vector_t father, igraph_vector_t pred, igraph_vector_t succ, igraph_vector_t dist, igraph_bfshandler_t callback, object tag) { 116 return MarshalIfExistsAndCall(tag, ptr => X86 ? igraph_bfs_x86(graph, root, roots, mode, unreachable, restricted, order, rank, father, pred, succ, dist, callback, ptr) : igraph_bfs_x64(graph, root, roots, mode, unreachable, restricted, order, rank, father, pred, succ, dist, callback, ptr)); 117 } 118 internal static int igraph_dfs(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, igraph_vector_t order, igraph_vector_t order_out, igraph_vector_t father, igraph_vector_t dist, igraph_dfshandler_t inWrapper, igraph_dfshandler_t outWrapper, object tag) { 119 return MarshalIfExistsAndCall(tag, ptr => X86 ? igraph_dfs_x86(graph, root, mode, unreachable, order, order_out, father, dist, inWrapper, outWrapper, ptr) : igraph_dfs_x64(graph, root, mode, unreachable, order, order_out, father, dist, inWrapper, outWrapper, ptr)); 55 120 } 56 121 #endregion … … 73 138 [DllImport(X64Dll, EntryPoint = "igraph_add_edge", CallingConvention = CallingConvention.Cdecl)] 74 139 private static extern int igraph_add_edge_x64([In, Out]igraph_t graph, int from, int to); 140 [DllImport(X86Dll, EntryPoint = "igraph_density", CallingConvention = CallingConvention.Cdecl)] 141 private static extern int igraph_density_x86(igraph_t graph, ref double density, bool loops); 142 [DllImport(X64Dll, EntryPoint = "igraph_density", CallingConvention = CallingConvention.Cdecl)] 143 private static extern int igraph_density_x64(igraph_t graph, ref double density, bool loops); 144 [DllImport(X86Dll, EntryPoint = "igraph_pagerank", CallingConvention = CallingConvention.Cdecl)] 145 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); 146 [DllImport(X64Dll, EntryPoint = "igraph_pagerank", CallingConvention = CallingConvention.Cdecl)] 147 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); 148 [DllImport(X86Dll, EntryPoint = "igraph_bfs", CallingConvention = CallingConvention.Cdecl)] 149 private static extern int igraph_bfs_x86(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t rank, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t pred, [In, Out]igraph_vector_t succ, [In, Out]igraph_vector_t dist, igraph_bfshandler_t callback, IntPtr extra); 150 [DllImport(X64Dll, EntryPoint = "igraph_bfs", CallingConvention = CallingConvention.Cdecl)] 151 private static extern int igraph_bfs_x64(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t rank, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t pred, [In, Out]igraph_vector_t succ, [In, Out]igraph_vector_t dist, igraph_bfshandler_t callback, IntPtr extra); 152 [DllImport(X86Dll, EntryPoint = "igraph_dfs", CallingConvention = CallingConvention.Cdecl)] 153 private static extern int igraph_dfs_x86(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t order_out, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t dist, igraph_dfshandler_t in_callback, igraph_dfshandler_t out_callback, IntPtr extra); 154 [DllImport(X64Dll, EntryPoint = "igraph_dfs", CallingConvention = CallingConvention.Cdecl)] 155 private static extern int igraph_dfs_x64(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t order_out, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t dist, igraph_dfshandler_t in_callback, igraph_dfshandler_t out_callback, IntPtr extra); 75 156 #endregion 76 157 #endregion … … 78 159 #region igraph_rng 79 160 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);161 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 162 } 82 163 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);164 return X86 ? igraph_rng_seed_x86(igraph_rng_default_x86(), seed) : igraph_rng_seed_x64(igraph_rng_default_x64(), seed); 84 165 } 85 166 … … 100 181 #endregion 101 182 183 #region igraph_vector 184 internal static int igraph_vector_init(igraph_vector_t vector, int length) { 185 return X86 ? igraph_vector_init_x86(vector, length) : igraph_vector_init_x64(vector, length); 186 } 187 internal static int igraph_vector_init_copy(igraph_vector_t vector, double[] vec) { 188 return X86 ? igraph_vector_init_copy_x86(vector, vec, vec.Length) : igraph_vector_init_copy_x64(vector, vec, vec.Length); 189 } 190 internal static void igraph_vector_destroy(igraph_vector_t vector) { 191 if (X86) igraph_vector_destroy_x86(vector); 192 else igraph_vector_destroy_x64(vector); 193 } 194 internal static int igraph_vector_copy(igraph_vector_t to, igraph_vector_t from) { 195 return X86 ? igraph_vector_copy_x86(to, from) : igraph_vector_copy_x64(to, from); 196 } 197 internal static double[] igraph_vector_to_array(igraph_vector_t from) { 198 var len = igraph_vector_size(from); 199 var result = new double[len]; 200 if (X86) igraph_vector_copy_to_x86(from, result); 201 else igraph_vector_copy_to_x64(from, result); 202 return result; 203 } 204 205 internal static int igraph_vector_size(igraph_vector_t vector) { 206 return X86 ? igraph_vector_size_x86(vector) : igraph_vector_size_x64(vector); 207 } 208 209 internal static double igraph_vector_e(igraph_vector_t vector, int index) { 210 return X86 ? igraph_vector_e_x86(vector, index) : igraph_vector_e_x64(vector, index); 211 } 212 213 internal static void igraph_vector_set(igraph_vector_t vector, int index, double value) { 214 if (X86) igraph_vector_set_x86(vector, index, value); 215 else igraph_vector_set_x64(vector, index, value); 216 } 217 internal static void igraph_vector_fill(igraph_vector_t vector, double v) { 218 if (X86) igraph_vector_fill_x86(vector, v); 219 else igraph_vector_fill_x64(vector, v); 220 } 221 internal static void igraph_vector_scale(igraph_vector_t vector, double by) { 222 if (X86) igraph_vector_scale_x86(vector, by); 223 else igraph_vector_scale_x64(vector, by); 224 } 225 226 internal static int igraph_vector_reverse(igraph_vector_t vector) { 227 return X86 ? igraph_vector_reverse_x86(vector) : igraph_vector_reverse_x64(vector); 228 } 229 internal static int igraph_vector_shuffle(igraph_vector_t vector) { 230 return X86 ? igraph_vector_shuffle_x86(vector) : igraph_vector_shuffle_x64(vector); 231 } 232 233 #region Platform specific DLL imports 234 [DllImport(X86Dll, EntryPoint = "igraph_vector_init", CallingConvention = CallingConvention.Cdecl)] 235 private static extern int igraph_vector_init_x86([In, Out]igraph_vector_t vector, int length); 236 [DllImport(X64Dll, EntryPoint = "igraph_vector_init", CallingConvention = CallingConvention.Cdecl)] 237 private static extern int igraph_vector_init_x64([In, Out]igraph_vector_t vector, int length); 238 [DllImport(X86Dll, EntryPoint = "igraph_vector_init_copy", CallingConvention = CallingConvention.Cdecl)] 239 private static extern int igraph_vector_init_copy_x86([In, Out]igraph_vector_t vector, double[] vec, int length); 240 [DllImport(X64Dll, EntryPoint = "igraph_vector_init_copy", CallingConvention = CallingConvention.Cdecl)] 241 private static extern int igraph_vector_init_copy_x64([In, Out]igraph_vector_t vector, double[] vec, int length); 242 [DllImport(X86Dll, EntryPoint = "igraph_vector_destroy", CallingConvention = CallingConvention.Cdecl)] 243 private static extern void igraph_vector_destroy_x86([In, Out]igraph_vector_t vector); 244 [DllImport(X64Dll, EntryPoint = "igraph_vector_destroy", CallingConvention = CallingConvention.Cdecl)] 245 private static extern void igraph_vector_destroy_x64([In, Out]igraph_vector_t vector); 246 [DllImport(X86Dll, EntryPoint = "igraph_vector_size", CallingConvention = CallingConvention.Cdecl)] 247 private static extern int igraph_vector_size_x86(igraph_vector_t vector); 248 [DllImport(X64Dll, EntryPoint = "igraph_vector_size", CallingConvention = CallingConvention.Cdecl)] 249 private static extern int igraph_vector_size_x64(igraph_vector_t vector); 250 [DllImport(X86Dll, EntryPoint = "igraph_vector_e", CallingConvention = CallingConvention.Cdecl)] 251 private static extern double igraph_vector_e_x86(igraph_vector_t vector, int index); 252 [DllImport(X64Dll, EntryPoint = "igraph_vector_e", CallingConvention = CallingConvention.Cdecl)] 253 private static extern double igraph_vector_e_x64(igraph_vector_t vector, int index); 254 [DllImport(X86Dll, EntryPoint = "igraph_vector_set", CallingConvention = CallingConvention.Cdecl)] 255 private static extern double igraph_vector_set_x86([In, Out]igraph_vector_t vector, int index, double value); 256 [DllImport(X64Dll, EntryPoint = "igraph_vector_set", CallingConvention = CallingConvention.Cdecl)] 257 private static extern double igraph_vector_set_x64([In, Out]igraph_vector_t vector, int index, double value); 258 [DllImport(X86Dll, EntryPoint = "igraph_vector_copy", CallingConvention = CallingConvention.Cdecl)] 259 private static extern int igraph_vector_copy_x86([In, Out]igraph_vector_t to, igraph_vector_t from); 260 [DllImport(X64Dll, EntryPoint = "igraph_vector_copy", CallingConvention = CallingConvention.Cdecl)] 261 private static extern int igraph_vector_copy_x64([In, Out]igraph_vector_t to, igraph_vector_t from); 262 [DllImport(X86Dll, EntryPoint = "igraph_vector_copy_to", CallingConvention = CallingConvention.Cdecl)] 263 private static extern void igraph_vector_copy_to_x86(igraph_vector_t from, [In, Out]double[] to); 264 [DllImport(X64Dll, EntryPoint = "igraph_vector_copy_to", CallingConvention = CallingConvention.Cdecl)] 265 private static extern void igraph_vector_copy_to_x64(igraph_vector_t from, [In, Out]double[] to); 266 [DllImport(X86Dll, EntryPoint = "igraph_vector_fill", CallingConvention = CallingConvention.Cdecl)] 267 private static extern int igraph_vector_fill_x86([In, Out]igraph_vector_t vector, double v); 268 [DllImport(X64Dll, EntryPoint = "igraph_vector_fill", CallingConvention = CallingConvention.Cdecl)] 269 private static extern int igraph_vector_fill_x64([In, Out]igraph_vector_t vector, double v); 270 [DllImport(X86Dll, EntryPoint = "igraph_vector_reverse", CallingConvention = CallingConvention.Cdecl)] 271 private static extern int igraph_vector_reverse_x86([In, Out]igraph_vector_t vector); 272 [DllImport(X64Dll, EntryPoint = "igraph_vector_reverse", CallingConvention = CallingConvention.Cdecl)] 273 private static extern int igraph_vector_reverse_x64([In, Out]igraph_vector_t vector); 274 [DllImport(X86Dll, EntryPoint = "igraph_vector_shuffle", CallingConvention = CallingConvention.Cdecl)] 275 private static extern int igraph_vector_shuffle_x86([In, Out]igraph_vector_t vector); 276 [DllImport(X64Dll, EntryPoint = "igraph_vector_shuffle", CallingConvention = CallingConvention.Cdecl)] 277 private static extern int igraph_vector_shuffle_x64([In, Out]igraph_vector_t vector); 278 [DllImport(X86Dll, EntryPoint = "igraph_vector_scale", CallingConvention = CallingConvention.Cdecl)] 279 private static extern void igraph_vector_scale_x86([In, Out]igraph_vector_t vector, double by); 280 [DllImport(X64Dll, EntryPoint = "igraph_vector_scale", CallingConvention = CallingConvention.Cdecl)] 281 private static extern void igraph_vector_scale_x64([In, Out]igraph_vector_t vector, double by); 282 #endregion 283 #endregion 284 102 285 #region igraph_matrix 103 286 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);287 return X86 ? igraph_matrix_init_x86(matrix, nrows, ncols) : igraph_matrix_init_x64(matrix, nrows, ncols); 105 288 } 106 289 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); 290 if (X86) igraph_matrix_destroy_x86(matrix); 291 else igraph_matrix_destroy_x64(matrix); 292 } 293 internal static int igraph_matrix_copy(igraph_matrix_t to, igraph_matrix_t from) { 294 return X86 ? igraph_matrix_copy_x86(to, from) : igraph_matrix_copy_x64(to, from); 109 295 } 110 296 111 297 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);298 return X86 ? igraph_matrix_e_x86(matrix, row, col) : igraph_matrix_e_x64(matrix, row, col); 113 299 } 114 300 115 301 internal static void igraph_matrix_set(igraph_matrix_t matrix, int row, int col, double value) { 116 if (X64) igraph_matrix_set_x64(matrix, row, col, value); 117 else igraph_matrix_set_x86(matrix, row, col, value); 302 if (X86) igraph_matrix_set_x86(matrix, row, col, value); 303 else igraph_matrix_set_x64(matrix, row, col, value); 304 } 305 306 internal static void igraph_matrix_fill(igraph_matrix_t matrix, double v) { 307 if (X86) igraph_matrix_fill_x86(matrix, v); 308 else igraph_matrix_fill_x64(matrix, v); 309 } 310 311 internal static int igraph_matrix_transpose(igraph_matrix_t matrix) { 312 return X86 ? igraph_matrix_transpose_x86(matrix) : igraph_matrix_transpose_x64(matrix); 313 } 314 315 internal static void igraph_matrix_scale(igraph_matrix_t matrix, double by) { 316 if (X86) igraph_matrix_scale_x86(matrix, by); 317 else igraph_matrix_scale_x64(matrix, by); 118 318 } 119 319 … … 132 332 private static extern double igraph_matrix_e_x64(igraph_matrix_t matrix, int row, int col); 133 333 [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);334 private static extern double igraph_matrix_set_x86([In, Out]igraph_matrix_t matrix, int row, int col, double value); 135 335 [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); 336 private static extern double igraph_matrix_set_x64([In, Out]igraph_matrix_t matrix, int row, int col, double value); 337 [DllImport(X86Dll, EntryPoint = "igraph_matrix_copy", CallingConvention = CallingConvention.Cdecl)] 338 private static extern int igraph_matrix_copy_x86([In, Out]igraph_matrix_t to, igraph_matrix_t from); 339 [DllImport(X64Dll, EntryPoint = "igraph_matrix_copy", CallingConvention = CallingConvention.Cdecl)] 340 private static extern int igraph_matrix_copy_x64([In, Out]igraph_matrix_t to, igraph_matrix_t from); 341 [DllImport(X86Dll, EntryPoint = "igraph_matrix_fill", CallingConvention = CallingConvention.Cdecl)] 342 private static extern void igraph_matrix_fill_x86([In, Out]igraph_matrix_t matrix, double v); 343 [DllImport(X64Dll, EntryPoint = "igraph_matrix_fill", CallingConvention = CallingConvention.Cdecl)] 344 private static extern void igraph_matrix_fill_x64([In, Out]igraph_matrix_t matrix, double v); 345 [DllImport(X86Dll, EntryPoint = "igraph_matrix_transpose", CallingConvention = CallingConvention.Cdecl)] 346 private static extern int igraph_matrix_transpose_x86([In, Out]igraph_matrix_t matrix); 347 [DllImport(X64Dll, EntryPoint = "igraph_matrix_transpose", CallingConvention = CallingConvention.Cdecl)] 348 private static extern int igraph_matrix_transpose_x64([In, Out]igraph_matrix_t matrix); 349 [DllImport(X86Dll, EntryPoint = "igraph_matrix_scale", CallingConvention = CallingConvention.Cdecl)] 350 private static extern int igraph_matrix_scale_x86([In, Out]igraph_matrix_t matrix, double by); 351 [DllImport(X64Dll, EntryPoint = "igraph_matrix_scale", CallingConvention = CallingConvention.Cdecl)] 352 private static extern int igraph_matrix_scale_x64([In, Out]igraph_matrix_t matrix, double by); 137 353 #endregion 138 354 #endregion … … 140 356 #region igraph_layout 141 357 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); 358 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); 359 } 360 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) { 361 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); 362 } 363 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) { 364 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); 365 } 366 internal static int igraph_layout_mds(igraph_t graph, igraph_matrix_t res, igraph_matrix_t dist = null, int dim = 2) { 367 return MarshalIfExistsAndCall(GetDefaultArpackOptions(), ptr => X86 ? igraph_layout_mds_x86(graph, res, dist, dim, ptr) : igraph_layout_mds_x64(graph, res, dist, dim, ptr)); 143 368 } 144 369 … … 148 373 [DllImport(X64Dll, EntryPoint = "igraph_layout_fruchterman_reingold", CallingConvention = CallingConvention.Cdecl)] 149 374 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 375 [DllImport(X86Dll, EntryPoint = "igraph_layout_kamada_kawai", CallingConvention = CallingConvention.Cdecl)] 376 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); 377 [DllImport(X64Dll, EntryPoint = "igraph_layout_kamada_kawai", CallingConvention = CallingConvention.Cdecl)] 378 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); 379 [DllImport(X86Dll, EntryPoint = "igraph_layout_davidson_harel", CallingConvention = CallingConvention.Cdecl)] 380 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); 381 [DllImport(X64Dll, EntryPoint = "igraph_layout_davidson_harel", CallingConvention = CallingConvention.Cdecl)] 382 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); 383 [DllImport(X86Dll, EntryPoint = "igraph_layout_mds", CallingConvention = CallingConvention.Cdecl)] 384 private static extern int igraph_layout_mds_x86(igraph_t graph, [In, Out]igraph_matrix_t res, igraph_matrix_t dist, int dim, IntPtr options); 385 [DllImport(X64Dll, EntryPoint = "igraph_layout_mds", CallingConvention = CallingConvention.Cdecl)] 386 private static extern int igraph_layout_mds_x64(igraph_t graph, [In, Out]igraph_matrix_t res, igraph_matrix_t dist, int dim, IntPtr options); 387 #endregion 388 #endregion 389 390 #region igraph_iterators 391 internal static int igraph_vs_all(ref igraph_vs_t vs) { 392 return X86 ? igraph_vs_all_x86(ref vs) : igraph_vs_all_x64(ref vs); 393 } 394 internal static void igraph_vs_destroy(ref igraph_vs_t vs) { 395 if (X86) igraph_vs_destroy_x86(ref vs); 396 else igraph_vs_destroy_x64(ref vs); 397 } 398 399 #region Platform specific DLL imports 400 [DllImport(X86Dll, EntryPoint = "igraph_vs_all", CallingConvention = CallingConvention.Cdecl)] 401 private static extern int igraph_vs_all_x86([In, Out]ref igraph_vs_t vs); 402 [DllImport(X64Dll, EntryPoint = "igraph_vs_all", CallingConvention = CallingConvention.Cdecl)] 403 private static extern int igraph_vs_all_x64([In, Out]ref igraph_vs_t vs); 404 [DllImport(X86Dll, EntryPoint = "igraph_vs_destroy", CallingConvention = CallingConvention.Cdecl)] 405 private static extern void igraph_vs_destroy_x86([In, Out]ref igraph_vs_t vs); 406 [DllImport(X64Dll, EntryPoint = "igraph_vs_destroy", CallingConvention = CallingConvention.Cdecl)] 407 private static extern void igraph_vs_destroy_x64([In, Out]ref igraph_vs_t vs); 408 #endregion 409 #endregion 410 411 private static int MarshalIfExistsAndCall(object o, Func<IntPtr, int> call) { 412 var ptr = IntPtr.Zero; 413 if (o != null) { 414 try { 415 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(o)); 416 } catch (OutOfMemoryException e) { throw new InvalidOperationException("Not enough memory to perform operation.", e); } 417 Marshal.StructureToPtr(o, ptr, false); 418 } 419 try { 420 return call(ptr); 421 } finally { 422 if (o != null) { 423 Marshal.DestroyStructure(ptr, o.GetType()); 424 Marshal.FreeHGlobal(ptr); 425 } 426 } 427 } 428 429 private static void MarshalIfExistsAndCall(object o, Action<IntPtr> call) { 430 var ptr = IntPtr.Zero; 431 if (o != null) { 432 try { 433 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(o)); 434 } catch (OutOfMemoryException e) { throw new InvalidOperationException("Not enough memory to perform operation.", e); } 435 Marshal.StructureToPtr(o, ptr, false); 436 } 437 try { 438 call(ptr); 439 } finally { 440 if (o != null) { 441 Marshal.DestroyStructure(ptr, o.GetType()); 442 Marshal.FreeHGlobal(ptr); 443 } 444 } 445 } 153 446 } 154 447 }
Note: See TracChangeset
for help on using the changeset viewer.