|
|
|
@ -75,67 +75,147 @@ namespace MathNet.Numerics.LinearAlgebra.Generic |
|
|
|
return Storage.GetHashCode(); |
|
|
|
} |
|
|
|
|
|
|
|
#if !PORTABLE
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <see cref="System.String"/> that represents this instance.
|
|
|
|
/// Creates a new object that is a copy of the current instance.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="System.String"/> that represents this instance.
|
|
|
|
/// A new object that is a copy of this instance.
|
|
|
|
/// </returns>
|
|
|
|
public override string ToString() |
|
|
|
object ICloneable.Clone() |
|
|
|
{ |
|
|
|
return ToString(null, null); |
|
|
|
return Clone(); |
|
|
|
} |
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <see cref="System.String"/> that represents this instance.
|
|
|
|
/// Returns a <see cref="System.String"/> that describes the type, dimensions and shape of this matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="format">
|
|
|
|
/// The format to use.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="formatProvider">
|
|
|
|
/// The format provider to use.
|
|
|
|
/// </param>
|
|
|
|
/// <returns>
|
|
|
|
/// A <see cref="System.String"/> that represents this instance.
|
|
|
|
/// </returns>
|
|
|
|
public virtual string ToString(string format, IFormatProvider formatProvider = null) |
|
|
|
public virtual string ToTypeString() |
|
|
|
{ |
|
|
|
return string.Format("{0} {1}x{2}-{3}", GetType().Name, RowCount, ColumnCount, typeof(T).Name); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <see cref="System.String"/> that represents the content of this matrix.
|
|
|
|
/// </summary>
|
|
|
|
public string ToMatrixString(int maxRows, int maxColumns, IFormatProvider provider) |
|
|
|
{ |
|
|
|
return ToMatrixString(maxRows, maxColumns, 12, "G6", provider); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <see cref="System.String"/> that represents the content of this matrix.
|
|
|
|
/// </summary>
|
|
|
|
public string ToMatrixString(int maxRows, int maxColumns, int padding, string format, IFormatProvider provider) |
|
|
|
{ |
|
|
|
var separator = (formatProvider.GetTextInfo().ListSeparator); |
|
|
|
int rowN = RowCount <= maxRows ? RowCount : maxRows < 3 ? maxRows : maxRows - 1; |
|
|
|
bool rowDots = maxRows < RowCount; |
|
|
|
bool rowLast = rowDots && maxRows > 2; |
|
|
|
|
|
|
|
int colN = ColumnCount <= maxColumns ? ColumnCount : maxColumns < 3 ? maxColumns : maxColumns - 1; |
|
|
|
bool colDots = maxColumns < ColumnCount; |
|
|
|
bool colLast = colDots && maxColumns > 2; |
|
|
|
|
|
|
|
const string separator = " "; |
|
|
|
const string dots = "..."; |
|
|
|
string pdots = "...".PadLeft(padding); |
|
|
|
|
|
|
|
var stringBuilder = new StringBuilder(); |
|
|
|
|
|
|
|
for (var row = 0; row < RowCount; row++) |
|
|
|
for (var row = 0; row < rowN; row++) |
|
|
|
{ |
|
|
|
stringBuilder.Append(At(row, 0).ToString(format, provider).PadLeft(padding)); |
|
|
|
for (var column = 1; column < colN; column++) |
|
|
|
{ |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(At(row, column).ToString(format, provider).PadLeft(padding)); |
|
|
|
} |
|
|
|
if (colDots) |
|
|
|
{ |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(dots); |
|
|
|
if (colLast) |
|
|
|
{ |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(At(row, ColumnCount - 1).ToString(format, provider).PadLeft(12)); |
|
|
|
} |
|
|
|
} |
|
|
|
stringBuilder.Append(Environment.NewLine); |
|
|
|
} |
|
|
|
|
|
|
|
if (rowDots) |
|
|
|
{ |
|
|
|
for (var column = 0; column < ColumnCount; column++) |
|
|
|
stringBuilder.Append(pdots); |
|
|
|
for (var column = 1; column < colN; column++) |
|
|
|
{ |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(pdots); |
|
|
|
} |
|
|
|
if (colDots) |
|
|
|
{ |
|
|
|
stringBuilder.Append(At(row, column).ToString(format, formatProvider)); |
|
|
|
if (column != ColumnCount - 1) |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(dots); |
|
|
|
if (colLast) |
|
|
|
{ |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(pdots); |
|
|
|
} |
|
|
|
} |
|
|
|
stringBuilder.Append(Environment.NewLine); |
|
|
|
} |
|
|
|
|
|
|
|
if (row != RowCount - 1) |
|
|
|
if (rowLast) |
|
|
|
{ |
|
|
|
stringBuilder.Append(At(RowCount - 1, 0).ToString(format, provider).PadLeft(padding)); |
|
|
|
for (var column = 1; column < colN; column++) |
|
|
|
{ |
|
|
|
stringBuilder.Append(Environment.NewLine); |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(At(RowCount - 1, column).ToString(format, provider).PadLeft(padding)); |
|
|
|
} |
|
|
|
if (colDots) |
|
|
|
{ |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(dots); |
|
|
|
if (colLast) |
|
|
|
{ |
|
|
|
stringBuilder.Append(separator); |
|
|
|
stringBuilder.Append(At(RowCount - 1, ColumnCount - 1).ToString(format, provider).PadLeft(padding)); |
|
|
|
} |
|
|
|
} |
|
|
|
stringBuilder.Append(Environment.NewLine); |
|
|
|
} |
|
|
|
|
|
|
|
return stringBuilder.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
#if !PORTABLE
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <see cref="System.String"/> that summarizes this matrix.
|
|
|
|
/// </summary>
|
|
|
|
public string ToString(int maxRows, int maxColumns, IFormatProvider provider = null) |
|
|
|
{ |
|
|
|
return string.Concat(ToTypeString(), Environment.NewLine, ToMatrixString(maxRows, maxColumns, provider)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new object that is a copy of the current instance.
|
|
|
|
/// Returns a <see cref="System.String"/> that summarizes this matrix.
|
|
|
|
/// The maximum number of cells can be configured in the <see cref="Control"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>
|
|
|
|
/// A new object that is a copy of this instance.
|
|
|
|
/// </returns>
|
|
|
|
object ICloneable.Clone() |
|
|
|
public override sealed string ToString() |
|
|
|
{ |
|
|
|
return Clone(); |
|
|
|
return string.Concat(ToTypeString(), Environment.NewLine, ToMatrixString(Control.MaxToStringRows, Control.MaxToStringColumns, null)); |
|
|
|
} |
|
|
|
|
|
|
|
#endif
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <see cref="System.String"/> that summarizes this matrix.
|
|
|
|
/// The maximum number of cells can be configured in the <see cref="Control"/> class.
|
|
|
|
/// The format string is ignored.
|
|
|
|
/// </summary>
|
|
|
|
public string ToString(string format, IFormatProvider formatProvider) |
|
|
|
{ |
|
|
|
return string.Concat(ToTypeString(), Environment.NewLine, ToMatrixString(Control.MaxToStringRows, Control.MaxToStringColumns, formatProvider)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|