/// <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()); }
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); } } }
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(); }
public GpuMatrix(CudaProvider cuda, IIndexableMatrix matrix) : this(cuda, matrix.RowCount, matrix.ColumnCount, (j, k) => matrix[j, k]) { }
public IMatrix Create(IIndexableMatrix matrix) { return(Create(matrix.RowCount, matrix.ColumnCount, (x, y) => matrix[x, y])); }
/// <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])); }