/// <summary> /// Writes the matrix to a file in sparse format. A directory will be created if needed. /// The first line is "var" TAB "cid" TAB "val" /// Next is one line per nonmissing value. Each line is: rowKey TAB colKey TAB value /// </summary> /// <typeparam name="TRowKey">The type of the row key. Usually "String"</typeparam> /// <typeparam name="TColKey">The type of the col key. Usually "String"</typeparam> /// <typeparam name="TValue">The type of the value, for example, double, int, char, etc.</typeparam> /// <param name="matrix">The matrix to write</param> /// <param name="filename">The filename to write to.</param> public static void WriteSparse <TRowKey, TColKey, TValue>(this Matrix <TRowKey, TColKey, TValue> matrix, string filename) { FileUtils.CreateDirectoryForFileIfNeeded(filename); using (TextWriter writer = File.CreateText(filename)) { matrix.WriteSparse(writer); } }