Browse Source

Release Data Extensions: v3.0.0-beta02

pull/222/head data-v3.0.0-beta02
Christoph Ruegg 12 years ago
parent
commit
64e9a04819
  1. 5
      RELEASENOTES-Data.md
  2. 2
      src/Data/Matlab/Properties/AssemblyInfo.cs
  3. 72
      src/Data/Text/MatrixMarketReader.cs
  4. 68
      src/Data/Text/MatrixMarketWriter.cs
  5. 38
      src/Data/Text/Options.cs
  6. 2
      src/Data/Text/Properties/AssemblyInfo.cs
  7. 1
      src/Data/Text/Text.csproj
  8. 2
      src/DataUnitTests/Properties/AssemblyInfo.cs

5
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

2
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")]

72
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
/// </summary>
public static class MatrixMarketReader
{
static readonly char[] Separators = {' '};
static readonly char[] Separators = { ' ' };
static readonly NumberFormatInfo Format = CultureInfo.InvariantCulture.NumberFormat;
public static Matrix<T> ReadMatrix<T>(string filePath, bool compressed = false) where T : struct, IEquatable<T>, IFormattable
public static Matrix<T> ReadMatrix<T>(string filePath, Compression compression = Compression.Uncompressed) where T : struct, IEquatable<T>, 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<T>(reader);
}
}
using (var reader = new StreamReader(stream))
{
return ReadMatrix<T>(reader);
case Compression.Uncompressed:
using (var reader = new StreamReader(stream))
{
return ReadMatrix<T>(reader);
}
case Compression.GZip:
using (var decompressed = new GZipStream(stream, CompressionMode.Decompress))
using (var reader = new StreamReader(decompressed))
{
return ReadMatrix<T>(reader);
}
default:
throw new NotSupportedException("Compression not supported: " + compression);
}
}
}
public static Vector<T> ReadVector<T>(string filePath, bool compressed = false) where T : struct, IEquatable<T>, IFormattable
public static Vector<T> ReadVector<T>(string filePath, Compression compression = Compression.Uncompressed) where T : struct, IEquatable<T>, 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<T>(reader);
}
}
using (var reader = new StreamReader(stream))
{
return ReadVector<T>(reader);
case Compression.Uncompressed:
using (var reader = new StreamReader(stream))
{
return ReadVector<T>(reader);
}
case Compression.GZip:
using (var decompressed = new GZipStream(stream, CompressionMode.Decompress))
using (var reader = new StreamReader(decompressed))
{
return ReadVector<T>(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<int, string[], T>) ((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<int, string[], T>)((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<int, string[], T>) ((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<int, string[], T>)((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();
}
}

68
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<T>(string filePath, Matrix<T> matrix, bool compress = false) where T : struct, IEquatable<T>, IFormattable
public static void WriteMatrix<T>(string filePath, Matrix<T> matrix, Compression compression = Compression.Uncompressed) where T : struct, IEquatable<T>, 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<T>(string filePath, Vector<T> vector, bool compress = false) where T : struct, IEquatable<T>, IFormattable
public static void WriteVector<T>(string filePath, Vector<T> vector, Compression compression = Compression.Uncompressed) where T : struct, IEquatable<T>, 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);
};
}

38
src/Data/Text/Options.cs

@ -0,0 +1,38 @@
// <copyright file="Options.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-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.
// </copyright>
namespace MathNet.Numerics.Data.Text
{
public enum Compression
{
Uncompressed = 0,
GZip = 1
}
}

2
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")]

1
src/Data/Text/Text.csproj

@ -53,6 +53,7 @@
<Compile Include="DelimitedWriter.cs" />
<Compile Include="MatrixMarketReader.cs" />
<Compile Include="MatrixMarketWriter.cs" />
<Compile Include="Options.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

2
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")]

Loading…
Cancel
Save