diff --git a/RELEASENOTES-Data.md b/RELEASENOTES-Data.md index 62b078ba..09c0f94c 100644 --- a/RELEASENOTES-Data.md +++ b/RELEASENOTES-Data.md @@ -1,2 +1,7 @@ +### 3.0.0-beta02 - 2014-06-15 +* MATLAB Reader now static and stateless; easier to use +* MatrixMarket: Compression enum instead of boolean flag +* Require Math.NET Numerics v3.0.0-beta03 (fixes build-version issue) + ### 3.0.0-beta01 - 2014-04-23 * First v3 beta release diff --git a/src/Data/Matlab/Properties/AssemblyInfo.cs b/src/Data/Matlab/Properties/AssemblyInfo.cs index f4b9797b..329d571a 100644 --- a/src/Data/Matlab/Properties/AssemblyInfo.cs +++ b/src/Data/Matlab/Properties/AssemblyInfo.cs @@ -44,4 +44,4 @@ using System.Runtime.InteropServices; [assembly: AssemblyVersion("3.0.0.0")] [assembly: AssemblyFileVersion("3.0.0.0")] -[assembly: AssemblyInformationalVersion("3.0.0-beta01")] +[assembly: AssemblyInformationalVersion("3.0.0-beta02")] diff --git a/src/Data/Text/MatrixMarketReader.cs b/src/Data/Text/MatrixMarketReader.cs index f357fce4..48b6fafd 100644 --- a/src/Data/Text/MatrixMarketReader.cs +++ b/src/Data/Text/MatrixMarketReader.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2014 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -52,43 +52,51 @@ namespace MathNet.Numerics.Data.Text /// public static class MatrixMarketReader { - static readonly char[] Separators = {' '}; + static readonly char[] Separators = { ' ' }; static readonly NumberFormatInfo Format = CultureInfo.InvariantCulture.NumberFormat; - public static Matrix ReadMatrix(string filePath, bool compressed = false) where T : struct, IEquatable, IFormattable + public static Matrix ReadMatrix(string filePath, Compression compression = Compression.Uncompressed) where T : struct, IEquatable, IFormattable { using (var stream = File.OpenRead(filePath)) { - if (compressed) + switch (compression) { - using (var decompressed = new GZipStream(stream, CompressionMode.Decompress)) - using (var reader = new StreamReader(decompressed)) - { - return ReadMatrix(reader); - } - } - using (var reader = new StreamReader(stream)) - { - return ReadMatrix(reader); + case Compression.Uncompressed: + using (var reader = new StreamReader(stream)) + { + return ReadMatrix(reader); + } + case Compression.GZip: + using (var decompressed = new GZipStream(stream, CompressionMode.Decompress)) + using (var reader = new StreamReader(decompressed)) + { + return ReadMatrix(reader); + } + default: + throw new NotSupportedException("Compression not supported: " + compression); } } } - public static Vector ReadVector(string filePath, bool compressed = false) where T : struct, IEquatable, IFormattable + public static Vector ReadVector(string filePath, Compression compression = Compression.Uncompressed) where T : struct, IEquatable, IFormattable { using (var stream = File.OpenRead(filePath)) { - if (compressed) + switch (compression) { - using (var decompressed = new GZipStream(stream, CompressionMode.Decompress)) - using (var reader = new StreamReader(decompressed)) - { - return ReadVector(reader); - } - } - using (var reader = new StreamReader(stream)) - { - return ReadVector(reader); + case Compression.Uncompressed: + using (var reader = new StreamReader(stream)) + { + return ReadVector(reader); + } + case Compression.GZip: + using (var decompressed = new GZipStream(stream, CompressionMode.Decompress)) + using (var reader = new StreamReader(decompressed)) + { + return ReadVector(reader); + } + default: + throw new NotSupportedException("Compression not supported: " + compression); } } } @@ -340,24 +348,24 @@ namespace MathNet.Numerics.Data.Text if (typeof (T) == typeof (double)) { // ignore imaginary part if source is complex - return (offset, tokens) => (T) (object) double.Parse(tokens[offset], NumberStyles.Any, Format); + return (offset, tokens) => (T)(object)double.Parse(tokens[offset], NumberStyles.Any, Format); } if (typeof (T) == typeof (float)) { // ignore imaginary part if source is complex - return (offset, tokens) => (T) (object) float.Parse(tokens[offset], NumberStyles.Any, Format); + return (offset, tokens) => (T)(object)float.Parse(tokens[offset], NumberStyles.Any, Format); } if (typeof (T) == typeof (Complex)) { return sourceIsComplex - ? ((offset, tokens) => (T) (object) new Complex(double.Parse(tokens[offset], NumberStyles.Any, Format), double.Parse(tokens[offset + 1], NumberStyles.Any, Format))) - : (Func) ((offset, tokens) => (T) (object) new Complex(double.Parse(tokens[offset], NumberStyles.Any, Format), 0d)); + ? ((offset, tokens) => (T)(object)new Complex(double.Parse(tokens[offset], NumberStyles.Any, Format), double.Parse(tokens[offset + 1], NumberStyles.Any, Format))) + : (Func)((offset, tokens) => (T)(object)new Complex(double.Parse(tokens[offset], NumberStyles.Any, Format), 0d)); } if (typeof (T) == typeof (Complex32)) { return sourceIsComplex - ? ((offset, tokens) => (T) (object) new Complex32(float.Parse(tokens[offset], NumberStyles.Any, Format), float.Parse(tokens[offset + 1], NumberStyles.Any, Format))) - : (Func) ((offset, tokens) => (T) (object) new Complex32(float.Parse(tokens[offset], NumberStyles.Any, Format), 0f)); + ? ((offset, tokens) => (T)(object)new Complex32(float.Parse(tokens[offset], NumberStyles.Any, Format), float.Parse(tokens[offset + 1], NumberStyles.Any, Format))) + : (Func)((offset, tokens) => (T)(object)new Complex32(float.Parse(tokens[offset], NumberStyles.Any, Format), 0f)); } throw new NotSupportedException(); } @@ -366,8 +374,8 @@ namespace MathNet.Numerics.Data.Text { if (symmetry != MatrixMarketSymmetry.Hermitian) return x => x; if (typeof (T) == typeof (double) || typeof (T) == typeof (float)) return x => x; - if (typeof (T) == typeof (Complex)) return x => (T) (object) ((Complex) (object) x).Conjugate(); - if (typeof (T) == typeof (Complex32)) return x => (T) (object) ((Complex32) (object) x).Conjugate(); + if (typeof (T) == typeof (Complex)) return x => (T)(object)((Complex)(object)x).Conjugate(); + if (typeof (T) == typeof (Complex32)) return x => (T)(object)((Complex32)(object)x).Conjugate(); throw new NotSupportedException(); } } diff --git a/src/Data/Text/MatrixMarketWriter.cs b/src/Data/Text/MatrixMarketWriter.cs index a19e31eb..7e15b808 100644 --- a/src/Data/Text/MatrixMarketWriter.cs +++ b/src/Data/Text/MatrixMarketWriter.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2014 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -45,44 +45,54 @@ namespace MathNet.Numerics.Data.Text { static readonly NumberFormatInfo Format = CultureInfo.InvariantCulture.NumberFormat; - public static void WriteMatrix(string filePath, Matrix matrix, bool compress = false) where T : struct, IEquatable, IFormattable + public static void WriteMatrix(string filePath, Matrix matrix, Compression compression = Compression.Uncompressed) where T : struct, IEquatable, IFormattable { using (var stream = File.OpenWrite(filePath)) { - if (compress) + switch (compression) { - using (var compressed = new GZipStream(stream, CompressionMode.Compress)) - using (var buffered = new BufferedStream(compressed, 4096)) - using (var writer = new StreamWriter(buffered)) - { - WriteMatrix(writer, matrix); - return; - } - } - using (var writer = new StreamWriter(stream)) - { - WriteMatrix(writer, matrix); + case Compression.Uncompressed: + using (var writer = new StreamWriter(stream)) + { + WriteMatrix(writer, matrix); + } + break; + case Compression.GZip: + using (var compressed = new GZipStream(stream, CompressionMode.Compress)) + using (var buffered = new BufferedStream(compressed, 4096)) + using (var writer = new StreamWriter(buffered)) + { + WriteMatrix(writer, matrix); + } + break; + default: + throw new NotSupportedException("Compression not supported: " + compression); } } } - public static void WriteVector(string filePath, Vector vector, bool compress = false) where T : struct, IEquatable, IFormattable + public static void WriteVector(string filePath, Vector vector, Compression compression = Compression.Uncompressed) where T : struct, IEquatable, IFormattable { using (var stream = File.OpenRead(filePath)) { - if (compress) - { - using (var compressed = new GZipStream(stream, CompressionMode.Compress)) - using (var buffered = new BufferedStream(compressed, 4096)) - using (var writer = new StreamWriter(buffered)) - { - WriteVector(writer, vector); - return; - } - } - using (var writer = new StreamWriter(stream)) + switch (compression) { - WriteVector(writer, vector); + case Compression.Uncompressed: + using (var writer = new StreamWriter(stream)) + { + WriteVector(writer, vector); + } + break; + case Compression.GZip: + using (var compressed = new GZipStream(stream, CompressionMode.Compress)) + using (var buffered = new BufferedStream(compressed, 4096)) + using (var writer = new StreamWriter(buffered)) + { + WriteVector(writer, vector); + } + break; + default: + throw new NotSupportedException("Compression not supported: " + compression); } } } @@ -209,7 +219,7 @@ namespace MathNet.Numerics.Data.Text { return value => { - var c = (Complex) (object) value; + var c = (Complex)(object)value; return string.Format(Format, "{0:G14} {1:G14}", c.Real, c.Imaginary); }; } @@ -217,7 +227,7 @@ namespace MathNet.Numerics.Data.Text { return value => { - var c = (Complex32) (object) value; + var c = (Complex32)(object)value; return string.Format(Format, "{0:G7} {1:G7}", c.Real, c.Imaginary); }; } diff --git a/src/Data/Text/Options.cs b/src/Data/Text/Options.cs new file mode 100644 index 00000000..0dff9fc6 --- /dev/null +++ b/src/Data/Text/Options.cs @@ -0,0 +1,38 @@ +// +// 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-2014 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. +// + +namespace MathNet.Numerics.Data.Text +{ + public enum Compression + { + Uncompressed = 0, + GZip = 1 + } +} diff --git a/src/Data/Text/Properties/AssemblyInfo.cs b/src/Data/Text/Properties/AssemblyInfo.cs index f8b92b35..f0f25374 100644 --- a/src/Data/Text/Properties/AssemblyInfo.cs +++ b/src/Data/Text/Properties/AssemblyInfo.cs @@ -44,4 +44,4 @@ using System.Runtime.InteropServices; [assembly: AssemblyVersion("3.0.0.0")] [assembly: AssemblyFileVersion("3.0.0.0")] -[assembly: AssemblyInformationalVersion("3.0.0-beta01")] +[assembly: AssemblyInformationalVersion("3.0.0-beta02")] diff --git a/src/Data/Text/Text.csproj b/src/Data/Text/Text.csproj index a38e7dc4..7fec0562 100644 --- a/src/Data/Text/Text.csproj +++ b/src/Data/Text/Text.csproj @@ -53,6 +53,7 @@ + diff --git a/src/DataUnitTests/Properties/AssemblyInfo.cs b/src/DataUnitTests/Properties/AssemblyInfo.cs index 13ae129a..fc1395aa 100644 --- a/src/DataUnitTests/Properties/AssemblyInfo.cs +++ b/src/DataUnitTests/Properties/AssemblyInfo.cs @@ -16,4 +16,4 @@ using System.Runtime.InteropServices; [assembly: AssemblyVersion("3.0.0.0")] [assembly: AssemblyFileVersion("3.0.0.0")] -[assembly: AssemblyInformationalVersion("3.0.0-beta01")] +[assembly: AssemblyInformationalVersion("3.0.0-beta02")]