コード例 #1
0
 /// <summary>
 /// Zips two matrices and writes the values side by side
 /// </summary>
 /// <param name="m1">First matrix</param>
 /// <param name="m2">Second matrix</param>
 /// <returns>Xml string</returns>
 public static string WriteComparison(IIndexableMatrix m1, IIndexableMatrix m2)
 {
     using var stringWriter = new StringWriter();
     using var writer       = new XmlTextWriter(stringWriter);
     _Write(m1, m2, writer);
     writer.Flush();
     return(stringWriter.ToString());
 }
コード例 #2
0
 public static void AssertEqual(IIndexableMatrix m1, IIndexableMatrix m2, int maxDifference = 6)
 {
     Assert.AreEqual(m1.RowCount, m2.RowCount);
     Assert.AreEqual(m1.ColumnCount, m2.ColumnCount);
     for (var i = 0; i < m1.RowCount; i++)
     {
         for (var j = 0; j < m1.ColumnCount; j++)
         {
             AssertEqual(m1[i, j], m2[i, j], maxDifference);
         }
     }
 }
コード例 #3
0
ファイル: DebugHelpers.cs プロジェクト: zheng1748/brightwire
 static void _Write(IIndexableMatrix m1, IIndexableMatrix m2, XmlTextWriter writer)
 {
     writer.WriteStartElement("matrix");
     writer.WriteAttributeString("r1", m1.RowCount.ToString());
     writer.WriteAttributeString("r2", m2.RowCount.ToString());
     foreach (var row in m1.Rows.Zip(m2.Rows, (x, y) => (x, y)))
     {
         writer.WriteStartElement("row");
         writer.WriteAttributeString("c1", row.Item1.Count.ToString());
         writer.WriteAttributeString("c2", row.Item2.Count.ToString());
         foreach (var cell in row.Item1.Values.Zip(row.Item2.Values, (i, j) => (i, j)))
         {
             writer.WriteStartElement("cell");
             writer.WriteAttributeString("v1", cell.Item1.ToString(CultureInfo.InvariantCulture));
             writer.WriteAttributeString("v2", cell.Item2.ToString(CultureInfo.InvariantCulture));
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
コード例 #4
0
 public GpuMatrix(CudaProvider cuda, IIndexableMatrix matrix) : this(cuda, matrix.RowCount, matrix.ColumnCount, (j, k) => matrix[j, k])
 {
 }
コード例 #5
0
ファイル: CudaProvider.cs プロジェクト: fcmai/brightwire
 public IMatrix Create(IIndexableMatrix matrix)
 {
     return(Create(matrix.RowCount, matrix.ColumnCount, (x, y) => matrix[x, y]));
 }
コード例 #6
0
 /// <summary>
 /// Create a matrix
 /// </summary>
 /// <param name="lap"></param>
 /// <param name="matrix">Indexable matrix to copy</param>
 /// <returns></returns>
 public static IMatrix CreateMatrix(this ILinearAlgebraProvider lap, IIndexableMatrix matrix)
 {
     return(lap.CreateMatrix(matrix.RowCount, matrix.ColumnCount, (i, j) => matrix[i, j]));
 }