Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/21/20 17:06:15 (4 years ago)
Author:
abeham
Message:

#2521: worked on multi-objective test function

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3/DoubleMatrix.cs

    r17253 r17690  
    4242    public DoubleMatrix(double[,] elements, IEnumerable<string> columnNames, bool @readonly = false) : base(elements, columnNames, @readonly) { }
    4343    public DoubleMatrix(double[,] elements, IEnumerable<string> columnNames, IEnumerable<string> rowNames, bool @readonly = false) : base(elements, columnNames, rowNames, @readonly) { }
     44   
     45    public static DoubleMatrix FromRows(IList<double[]> elements, bool @readonly = false, IEnumerable<string> columnNames = null, IEnumerable<string> rowNames = null) {
     46      if (elements.Count == 0) return new DoubleMatrix(0, 0);
     47      var mat = new double[elements.Count, elements[0].Length];
     48      for (var r = 0; r < mat.GetLength(0); r++)
     49        for (var c = 0; c < mat.GetLength(1); c++)
     50          mat[r, c] = elements[r][c];
     51      // TODO: We should avoid the memory copy in this case
     52      return new DoubleMatrix(mat, columnNames, rowNames, @readonly);
     53    }
     54    public static DoubleMatrix FromColumns(IList<double[]> elements, bool @readonly = false, IEnumerable<string> columnNames = null, IEnumerable<string> rowNames = null) {
     55      if (elements.Count == 0) return new DoubleMatrix(0, 0);
     56      var mat = new double[elements[0].Length, elements.Count];
     57      for (var c = 0; c < mat.GetLength(1); c++)
     58        for (var r = 0; r < mat.GetLength(0); r++)
     59          mat[r, c] = elements[c][r];
     60      // TODO: We should avoid the memory copy in this case
     61      return new DoubleMatrix(mat, columnNames, rowNames, @readonly);
     62    }
    4463
    4564    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3/ValueTypeMatrix.cs

    r17253 r17690  
    202202    }
    203203
     204    public IEnumerable<T[]> CloneByRows() {
     205      for (var r = 0; r < matrix.GetLength(0); r++)
     206        yield return GetRow(r).ToArray();
     207    }
     208
     209    public IEnumerable<T[]> CloneByColumn() {
     210      for (var c = 0; c < matrix.GetLength(1); c++)
     211        yield return GetColumn(c).ToArray();
     212    }
     213
    204214    public virtual IEnumerable<T> GetRow(int row) {
    205215      for (var col = 0; col < Columns; col++) {
Note: See TracChangeset for help on using the changeset viewer.