Browse Source

changed Complex32.ToString to match Complex.ToString

refactored MatrixWriter and DelimitedWriter
pull/36/head
Marcus Cuda 16 years ago
parent
commit
86eefc56b2
  1. 46
      src/Numerics/Complex32.cs
  2. 17
      src/Numerics/LinearAlgebra/IO/DelimitedWriter.cs
  3. 33
      src/Numerics/LinearAlgebra/IO/MatrixWriter.cs
  4. 168
      src/Numerics/LinearAlgebra/Single/IO/DelimitedWriter.cs
  5. 197
      src/Numerics/LinearAlgebra/Single/IO/MatrixWriter.cs
  6. 6
      src/Numerics/Numerics.csproj
  7. 89
      src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs
  8. 90
      src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedWriterTests.cs
  9. 26
      src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorTest.TextHandling.cs
  10. 90
      src/UnitTests/LinearAlgebraTests/Complex32/IO/DelimitedWriterTests.cs
  11. 26
      src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.TextHandling.cs
  12. 2
      src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
  13. 11
      src/UnitTests/LinearAlgebraTests/Double/IO/DelimitedWriterTests.cs
  14. 9
      src/UnitTests/LinearAlgebraTests/Single/IO/DelimitedWriterTests.cs
  15. 2
      src/UnitTests/UnitTests.csproj

46
src/Numerics/Complex32.cs

@ -682,52 +682,8 @@ namespace MathNet.Numerics
/// </param>
public string ToString(string format, IFormatProvider formatProvider)
{
var numberFormatInfo = formatProvider.GetNumberFormatInfo();
if (IsNaN())
{
return numberFormatInfo.NaNSymbol;
}
if (IsInfinity())
{
return numberFormatInfo.PositiveInfinitySymbol;
}
var ret = new StringBuilder();
if (_real != 0.0f)
{
ret.Append(_real.ToString(format, formatProvider));
}
if (_imag != 0.0f)
{
if (_real != 0.0f)
{
if (_imag < 0)
{
ret.Append(" - ");
}
else
{
ret.Append(" + ");
}
ret.Append(Math.Abs(_imag).ToString(format, formatProvider)).Append("i");
}
else
{
ret.Append(_imag.ToString(format, formatProvider)).Append("i");
}
}
if (ret.Length == 0)
{
ret.Append(0.0f.ToString(format, formatProvider));
}
ret.Append("(").Append(_real.ToString(format, formatProvider)).Append(", ").Append(_imag.ToString(format, formatProvider)).Append(")");
return ret.ToString();
}

17
src/Numerics/LinearAlgebra/Double/IO/DelimitedWriter.cs → src/Numerics/LinearAlgebra/IO/DelimitedWriter.cs

@ -26,7 +26,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Double.IO
namespace MathNet.Numerics.LinearAlgebra.IO
{
using System;
using System.Collections.Generic;
@ -35,10 +35,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
using Generic;
/// <summary>
/// Writes an <see cref="Matrix{T}"/> to delimited text file. If the user does not
/// Writes an <see cref="Matrix{TDataType}"/> to delimited text file. If the user does not
/// specify a delimiter, a tab separator is used.
/// </summary>
public class DelimitedWriter : MatrixWriter
/// <typeparam name="TDataType">The data type of the matrix.</typeparam>
public class DelimitedWriter<TDataType> : MatrixWriter<TDataType> where TDataType : struct, IEquatable<TDataType>, IFormattable
{
/// <summary>
/// The delimiter to use.
@ -51,7 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
private CultureInfo _cultureInfo = CultureInfo.CurrentCulture;
/// <summary>
/// Initializes a new instance of the <see cref="DelimitedWriter"/> class using
/// Initializes a new instance of the <see cref="DelimitedWriter{TDataType}"/> class.
/// a comma as the delimiter.
/// </summary>
public DelimitedWriter()
@ -60,7 +61,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
}
/// <summary>
/// Initializes a new instance of the <see cref="DelimitedWriter"/> class
/// Initializes a new instance of the <see cref="DelimitedWriter{TDataType}"/> class.
/// using the given delimiter.
/// </summary>
/// <param name="delimiter">
@ -72,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
}
/// <summary>
/// Initializes a new instance of the <see cref="DelimitedWriter"/> class
/// Initializes a new instance of the <see cref="DelimitedWriter{TDataType}"/> class.
/// using the given delimiter.
/// </summary>
/// <param name="delimiter">
@ -116,13 +117,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given <see cref="TextWriter"/>.
/// Writes the given <see cref="Matrix{TDataType}"/> to the given <see cref="TextWriter"/>.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="writer">The <see cref="TextWriter"/> to write the matrix to.</param>
/// <param name="format">The format to use on each element.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="writer"/> is <c>null</c>.</exception>
protected override void DoWriteMatrix(Matrix<double> matrix, TextWriter writer, string format)
protected override void DoWriteMatrix(Matrix<TDataType> matrix, TextWriter writer, string format)
{
if (matrix == null)
{

33
src/Numerics/LinearAlgebra/Double/IO/MatrixWriter.cs → src/Numerics/LinearAlgebra/IO/MatrixWriter.cs

@ -29,23 +29,24 @@
using System;
using System.IO;
namespace MathNet.Numerics.LinearAlgebra.Double.IO
namespace MathNet.Numerics.LinearAlgebra.IO
{
using Generic;
/// <summary>
/// Base class to write a single <see cref="Matrix{T}"/> to a file or stream.
/// Base class to write a single <see cref="Matrix{DataType}"/> to a file or stream.
/// </summary>
public abstract class MatrixWriter
/// <typeparam name="TDataType">The data type of the matrix.</typeparam>
public abstract class MatrixWriter<TDataType> where TDataType : struct, IEquatable<TDataType>, IFormattable
{
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given file. If the file already exists,
/// Writes the given <see cref="Matrix{DataType}"/> to the given file. If the file already exists,
/// the file will be overwritten.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="file">The file to write the matrix to.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="file"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<double> matrix, string file)
public void WriteMatrix(Matrix<TDataType> matrix, string file)
{
if (matrix == null)
{
@ -64,14 +65,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given file. If the file already exists,
/// Writes the given <see cref="Matrix{DataType}"/> to the given file. If the file already exists,
/// the file will be overwritten.
/// </summary>
/// <param name="matrix">the matrix to write.</param>
/// <param name="file">The file to write the matrix to.</param>
/// <param name="format">The format to use on each element.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="file"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<double> matrix, string file, string format)
public void WriteMatrix(Matrix<TDataType> matrix, string file, string format)
{
if (matrix == null)
{
@ -95,12 +96,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given stream.
/// Writes the given <see cref="Matrix{DataType}"/> to the given stream.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="stream">The <see cref="Stream"/> to write the matrix to.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="stream"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<double> matrix, Stream stream)
public void WriteMatrix(Matrix<TDataType> matrix, Stream stream)
{
if (matrix == null)
{
@ -119,13 +120,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given stream.
/// Writes the given <see cref="Matrix{DataType}"/> to the given stream.
/// </summary>
/// <param name="matrix">The <see cref="TextWriter"/> to write.</param>
/// <param name="stream">The <see cref="Stream"/> to write the matrix to.</param>
/// <param name="format">The format to use on each element.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="stream"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<double> matrix, Stream stream, string format)
public void WriteMatrix(Matrix<TDataType> matrix, Stream stream, string format)
{
if (matrix == null)
{
@ -144,12 +145,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given <see cref="TextWriter"/>.
/// Writes the given <see cref="Matrix{DataType}"/> to the given <see cref="TextWriter"/>.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="writer">The <see cref="TextWriter"/> to write the matrix to.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="writer"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<double> matrix, TextWriter writer)
public void WriteMatrix(Matrix<TDataType> matrix, TextWriter writer)
{
if (matrix == null)
{
@ -165,13 +166,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given <see cref="TextWriter"/>.
/// Writes the given <see cref="Matrix{DataType}"/> to the given <see cref="TextWriter"/>.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="writer">The <see cref="TextWriter"/> to write the matrix to.</param>
/// <param name="format">The format to use on each element.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="writer"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<double> matrix, TextWriter writer, string format)
public void WriteMatrix(Matrix<TDataType> matrix, TextWriter writer, string format)
{
if (matrix == null)
{
@ -192,6 +193,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO
/// <param name="matrix">The matrix to serialize.</param>
/// <param name="writer">The <see cref="TextWriter"/> to write the matrix to.</param>
/// <param name="format">The format for the new matrix.</param>
protected abstract void DoWriteMatrix(Matrix<double> matrix, TextWriter writer, string format);
protected abstract void DoWriteMatrix(Matrix<TDataType> matrix, TextWriter writer, string format);
}
}

168
src/Numerics/LinearAlgebra/Single/IO/DelimitedWriter.cs

@ -1,168 +0,0 @@
// <copyright file="DelimitedWriter.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Single.IO
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using Generic;
/// <summary>
/// Writes an <see cref="Matrix{T}"/> to delimited text file. If the user does not
/// specify a delimiter, a tab separator is used.
/// </summary>
public class DelimitedWriter : MatrixWriter
{
/// <summary>
/// The delimiter to use.
/// </summary>
private readonly string _delimiter;
/// <summary>
/// The <see cref="CultureInfo"/> to use.
/// </summary>
private CultureInfo _cultureInfo = CultureInfo.CurrentCulture;
/// <summary>
/// Initializes a new instance of the <see cref="DelimitedWriter"/> class using
/// a comma as the delimiter.
/// </summary>
public DelimitedWriter()
{
_delimiter = ",";
}
/// <summary>
/// Initializes a new instance of the <see cref="DelimitedWriter"/> class
/// using the given delimiter.
/// </summary>
/// <param name="delimiter">
/// the delimiter to use.
/// </param>
public DelimitedWriter(char delimiter)
{
_delimiter = new string(delimiter, 1);
}
/// <summary>
/// Initializes a new instance of the <see cref="DelimitedWriter"/> class
/// using the given delimiter.
/// </summary>
/// <param name="delimiter">
/// the delimiter to use.
/// </param>
public DelimitedWriter(string delimiter)
{
_delimiter = delimiter;
}
/// <summary>
/// Gets or sets the column header values.
/// </summary>
/// <value>The column header values.</value>
/// <remarks>Will write the column headers if the list is not empty or <c>null</c>.</remarks>
public IList<string> ColumnHeaders
{
get;
set;
}
/// <summary>
/// Gets or sets the <see cref="CultureInfo"/> to use when parsing the numbers.
/// </summary>
/// <value>The culture info.</value>
/// <remarks>Defaults to <c>CultureInfo.CurrentCulture</c>.</remarks>
public CultureInfo CultureInfo
{
get
{
return _cultureInfo;
}
set
{
if (value != null)
{
_cultureInfo = value;
}
}
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given <see cref="TextWriter"/>.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="writer">The <see cref="TextWriter"/> to write the matrix to.</param>
/// <param name="format">The format to use on each element.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="writer"/> is <c>null</c>.</exception>
protected override void DoWriteMatrix(Matrix<float> matrix, TextWriter writer, string format)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (ColumnHeaders != null && ColumnHeaders.Count > 0)
{
for (var i = 0; i < ColumnHeaders.Count - 1; i++)
{
writer.Write(ColumnHeaders[i]);
writer.Write(_delimiter);
}
writer.WriteLine(ColumnHeaders[ColumnHeaders.Count - 1]);
}
var cols = matrix.ColumnCount - 1;
var rows = matrix.RowCount - 1;
for (var i = 0; i < matrix.RowCount; i++)
{
for (var j = 0; j < matrix.ColumnCount; j++)
{
writer.Write(matrix[i, j].ToString(format, _cultureInfo));
if (j != cols)
{
writer.Write(_delimiter);
}
}
if (i != rows)
{
writer.Write(Environment.NewLine);
}
}
}
}
}

197
src/Numerics/LinearAlgebra/Single/IO/MatrixWriter.cs

@ -1,197 +0,0 @@
// <copyright file="MatrixWriter.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using System.IO;
namespace MathNet.Numerics.LinearAlgebra.Single.IO
{
using Generic;
/// <summary>
/// Base class to write a single <see cref="Matrix{T}"/> to a file or stream.
/// </summary>
public abstract class MatrixWriter
{
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given file. If the file already exists,
/// the file will be overwritten.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="file">The file to write the matrix to.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="file"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<float> matrix, string file)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (file == null)
{
throw new ArgumentNullException("file");
}
using (var writer = new StreamWriter(file))
{
DoWriteMatrix(matrix, writer, null);
}
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given file. If the file already exists,
/// the file will be overwritten.
/// </summary>
/// <param name="matrix">the matrix to write.</param>
/// <param name="file">The file to write the matrix to.</param>
/// <param name="format">The format to use on each element.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="file"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<float> matrix, string file, string format)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (file == null)
{
throw new ArgumentNullException("file");
}
if (File.Exists(file))
{
File.Delete(file);
}
using (var writer = new StreamWriter(file))
{
DoWriteMatrix(matrix, writer, format);
}
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given stream.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="stream">The <see cref="Stream"/> to write the matrix to.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="stream"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<float> matrix, Stream stream)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (stream == null)
{
throw new ArgumentNullException("stream");
}
using (var writer = new StreamWriter(stream))
{
DoWriteMatrix(matrix, writer, null);
}
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given stream.
/// </summary>
/// <param name="matrix">The <see cref="TextWriter"/> to write.</param>
/// <param name="stream">The <see cref="Stream"/> to write the matrix to.</param>
/// <param name="format">The format to use on each element.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="stream"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<float> matrix, Stream stream, string format)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (stream == null)
{
throw new ArgumentNullException("stream");
}
using (var writer = new StreamWriter(stream))
{
DoWriteMatrix(matrix, writer, format);
}
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given <see cref="TextWriter"/>.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="writer">The <see cref="TextWriter"/> to write the matrix to.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="writer"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<float> matrix, TextWriter writer)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (writer == null)
{
throw new ArgumentNullException("writer");
}
DoWriteMatrix(matrix, writer, null);
}
/// <summary>
/// Writes the given <see cref="Matrix{T}"/> to the given <see cref="TextWriter"/>.
/// </summary>
/// <param name="matrix">The matrix to write.</param>
/// <param name="writer">The <see cref="TextWriter"/> to write the matrix to.</param>
/// <param name="format">The format to use on each element.</param>
/// <exception cref="ArgumentNullException">If either <paramref name="matrix"/> or <paramref name="writer"/> is <c>null</c>.</exception>
public void WriteMatrix(Matrix<float> matrix, TextWriter writer, string format)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (writer == null)
{
throw new ArgumentNullException("writer");
}
DoWriteMatrix(matrix, writer, format);
}
/// <summary>
/// Subclasses must implement this method to do the actually writing.
/// </summary>
/// <param name="matrix">The matrix to serialize.</param>
/// <param name="writer">The <see cref="TextWriter"/> to write the matrix to.</param>
/// <param name="format">The format for the new matrix.</param>
protected abstract void DoWriteMatrix(Matrix<float> matrix, TextWriter writer, string format);
}
}

6
src/Numerics/Numerics.csproj

@ -199,6 +199,8 @@
<Compile Include="LinearAlgebra\Double\Factorization\UserEvd.cs" />
<Compile Include="LinearAlgebra\Generic\Factorization\GramSchmidt.cs" />
<Compile Include="LinearAlgebra\Generic\Factorization\Evd.cs" />
<Compile Include="LinearAlgebra\IO\DelimitedWriter.cs" />
<Compile Include="LinearAlgebra\IO\MatrixWriter.cs" />
<Compile Include="LinearAlgebra\Single\DenseMatrix.cs" />
<Compile Include="LinearAlgebra\Single\DenseVector.cs" />
<Compile Include="LinearAlgebra\Single\DiagonalMatrix.cs" />
@ -215,12 +217,10 @@
<Compile Include="LinearAlgebra\Single\Factorization\UserQR.cs" />
<Compile Include="LinearAlgebra\Single\Factorization\UserSvd.cs" />
<Compile Include="LinearAlgebra\Single\IO\DelimitedReader.cs" />
<Compile Include="LinearAlgebra\Single\IO\DelimitedWriter.cs" />
<Compile Include="LinearAlgebra\Single\IO\MatlabReader.cs" />
<Compile Include="LinearAlgebra\Single\IO\Matlab\MatlabFile.cs" />
<Compile Include="LinearAlgebra\Single\IO\Matlab\MatlabParser.cs" />
<Compile Include="LinearAlgebra\Single\IO\MatrixReader.cs" />
<Compile Include="LinearAlgebra\Single\IO\MatrixWriter.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Iterative\BiCgStab.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Iterative\CompositeSolver.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Iterative\GpBiCg.cs" />
@ -257,12 +257,10 @@
<Compile Include="LinearAlgebra\Double\Factorization\UserQR.cs" />
<Compile Include="LinearAlgebra\Double\Factorization\UserSvd.cs" />
<Compile Include="LinearAlgebra\Double\IO\DelimitedReader.cs" />
<Compile Include="LinearAlgebra\Double\IO\DelimitedWriter.cs" />
<Compile Include="LinearAlgebra\Double\IO\MatlabReader.cs" />
<Compile Include="LinearAlgebra\Double\IO\Matlab\MatlabFile.cs" />
<Compile Include="LinearAlgebra\Double\IO\Matlab\MatlabParser.cs" />
<Compile Include="LinearAlgebra\Double\IO\MatrixReader.cs" />
<Compile Include="LinearAlgebra\Double\IO\MatrixWriter.cs" />
<Compile Include="LinearAlgebra\Generic\ISolver.cs" />
<Compile Include="LinearAlgebra\Generic\Solvers\IIterativeSolver.cs" />
<Compile Include="LinearAlgebra\Generic\Solvers\IIterativeSolverSetup.cs" />

89
src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs

@ -38,22 +38,21 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
public class Complex32TextHandlingTest
{
[Test]
[Row(1, -2, "1 - 2i")]
[Row(1, 2, "1 + 2i")]
[Row(1, 0, "1")]
[Row(0, -2, "-2i")]
[Row(0, 2, "2i")]
[Row(0, 2, "2i")]
[Row(0, 0, "0")]
[Row(Double.NaN, Double.NaN, "{1}")]
[Row(Double.NaN, 0, "{1}")]
[Row(0, Double.NaN, "{1}")]
[Row(Double.PositiveInfinity, Double.PositiveInfinity, "{2}")]
[Row(1.1, 0, "1{0}1")]
[Row(-1.1, 0, "-1{0}1")]
[Row(0, 1.1, "1{0}1i")]
[Row(0, -1.1, "-1{0}1i")]
[Row(1.1, 1.1, "1{0}1 + 1{0}1i")]
[Row(1, -2, "(1, -2)")]
[Row(1, 2, "(1, 2)")]
[Row(1, 0, "(1, 0)")]
[Row(0, -2, "(0, -2)")]
[Row(0, 2, "(0, 2)")]
[Row(0, 0, "(0, 0)")]
[Row(Double.NaN, Double.NaN, "({1}, {1})")]
[Row(Double.NaN, 0, "({1}, 0)")]
[Row(0, Double.NaN, "(0, {1})")]
[Row(Double.PositiveInfinity, Double.PositiveInfinity, "({2}, {2})")]
[Row(1.1, 0, "(1{0}1, 0)")]
[Row(-1.1, 0, "(-1{0}1, 0)")]
[Row(0, 1.1, "(0, 1{0}1)")]
[Row(0, -1.1, "(0, -1{0}1)")]
[Row(1.1, 1.1, "(1{0}1, 1{0}1)")]
public void CanFormatComplexToString(float real, float imag, string expected)
{
var numberFormat = NumberFormatInfo.CurrentInfo;
@ -78,31 +77,31 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
string cultureName, string nan, string infinity, string number)
{
var provider = CultureInfo.GetCultureInfo(cultureName);
Assert.AreEqual(nan, Complex32.NaN.ToString(provider));
Assert.AreEqual(infinity, Complex32.Infinity.ToString(provider));
Assert.AreEqual("0", Complex32.Zero.ToString(provider));
Assert.AreEqual(String.Format("{0}", number), new Complex32(1.1f, 0.0f).ToString(provider));
Assert.AreEqual(String.Format("-{0}", number), new Complex32(-1.1f, 0f).ToString(provider));
Assert.AreEqual(String.Format("-{0}i", number), new Complex32(0.0f, -1.1f).ToString(provider));
Assert.AreEqual(String.Format("{0}i", number), new Complex32(0.0f, 1.1f).ToString(provider));
Assert.AreEqual(String.Format("{0} + {0}i", number), new Complex32(1.1f, 1.1f).ToString(provider));
Assert.AreEqual("(" + nan + ", " + nan + ")", Complex32.NaN.ToString(provider));
Assert.AreEqual("(" + infinity + ", " + infinity + ")", Complex32.Infinity.ToString(provider));
Assert.AreEqual("(0, 0)", Complex32.Zero.ToString(provider));
Assert.AreEqual("(" + String.Format("{0}", number) + ", 0)", new Complex32(1.1f, 0.0f).ToString(provider));
Assert.AreEqual("(" + String.Format("-{0}", number) + ", 0)", new Complex32(-1.1f, 0f).ToString(provider));
Assert.AreEqual("(0, " + String.Format("-{0}", number) + ")", new Complex32(0.0f, -1.1f).ToString(provider));
Assert.AreEqual("(0, " + String.Format("{0}", number) + ")", new Complex32(0.0f, 1.1f).ToString(provider));
Assert.AreEqual("(" + String.Format("{0}", number) + ", " + String.Format("{0}", number) + ")", new Complex32(1.1f, 1.1f).ToString(provider));
}
[Test]
[MultipleAsserts]
public void CanFormatComplexToStringWithFormat()
{
Assert.AreEqual("0", String.Format("{0:G}", Complex32.Zero));
Assert.AreEqual("1 + 2i", String.Format("{0:G}", new Complex32(1, 2)));
Assert.AreEqual("001 + 002i", String.Format("{0:000;minus 000;zero}", new Complex32(1, 2)));
Assert.AreEqual("minus 002i", String.Format("{0:000;minus 000;zero}", new Complex32(0, -2)));
Assert.AreEqual("zero", String.Format("{0:000;minus 000;zero}", Complex32.Zero));
Assert.AreEqual("(0, 0)", String.Format("{0:G}", Complex32.Zero));
Assert.AreEqual("(1, 2)", String.Format("{0:G}", new Complex32(1, 2)));
Assert.AreEqual("(001, 002)", String.Format("{0:000;minus 000;zero}", new Complex32(1, 2)));
Assert.AreEqual("(zero, minus 002)", String.Format("{0:000;minus 000;zero}", new Complex32(0, -2)));
Assert.AreEqual("(zero, zero)", String.Format("{0:000;minus 000;zero}", Complex32.Zero));
Assert.AreEqual("0", Complex32.Zero.ToString("G"));
Assert.AreEqual("1 + 2i", new Complex32(1, 2).ToString("G"));
Assert.AreEqual("001 + 002i", new Complex32(1, 2).ToString("#000;minus 000;zero"));
Assert.AreEqual("minus 002i", new Complex32(0, -2).ToString("#000;minus 000;zero"));
Assert.AreEqual("zero", Complex32.Zero.ToString("#000;minus 000;zero"));
Assert.AreEqual("(0, 0)", Complex32.Zero.ToString("G"));
Assert.AreEqual("(1, 2)", new Complex32(1, 2).ToString("G"));
Assert.AreEqual("(001, 002)", new Complex32(1, 2).ToString("#000;minus 000;zero"));
Assert.AreEqual("(zero, minus 002)", new Complex32(0, -2).ToString("#000;minus 000;zero"));
Assert.AreEqual("(zero, zero)", Complex32.Zero.ToString("#000;minus 000;zero"));
}
[Test]
@ -111,18 +110,18 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var culture = CultureInfo.InvariantCulture;
Assert.AreEqual("NaN", String.Format(culture, "{0:.000}", Complex32.NaN));
Assert.AreEqual(".000", String.Format(culture, "{0:.000}", Complex32.Zero));
Assert.AreEqual("1.100", String.Format(culture, "{0:.000}", new Complex32(1.1f, 0.0f)));
Assert.AreEqual("1.100 + 1.100i", String.Format(culture, "{0:.000}", new Complex32(1.1f, 1.1f)));
Assert.AreEqual("(NaN, NaN)", String.Format(culture, "{0:.000}", Complex32.NaN));
Assert.AreEqual("(.000, .000)", String.Format(culture, "{0:.000}", Complex32.Zero));
Assert.AreEqual("(1.100, .000)", String.Format(culture, "{0:.000}", new Complex32(1.1f, 0.0f)));
Assert.AreEqual("(1.100, 1.100)", String.Format(culture, "{0:.000}", new Complex32(1.1f, 1.1f)));
Assert.AreEqual("NaN", Complex32.NaN.ToString("#.000", culture));
Assert.AreEqual("Infinity", Complex32.Infinity.ToString("#.000", culture));
Assert.AreEqual(".000", Complex32.Zero.ToString("#.000", culture));
Assert.AreEqual("1.100", new Complex32(1.1f, 0.0f).ToString("#.000", culture));
Assert.AreEqual("-1.100i", new Complex32(0.0f, -1.1f).ToString("#.000", culture));
Assert.AreEqual("1.100i", new Complex32(0.0f, 1.1f).ToString("#.000", culture));
Assert.AreEqual("1.100 + 1.100i", new Complex32(1.1f, 1.1f).ToString("#.000", culture));
Assert.AreEqual("(NaN, NaN)", Complex32.NaN.ToString("#.000", culture));
Assert.AreEqual("(Infinity, Infinity)", Complex32.Infinity.ToString("#.000", culture));
Assert.AreEqual("(.000, .000)", Complex32.Zero.ToString("#.000", culture));
Assert.AreEqual("(1.100, .000)", new Complex32(1.1f, 0.0f).ToString("#.000", culture));
Assert.AreEqual("(.000, -1.100)", new Complex32(0.0f, -1.1f).ToString("#.000", culture));
Assert.AreEqual("(.000, 1.100)", new Complex32(0.0f, 1.1f).ToString("#.000", culture));
Assert.AreEqual("(1.100, 1.100)", new Complex32(1.1f, 1.1f).ToString("#.000", culture));
}
[Test]

90
src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedWriterTests.cs

@ -0,0 +1,90 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.IO
{
using System;
using System.Globalization;
using System.Numerics;
using System.IO;
using LinearAlgebra.Complex;
using LinearAlgebra.IO;
using MbUnit.Framework;
[TestFixture]
public class DelimitedWriterTests
{
[Test]
public void CanWriteCommaDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { new Complex(1.1, 1.1), new Complex(2.2, 2.2), new Complex(3.3, 3.3) }, { new Complex(4.4, 4.4), new Complex(5.5, 5.5), new Complex(6.6, 6.6) }, { new Complex(7.7, 7.7), new Complex(8.8, 8.8), new Complex(9.9, 9.9) } });
var writer = new DelimitedWriter<Complex>(',');
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
const string expected = @"(1.1, 1.1),(2.2, 2.2),(3.3, 3.3)
(4.4, 4.4),(5.5, 5.5),(6.6, 6.6)
(7.7, 7.7),(8.8, 8.8),(9.9, 9.9)";
Assert.AreEqual(expected, text);
}
[Test]
public void CanWritePeriodDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { new Complex(1.1, 1.1), new Complex(2.2, 2.2), new Complex(3.3, 3.3) }, { new Complex(4.4, 4.4), new Complex(5.5, 5.5), new Complex(6.6, 6.6) }, { new Complex(7.7, 7.7), new Complex(8.8, 8.8), new Complex(9.9, 9.9) } });
var culture = new CultureInfo("tr-TR");
var writer = new DelimitedWriter<Complex>('.')
{
CultureInfo = culture
};
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
const string expected = @"(1,1, 1,1).(2,2, 2,2).(3,3, 3,3)
(4,4, 4,4).(5,5, 5,5).(6,6, 6,6)
(7,7, 7,7).(8,8, 8,8).(9,9, 9,9)";
Assert.AreEqual(expected, text);
}
[Test]
public void CanWriteSpaceDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { new Complex(1.1, 1.1), new Complex(2.2, 2.2), new Complex(3.3, 3.3) }, { new Complex(4.4, 4.4), new Complex(5.5, 5.5), new Complex(6.6, 6.6) }, { new Complex(7.7, 7.7), new Complex(8.8, 8.8), new Complex(9.9, 9.9) } });
var writer = new DelimitedWriter<Complex>(' ');
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
const string expected = @"(1.1, 1.1) (2.2, 2.2) (3.3, 3.3)
(4.4, 4.4) (5.5, 5.5) (6.6, 6.6)
(7.7, 7.7) (8.8, 8.8) (9.9, 9.9)";
Assert.AreEqual(expected, text);
}
[Test]
public void CanWriteTabDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { new Complex(1.1, 1.1), new Complex(2.2, 2.2), new Complex(3.3, 3.3) }, { new Complex(4.4, 4.4), new Complex(5.5, 5.5), new Complex(6.6, 6.6) }, { new Complex(7.7, 7.7), new Complex(8.8, 8.8), new Complex(9.9, 9.9) } });
var headers = new[] { "a", "b", "c" };
var writer = new DelimitedWriter<Complex>('\t')
{
ColumnHeaders = headers
};
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
var expected = "a\tb\tc"
+ Environment.NewLine
+ "(1.1, 1.1)\t(2.2, 2.2)\t(3.3, 3.3)"
+ Environment.NewLine
+ "(4.4, 4.4)\t(5.5, 5.5)\t(6.6, 6.6)"
+ Environment.NewLine
+ "(7.7, 7.7)\t(8.8, 8.8)\t(9.9, 9.9)";
Assert.AreEqual(expected, text);
}
}
}

26
src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorTest.TextHandling.cs

@ -39,16 +39,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public class DenseVectorTextHandlingTest
{
[Test]
[Row("2", "2")]
[Row("(3)", "3")]
[Row("[1,2,3]", "1,2,3")]
[Row(" [ 1.1 , 2.1 , 3.1 ] ", "1.1,2.1,3.1")]
[Row(" [ -1.1 , 2.1 , +3.1 ] ", "-1.1,2.1,3.1")]
[Row(" [1.2,3.4 , 5.6] ", "1.2,3.4,5.6")]
[Row("[1+1i,2+1i,3+1i]", "1 + 1i,2 + 1i,3 + 1i")]
[Row(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "1.1 + 1i,2.1 + 1i,3.1 + 1i")]
[Row(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "-1.1 + 1i,2.1 - 1i,3.1 + 1i")]
[Row(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "1.2 + 2.3i,3.4 + 4.5i,5.6 + 6.7i")]
[Row("2", "(2, 0)")]
[Row("(3)", "(3, 0)")]
[Row("[1,2,3]", "(1, 0),(2, 0),(3, 0)")]
[Row(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")]
[Row(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")]
[Row(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")]
[Row("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")]
[Row(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")]
[Row(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")]
[Row(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3),(3.4, 4.5),(5.6, 6.7)")]
public void CanParseComplexDenseVectorsWithInvariant(string stringToParse, string expectedToString)
{
var formatProvider = CultureInfo.InvariantCulture;
@ -58,9 +58,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
}
[Test]
[Row(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "1.2 + 1i,3.4 + 1i,5.6 + 1i", "en-US")]
[Row(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "1.2 + 1i;3.4 + 1i;5.6 + 1i", "de-CH")]
[Row(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "1,2 + 1i;3,4 + 1i;5,6 + 1i", "de-DE")]
[Row(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")]
[Row(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")]
[Row(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")]
public void CanParseComplexDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{
var formatProvider = CultureInfo.GetCultureInfo(culture);

90
src/UnitTests/LinearAlgebraTests/Complex32/IO/DelimitedWriterTests.cs

@ -0,0 +1,90 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.IO
{
using System;
using System.Globalization;
using System.IO;
using LinearAlgebra.Complex32;
using Numerics;
using LinearAlgebra.IO;
using MbUnit.Framework;
[TestFixture]
public class DelimitedWriterTests
{
[Test]
public void CanWriteCommaDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { new Complex32(1.1f, 1.1f), new Complex32(2.2f, 2.2f), new Complex32(3.3f, 3.3f) }, { new Complex32(4.4f, 4.4f), new Complex32(5.5f, 5.5f), new Complex32(6.6f, 6.6f) }, { new Complex32(7.7f, 7.7f), new Complex32(8.8f, 8.8f), new Complex32(9.9f, 9.9f) } });
var writer = new DelimitedWriter<Complex32>(',');
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
const string expected = @"(1.1, 1.1),(2.2, 2.2),(3.3, 3.3)
(4.4, 4.4),(5.5, 5.5),(6.6, 6.6)
(7.7, 7.7),(8.8, 8.8),(9.9, 9.9)";
Assert.AreEqual(expected, text);
}
[Test]
public void CanWritePeriodDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { new Complex32(1.1f, 1.1f), new Complex32(2.2f, 2.2f), new Complex32(3.3f, 3.3f) }, { new Complex32(4.4f, 4.4f), new Complex32(5.5f, 5.5f), new Complex32(6.6f, 6.6f) }, { new Complex32(7.7f, 7.7f), new Complex32(8.8f, 8.8f), new Complex32(9.9f, 9.9f) } });
var culture = new CultureInfo("tr-TR");
var writer = new DelimitedWriter<Complex32>('.')
{
CultureInfo = culture
};
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
const string expected = @"(1,1, 1,1).(2,2, 2,2).(3,3, 3,3)
(4,4, 4,4).(5,5, 5,5).(6,6, 6,6)
(7,7, 7,7).(8,8, 8,8).(9,9, 9,9)";
Assert.AreEqual(expected, text);
}
[Test]
public void CanWriteSpaceDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { new Complex32(1.1f, 1.1f), new Complex32(2.2f, 2.2f), new Complex32(3.3f, 3.3f) }, { new Complex32(4.4f, 4.4f), new Complex32(5.5f, 5.5f), new Complex32(6.6f, 6.6f) }, { new Complex32(7.7f, 7.7f), new Complex32(8.8f, 8.8f), new Complex32(9.9f, 9.9f) } });
var writer = new DelimitedWriter<Complex32>(' ');
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
const string expected = @"(1.1, 1.1) (2.2, 2.2) (3.3, 3.3)
(4.4, 4.4) (5.5, 5.5) (6.6, 6.6)
(7.7, 7.7) (8.8, 8.8) (9.9, 9.9)";
Assert.AreEqual(expected, text);
}
[Test]
public void CanWriteTabDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { new Complex32(1.1f, 1.1f), new Complex32(2.2f, 2.2f), new Complex32(3.3f, 3.3f) }, { new Complex32(4.4f, 4.4f), new Complex32(5.5f, 5.5f), new Complex32(6.6f, 6.6f) }, { new Complex32(7.7f, 7.7f), new Complex32(8.8f, 8.8f), new Complex32(9.9f, 9.9f) } });
var headers = new[] { "a", "b", "c" };
var writer = new DelimitedWriter<Complex32>('\t')
{
ColumnHeaders = headers
};
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
var expected = "a\tb\tc"
+ Environment.NewLine
+ "(1.1, 1.1)\t(2.2, 2.2)\t(3.3, 3.3)"
+ Environment.NewLine
+ "(4.4, 4.4)\t(5.5, 5.5)\t(6.6, 6.6)"
+ Environment.NewLine
+ "(7.7, 7.7)\t(8.8, 8.8)\t(9.9, 9.9)";
Assert.AreEqual(expected, text);
}
}
}

26
src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.TextHandling.cs

@ -38,16 +38,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public class SparseVectorTextHandlingTest
{
[Test]
[Row("2", "2")]
[Row("(3)", "3")]
[Row("[1,2,3]", "1,2,3")]
[Row(" [ 1.1 , 2.1 , 3.1 ] ", "1.1,2.1,3.1")]
[Row(" [ -1.1 , 2.1 , +3.1 ] ", "-1.1,2.1,3.1")]
[Row(" [1.2,3.4 , 5.6] ", "1.2,3.4,5.6")]
[Row("[1+1i,2+1i,3+1i]", "1 + 1i,2 + 1i,3 + 1i")]
[Row(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "1.1 + 1i,2.1 + 1i,3.1 + 1i")]
[Row(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "-1.1 + 1i,2.1 - 1i,3.1 + 1i")]
[Row(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "1.2 + 2.3i,3.4 + 4.5i,5.6 + 6.7i")]
[Row("2", "(2, 0)")]
[Row("(3)", "(3, 0)")]
[Row("[1,2,3]", "(1, 0),(2, 0),(3, 0)")]
[Row(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")]
[Row(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")]
[Row(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")]
[Row("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")]
[Row(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")]
[Row(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")]
[Row(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3),(3.4, 4.5),(5.6, 6.7)")]
public void CanParseComplexSparseVectorsWithInvariant(string stringToParse, string expectedToString)
{
var formatProvider = CultureInfo.InvariantCulture;
@ -57,9 +57,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
}
[Test]
[Row(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "1.2 + 1i,3.4 + 1i,5.6 + 1i", "en-US")]
[Row(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "1.2 + 1i;3.4 + 1i;5.6 + 1i", "de-CH")]
[Row(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "1,2 + 1i;3,4 + 1i;5,6 + 1i", "de-DE")]
[Row(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")]
[Row(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")]
[Row(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")]
public void CanParseComplexSparseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{
var formatProvider = CultureInfo.GetCultureInfo(culture);

2
src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs

@ -77,7 +77,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
var vector = CreateVector(Data);
var str = vector.ToString();
var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
Assert.AreEqual(string.Format("1 + 1i{0}2 + 1i{0}3 + 1i{0}4 + 1i{0}5 + 1i", sep), str);
Assert.AreEqual(string.Format("(1, 1){0}(2, 1){0}(3, 1){0}(4, 1){0}(5, 1)", sep), str);
}
[Test]

11
src/UnitTests/LinearAlgebraTests/Double/IO/DelimitedWriterTests.cs

@ -3,9 +3,8 @@
using System;
using System.Globalization;
using System.IO;
using System.Text;
using LinearAlgebra.Double;
using LinearAlgebra.Double.IO;
using LinearAlgebra.IO;
using MbUnit.Framework;
[TestFixture]
@ -15,7 +14,7 @@
public void CanWriteCommaDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 7.7, 8.8, 9.9 } });
var writer = new DelimitedWriter(',');
var writer = new DelimitedWriter<double>(',');
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
@ -32,7 +31,7 @@
{
var matrix = new DenseMatrix(new[,] { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 7.7, 8.8, 9.9 } });
var culture = new CultureInfo("tr-TR");
var writer = new DelimitedWriter('.')
var writer = new DelimitedWriter<double>('.')
{
CultureInfo = culture
};
@ -51,7 +50,7 @@
public void CanWriteSpaceDelimitedData()
{
var matrix = new SparseMatrix(new[,] { { 1.1, 0, 0 }, { 0, 5.5, 0 }, { 0, 0, 9.9 } });
var writer = new DelimitedWriter(' ');
var writer = new DelimitedWriter<double>(' ');
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
@ -68,7 +67,7 @@
{
var matrix = new UserDefinedMatrix(new[,] { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 7.7, 8.8, 9.9 } });
var headers = new[] { "a", "b", "c" };
var writer = new DelimitedWriter('\t')
var writer = new DelimitedWriter<double>('\t')
{
ColumnHeaders = headers
};

9
src/UnitTests/LinearAlgebraTests/Single/IO/DelimitedWriterTests.cs

@ -4,6 +4,7 @@
using System.Globalization;
using System.IO;
using System.Text;
using LinearAlgebra.IO;
using LinearAlgebra.Single;
using LinearAlgebra.Single.IO;
using MbUnit.Framework;
@ -15,7 +16,7 @@
public void CanWriteCommaDelimitedData()
{
var matrix = new DenseMatrix(new[,] { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 7.7f, 8.8f, 9.9f } });
var writer = new DelimitedWriter(',');
var writer = new DelimitedWriter<float>(',');
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
@ -32,7 +33,7 @@
{
var matrix = new DenseMatrix(new[,] { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 7.7f, 8.8f, 9.9f } });
var culture = new CultureInfo("tr-TR");
var writer = new DelimitedWriter('.')
var writer = new DelimitedWriter<float>('.')
{
CultureInfo = culture
};
@ -51,7 +52,7 @@
public void CanWriteSpaceDelimitedData()
{
var matrix = new SparseMatrix(new[,] { { 1.1f, 0, 0 }, { 0, 5.5f, 0 }, { 0, 0, 9.9f } });
var writer = new DelimitedWriter(' ');
var writer = new DelimitedWriter<float>(' ');
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
@ -68,7 +69,7 @@
{
var matrix = new UserDefinedMatrix(new[,] { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 7.7f, 8.8f, 9.9f } });
var headers = new[] { "a", "b", "c" };
var writer = new DelimitedWriter('\t')
var writer = new DelimitedWriter<float>('\t')
{
ColumnHeaders = headers
};

2
src/UnitTests/UnitTests.csproj

@ -136,6 +136,7 @@
<Compile Include="LinearAlgebraTests\Complex32\Factorization\UserLUTests.cs" />
<Compile Include="LinearAlgebraTests\Complex32\Factorization\UserQRTests.cs" />
<Compile Include="LinearAlgebraTests\Complex32\Factorization\UserSvdTests.cs" />
<Compile Include="LinearAlgebraTests\Complex32\IO\DelimitedWriterTests.cs" />
<Compile Include="LinearAlgebraTests\Complex32\MatrixLoader.cs" />
<Compile Include="LinearAlgebraTests\Complex32\MatrixTests.Arithmetic.cs" />
<Compile Include="LinearAlgebraTests\Complex32\MatrixTests.cs" />
@ -178,6 +179,7 @@
<Compile Include="LinearAlgebraTests\Complex\Factorization\UserLUTests.cs" />
<Compile Include="LinearAlgebraTests\Complex\Factorization\UserQRTests.cs" />
<Compile Include="LinearAlgebraTests\Complex\Factorization\UserSvdTests.cs" />
<Compile Include="LinearAlgebraTests\Complex\IO\DelimitedWriterTests.cs" />
<Compile Include="LinearAlgebraTests\Complex\MatrixLoader.cs" />
<Compile Include="LinearAlgebraTests\Complex\MatrixTests.Arithmetic.cs" />
<Compile Include="LinearAlgebraTests\Complex\MatrixTests.cs" />

Loading…
Cancel
Save