1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | * and the BEACON Center for the Study of Evolution in Action.
|
---|
5 | *
|
---|
6 | * This file is part of HeuristicLab.
|
---|
7 | *
|
---|
8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
9 | * it under the terms of the GNU General Public License as published by
|
---|
10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
11 | * (at your option) any later version.
|
---|
12 | *
|
---|
13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public License
|
---|
19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 | #endregion
|
---|
22 |
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy {
|
---|
28 | internal static class DoubleMatrixHelper {
|
---|
29 | internal static double[][] ToJaggedArray(this DoubleMatrix m) {
|
---|
30 | if (m == null) return null;
|
---|
31 | var i = m.Rows - 1;
|
---|
32 | var a = new double[i][];
|
---|
33 | for (i--; i >= 0; i--) {
|
---|
34 | var j = m.Columns;
|
---|
35 | a[i] = new double[j];
|
---|
36 | for (j--; j >= 0; j--) a[i][j] = m[i, j];
|
---|
37 | }
|
---|
38 | return a;
|
---|
39 | }
|
---|
40 |
|
---|
41 | internal static DoubleMatrix ToMatrix(this IEnumerable<IReadOnlyList<double>> data) {
|
---|
42 | var d2 = data.ToArray();
|
---|
43 | var mat = new DoubleMatrix(d2.Length, d2[0].Count);
|
---|
44 | for (var i = 0; i < mat.Rows; i++)
|
---|
45 | for (var j = 0; j < mat.Columns; j++)
|
---|
46 | mat[i, j] = d2[i][j];
|
---|
47 | return mat;
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|