Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/08/16 11:41:45 (8 years ago)
Author:
gkronber
Message:

#2650: merged r14245:14273 from trunk to branch (fixing conflicts in RegressionSolutionTargetResponseGradientView)

Location:
branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre
Files:
2 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Datatypes.cs

    r14276 r14277  
    4949  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    5050  internal class igraph_matrix_t {
    51     igraph_vector_t data = new igraph_vector_t();
     51    internal igraph_vector_t data = new igraph_vector_t();
    5252    internal int nrow;
    5353    internal int ncol;
     
    128128  #endregion
    129129
     130  #region Delegates
     131  [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
     132  internal delegate bool igraph_bfshandler_t(igraph_t graph, int vid, int pred, int succ, int rank, int dist, IntPtr extra);
     133
     134  [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
     135  internal delegate bool igraph_dfshandler_t(igraph_t graph, int vid, int dist, IntPtr extra);
     136  #endregion
     137
    130138  #region Enums
    131139  internal enum igraph_layout_grid_t {
  • branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/DllImporter.cs

    r14276 r14277  
    8787      arpackoptions.nev = 1;
    8888      arpackoptions.ishift = 1;
    89       arpackoptions.mxiter = 3000;
     89      arpackoptions.mxiter = 1000;
    9090      arpackoptions.nb = 1;
    9191      arpackoptions.mode = 1;
     
    109109    internal static int igraph_add_edge(igraph_t graph, int from, int to) {
    110110      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));
    111120    }
    112121    #endregion
     
    137146    [DllImport(X64Dll, EntryPoint = "igraph_pagerank", CallingConvention = CallingConvention.Cdecl)]
    138147    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);
    139156    #endregion
    140157    #endregion
     
    168185      return X86 ? igraph_vector_init_x86(vector, length) : igraph_vector_init_x64(vector, length);
    169186    }
     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    }
    170190    internal static void igraph_vector_destroy(igraph_vector_t vector) {
    171191      if (X86) igraph_vector_destroy_x86(vector);
     
    175195      return X86 ? igraph_vector_copy_x86(to, from) : igraph_vector_copy_x64(to, from);
    176196    }
     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    }
    177204
    178205    internal static int igraph_vector_size(igraph_vector_t vector) {
     
    187214      if (X86) igraph_vector_set_x86(vector, index, value);
    188215      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);
    189231    }
    190232
     
    194236    [DllImport(X64Dll, EntryPoint = "igraph_vector_init", CallingConvention = CallingConvention.Cdecl)]
    195237    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);
    196242    [DllImport(X86Dll, EntryPoint = "igraph_vector_destroy", CallingConvention = CallingConvention.Cdecl)]
    197243    private static extern void igraph_vector_destroy_x86([In, Out]igraph_vector_t vector);
     
    214260    [DllImport(X64Dll, EntryPoint = "igraph_vector_copy", CallingConvention = CallingConvention.Cdecl)]
    215261    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);
    216282    #endregion
    217283    #endregion
     
    236302      if (X86) igraph_matrix_set_x86(matrix, row, col, value);
    237303      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);
    238318    }
    239319
     
    259339    [DllImport(X64Dll, EntryPoint = "igraph_matrix_copy", CallingConvention = CallingConvention.Cdecl)]
    260340    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);
    261353    #endregion
    262354    #endregion
     
    271363    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) {
    272364      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));
    273368    }
    274369
     
    286381    [DllImport(X64Dll, EntryPoint = "igraph_layout_davidson_harel", CallingConvention = CallingConvention.Cdecl)]
    287382    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);
    288387    #endregion
    289388    #endregion
     
    309408    #endregion
    310409    #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    }
    311446  }
    312447}
  • branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Graph.cs

    r14276 r14277  
    8686    }
    8787    public Matrix LayoutWithFruchtermanReingold(int niter, double startTemp, Matrix initialCoords = null) {
    88       if (initialCoords != null && (initialCoords.Rows != graph.n || initialCoords.Columns != 2))
     88      if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
    8989        throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords");
    90       var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(graph.n, 2);
     90      var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);
    9191      DllImporter.igraph_layout_fruchterman_reingold(graph, coords.NativeInstance, initialCoords != null, niter, startTemp, igraph_layout_grid_t.IGRAPH_LAYOUT_AUTOGRID, null, null, null, null, null);
    9292      return coords;
     
    9797    }
    9898    public Matrix LayoutWithKamadaKawai(int maxiter, double epsilon, double kkconst, Matrix initialCoords = null) {
    99       if (initialCoords != null && (initialCoords.Rows != graph.n || initialCoords.Columns != 2))
     99      if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
    100100        throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords");
    101       var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(graph.n, 2);
     101      var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);
    102102      DllImporter.igraph_layout_kamada_kawai(graph, coords.NativeInstance, initialCoords != null, maxiter, epsilon, kkconst, null, null, null, null, null);
    103103      return coords;
     
    109109    }
    110110    public Matrix LayoutWithDavidsonHarel(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, Matrix initialCoords = null) {
    111       if (initialCoords != null && (initialCoords.Rows != graph.n || initialCoords.Columns != 2))
     111      if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
    112112        throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords");
    113       var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(graph.n, 2);
     113      var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);
    114114      DllImporter.igraph_layout_davidson_harel(graph, coords.NativeInstance, initialCoords != null, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist);
    115115      return coords;
    116116    }
     117
     118    /// <summary>
     119    /// Use multi-dimensional scaling to layout vertices.
     120    /// A distance matrix can be used to specify the distances between the vertices.
     121    /// Otherwise the distances will be calculated by shortest-path-length.
     122    /// </summary>
     123    /// <remarks>
     124    /// For disconnected graphs, dimension must be 2.
     125    /// </remarks>
     126    /// <param name="dist">The distance matrix to layout the vertices.</param>
     127    /// <param name="dim">How many dimensions should be used.</param>
     128    /// <returns>The coordinates matrix of the aligned vertices.</returns>
     129    public Matrix LayoutWithMds(Matrix dist = null, int dim = 2) {
     130      var coords = new Matrix(Vertices, dim);
     131      DllImporter.igraph_layout_mds(graph, coords.NativeInstance, dist != null ? dist.NativeInstance : null, dim);
     132      return coords;
     133    }
     134
     135    public void BreadthFirstWalk(BreadthFirstHandler handler, int root, DirectedWalkMode mode, bool includeUnreachableFromRoot = false, object tag = null) {
     136      igraph_bfshandler_t wrapper = (t, vid, pred, succ, rank, dist, extra) => handler != null && handler(this, vid, pred, succ, rank, dist, tag);
     137      DllImporter.igraph_bfs(graph, root, null, (igraph_neimode_t)mode, includeUnreachableFromRoot, null, null, null, null, null, null, null, wrapper, tag);
     138    }
     139
     140    public void DepthFirstWalk(DepthFirstHandler inHandler, DepthFirstHandler outHandler, int root, DirectedWalkMode mode, bool includeUnreachableFromRoot = false, object tag = null) {
     141      igraph_dfshandler_t inWrapper = (t, vid, dist, extra) => inHandler != null && inHandler(this, vid, dist, tag);
     142      igraph_dfshandler_t outWrapper = (t, vid, dist, extra) => outHandler != null && outHandler(this, vid, dist, tag);
     143      DllImporter.igraph_dfs(graph, root, (igraph_neimode_t)mode, includeUnreachableFromRoot, null, null, null, null, inWrapper, outWrapper, tag);
     144    }
    117145  }
    118146}
  • branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Matrix.cs

    r14276 r14277  
    3939      DllImporter.igraph_matrix_copy(matrix, other.NativeInstance);
    4040    }
     41    public Matrix(double[,] mat) {
     42      if (mat == null) throw new ArgumentNullException("mat");
     43      matrix = new igraph_matrix_t();
     44      var nrows = mat.GetLength(0);
     45      var ncols = mat.GetLength(1);
     46      DllImporter.igraph_matrix_init(matrix, nrows, ncols);
     47      var colwise = new double[ncols * nrows];
     48      for (var j = 0; j < ncols; j++)
     49        for (var i = 0; i < nrows; i++)
     50          colwise[j * nrows + i] = mat[i, j];
     51      DllImporter.igraph_vector_init_copy(matrix.data, colwise);
     52    }
    4153    ~Matrix() {
    4254      DllImporter.igraph_matrix_destroy(matrix);
     
    4860      matrix = null;
    4961      GC.SuppressFinalize(this);
     62    }
     63
     64    public void Fill(double v) {
     65      DllImporter.igraph_matrix_fill(matrix, v);
     66    }
     67
     68    public void Transpose() {
     69      DllImporter.igraph_matrix_transpose(matrix);
     70    }
     71
     72    public void Scale(double by) {
     73      DllImporter.igraph_matrix_scale(matrix, by);
    5074    }
    5175
  • branches/symbreg-factors-2650/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Vector.cs

    r14276 r14277  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2325
    2426namespace HeuristicLab.IGraph.Wrappers {
     
    3941      DllImporter.igraph_vector_init(vector, length);
    4042    }
    41 
     43    public Vector(IEnumerable<double> data) {
     44      if (data == null) throw new ArgumentNullException("data");
     45      var vec = data.ToArray();
     46      vector = new igraph_vector_t();
     47      DllImporter.igraph_vector_init_copy(vector, vec);
     48    }
    4249    public Vector(Vector other) {
    4350      if (other == null) throw new ArgumentNullException("other");
     
    4552      DllImporter.igraph_vector_copy(vector, other.NativeInstance);
    4653    }
    47 
    4854    ~Vector() {
    4955      DllImporter.igraph_vector_destroy(vector);
     
    5561      vector = null;
    5662      GC.SuppressFinalize(this);
     63    }
     64
     65    public void Fill(double v) {
     66      DllImporter.igraph_vector_fill(vector, v);
     67    }
     68
     69    public void Reverse() {
     70      DllImporter.igraph_vector_reverse(vector);
     71    }
     72
     73    public void Shuffle() {
     74      DllImporter.igraph_vector_shuffle(vector);
     75    }
     76
     77    public void Scale(double by) {
     78      DllImporter.igraph_vector_scale(vector, by);
    5779    }
    5880
     
    6991
    7092    public double[] ToArray() {
    71       var result = new double[Length];
    72       for (var i = 0; i < result.Length; i++) {
    73         result[i] = DllImporter.igraph_vector_e(vector, i);
    74       }
    75       return result;
     93      return DllImporter.igraph_vector_to_array(vector);
    7694    }
    7795  }
Note: See TracChangeset for help on using the changeset viewer.