Changeset 17690 for branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3
- Timestamp:
- 07/21/20 17:06:15 (4 years ago)
- 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 42 42 public DoubleMatrix(double[,] elements, IEnumerable<string> columnNames, bool @readonly = false) : base(elements, columnNames, @readonly) { } 43 43 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 } 44 63 45 64 public override IDeepCloneable Clone(Cloner cloner) { -
branches/2521_ProblemRefactoring/HeuristicLab.Data/3.3/ValueTypeMatrix.cs
r17253 r17690 202 202 } 203 203 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 204 214 public virtual IEnumerable<T> GetRow(int row) { 205 215 for (var col = 0; col < Columns; col++) {
Note: See TracChangeset
for help on using the changeset viewer.