Browse Source

Data: Matlab: simplify names

pull/248/head
Christoph Ruegg 12 years ago
parent
commit
67e0336993
  1. 82
      MathNet.Numerics.Data.sln.DotSettings
  2. 2
      src/Data/Matlab/Matlab.csproj
  3. 6
      src/Data/Matlab/MatlabReader.cs
  4. 6
      src/Data/Matlab/MatlabWriter.cs
  5. 20
      src/Data/Matlab/Parser.cs
  6. 4
      src/Data/Matlab/SparseArrayReader.cs
  7. 102
      src/DataUnitTests/Matlab/MatlabReaderTests.cs
  8. 30
      src/DataUnitTests/Matlab/MatlabWriterTests.cs
  9. 2
      src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs

82
MathNet.Numerics.Data.sln.DotSettings

@ -0,0 +1,82 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=_002A_002Ecshtml/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBeConvertedToQuery/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Full_0020Cleanup_0020_0028Math_002ENET_0029/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Full Cleanup (Math.NET)"&gt;&lt;CSArrangeThisQualifier&gt;True&lt;/CSArrangeThisQualifier&gt;&lt;CSRemoveCodeRedundancies&gt;True&lt;/CSRemoveCodeRedundancies&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSUpdateFileHeader&gt;True&lt;/CSUpdateFileHeader&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;CssAlphabetizeProperties&gt;True&lt;/CssAlphabetizeProperties&gt;&lt;CssReformatCode&gt;True&lt;/CssReformatCode&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;VBFormatDocComments&gt;True&lt;/VBFormatDocComments&gt;&lt;VBReformatCode&gt;True&lt;/VBReformatCode&gt;&lt;VBShortenReferences&gt;True&lt;/VBShortenReferences&gt;&lt;VBOptimizeImports&gt;True&lt;/VBOptimizeImports&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;CSUseVar&gt;&lt;BehavourStyle&gt;CAN_CHANGE_BOTH&lt;/BehavourStyle&gt;&lt;LocalVariableStyle&gt;IMPLICIT_WHEN_INITIALIZER_HAS_TYPE&lt;/LocalVariableStyle&gt;&lt;ForeachVariableStyle&gt;ALWAYS_EXPLICIT&lt;/ForeachVariableStyle&gt;&lt;/CSUseVar&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">Full Cleanup (Math.NET)</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARGUMENT/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARRAY_AND_OBJECT_INITIALIZER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXPRESSION/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_CONSTRAINS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_LIST/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EXPLICIT_PRIVATE_MODIFIER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_ANONYMOUS_METHOD_BLOCK/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_EMBRACED_INITIALIZER_BLOCK/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_BINARY_OPSIGN/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">&lt;copyright file="$FILENAME$" company="Math.NET"&gt;&#xD;
Math.NET Numerics, part of the Math.NET Project&#xD;
http://numerics.mathdotnet.com&#xD;
http://github.com/mathnet/mathnet-numerics&#xD;
http://mathnetnumerics.codeplex.com&#xD;
&#xD;
Copyright (c) 2009-$CURRENT_YEAR$ Math.NET&#xD;
&#xD;
Permission is hereby granted, free of charge, to any person&#xD;
obtaining a copy of this software and associated documentation&#xD;
files (the "Software"), to deal in the Software without&#xD;
restriction, including without limitation the rights to use,&#xD;
copy, modify, merge, publish, distribute, sublicense, and/or sell&#xD;
copies of the Software, and to permit persons to whom the&#xD;
Software is furnished to do so, subject to the following&#xD;
conditions:&#xD;
&#xD;
The above copyright notice and this permission notice shall be&#xD;
included in all copies or substantial portions of the Software.&#xD;
&#xD;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,&#xD;
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES&#xD;
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND&#xD;
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT&#xD;
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,&#xD;
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING&#xD;
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR&#xD;
OTHER DEALINGS IN THE SOFTWARE.&#xD;
&lt;/copyright&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AVX/@EntryIndexedValue">AVX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CDF/@EntryIndexedValue">CDF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DFT/@EntryIndexedValue">DFT</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FFT/@EntryIndexedValue">FFT</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IA/@EntryIndexedValue">IA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ILU/@EntryIndexedValue">ILU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ILUTP/@EntryIndexedValue">ILUTP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IX/@EntryIndexedValue">IX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LU/@EntryIndexedValue">LU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MAE/@EntryIndexedValue">MAE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MC/@EntryIndexedValue">MC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MCMC/@EntryIndexedValue">MCMC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MILU/@EntryIndexedValue">MILU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MKL/@EntryIndexedValue">MKL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSE/@EntryIndexedValue">MSE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PDF/@EntryIndexedValue">PDF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PMF/@EntryIndexedValue">PMF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QR/@EntryIndexedValue">QR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAD/@EntryIndexedValue">SAD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAS/@EntryIndexedValue">SAS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SPSS/@EntryIndexedValue">SPSS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSD/@EntryIndexedValue">SSD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSE/@EntryIndexedValue">SSE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SVD/@EntryIndexedValue">SVD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TFQMR/@EntryIndexedValue">TFQMR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WH/@EntryIndexedValue">WH</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String></wpf:ResourceDictionary>

2
src/Data/Matlab/Matlab.csproj

@ -55,7 +55,7 @@
<Compile Include="NumericArrayReader.cs" />
<Compile Include="DataType.cs" />
<Compile Include="MatlabFile.cs" />
<Compile Include="MatlabParser.cs" />
<Compile Include="Parser.cs" />
<Compile Include="MatlabReader.cs" />
<Compile Include="MatlabWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

6
src/Data/Matlab/MatlabReader.cs

@ -39,14 +39,14 @@ namespace MathNet.Numerics.Data.Matlab
/// <summary>
/// Creates matrices from MATLAB files.
/// </summary>
public static class MatlabMatrixReader
public static class MatlabReader
{
/// <typeparam name="TDataType">The data type of the Matrix. It can be either: double, float, Complex, or Complex32.</typeparam>
public static Matrix<TDataType> ReadMatrix<TDataType>(Stream stream, string matrixName = null)
where TDataType : struct, IEquatable<TDataType>, IFormattable
{
var names = string.IsNullOrEmpty(matrixName) ? new string[] { } : new[] { matrixName };
var parser = new MatlabParser<TDataType>(stream, names);
var parser = new Parser<TDataType>(stream, names);
var file = parser.Parse();
if (string.IsNullOrEmpty(matrixName))
@ -76,7 +76,7 @@ namespace MathNet.Numerics.Data.Matlab
public static Dictionary<string, Matrix<TDataType>> ReadMatrices<TDataType>(Stream stream, params string[] matrixNames)
where TDataType : struct, IEquatable<TDataType>, IFormattable
{
var parser = new MatlabParser<TDataType>(stream, matrixNames);
var parser = new Parser<TDataType>(stream, matrixNames);
var file = parser.Parse();
return file.Matrices.ToDictionary(matrix => matrix.Key, matrix => matrix.Value);
}

6
src/Data/Matlab/MatlabWriter.cs

@ -43,7 +43,7 @@ namespace MathNet.Numerics.Data.Matlab
/// <summary>
/// Writes matrices to a MATLAB file.
/// </summary>
public class MatlabMatrixWriter : IDisposable
public class MatlabWriter : IDisposable
{
/// <summary>
/// The file header value
@ -66,10 +66,10 @@ namespace MathNet.Numerics.Data.Matlab
BinaryWriter _writer;
/// <summary>
/// Initializes a new instance of the <see cref="MatlabMatrixWriter"/> class.
/// Initializes a new instance of the <see cref="MatlabWriter"/> class.
/// </summary>
/// <param name="filename">The name of the MATLAB file to save the matrices to.</param>
public MatlabMatrixWriter(string filename)
public MatlabWriter(string filename)
{
if (string.IsNullOrEmpty(filename))
{

20
src/Data/Matlab/MatlabParser.cs → src/Data/Matlab/Parser.cs

@ -1,4 +1,4 @@
// <copyright file="MatlabParser.cs" company="Math.NET">
// <copyright file="Parser.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -42,7 +42,7 @@ namespace MathNet.Numerics.Data.Matlab
/// Parse a MATLAB file
/// </summary>
/// <typeparam name="TDataType">The data type of the matrix.</typeparam>
internal class MatlabParser<TDataType>
internal class Parser<TDataType>
where TDataType : struct, IEquatable<TDataType>, IFormattable
{
/// <summary>
@ -71,29 +71,29 @@ namespace MathNet.Numerics.Data.Matlab
readonly Stream _stream;
/// <summary>
/// Initializes a new instance of the <see cref="MatlabParser{TDataType}"/> class.
/// Initializes a new instance of the <see cref="Parser{TDataType}"/> class.
/// </summary>
/// <param name="fileName">Name of the file.</param>
internal MatlabParser(string fileName)
internal Parser(string fileName)
: this(fileName, new string[0])
{
}
/// <summary>
/// Initializes a new instance of the <see cref="MatlabParser{TDataType}"/> class.
/// Initializes a new instance of the <see cref="Parser{TDataType}"/> class.
/// </summary>
/// <param name="stream">The stream to read from.</param>
internal MatlabParser(Stream stream)
internal Parser(Stream stream)
: this(stream, new string[0])
{
}
/// <summary>
/// Initializes a new instance of the <see cref="MatlabParser{TDataType}"/> class.
/// Initializes a new instance of the <see cref="Parser{TDataType}"/> class.
/// </summary>
/// <param name="stream">The stream to read from.</param>
/// <param name="objectNames">The name of the objects to retrieve.</param>
internal MatlabParser(Stream stream, IEnumerable<string> objectNames)
internal Parser(Stream stream, IEnumerable<string> objectNames)
{
if (stream == null)
{
@ -105,11 +105,11 @@ namespace MathNet.Numerics.Data.Matlab
}
/// <summary>
/// Initializes a new instance of the <see cref="MatlabParser{TDataType}"/> class.
/// Initializes a new instance of the <see cref="Parser{TDataType}"/> class.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <param name="objectNames">The name of the objects to retrieve.</param>
MatlabParser(string fileName, IEnumerable<string> objectNames)
Parser(string fileName, IEnumerable<string> objectNames)
{
if (string.IsNullOrEmpty(fileName))
{

4
src/Data/Matlab/SparseArrayReader.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.Data.Matlab
ir[i] = reader.ReadInt32();
}
MatlabParser<TDataType>.AlignData(reader.BaseStream, size, false);
Parser<TDataType>.AlignData(reader.BaseStream, size, false);
// skip data type since it will always be int32
reader.BaseStream.Seek(4, SeekOrigin.Current);
@ -81,7 +81,7 @@ namespace MathNet.Numerics.Data.Matlab
jc[j] = reader.ReadInt32();
}
MatlabParser<TDataType>.AlignData(reader.BaseStream, jcsize, false);
Parser<TDataType>.AlignData(reader.BaseStream, jcsize, false);
var type = (DataType)reader.ReadInt32();
var dataSize = reader.ReadInt32();

102
src/DataUnitTests/Matlab/MatlabReaderTests.cs

@ -34,7 +34,7 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
/// Matlab matrix reader test.
/// </summary>
[TestFixture]
public class MatlabMatrixReaderTests
public class MatlabReaderTests
{
/// <summary>
/// Can read all matrices.
@ -42,11 +42,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadAllMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<double>("./data/Matlab/collection.mat");
var matrices = MatlabReader.ReadMatrices<double>("./data/Matlab/collection.mat");
Assert.AreEqual(30, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Double.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Double.DenseMatrix), matrix.Value.GetType());
}
}
@ -56,10 +56,10 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadFirstMatrix()
{
var matrix = MatlabMatrixReader.ReadMatrix<double>("./data/Matlab/A.mat");
var matrix = MatlabReader.ReadMatrix<double>("./data/Matlab/A.mat");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(LinearAlgebra.Double.DenseMatrix), matrix.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Double.DenseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(100.108979553704, matrix.FrobeniusNorm(), 5);
}
@ -69,11 +69,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNamedMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<double>("./data/Matlab/collection.mat", "Ad", "Au64");
var matrices = MatlabReader.ReadMatrices<double>("./data/Matlab/collection.mat", "Ad", "Au64");
Assert.AreEqual(2, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Double.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Double.DenseMatrix), matrix.Value.GetType());
}
}
@ -83,13 +83,13 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNamedMatrix()
{
var matrices = MatlabMatrixReader.ReadMatrices<double>("./data/Matlab/collection.mat", "Ad");
var matrices = MatlabReader.ReadMatrices<double>("./data/Matlab/collection.mat", "Ad");
Assert.AreEqual(1, matrices.Count);
var ad = matrices["Ad"];
Assert.AreEqual(100, ad.RowCount);
Assert.AreEqual(100, ad.ColumnCount);
AssertHelpers.AlmostEqual(100.431635988639, ad.FrobeniusNorm(), 5);
Assert.AreEqual(typeof(LinearAlgebra.Double.DenseMatrix), ad.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Double.DenseMatrix), ad.GetType());
}
/// <summary>
@ -98,24 +98,24 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNamedSparseMatrix()
{
var matrix = MatlabMatrixReader.ReadMatrix<double>("./data/Matlab/sparse-small.mat", "S");
var matrix = MatlabReader.ReadMatrix<double>("./data/Matlab/sparse-small.mat", "S");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(LinearAlgebra.Double.SparseMatrix), matrix.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Double.SparseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(17.6385090630805, matrix.FrobeniusNorm(), 12);
}
/// <summary>
/// <summary>
/// Can read all complex matrices.
/// </summary>
[Test]
public void CanReadComplexAllMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex>("./data/Matlab/complex.mat");
var matrices = MatlabReader.ReadMatrices<Complex>("./data/Matlab/complex.mat");
Assert.AreEqual(3, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Complex.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex.DenseMatrix), matrix.Value.GetType());
}
var a = matrices["a"];
@ -131,11 +131,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadSparseComplexAllMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex>("./data/Matlab/sparse_complex.mat");
var matrices = MatlabReader.ReadMatrices<Complex>("./data/Matlab/sparse_complex.mat");
Assert.AreEqual(3, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Complex.SparseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex.SparseMatrix), matrix.Value.GetType());
}
var a = matrices["sa"];
@ -151,11 +151,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplexAllMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex>("./data/Matlab/collection.mat");
var matrices = MatlabReader.ReadMatrices<Complex>("./data/Matlab/collection.mat");
Assert.AreEqual(30, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Complex.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex.DenseMatrix), matrix.Value.GetType());
}
}
@ -165,10 +165,10 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplexFirstMatrix()
{
var matrix = MatlabMatrixReader.ReadMatrix<Complex>("./data/Matlab/A.mat");
var matrix = MatlabReader.ReadMatrix<Complex>("./data/Matlab/A.mat");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(LinearAlgebra.Complex.DenseMatrix), matrix.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex.DenseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(100.108979553704, matrix.FrobeniusNorm(), 13);
}
@ -178,11 +178,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplexNamedMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex>("./data/Matlab/collection.mat", "Ad", "Au64");
var matrices = MatlabReader.ReadMatrices<Complex>("./data/Matlab/collection.mat", "Ad", "Au64");
Assert.AreEqual(2, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Complex.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex.DenseMatrix), matrix.Value.GetType());
}
}
@ -192,13 +192,13 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplexNamedMatrix()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex>("./data/Matlab/collection.mat", "Ad");
var matrices = MatlabReader.ReadMatrices<Complex>("./data/Matlab/collection.mat", "Ad");
Assert.AreEqual(1, matrices.Count);
var ad = matrices["Ad"];
Assert.AreEqual(100, ad.RowCount);
Assert.AreEqual(100, ad.ColumnCount);
AssertHelpers.AlmostEqual(100.431635988639, ad.FrobeniusNorm(), 13);
Assert.AreEqual(typeof(LinearAlgebra.Complex.DenseMatrix), ad.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex.DenseMatrix), ad.GetType());
}
/// <summary>
@ -207,10 +207,10 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplexNamedSparseMatrix()
{
var matrix = MatlabMatrixReader.ReadMatrix<Complex>("./data/Matlab/sparse-small.mat", "S");
var matrix = MatlabReader.ReadMatrix<Complex>("./data/Matlab/sparse-small.mat", "S");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(LinearAlgebra.Complex.SparseMatrix), matrix.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex.SparseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(17.6385090630805, matrix.FrobeniusNorm(), 12);
}
@ -220,11 +220,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadComplex32AllMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex32>("./data/Matlab/complex.mat");
var matrices = MatlabReader.ReadMatrices<Complex32>("./data/Matlab/complex.mat");
Assert.AreEqual(3, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Complex32.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex32.DenseMatrix), matrix.Value.GetType());
}
var a = matrices["a"];
@ -240,11 +240,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadSparseComplex32AllMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex32>("./data/Matlab/sparse_complex.mat");
var matrices = MatlabReader.ReadMatrices<Complex32>("./data/Matlab/sparse_complex.mat");
Assert.AreEqual(3, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Complex32.SparseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex32.SparseMatrix), matrix.Value.GetType());
}
var a = matrices["sa"];
@ -260,11 +260,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplex32AllMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex32>("./data/Matlab/collection.mat");
var matrices = MatlabReader.ReadMatrices<Complex32>("./data/Matlab/collection.mat");
Assert.AreEqual(30, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Complex32.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex32.DenseMatrix), matrix.Value.GetType());
}
}
@ -274,10 +274,10 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplex32FirstMatrix()
{
var matrix = MatlabMatrixReader.ReadMatrix<Complex32>("./data/Matlab/A.mat");
var matrix = MatlabReader.ReadMatrix<Complex32>("./data/Matlab/A.mat");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(LinearAlgebra.Complex32.DenseMatrix), matrix.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex32.DenseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(100.108979553704, matrix.FrobeniusNorm(), 6);
}
@ -287,11 +287,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplex32NamedMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex32>("./data/Matlab/collection.mat", "Ad", "Au64");
var matrices = MatlabReader.ReadMatrices<Complex32>("./data/Matlab/collection.mat", "Ad", "Au64");
Assert.AreEqual(2, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Complex32.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex32.DenseMatrix), matrix.Value.GetType());
}
}
@ -301,13 +301,13 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplex32NamedMatrix()
{
var matrices = MatlabMatrixReader.ReadMatrices<Complex32>("./data/Matlab/collection.mat", "Ad");
var matrices = MatlabReader.ReadMatrices<Complex32>("./data/Matlab/collection.mat", "Ad");
Assert.AreEqual(1, matrices.Count);
var ad = matrices["Ad"];
Assert.AreEqual(100, ad.RowCount);
Assert.AreEqual(100, ad.ColumnCount);
AssertHelpers.AlmostEqual(100.431635988639, ad.FrobeniusNorm(), 6);
Assert.AreEqual(typeof(LinearAlgebra.Complex32.DenseMatrix), ad.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex32.DenseMatrix), ad.GetType());
}
/// <summary>
@ -316,10 +316,10 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadNonComplex32NamedSparseMatrix()
{
var matrix = MatlabMatrixReader.ReadMatrix<Complex32>("./data/Matlab/sparse-small.mat", "S");
var matrix = MatlabReader.ReadMatrix<Complex32>("./data/Matlab/sparse-small.mat", "S");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(LinearAlgebra.Complex32.SparseMatrix), matrix.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Complex32.SparseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(17.6385090630805, matrix.FrobeniusNorm(), 6);
}
@ -329,11 +329,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadFloatAllMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<float>("./data/Matlab/collection.mat");
var matrices = MatlabReader.ReadMatrices<float>("./data/Matlab/collection.mat");
Assert.AreEqual(30, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Single.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Single.DenseMatrix), matrix.Value.GetType());
}
}
@ -343,10 +343,10 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadFloatFirstMatrix()
{
var matrix = MatlabMatrixReader.ReadMatrix<float>("./data/Matlab/A.mat");
var matrix = MatlabReader.ReadMatrix<float>("./data/Matlab/A.mat");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(LinearAlgebra.Single.DenseMatrix), matrix.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Single.DenseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(100.108979553704f, matrix.FrobeniusNorm(), 6);
}
@ -356,11 +356,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadFloatNamedMatrices()
{
var matrices = MatlabMatrixReader.ReadMatrices<float>("./data/Matlab/collection.mat", "Ad", "Au64");
var matrices = MatlabReader.ReadMatrices<float>("./data/Matlab/collection.mat", "Ad", "Au64");
Assert.AreEqual(2, matrices.Count);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(LinearAlgebra.Single.DenseMatrix), matrix.Value.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Single.DenseMatrix), matrix.Value.GetType());
}
}
@ -370,13 +370,13 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadFloatNamedMatrix()
{
var matrices = MatlabMatrixReader.ReadMatrices<float>("./data/Matlab/collection.mat", "Ad");
var matrices = MatlabReader.ReadMatrices<float>("./data/Matlab/collection.mat", "Ad");
Assert.AreEqual(1, matrices.Count);
var ad = matrices["Ad"];
Assert.AreEqual(100, ad.RowCount);
Assert.AreEqual(100, ad.ColumnCount);
AssertHelpers.AlmostEqual(100.431635988639f, ad.FrobeniusNorm(), 6);
Assert.AreEqual(typeof(LinearAlgebra.Single.DenseMatrix), ad.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Single.DenseMatrix), ad.GetType());
}
/// <summary>
@ -385,10 +385,10 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void CanReadFloatNamedSparseMatrix()
{
var matrix = MatlabMatrixReader.ReadMatrix<float>("./data/Matlab/sparse-small.mat", "S");
var matrix = MatlabReader.ReadMatrix<float>("./data/Matlab/sparse-small.mat", "S");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(LinearAlgebra.Single.SparseMatrix), matrix.GetType());
Assert.AreEqual(typeof (LinearAlgebra.Single.SparseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(17.6385090630805f, matrix.FrobeniusNorm(), 6);
}
}

30
src/DataUnitTests/Matlab/MatlabWriterTests.cs

@ -36,7 +36,7 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
/// Matlab matrix writer tests.
/// </summary>
[TestFixture]
public class MatlabMatrixWriterTests
public class MatlabWriterTests
{
/// <summary>
/// Invalid constructor throws <c>ArgumentException</c>.
@ -44,8 +44,8 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void InvalidConstructorThrowsArgumentException()
{
Assert.Throws<ArgumentException>(() => new MatlabMatrixWriter(string.Empty));
Assert.Throws<ArgumentException>(() => new MatlabMatrixWriter(null));
Assert.Throws<ArgumentException>(() => new MatlabWriter(string.Empty));
Assert.Throws<ArgumentException>(() => new MatlabWriter(null));
}
/// <summary>
@ -55,7 +55,7 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
public void WriteBadMatricesThrowsArgumentException()
{
var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);
var writer = new MatlabMatrixWriter("somefile3");
var writer = new MatlabWriter("somefile3");
Assert.Throws<ArgumentException>(() => writer.WriteMatrices(new[] { matrix }, new[] { string.Empty }));
Assert.Throws<ArgumentException>(() => writer.WriteMatrices(new[] { matrix }, new string[] { null }));
Assert.Throws<ArgumentException>(() => writer.WriteMatrices(new[] { matrix, matrix }, new[] { "matrix" }));
@ -69,7 +69,7 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void WriteNullMatricesThrowsArgumentNullException()
{
var writer = new MatlabMatrixWriter("somefile4");
var writer = new MatlabWriter("somefile4");
Assert.Throws<ArgumentNullException>(() => writer.WriteMatrices(new LinearAlgebra.Single.Matrix[] { null }, new[] { "matrix" }));
var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);
Assert.Throws<ArgumentNullException>(() => writer.WriteMatrices(new LinearAlgebra.Single.Matrix[] { matrix }, null));
@ -112,11 +112,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
File.Delete("testd.mat");
}
var writer = new MatlabMatrixWriter("testd.mat");
var writer = new MatlabWriter("testd.mat");
writer.WriteMatrices(write, names);
writer.Dispose();
var read = MatlabMatrixReader.ReadMatrices<double>("testd.mat", names);
var read = MatlabReader.ReadMatrices<double>("testd.mat", names);
Assert.AreEqual(write.Length, read.Count);
@ -167,11 +167,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
File.Delete("tests.mat");
}
var writer = new MatlabMatrixWriter("tests.mat");
var writer = new MatlabWriter("tests.mat");
writer.WriteMatrices(write, names);
writer.Dispose();
var read = MatlabMatrixReader.ReadMatrices<float>("tests.mat", names);
var read = MatlabReader.ReadMatrices<float>("tests.mat", names);
Assert.AreEqual(write.Length, read.Count);
@ -222,11 +222,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
File.Delete("testc.mat");
}
var writer = new MatlabMatrixWriter("testc.mat");
var writer = new MatlabWriter("testc.mat");
writer.WriteMatrices(write, names);
writer.Dispose();
var read = MatlabMatrixReader.ReadMatrices<Complex32>("testc.mat", names);
var read = MatlabReader.ReadMatrices<Complex32>("testc.mat", names);
Assert.AreEqual(write.Length, read.Count);
@ -277,11 +277,11 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
File.Delete("testz.mat");
}
var writer = new MatlabMatrixWriter("testz.mat");
var writer = new MatlabWriter("testz.mat");
writer.WriteMatrices(write, names);
writer.Dispose();
var read = MatlabMatrixReader.ReadMatrices<Complex>("testz.mat", names);
var read = MatlabReader.ReadMatrices<Complex>("testz.mat", names);
Assert.AreEqual(write.Length, read.Count);
@ -303,7 +303,7 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
public void WriteBadMatrixThrowsArgumentException()
{
var matrix = new LinearAlgebra.Single.DenseMatrix(1, 1);
var writer = new MatlabMatrixWriter("somefile1");
var writer = new MatlabWriter("somefile1");
Assert.Throws<ArgumentException>(() => writer.WriteMatrix(matrix, string.Empty));
Assert.Throws<ArgumentException>(() => writer.WriteMatrix(matrix, null));
writer.Dispose();
@ -315,7 +315,7 @@ namespace MathNet.Numerics.Data.UnitTests.Matlab
[Test]
public void WriteNullMatrixThrowsArgumentNullException()
{
var writer = new MatlabMatrixWriter("somefile2");
var writer = new MatlabWriter("somefile2");
Assert.Throws<ArgumentNullException>(() => writer.WriteMatrix<double>(null, "matrix"));
writer.Dispose();
}

2
src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs

@ -95,7 +95,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
ILinearAlgebraProvider<Complex32>
{
/// <summary>
/// Initialize and verify that the provided is indeed available. If not, fall back to alernatives like the managed provider
/// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider
/// </summary>
void InitializeVerify();
}

Loading…
Cancel
Save