Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/21 21:35:37 (3 years ago)
Author:
gkronber
Message:

#3128: first dump of exploratory work-in-progress code to make sure the working copy is not lost.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3128_Prediction_Intervals/HeuristicLab.Common/3.3/MatrixExtensions.cs

    r17180 r17991  
    9696      return result;
    9797    }
     98
     99    /// <summary>
     100    /// Concatenates matrices horizontally.
     101    /// A      B
     102    /// 1 2    9 8
     103    /// 3 4    7 6
     104    ///
     105    /// HorzCat(A, B)
     106    /// 1 2 9 8
     107    /// 3 4 7 6
     108    /// </summary>
     109    /// <typeparam name="T"></typeparam>
     110    /// <param name="a"></param>
     111    /// <param name="b"></param>
     112    /// <returns>A new matrix with the number of columns = a.GetLength(1) + b.GetLength(1)</returns>
     113    public static T[,] HorzCat<T>(this T[,] a, T[] b) {
     114      Contract.Assert(a.GetLength(0) == b.Length);
     115      var aLen = a.GetLength(1);
     116      var bLen = 1;
     117      var result = new T[a.GetLength(0), aLen + bLen];
     118      for (int i = 0; i < a.GetLength(0); i++)
     119        for (int j = 0; j < aLen; j++)
     120          result[i, j] = a[i, j];
     121      for (int i = 0; i < a.GetLength(0); i++)
     122        result[i, aLen] = b[i];
     123      return result;
     124    }
    98125  }
    99126}
Note: See TracChangeset for help on using the changeset viewer.