Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Vector.cs @ 15584

Last change on this file since 15584 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 3.1 KB
RevLine 
[14244]1#region License Information
2/* HeuristicLab
[15584]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[14244]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
22using System;
[14245]23using System.Collections.Generic;
24using System.Linq;
[14244]25
26namespace HeuristicLab.IGraph.Wrappers {
27  public sealed class Vector : IDisposable {
28    private igraph_vector_t vector;
29
30    internal igraph_vector_t NativeInstance {
31      get { return vector; }
32    }
33
34    public int Length {
35      get { return DllImporter.igraph_vector_size(vector); }
36    }
37
38    public Vector(int length) {
39      if (length < 0) throw new ArgumentException("Rows and Columns must be >= 0");
40      vector = new igraph_vector_t();
41      DllImporter.igraph_vector_init(vector, length);
42    }
[14245]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    }
[14244]49    public Vector(Vector other) {
50      if (other == null) throw new ArgumentNullException("other");
51      vector = new igraph_vector_t();
52      DllImporter.igraph_vector_copy(vector, other.NativeInstance);
53    }
54    ~Vector() {
55      DllImporter.igraph_vector_destroy(vector);
56    }
57
58    public void Dispose() {
59      if (vector == null) return;
60      DllImporter.igraph_vector_destroy(vector);
61      vector = null;
62      GC.SuppressFinalize(this);
63    }
64
[14245]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);
79    }
80
[14244]81    public double this[int index] {
82      get {
83        if (index < 0 || index > Length) throw new IndexOutOfRangeException("Trying to get index(" + index + ") of vector(" + Length + ").");
84        return DllImporter.igraph_vector_e(vector, index);
85      }
86      set {
87        if (index < 0 || index > Length) throw new IndexOutOfRangeException("Trying to set index(" + index + ") of vector(" + Length + ").");
88        DllImporter.igraph_vector_set(vector, index, value);
89      }
90    }
91
92    public double[] ToArray() {
[14245]93      return DllImporter.igraph_vector_to_array(vector);
[14244]94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.