public static double[][] ParseJagged(string str, IMatrixFormatProvider provider) { // remove excess spaces str = Regex.Replace(str, @" +", " "); // First remove starting and trailing tokens str = str.Remove(0, provider.ParseMatrixStart.Length); str = str.Remove(str.Length - provider.ParseMatrixEnd.Length, provider.ParseMatrixEnd.Length); // Now split rows string[] strRows = str.Split(new string[] { provider.ParseRowDelimiter }, StringSplitOptions.RemoveEmptyEntries); List <double[]> rows = new List <double[]>(); foreach (string strRow in strRows) { string row = strRow.Trim(); // Remove starting and trailing tokens if (row.StartsWith(provider.ParseRowStart, StringComparison.Ordinal)) { row = row.Remove(0, provider.ParseRowStart.Length); } if (row.EndsWith(provider.ParseRowEnd, StringComparison.Ordinal)) { row = row.Remove(row.Length - provider.ParseRowEnd.Length, provider.ParseRowEnd.Length); } // Now split rows values string[] strCols = row.Split(new string[] { provider.ParseColDelimiter }, StringSplitOptions.RemoveEmptyEntries); List <double> values = new List <double>(); foreach (string strCol in strCols) { string col = Regex.Replace(strCol, @"\s", String.Empty); // Remove starting and trailing tokens if (col.StartsWith(provider.ParseColStart, StringComparison.Ordinal)) { col = col.Remove(0, provider.ParseColStart.Length); } if (col.EndsWith(provider.ParseColEnd, StringComparison.Ordinal)) { col = col.Remove(col.Length - provider.ParseColEnd.Length, provider.ParseColEnd.Length); } // finally, parse the value and store values.Add(Double.Parse(col, provider.InnerProvider)); } rows.Add(values.ToArray()); } return(rows.ToArray()); }
/// <summary> /// Returns a <see cref="System.String"/> that represents a matrix. /// </summary> /// /// <param name="matrix">The matrix.</param> /// /// <param name="multiline"> /// If set to <c>true</c>, the matrix will be written using multiple /// lines. If set to <c>false</c>, the matrix will be written in a /// single line.</param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="CSharpJaggedMatrixFormatProvider"/>, <see cref="CSharpArrayFormatProvider"/>, /// <see cref="OctaveMatrixFormatProvider"/>, or <see cref="OctaveArrayFormatProvider"/> /// for more details. /// </example> /// /// public static string ToString(this double[,] matrix, bool multiline, IMatrixFormatProvider provider) { if (multiline) { return(ToString(matrix, Environment.NewLine, provider)); } else { return(ToString(matrix, null, provider)); } }
/// <summary> /// Converts the value of a specified object to an equivalent string /// representation using specified formatting information. /// </summary> /// <param name="format">A format string containing formatting specifications.</param> /// <param name="arg">An object to format.</param> /// <param name="formatProvider"> /// An <see cref="T:System.IFormatProvider"/> object that supplies /// format information about the current instance.</param> /// <returns> /// The string representation of the value of <paramref name="arg"/>, /// formatted as specified by <paramref name="format"/> and /// <paramref name="formatProvider"/>. /// </returns> /// public string Format(string format, object arg, IFormatProvider formatProvider) { IMatrixFormatProvider provider = formatProvider as IMatrixFormatProvider; Array obj = arg as Array; // Check if the user has provided the correct format provider // for a matrix or if the argument is indeed an array (matrix) if (provider is not null && obj is not null) { return(Format(format, obj, provider)); }
/// <summary> /// Returns a <see cref="System.String"/> that represents a matrix. /// </summary> /// /// <param name="matrix">The matrix.</param> /// /// <param name="multiline"> /// If set to <c>true</c>, the matrix will be written using multiple /// lines. If set to <c>false</c>, the matrix will be written in a /// single line.</param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="CSharpJaggedMatrixFormatProvider"/>, <see cref="CSharpArrayFormatProvider"/>, /// <see cref="OctaveMatrixFormatProvider"/>, or <see cref="OctaveArrayFormatProvider"/> /// for more details. /// </example> /// /// public static string ToString(this double[,] matrix, bool multiline, IMatrixFormatProvider provider) { if (multiline) { return ToString(matrix, Environment.NewLine, provider); } else { return ToString(matrix, null, provider); } }
public string Format(string format, object arg, IFormatProvider formatProvider) { IMatrixFormatProvider provider = formatProvider as IMatrixFormatProvider; Array obj = arg as Array; if (provider != null && obj != null) { return(Format(format, obj, provider)); } else { return(handleOtherFormats(format, arg, CultureInfo.CurrentCulture)); } }
/// <summary> /// Converts the value of a specified object to an equivalent string /// representation using specified formatting information. /// </summary> /// <param name="format">A format string containing formatting specifications.</param> /// <param name="arg">An object to format.</param> /// <param name="formatProvider"> /// An <see cref="T:System.IFormatProvider"/> object that supplies /// format information about the current instance.</param> /// <returns> /// The string representation of the value of <paramref name="arg"/>, /// formatted as specified by <paramref name="format"/> and <paramref /// name="formatProvider"/>. /// </returns> /// public string Format(string format, object arg, IFormatProvider formatProvider) { IMatrixFormatProvider provider = formatProvider as IMatrixFormatProvider; Array obj = arg as Array; // Check if the user has provided the correct format provider // for a matrix or if the argument is indeed an array (matrix) if (provider != null && obj != null) { return(Format(format, obj, provider)); } else { // No, it has not. Try to provide standard formatting for the type return(handleOtherFormats(format, arg, CultureInfo.CurrentCulture)); } }
public static bool TryParse(string s, IMatrixFormatProvider provider, out double[,] matrix) { try { matrix = Parse(s, provider); } catch (FormatException) { matrix = null; } catch (ArgumentNullException) { matrix = null; } return(matrix != null); }
/// <summary> /// Converts the string representation of a matrix to its /// double-precision floating-point number matrix equivalent. /// A return value indicates whether the conversion succeeded or failed. /// </summary> /// <param name="s">The string representation of the matrix.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// <param name="matrix">A double-precision floating-point number matrix parsed /// from the given string using the given format provider.</param> /// <result>When this method returns, contains the double-precision floating-point /// number matrix equivalent to the <see param="s"/> parameter, if the conversion succeeded, /// or null if the conversion failed. The conversion fails if the <see param="s"/> parameter /// is null, is not a matrix in a valid format, or contains elements which represent /// a number less than MinValue or greater than MaxValue. This parameter is passed /// uninitialized. </result> /// public static bool TryParse(string s, IMatrixFormatProvider provider, out double[][] matrix) { // TODO: Create a proper TryParse method without // resorting to a underlying try-catch block. try { matrix = ParseJagged(s, provider); } catch (FormatException) { matrix = null; } catch (ArgumentNullException) { matrix = null; } return(matrix != null); }
/// <summary> /// Converts the string representation of a vector to its /// double-precision floating-point number vector equivalent. /// A return value indicates whether the conversion succeeded or failed. /// </summary> /// <param name="s">The string representation of the vector.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture" />. /// </param> /// <param name="vector"> /// A double-precision floating-point number matrix parsed /// from the given string using the given format provider. /// </param> /// <result> /// When this method returns, contains the double-precision floating-point /// number matrix equivalent to the <see param="s" /> parameter, if the conversion succeeded, /// or null if the conversion failed. The conversion fails if the <see param="s" /> parameter /// is null, is not a matrix in a valid format, or contains elements which represent /// a number less than MinValue or greater than MaxValue. This parameter is passed /// uninitialized. /// </result> public static bool TryParse(string s, IMatrixFormatProvider provider, out double[] vector) { // TODO: Create a proper TryParse method without // resorting to a underlying try-catch block. try { vector = Parse(s, provider); } catch (FormatException) { vector = null; } catch (ArgumentNullException) { vector = null; } return(vector is not null); }
/// <summary> /// Converts a jagged or multidimensional array into a <a cref="System.String">System.String</a> representation. /// </summary> /// public static string Format(string format, Array matrix, IMatrixFormatProvider formatProvider) { // Initial argument checking if (matrix.Rank > 2) { throw new NotSupportedException("Matrices with more than two dimensions are not supported."); } // Try to parse the format options passed through the "format" argument string newline, elementFormat; if (!parseOptions(format, out newline, out elementFormat)) { throw new FormatException(String.Format("The format of '{0}' is invalid.", format)); } CultureInfo culture = formatProvider.CultureInfo; // Retrieve matrix dimensions. If the matrix is a jagged array, // we will compute the columns for each of the rows. int rows = matrix.GetLength(0); int cols = (matrix.Rank == 2) ? matrix.GetLength(1) : 0; // Initialize the matrix construction StringBuilder sb = new StringBuilder(); sb.Append(formatProvider.FormatMatrixStart); // For each row for (int i = 0; i < rows; i++) { // Start constructing the row sb.Append(formatProvider.FormatRowStart); // Construct the columns for the row if (matrix.Rank == 1) { Object obj = matrix.GetValue(i); Array row = obj as Array; if (row == null) { handleOtherFormats(elementFormat, obj, culture); } else { #region Process row for jagged arrays cols = row.Length; // For each column for (int j = 0; j < cols; j++) { sb.Append(handleOtherFormats(elementFormat, row.GetValue(j), culture)); if (j < cols - 1) { sb.Append(formatProvider.FormatColDelimiter); } } #endregion } } else { #region Process row for multidimensional arrays // For each column for (int j = 0; j < cols; j++) { sb.Append(handleOtherFormats(elementFormat, matrix.GetValue(i, j), culture)); if (j < cols - 1) { sb.Append(formatProvider.FormatColDelimiter); } } #endregion } // Finalize constructing the row sb.Append(formatProvider.FormatRowEnd); // Check if we are still in the middle of the row if (i < rows - 1) { sb.Append(formatProvider.FormatRowDelimiter); } } // Finalize constructing the matrix sb.Append(formatProvider.FormatMatrixEnd); // Finally, perform post-processing such as replacing user // selected newlines or presenting the output in just one line. String str = sb.ToString(); str = str.Replace("\n", newline); if (String.IsNullOrEmpty(newline)) { str = Regex.Replace(str, " +", " "); } return(str); }
/// <summary> /// Converts the string representation of a matrix to its /// double-precision floating-point number matrix equivalent. /// A return value indicates whether the conversion succeeded or failed. /// </summary> /// <param name="s">The string representation of the matrix.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// <param name="matrix">A double-precision floating-point number matrix parsed /// from the given string using the given format provider.</param> /// <result>When this method returns, contains the double-precision floating-point /// number matrix equivalent to the <see param="s"/> parameter, if the conversion succeeded, /// or null if the conversion failed. The conversion fails if the <see param="s"/> parameter /// is null, is not a matrix in a valid format, or contains elements which represent /// a number less than MinValue or greater than MaxValue. This parameter is passed /// uninitialized. </result> /// public static bool TryParse(string s, IMatrixFormatProvider provider, out double[][] matrix) { return(Jagged.TryParse(s, provider, out matrix)); }
/// <summary> /// Converts the string representation of a matrix to its /// double-precision floating-point number matrix equivalent. /// </summary> /// <param name="str">The string representation of the matrix.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// <returns>A double-precision floating-point number matrix parsed /// from the given string using the given format provider.</returns> /// public static double[,] Parse(string str, IMatrixFormatProvider provider) { return(MatrixFormatter.ParseMultidimensional(str, provider)); }
/// <summary> /// Returns a <see cref="System.String"/> that represents an array. /// </summary> /// /// <param name="array">The array.</param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="OctaveArrayFormatProvider"/> or <see cref="DefaultArrayFormatProvider"/> /// for examples and more details. /// </example> /// public static string ToString(this double[] array, IMatrixFormatProvider provider) { return(ToString(array, null, provider)); }
/// <summary> /// Converts a jagged or multidimensional array into a <a cref="System.String">System.String</a> representation. /// </summary> /// public static string Format(string format, Array matrix, IMatrixFormatProvider formatProvider) { // Initial argument checking if (matrix.Rank > 2) { throw new NotSupportedException("Matrices with more than two dimensions are not supported."); } // Try to parse the format options passed through the "format" argument string newline, elementFormat; if (!parseOptions(format, out newline, out elementFormat)) { throw new FormatException(String.Format("The format of '{0}' is invalid.", format)); } IFormatProvider culture = formatProvider.InnerProvider; // Retrieve matrix dimensions. If the matrix is a jagged array, // we will compute the columns for each of the rows. int rows = matrix.GetLength(0); int cols = (matrix.Rank == 2) ? matrix.GetLength(1) : 0; // Initialize the matrix construction StringBuilder sb = new StringBuilder(); sb.Append(formatProvider.FormatMatrixStart); // For each row for (int i = 0; i < rows; i++) { // Start constructing the row sb.Append(formatProvider.FormatRowStart); // Construct the columns for the row if (matrix.Rank == 1) { Object obj = matrix.GetValue(i); Array row = obj as Array; if (row == null) { sb.Append(handleOtherFormats(elementFormat, obj, culture)); } else { #region Process row for jagged arrays cols = row.Length; // For each column for (int j = 0; j < cols; j++) { sb.Append(handleOtherFormats(elementFormat, row.GetValue(j), culture)); if (j < cols - 1) sb.Append(formatProvider.FormatColDelimiter); } #endregion } } else { #region Process row for multidimensional arrays // For each column for (int j = 0; j < cols; j++) { sb.Append(handleOtherFormats(elementFormat, matrix.GetValue(i, j), culture)); if (j < cols - 1) sb.Append(formatProvider.FormatColDelimiter); } #endregion } // Finalize constructing the row sb.Append(formatProvider.FormatRowEnd); // Check if we are still in the middle of the row if (i < rows - 1) sb.Append(formatProvider.FormatRowDelimiter); } // Finalize constructing the matrix sb.Append(formatProvider.FormatMatrixEnd); // Finally, perform post-processing such as replacing user // selected newlines or presenting the output in just one line. String str = sb.ToString(); str = str.Replace("\n", newline); if (String.IsNullOrEmpty(newline)) str = Regex.Replace(str, " +", " "); return str; }
/// <summary> /// Returns a <see cref="System.String"/> that represents an array. /// </summary> /// /// <param name="matrix">The matrix.</param> /// /// <param name="format"> /// The format to use when creating the resulting string. /// </param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="OctaveArrayFormatProvider"/> or <see cref="DefaultArrayFormatProvider"/> /// for examples and more details. /// </example> /// public static string ToString(this double[] matrix, string format, IMatrixFormatProvider provider) { return MatrixFormatter.Format(format, matrix, provider); }
/// <summary> /// Returns a <see cref="System.String"/> that represents an array. /// </summary> /// /// <param name="array">The array.</param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="OctaveArrayFormatProvider"/> or <see cref="DefaultArrayFormatProvider"/> /// for examples and more details. /// </example> /// public static string ToString(this double[] array, IMatrixFormatProvider provider) { return ToString(array, null, provider); }
/// <summary> /// Returns a <see cref="System.String"/> that represents a matrix. /// </summary> /// /// <param name="matrix">The matrix.</param> /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="CSharpJaggedMatrixFormatProvider"/>, <see cref="CSharpArrayFormatProvider"/>, /// <see cref="OctaveMatrixFormatProvider"/>, or <see cref="OctaveArrayFormatProvider"/> /// for more details. /// </example> /// /// public static string ToString(this double[][] matrix, IMatrixFormatProvider provider) { return ToString(matrix, null, provider); }
/// <summary> /// Converts the string representation of a vector to its /// double-precision floating-point number vector equivalent. /// </summary> /// <param name="str">The string representation of the vector.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture" />. /// </param> /// <returns> /// A double-precision floating-point number matrix parsed /// from the given string using the given format provider. /// </returns> public static double[] Parse(string str, IMatrixFormatProvider provider) { return(MatrixFormatter.ParseJagged(str, provider).Flatten()); }
/// <summary> /// Converts a matrix represented in a System.String into a jagged array. /// </summary> /// public static double[][] ParseJagged(string str, IMatrixFormatProvider provider) { // remove excess spaces str = Regex.Replace(str, @" +", " "); // First remove starting and trailing tokens str = str.Remove(0, provider.ParseMatrixStart.Length); str = str.Remove(str.Length - provider.ParseMatrixEnd.Length, provider.ParseMatrixEnd.Length); // Now split rows string[] strRows = str.Split(new string[] { provider.ParseRowDelimiter }, StringSplitOptions.RemoveEmptyEntries); List<double[]> rows = new List<double[]>(); foreach (string strRow in strRows) { string row = strRow.Trim(); // Remove starting and trailing tokens if (row.StartsWith(provider.ParseRowStart, StringComparison.Ordinal)) row = row.Remove(0, provider.ParseRowStart.Length); if (row.EndsWith(provider.ParseRowEnd, StringComparison.Ordinal)) row = row.Remove(row.Length - provider.ParseRowEnd.Length, provider.ParseRowEnd.Length); // Now split rows values string[] strCols = row.Split(new string[] { provider.ParseColDelimiter }, StringSplitOptions.RemoveEmptyEntries); List<double> values = new List<double>(); foreach (string strCol in strCols) { string col = Regex.Replace(strCol, @"\s", String.Empty); // Remove starting and trailing tokens if (col.StartsWith(provider.ParseColStart, StringComparison.Ordinal)) col = col.Remove(0, provider.ParseColStart.Length); if (col.EndsWith(provider.ParseColEnd, StringComparison.Ordinal)) col = col.Remove(col.Length - provider.ParseColEnd.Length, provider.ParseColEnd.Length); // finally, parse the value and store values.Add(Double.Parse(col, provider.InnerProvider)); } rows.Add(values.ToArray()); } return rows.ToArray(); }
/// <summary> /// Converts the string representation of a matrix to its /// double-precision floating-point number matrix equivalent. /// </summary> /// <param name="str">The string representation of the matrix.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// <returns>A double-precision floating-point number matrix parsed /// from the given string using the given format provider.</returns> /// public static double[,] Parse(string str, IMatrixFormatProvider provider) { return MatrixFormatter.ParseMultidimensional(str, provider); }
/// <summary> /// Converts a matrix represented in a System.String into a multi-dimensional array. /// </summary> /// public static double[,] ParseMultidimensional(string str, IMatrixFormatProvider provider) { return Matrix.ToMatrix(ParseJagged(str, provider)); }
/// <summary> /// Converts the string representation of a matrix to its /// double-precision floating-point number matrix equivalent. /// </summary> /// <param name="s">The string representation of the matrix.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// <returns>A double-precision floating-point number matrix parsed /// from the given string using the given format provider.</returns> /// public static double[][] ParseJagged(string s, IMatrixFormatProvider provider) { return MatrixFormatter.ParseJagged(s, provider); }
/// <summary> /// Returns a <see cref="System.String"/> that represents a matrix. /// </summary> /// /// <param name="matrix">The matrix.</param> /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="CSharpJaggedMatrixFormatProvider"/>, <see cref="CSharpArrayFormatProvider"/>, /// <see cref="OctaveMatrixFormatProvider"/>, or <see cref="OctaveArrayFormatProvider"/> /// for more details. /// </example> /// /// public static string ToString(this double[][] matrix, IMatrixFormatProvider provider) { return(ToString(matrix, null, provider)); }
/// <summary> /// Returns a <see cref="System.String"/> representation of a a given array. /// </summary> /// /// <param name="array">The array.</param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="OctaveArrayFormatProvider"/> or <see cref="DefaultArrayFormatProvider"/> /// for examples and more details. /// </example> /// public static string ToString<T>(this T[] array, IMatrixFormatProvider provider) { return ToString(array, null, provider); }
/// <summary> /// Returns a <see cref="System.String"/> that represents an array. /// </summary> /// /// <param name="matrix">The matrix.</param> /// /// <param name="format"> /// The format to use when creating the resulting string. /// </param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="OctaveArrayFormatProvider"/> or <see cref="DefaultArrayFormatProvider"/> /// for examples and more details. /// </example> /// public static string ToString(this double[] matrix, string format, IMatrixFormatProvider provider) { return(MatrixFormatter.Format(format, matrix, provider)); }
/// <summary> /// Returns a <see cref="System.String"/> representation of a a given array. /// </summary> /// /// <param name="matrix">The matrix.</param> /// /// <param name="format"> /// The format to use when creating the resulting string. /// </param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="OctaveArrayFormatProvider"/> or <see cref="DefaultArrayFormatProvider"/> /// for examples and more details. /// </example> /// public static string ToString<T>(this T[] matrix, string format, IMatrixFormatProvider provider) { return MatrixFormatter.Format(format, matrix, provider); }
/// <summary> /// Converts the string representation of a matrix to its /// double-precision floating-point number matrix equivalent. /// </summary> /// <param name="s">The string representation of the matrix.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// <returns>A double-precision floating-point number matrix parsed /// from the given string using the given format provider.</returns> /// public static double[][] ParseJagged(string s, IMatrixFormatProvider provider) { return(MatrixFormatter.ParseJagged(s, provider)); }
/// <summary> /// Converts a matrix represented in a System.String into a multi-dimensional array. /// </summary> /// public static double[,] ParseMultidimensional(string str, IMatrixFormatProvider provider) { return(Matrix.ToMatrix(ParseJagged(str, provider))); }
/// <summary> /// Converts the string representation of a matrix to its /// double-precision floating-point number matrix equivalent. /// A return value indicates whether the conversion succeeded or failed. /// </summary> /// <param name="s">The string representation of the matrix.</param> /// <param name="provider"> /// The format provider to use in the conversion. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// <param name="matrix">A double-precision floating-point number matrix parsed /// from the given string using the given format provider.</param> /// <result>When this method returns, contains the double-precision floating-point /// number matrix equivalent to the <see param="s"/> parameter, if the conversion succeeded, /// or null if the conversion failed. The conversion fails if the <see param="s"/> parameter /// is null, is not a matrix in a valid format, or contains elements which represent /// a number less than MinValue or greater than MaxValue. This parameter is passed /// uninitialized. </result> /// public static bool TryParse(string s, IMatrixFormatProvider provider, out double[][] matrix) { // TODO: Create a proper TryParse method without // resorting to a underlying try-catch block. try { matrix = ParseJagged(s, provider); } catch (FormatException) { matrix = null; } catch (ArgumentNullException) { matrix = null; } return matrix != null; }
/// <summary> /// Returns a <see cref="System.String"/> that represents a matrix. /// </summary> /// /// <param name="matrix">The matrix.</param> /// /// <param name="provider"> /// The <see cref="IMatrixFormatProvider"/> to be used /// when creating the resulting string. Default is to use /// <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>. /// </param> /// /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> /// /// <example> /// Please see <see cref="CSharpMatrixFormatProvider"/>, /// <see cref="CSharpJaggedMatrixFormatProvider"/>, <see cref="CSharpArrayFormatProvider"/>, /// <see cref="OctaveMatrixFormatProvider"/>, or <see cref="OctaveArrayFormatProvider"/> /// for more details. /// </example> /// /// public static string ToString <T>(this T[,] matrix, IMatrixFormatProvider provider) { return(ToString(matrix, null, provider)); }