# Changeset 14237 for branches/symbreg-factors-2650/HeuristicLab.Common/3.3/MatrixExtensions.cs

Ignore:
Timestamp:
08/05/16 14:25:28 (3 years ago)
Message:

#2650: work in progress..

File:
1 edited

Unmodified
Removed
• ## branches/symbreg-factors-2650/HeuristicLab.Common/3.3/MatrixExtensions.cs

 r14185 #endregion using System.Diagnostics.Contracts; namespace HeuristicLab.Common { public static class MatrixExtensions { return result; } /// /// Concatenates matrices horizontally. /// A      B /// 1 2    9 8 /// 3 4    7 6 /// /// HorzCat(A, B) /// 1 2 /// 3 4 /// 9 8 /// 7 6 /// /// /// /// /// A new matrix with the number of rows = a.GetLength(0) + b.GetLength(0) public static T[,] HorzCat(this T[,] a, T[,] b) { Contract.Assert(a.GetLength(1) == b.GetLength(1)); var aLen = a.GetLength(0); var bLen = b.GetLength(0); var result = new T[aLen + bLen, a.GetLength(1)]; for (int i = 0; i < aLen; i++) for (int j = 0; j < a.GetLength(1); j++) result[i, j] = a[i, j]; for (int i = 0; i < bLen; i++) for (int j = 0; j < b.GetLength(1); j++) result[i + aLen, j] = b[i, j]; return result; } /// /// Concatenates matrices vertically. /// A      B /// 1 2    9 8 /// 3 4    7 6 /// /// VertCat(A, B) /// 1 2 9 8 /// 3 4 7 6 /// /// /// /// /// A new matrix with the number of columns = a.GetLength(1) + b.GetLength(1) public static T[,] VertCat(this T[,] a, T[,] b) { Contract.Assert(a.GetLength(0) == b.GetLength(0)); var aLen = a.GetLength(1); var bLen = b.GetLength(1); var result = new T[a.GetLength(0), aLen + bLen]; for (int i = 0; i < a.GetLength(0); i++) for (int j = 0; j < aLen; j++) result[i, j] = a[i, j]; for (int i = 0; i < a.GetLength(0); i++) for (int j = 0; j < bLen; j++) result[i, j + aLen] = b[i, j]; return result; } } }
Note: See TracChangeset for help on using the changeset viewer.