[14234] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14234] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Runtime.InteropServices;
|
---|
| 24 |
|
---|
[14244] | 25 | namespace HeuristicLab.IGraph {
|
---|
[14234] | 26 | internal static class DllImporter {
|
---|
| 27 | private const string X86Dll = "igraph-0.8.0-pre-x86.dll";
|
---|
| 28 | private const string X64Dll = "igraph-0.8.0-pre-x64.dll";
|
---|
[14244] | 29 | private readonly static bool X86 = false;
|
---|
[14234] | 30 |
|
---|
| 31 | static DllImporter() {
|
---|
[14244] | 32 | X86 = !Environment.Is64BitProcess;
|
---|
[14234] | 33 | }
|
---|
| 34 |
|
---|
| 35 | #region igraph
|
---|
| 36 | #region igraph init/finalize
|
---|
| 37 | internal static void igraph_empty(igraph_t graph, int n, bool directed) {
|
---|
[14244] | 38 | if (X86) igraph_empty_x86(graph, n, directed);
|
---|
| 39 | else igraph_empty_x64(graph, n, directed);
|
---|
[14234] | 40 | }
|
---|
| 41 | internal static int igraph_destroy(igraph_t graph) {
|
---|
[14244] | 42 | return X86 ? igraph_destroy_x86(graph) : igraph_destroy_x64(graph);
|
---|
[14234] | 43 | }
|
---|
| 44 | #endregion
|
---|
| 45 |
|
---|
| 46 | #region igraph query
|
---|
| 47 | internal static int igraph_vcount(igraph_t graph) {
|
---|
[14244] | 48 | return X86 ? igraph_vcount_x86(graph) : igraph_vcount_x64(graph);
|
---|
[14234] | 49 | }
|
---|
| 50 | #endregion
|
---|
| 51 |
|
---|
[14244] | 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;
|
---|
[14245] | 89 | arpackoptions.mxiter = 1000;
|
---|
[14244] | 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;
|
---|
| 105 | }
|
---|
| 106 | #endregion
|
---|
| 107 |
|
---|
[14234] | 108 | #region igraph manipulation
|
---|
| 109 | internal static int igraph_add_edge(igraph_t graph, int from, int to) {
|
---|
[14244] | 110 | return X86 ? igraph_add_edge_x86(graph, from, to) : igraph_add_edge_x64(graph, from, to);
|
---|
[14234] | 111 | }
|
---|
| 112 | #endregion
|
---|
| 113 |
|
---|
[14247] | 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));
|
---|
| 120 | }
|
---|
| 121 | #endregion
|
---|
| 122 |
|
---|
[14234] | 123 | #region Platform specific DLL imports
|
---|
| 124 | [DllImport(X86Dll, EntryPoint = "igraph_empty", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 125 | private static extern void igraph_empty_x86([In, Out]igraph_t graph, int n, bool directed);
|
---|
| 126 | [DllImport(X64Dll, EntryPoint = "igraph_empty", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 127 | private static extern void igraph_empty_x64([In, Out]igraph_t graph, int n, bool directed);
|
---|
| 128 | [DllImport(X86Dll, EntryPoint = "igraph_destroy", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 129 | private static extern int igraph_destroy_x86([In, Out]igraph_t graph);
|
---|
| 130 | [DllImport(X64Dll, EntryPoint = "igraph_destroy", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 131 | private static extern int igraph_destroy_x64([In, Out]igraph_t graph);
|
---|
| 132 | [DllImport(X86Dll, EntryPoint = "igraph_vcount", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 133 | private static extern int igraph_vcount_x86(igraph_t graph);
|
---|
| 134 | [DllImport(X64Dll, EntryPoint = "igraph_vcount", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 135 | private static extern int igraph_vcount_x64(igraph_t graph);
|
---|
| 136 | [DllImport(X86Dll, EntryPoint = "igraph_add_edge", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 137 | private static extern int igraph_add_edge_x86([In, Out]igraph_t graph, int from, int to);
|
---|
| 138 | [DllImport(X64Dll, EntryPoint = "igraph_add_edge", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 139 | private static extern int igraph_add_edge_x64([In, Out]igraph_t graph, int from, int to);
|
---|
[14244] | 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);
|
---|
[14247] | 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);
|
---|
[14234] | 156 | #endregion
|
---|
| 157 | #endregion
|
---|
| 158 |
|
---|
| 159 | #region igraph_rng
|
---|
| 160 | internal static int igraph_rng_get_integer(int l, int h) {
|
---|
[14244] | 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);
|
---|
[14234] | 162 | }
|
---|
| 163 | internal static int igraph_rng_seed(uint seed) {
|
---|
[14244] | 164 | return X86 ? igraph_rng_seed_x86(igraph_rng_default_x86(), seed) : igraph_rng_seed_x64(igraph_rng_default_x64(), seed);
|
---|
[14234] | 165 | }
|
---|
| 166 |
|
---|
| 167 | #region Platform specific DLL imports
|
---|
| 168 | [DllImport(X86Dll, EntryPoint = "igraph_rng_default", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 169 | private static extern IntPtr igraph_rng_default_x86();
|
---|
| 170 | [DllImport(X64Dll, EntryPoint = "igraph_rng_default", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 171 | private static extern IntPtr igraph_rng_default_x64();
|
---|
| 172 | [DllImport(X86Dll, EntryPoint = "igraph_rng_get_integer", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 173 | private static extern int igraph_rng_get_integer_x86(IntPtr rng, int l, int h);
|
---|
| 174 | [DllImport(X64Dll, EntryPoint = "igraph_rng_get_integer", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 175 | private static extern int igraph_rng_get_integer_x64(IntPtr rng, int l, int h);
|
---|
| 176 | [DllImport(X86Dll, EntryPoint = "igraph_rng_seed", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 177 | private static extern int igraph_rng_seed_x86(IntPtr rng, uint seed);
|
---|
| 178 | [DllImport(X64Dll, EntryPoint = "igraph_rng_seed", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 179 | private static extern int igraph_rng_seed_x64(IntPtr rng, uint seed);
|
---|
| 180 | #endregion
|
---|
| 181 | #endregion
|
---|
| 182 |
|
---|
[14244] | 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 | }
|
---|
[14245] | 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 | }
|
---|
[14244] | 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 | }
|
---|
[14245] | 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 | }
|
---|
[14244] | 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 | }
|
---|
[14245] | 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 | }
|
---|
[14244] | 225 |
|
---|
[14245] | 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 |
|
---|
[14244] | 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);
|
---|
[14245] | 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);
|
---|
[14244] | 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);
|
---|
[14245] | 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);
|
---|
[14256] | 264 | [DllImport(X64Dll, EntryPoint = "igraph_vector_copy_to", CallingConvention = CallingConvention.Cdecl)]
|
---|
[14245] | 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);
|
---|
[14244] | 282 | #endregion
|
---|
| 283 | #endregion
|
---|
| 284 |
|
---|
[14234] | 285 | #region igraph_matrix
|
---|
| 286 | internal static int igraph_matrix_init(igraph_matrix_t matrix, int nrows, int ncols) {
|
---|
[14244] | 287 | return X86 ? igraph_matrix_init_x86(matrix, nrows, ncols) : igraph_matrix_init_x64(matrix, nrows, ncols);
|
---|
[14234] | 288 | }
|
---|
| 289 | internal static void igraph_matrix_destroy(igraph_matrix_t matrix) {
|
---|
[14244] | 290 | if (X86) igraph_matrix_destroy_x86(matrix);
|
---|
| 291 | else igraph_matrix_destroy_x64(matrix);
|
---|
[14234] | 292 | }
|
---|
[14244] | 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);
|
---|
| 295 | }
|
---|
[14234] | 296 |
|
---|
| 297 | internal static double igraph_matrix_e(igraph_matrix_t matrix, int row, int col) {
|
---|
[14244] | 298 | return X86 ? igraph_matrix_e_x86(matrix, row, col) : igraph_matrix_e_x64(matrix, row, col);
|
---|
[14234] | 299 | }
|
---|
| 300 |
|
---|
| 301 | internal static void igraph_matrix_set(igraph_matrix_t matrix, int row, int col, double value) {
|
---|
[14244] | 302 | if (X86) igraph_matrix_set_x86(matrix, row, col, value);
|
---|
| 303 | else igraph_matrix_set_x64(matrix, row, col, value);
|
---|
[14234] | 304 | }
|
---|
| 305 |
|
---|
[14245] | 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);
|
---|
| 318 | }
|
---|
| 319 |
|
---|
[14234] | 320 | #region Platform specific DLL imports
|
---|
| 321 | [DllImport(X86Dll, EntryPoint = "igraph_matrix_init", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 322 | private static extern int igraph_matrix_init_x86([In, Out]igraph_matrix_t matrix, int nrow, int ncol);
|
---|
| 323 | [DllImport(X64Dll, EntryPoint = "igraph_matrix_init", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 324 | private static extern int igraph_matrix_init_x64([In, Out]igraph_matrix_t matrix, int nrow, int ncol);
|
---|
| 325 | [DllImport(X86Dll, EntryPoint = "igraph_matrix_destroy", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 326 | private static extern void igraph_matrix_destroy_x86([In, Out]igraph_matrix_t matrix);
|
---|
| 327 | [DllImport(X64Dll, EntryPoint = "igraph_matrix_destroy", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 328 | private static extern void igraph_matrix_destroy_x64([In, Out]igraph_matrix_t matrix);
|
---|
| 329 | [DllImport(X86Dll, EntryPoint = "igraph_matrix_e", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 330 | private static extern double igraph_matrix_e_x86(igraph_matrix_t matrix, int row, int col);
|
---|
| 331 | [DllImport(X64Dll, EntryPoint = "igraph_matrix_e", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 332 | private static extern double igraph_matrix_e_x64(igraph_matrix_t matrix, int row, int col);
|
---|
| 333 | [DllImport(X86Dll, EntryPoint = "igraph_matrix_set", CallingConvention = CallingConvention.Cdecl)]
|
---|
[14244] | 334 | private static extern double igraph_matrix_set_x86([In, Out]igraph_matrix_t matrix, int row, int col, double value);
|
---|
[14234] | 335 | [DllImport(X64Dll, EntryPoint = "igraph_matrix_set", CallingConvention = CallingConvention.Cdecl)]
|
---|
[14244] | 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);
|
---|
[14245] | 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);
|
---|
[14234] | 353 | #endregion
|
---|
| 354 | #endregion
|
---|
| 355 |
|
---|
| 356 | #region igraph_layout
|
---|
| 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) {
|
---|
[14244] | 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);
|
---|
[14234] | 359 | }
|
---|
[14244] | 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 | }
|
---|
[14245] | 366 | internal static int igraph_layout_mds(igraph_t graph, igraph_matrix_t res, igraph_matrix_t dist = null, int dim = 2) {
|
---|
[14247] | 367 | return MarshalIfExistsAndCall(GetDefaultArpackOptions(), ptr => X86 ? igraph_layout_mds_x86(graph, res, dist, dim, ptr) : igraph_layout_mds_x64(graph, res, dist, dim, ptr));
|
---|
[14245] | 368 | }
|
---|
[14234] | 369 |
|
---|
| 370 | #region Platform specific DLL imports
|
---|
| 371 | [DllImport(X86Dll, EntryPoint = "igraph_layout_fruchterman_reingold", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 372 | private static extern int igraph_layout_fruchterman_reingold_x86(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);
|
---|
| 373 | [DllImport(X64Dll, EntryPoint = "igraph_layout_fruchterman_reingold", CallingConvention = CallingConvention.Cdecl)]
|
---|
| 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);
|
---|
[14244] | 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);
|
---|
[14245] | 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);
|
---|
[14234] | 387 | #endregion
|
---|
| 388 | #endregion
|
---|
| 389 |
|
---|
[14244] | 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
|
---|
[14247] | 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 | }
|
---|
[14234] | 446 | }
|
---|
| 447 | }
|
---|