diff --git a/MathNet.Numerics.Portable.sln b/MathNet.Numerics.Portable.sln
index f84b900a..2b8e76ad 100644
--- a/MathNet.Numerics.Portable.sln
+++ b/MathNet.Numerics.Portable.sln
@@ -1,8 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silverlight", "src\Silverlight\Silverlight.csproj", "{793E332F-E2B1-4D1D-9B2E-27E90B99BF93}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{C2F37492-38AE-4186-8A7F-17B0B080942C}"
ProjectSection(SolutionItems) = preProject
AUTHORS.markdown = AUTHORS.markdown
@@ -10,16 +8,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{C2F374
README.markdown = README.markdown
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Portable", "src\Portable\Portable.csproj", "{D877F358-A2D2-4CC3-A921-8AA5CF6187E8}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {793E332F-E2B1-4D1D-9B2E-27E90B99BF93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {793E332F-E2B1-4D1D-9B2E-27E90B99BF93}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {793E332F-E2B1-4D1D-9B2E-27E90B99BF93}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {793E332F-E2B1-4D1D-9B2E-27E90B99BF93}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D877F358-A2D2-4CC3-A921-8AA5CF6187E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D877F358-A2D2-4CC3-A921-8AA5CF6187E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D877F358-A2D2-4CC3-A921-8AA5CF6187E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D877F358-A2D2-4CC3-A921-8AA5CF6187E8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/build/NuGet/Numerics.Portable/MathNet.Numerics.Portable.nuspec b/build/NuGet/Numerics.Portable/MathNet.Numerics.Portable.nuspec
new file mode 100644
index 00000000..2114c26d
--- /dev/null
+++ b/build/NuGet/Numerics.Portable/MathNet.Numerics.Portable.nuspec
@@ -0,0 +1,17 @@
+
+
+
+ MathNet.Numerics.Portable
+ 1.0.0
+ Math.NET Numerics Portable Edition
+ Math.NET Numerics, providing methods and algorithms for numerical computations in science, engineering and every day use. Supports .Net 4.0.3, SL5, WinRT.
+ Math.NET Numerics is the numerical foundation of the Math.NET project, aiming to provide methods and algorithms for numerical computations in science, engineering and every day use. Numerics is the result of merging dnAnalytics with Math.NET Iridium and is intended to replace both. Portable edition, supports .Net 4.0.3, SL5, WinRT.
+ Marcus Cuda, Christoph Ruegg, Jurgen Van Gael
+ Christoph Ruegg
+ http://numerics.mathdotnet.com/
+ http://www.mathdotnet.com/images/MathNet128.png
+ http://mathnetnumerics.codeplex.com/license
+ false
+ math numeric portable SL WinRT statistics probability integration interpolation linear algebra matrix fft
+
+
\ No newline at end of file
diff --git a/build/NuGet/nuget.proj b/build/NuGet/nuget.proj
index 162ffc12..a2f8d531 100644
--- a/build/NuGet/nuget.proj
+++ b/build/NuGet/nuget.proj
@@ -9,6 +9,7 @@
$(MSBuildProjectDirectory)/../../out/lib
$(MSBuildProjectDirectory)/../../out/packages/NuGet
$(MSBuildProjectDirectory)/Numerics
+ $(MSBuildProjectDirectory)/Numerics.Portable
$(MSBuildProjectDirectory)/FSharp
$(MSBuildProjectDirectory)/Numerics.Sample
$(MSBuildProjectDirectory)/FSharp.Sample
@@ -17,7 +18,7 @@
-
+
@@ -31,7 +32,11 @@
-
+
+
+
+
+
@@ -49,6 +54,9 @@
+
+
+
@@ -56,12 +64,14 @@
%(NumericsAssemblyInfo.Version)
+ %(PortableAssemblyInfo.Version)
%(FSharpAssemblyInfo.Version)
$(NumericsAssemblyVersion.Substring(0, $(NumericsAssemblyVersion.LastIndexOf('.'))))
+ $(PortableAssemblyVersion.Substring(0, $(PortableAssemblyVersion.LastIndexOf('.'))))
$(FSharpAssemblyVersion.Substring(0, $(FSharpAssemblyVersion.LastIndexOf('.'))))
@@ -70,6 +80,12 @@
XmlFileName="$(NumericsPack)/MathNet.Numerics.nuspec"
XPath="//package/n:metadata/n:version"
Value="$(NumericsPackVersion)"/>
+
+
+
diff --git a/src/Numerics/Complex32.cs b/src/Numerics/Complex32.cs
index db2b4166..ae5473af 100644
--- a/src/Numerics/Complex32.cs
+++ b/src/Numerics/Complex32.cs
@@ -125,7 +125,7 @@ namespace MathNet.Numerics
///
/// The value for the imaginary component.
///
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
public Complex32(float real, float imaginary)
@@ -214,7 +214,7 @@ namespace MathNet.Numerics
/// The real component of the complex number.
public float Real
{
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
get
@@ -229,7 +229,7 @@ namespace MathNet.Numerics
/// The real imaginary component of the complex number.
public float Imaginary
{
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
get
@@ -943,7 +943,7 @@ namespace MathNet.Numerics
///
/// Returns the same complex number.
///
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
public Complex32 Plus()
@@ -957,7 +957,7 @@ namespace MathNet.Numerics
///
/// The negated value of this complex number.
///
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
public Complex32 Negate()
@@ -974,7 +974,7 @@ namespace MathNet.Numerics
///
/// The other complex number to add.
///
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
public Complex32 Add(Complex32 other)
@@ -991,7 +991,7 @@ namespace MathNet.Numerics
///
/// The other complex number to subtract from this one.
///
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
public Complex32 Subtract(Complex32 other)
@@ -1008,7 +1008,7 @@ namespace MathNet.Numerics
///
/// The complex number to multiply.
///
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
public Complex32 Multiply(Complex32 multiplier)
@@ -1025,7 +1025,7 @@ namespace MathNet.Numerics
///
/// The divisor.
///
-#if !SILVERLIGHT
+#if !PORTABLE
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
#endif
public Complex32 Divide(Complex32 divisor)
@@ -1235,7 +1235,7 @@ namespace MathNet.Numerics
}
}
-#if SILVERLIGHT
+#if PORTABLE
var value = GlobalizationHelper.ParseSingle(ref token);
#else
var value = GlobalizationHelper.ParseSingle(ref token, format.GetCultureInfo());
@@ -1392,6 +1392,7 @@ namespace MathNet.Numerics
return new Complex32(value, 0.0f);
}
+#if SYSNUMERICS
///
/// Implicit conversion of a BigInteger int to a Complex32.
///
@@ -1401,6 +1402,7 @@ namespace MathNet.Numerics
{
return new Complex32((long)value, 0.0f);
}
+#endif
///
/// Implicit conversion of a real long to a Complex32.
diff --git a/src/Numerics/Complex64.cs b/src/Numerics/Complex64.cs
new file mode 100644
index 00000000..1dc72339
--- /dev/null
+++ b/src/Numerics/Complex64.cs
@@ -0,0 +1,1700 @@
+//
+// 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.
+//
+
+using MathNet.Numerics;
+
+namespace System.Numerics
+{
+#if !SYSNUMERICS
+ using System;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices;
+ using System.Text;
+ using MathNet.Numerics.Properties;
+
+ ///
+ /// 64-bit Complex numbers class.
+ ///
+ ///
+ ///
+ /// The class Complex provides all elementary operations
+ /// on complex numbers. All the operators +, -,
+ /// *, /, ==, != are defined in the
+ /// canonical way. Additional complex trigonometric functions
+ /// are also provided. Note that the Complex structures
+ /// has two special constant values and
+ /// .
+ ///
+ ///
+ /// In order to avoid possible ambiguities resulting from a
+ /// Complex(double, double) constructor, the static methods
+ /// and
+ /// are provided instead.
+ ///
+ ///
+ ///
+ /// Complex x = Complex.FromRealImaginary(1d, 2d);
+ /// Complex y = Complex.FromModulusArgument(1d, Math.Pi);
+ /// Complex z = (x + y) / (x - y);
+ ///
+ ///
+ ///
+ /// For mathematical details about complex numbers, please
+ /// have a look at the
+ /// Wikipedia
+ ///
+ ///
+ [Serializable]
+ [StructLayout(LayoutKind.Sequential)]
+ public struct Complex : IFormattable, IEquatable, IPrecisionSupport
+ {
+ #region fields
+
+ ///
+ /// Represents imaginary unit number.
+ ///
+ private static readonly Complex _i = new Complex(0, 1);
+
+ ///
+ /// Represents a infinite complex number
+ ///
+ private static readonly Complex _infinity = new Complex(double.PositiveInfinity, double.PositiveInfinity);
+
+ ///
+ /// Represents not-a-number.
+ ///
+ private static readonly Complex _nan = new Complex(double.NaN, double.NaN);
+
+ ///
+ /// Representing the one value.
+ ///
+ private static readonly Complex _one = new Complex(1.0f, 0.0d);
+
+ ///
+ /// Representing the zero value.
+ ///
+ private static readonly Complex _zero = new Complex(0.0d, 0.0d);
+
+ ///
+ /// The real component of the complex number.
+ ///
+ private readonly double _real;
+
+ ///
+ /// The imaginary component of the complex number.
+ ///
+ private readonly double _imag;
+
+ #endregion fields
+
+ #region Constructor
+
+ ///
+ /// Initializes a new instance of the Complex structure with the given real
+ /// and imaginary parts.
+ ///
+ ///
+ /// The value for the real component.
+ ///
+ ///
+ /// The value for the imaginary component.
+ ///
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ public Complex(double real, double imaginary)
+ {
+ _real = real;
+ _imag = imaginary;
+ }
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets a value representing the infinity value. This field is constant.
+ ///
+ /// The infinity.
+ ///
+ /// The semantic associated to this value is a Complex of
+ /// infinite real and imaginary part. If you need more formal complex
+ /// number handling (according to the Riemann Sphere and the extended
+ /// complex plane C*, or using directed infinity) please check out the
+ /// alternative Math.NET symbolics packages instead.
+ ///
+ /// A value representing the infinity value.
+ public static Complex Infinity
+ {
+ get
+ {
+ return _infinity;
+ }
+ }
+
+ ///
+ /// Gets a value representing not-a-number. This field is constant.
+ ///
+ /// A value representing not-a-number.
+ public static Complex NaN
+ {
+ get
+ {
+ return _nan;
+ }
+ }
+
+ ///
+ /// Gets a value representing the imaginary unit number. This field is constant.
+ ///
+ /// A value representing the imaginary unit number.
+ public static Complex ImaginaryOne
+ {
+ get
+ {
+ return _i;
+ }
+ }
+
+ ///
+ /// Gets a value representing the zero value. This field is constant.
+ ///
+ /// A value representing the zero value.
+ public static Complex Zero
+ {
+ get
+ {
+ return new Complex(0.0d, 0.0d);
+ }
+ }
+
+ ///
+ /// Gets a value representing the 1 value. This field is constant.
+ ///
+ /// A value representing the 1 value.
+ public static Complex One
+ {
+ get
+ {
+ return _one;
+ }
+ }
+
+ #endregion Properties
+
+ ///
+ /// Gets the real component of the complex number.
+ ///
+ /// The real component of the complex number.
+ public double Real
+ {
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ get
+ {
+ return _real;
+ }
+ }
+
+ ///
+ /// Gets the real imaginary component of the complex number.
+ ///
+ /// The real imaginary component of the complex number.
+ public double Imaginary
+ {
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ get
+ {
+ return _imag;
+ }
+ }
+
+ ///
+ /// Gets a value indicating whether the Complex is zero.
+ ///
+ /// true if this instance is zero; otherwise, false.
+ public bool IsZero()
+ {
+ return _real == 0.0d && _imag == 0.0d;
+ }
+
+ ///
+ /// Gets a value indicating whether the Complex is one.
+ ///
+ /// true if this instance is one; otherwise, false.
+ public bool IsOne()
+ {
+ return _real == 1.0d && _imag == 0.0d;
+ }
+
+ ///
+ /// Gets a value indicating whether the Complex is the imaginary unit.
+ ///
+ /// true if this instance is ImaginaryOne; otherwise, false.
+ public bool IsImaginaryOne()
+ {
+ return _real == 0.0d && _imag == 1.0d;
+ }
+
+ ///
+ /// Gets a value indicating whether the provided Complexevaluates
+ /// to a value that is not a number.
+ ///
+ ///
+ /// true if this instance is ; otherwise,
+ /// false.
+ ///
+ public bool IsNaN()
+ {
+ return double.IsNaN(_real) || double.IsNaN(_imag);
+ }
+
+ ///
+ /// Gets a value indicating whether the provided Complex evaluates to an
+ /// infinite value.
+ ///
+ ///
+ /// true if this instance is infinite; otherwise, false.
+ ///
+ ///
+ /// True if it either evaluates to a complex infinity
+ /// or to a directed infinity.
+ ///
+ public bool IsInfinity()
+ {
+ return double.IsInfinity(_real) || double.IsInfinity(_imag);
+ }
+
+ ///
+ /// Gets a value indicating whether the provided Complex is real.
+ ///
+ /// true if this instance is a real number; otherwise, false.
+ public bool IsReal()
+ {
+ return _imag == 0.0d;
+ }
+
+ ///
+ /// Gets a value indicating whether the provided Complex is real and not negative, that is >= 0.
+ ///
+ ///
+ /// true if this instance is real nonnegative number; otherwise, false.
+ ///
+ public bool IsRealNonNegative()
+ {
+ return _imag == 0.0d && _real >= 0;
+ }
+
+ ///
+ /// Gets the conjugate of this Complex.
+ ///
+ ///
+ /// The semantic of setting the conjugate is such that
+ ///
+ /// // a, b of type Complex
+ /// a.Conjugate = b;
+ ///
+ /// is equivalent to
+ ///
+ /// // a, b of type Complex
+ /// a = b.Conjugate
+ ///
+ ///
+ /// The conjugate of this Complex
+ public Complex Conjugate()
+ {
+ return new Complex(_real, -_imag);
+ }
+
+ ///
+ /// Gets the magnitude or modulus of this Complex.
+ ///
+ /// The magnitude or modulus of this Complex
+ ///
+ public double Magnitude
+ {
+ get
+ {
+ return Math.Sqrt((_real * _real) + (_imag * _imag));
+ }
+ }
+
+ ///
+ /// Gets the squared magnitude of this Complex.
+ ///
+ /// The squared magnitude of this Complex
+ public double MagnitudeSquared
+ {
+ get
+ {
+ return (_real * _real) + (_imag * _imag);
+ }
+ }
+
+ ///
+ /// Gets the phase or argument of this Complex.
+ ///
+ ///
+ /// Phase always returns a value bigger than negative Pi and
+ /// smaller or equal to Pi. If this Complex is zero, the Complex
+ /// is assumed to be positive real with an argument of zero.
+ ///
+ /// The phase or argument of this Complex
+ public double Phase
+ {
+ get
+ {
+ if (IsReal() && _real < 0)
+ {
+ return Math.PI;
+ }
+
+ return IsRealNonNegative() ? 0.0d : Math.Atan2(_imag, _real);
+ }
+ }
+
+ ///
+ /// Gets the unity of this complex (same argument, but on the unit circle; exp(I*arg))
+ ///
+ /// The unity of this Complex.
+ public Complex Sign
+ {
+ get
+ {
+ if (double.IsPositiveInfinity(_real) && double.IsPositiveInfinity(_imag))
+ {
+ return new Complex(Constants.Sqrt1Over2, Constants.Sqrt1Over2);
+ }
+
+ if (double.IsPositiveInfinity(_real) && double.IsNegativeInfinity(_imag))
+ {
+ return new Complex(Constants.Sqrt1Over2, -Constants.Sqrt1Over2);
+ }
+
+ if (double.IsNegativeInfinity(_real) && double.IsPositiveInfinity(_imag))
+ {
+ return new Complex(-Constants.Sqrt1Over2, -Constants.Sqrt1Over2);
+ }
+
+ if (double.IsNegativeInfinity(_real) && double.IsNegativeInfinity(_imag))
+ {
+ return new Complex(-Constants.Sqrt1Over2, Constants.Sqrt1Over2);
+ }
+
+ // don't replace this with "Magnitude"!
+ var mod = SpecialFunctions.Hypotenuse(_real, _imag);
+ if (mod == 0.0d)
+ {
+ return Zero;
+ }
+
+ return new Complex(_real / mod, _imag / mod);
+ }
+ }
+
+ #region Exponential Functions
+
+ ///
+ /// Exponential of this Complex (exp(x), E^x).
+ ///
+ ///
+ /// The exponential of this complex number.
+ ///
+ public Complex Exponential()
+ {
+ var exp = Math.Exp(_real);
+ if (IsReal())
+ {
+ return new Complex(exp, 0.0d);
+ }
+
+ return new Complex(exp * Trig.Cosine(_imag), exp * Trig.Sine(_imag));
+ }
+
+ ///
+ /// Natural Logarithm of this Complex (Base E).
+ ///
+ ///
+ /// The natural logarithm of this complex number.
+ ///
+ public Complex NaturalLogarithm()
+ {
+ if (IsRealNonNegative())
+ {
+ return new Complex(Math.Log(_real), 0.0d);
+ }
+
+ return new Complex(0.5d * Math.Log(MagnitudeSquared), Phase);
+ }
+
+ ///
+ /// Raise this Complex to the given value.
+ ///
+ ///
+ /// The exponent.
+ ///
+ ///
+ /// The complex number raised to the given exponent.
+ ///
+ public Complex Power(Complex exponent)
+ {
+ if (IsZero())
+ {
+ if (exponent.IsZero())
+ {
+ return One;
+ }
+
+ if (exponent.Real > 0.0d)
+ {
+ return Zero;
+ }
+
+ if (exponent.Real < 0)
+ {
+ if (exponent.Imaginary == 0.0d)
+ {
+ return new Complex(double.PositiveInfinity, 0.0d);
+ }
+
+ return new Complex(double.PositiveInfinity, double.PositiveInfinity);
+ }
+
+ return NaN;
+ }
+
+ return (exponent * NaturalLogarithm()).Exponential();
+ }
+
+ ///
+ /// Raise this Complex to the inverse of the given value.
+ ///
+ ///
+ /// The root exponent.
+ ///
+ ///
+ /// The complex raised to the inverse of the given exponent.
+ ///
+ public Complex Root(Complex rootExponent)
+ {
+ return Power(1 / rootExponent);
+ }
+
+ ///
+ /// The Square (power 2) of this Complex
+ ///
+ ///
+ /// The square of this complex number.
+ ///
+ public Complex Square()
+ {
+ if (IsReal())
+ {
+ return new Complex(_real * _real, 0.0d);
+ }
+
+ return new Complex((_real * _real) - (_imag * _imag), 2 * _real * _imag);
+ }
+
+ ///
+ /// The Square Root (power 1/2) of this Complex
+ ///
+ ///
+ /// The square root of this complex number.
+ ///
+ public Complex SquareRoot()
+ {
+ if (IsRealNonNegative())
+ {
+ return new Complex(Math.Sqrt(_real), 0.0d);
+ }
+
+ Complex result;
+
+ var absReal = Math.Abs(Real);
+ var absImag = Math.Abs(Imaginary);
+ double w;
+ if (absReal >= absImag)
+ {
+ var ratio = Imaginary / Real;
+ w = Math.Sqrt(absReal) * Math.Sqrt(0.5 * (1.0d + Math.Sqrt(1.0d + (ratio * ratio))));
+ }
+ else
+ {
+ var ratio = Real / Imaginary;
+ w = Math.Sqrt(absImag) * Math.Sqrt(0.5 * (Math.Abs(ratio) + Math.Sqrt(1.0d + (ratio * ratio))));
+ }
+
+ if (Real >= 0.0d)
+ {
+ result = new Complex(w, Imaginary / (2.0d * w));
+ }
+ else if (Imaginary >= 0.0d)
+ {
+ result = new Complex(absImag / (2.0 * w), w);
+ }
+ else
+ {
+ result = new Complex(absImag / (2.0 * w), -w);
+ }
+
+ return result;
+ }
+
+ #endregion
+
+ #region Static Initializers
+
+ ///
+ /// Constructs a Complex from its real
+ /// and imaginary parts.
+ ///
+ ///
+ /// The value for the real component.
+ ///
+ ///
+ /// The value for the imaginary component.
+ ///
+ ///
+ /// A new Complex with the given values.
+ ///
+ public static Complex WithRealImaginary(double real, double imaginary)
+ {
+ return new Complex(real, imaginary);
+ }
+
+ ///
+ /// Constructs a Complex from its modulus and
+ /// argument.
+ ///
+ ///
+ /// Must be non-negative.
+ ///
+ ///
+ /// Real number.
+ ///
+ ///
+ /// A new Complex from the given values.
+ ///
+ public static Complex WithModulusArgument(double modulus, double argument)
+ {
+ if (modulus < 0.0d)
+ {
+ throw new ArgumentOutOfRangeException("modulus", Resources.ArgumentNotNegative);
+ }
+
+ return new Complex(modulus * Math.Cos(argument), modulus * Math.Sin(argument));
+ }
+
+ #endregion
+
+ #region IFormattable Members
+
+ ///
+ /// A string representation of this complex number.
+ ///
+ ///
+ /// The string representation of this complex number.
+ ///
+ public override string ToString()
+ {
+ return ToString(null, null);
+ }
+
+ ///
+ /// A string representation of this complex number.
+ ///
+ ///
+ /// The string representation of this complex number formatted as specified by the
+ /// format string.
+ ///
+ ///
+ /// A format specification.
+ ///
+ public string ToString(string format)
+ {
+ return ToString(format, null);
+ }
+
+ ///
+ /// A string representation of this complex number.
+ ///
+ ///
+ /// The string representation of this complex number formatted as specified by the
+ /// format provider.
+ ///
+ ///
+ /// An that supplies culture-specific formatting information.
+ ///
+ public string ToString(IFormatProvider formatProvider)
+ {
+ return ToString(null, formatProvider);
+ }
+
+ ///
+ /// A string representation of this complex number.
+ ///
+ ///
+ /// The string representation of this complex number formatted as specified by the
+ /// format string and format provider.
+ ///
+ ///
+ /// if the n, is not a number.
+ ///
+ ///
+ /// if s, is .
+ ///
+ ///
+ /// A format specification.
+ ///
+ ///
+ /// An that supplies culture-specific formatting information.
+ ///
+ public string ToString(string format, IFormatProvider formatProvider)
+ {
+ var ret = new StringBuilder();
+ ret.Append("(").Append(_real.ToString(format, formatProvider)).Append(", ").Append(_imag.ToString(format, formatProvider)).Append(")");
+ return ret.ToString();
+ }
+
+ #endregion
+
+ #region IEquatable Members
+
+ ///
+ /// Checks if two complex numbers are equal. Two complex numbers are equal if their
+ /// corresponding real and imaginary components are equal.
+ ///
+ ///
+ /// Returns true if the two objects are the same object, or if their corresponding
+ /// real and imaginary components are equal, false otherwise.
+ ///
+ ///
+ /// The complex number to compare to with.
+ ///
+ public bool Equals(Complex other)
+ {
+ if (IsNaN() || other.IsNaN())
+ {
+ return false;
+ }
+
+ if (IsInfinity() && other.IsInfinity())
+ {
+ return true;
+ }
+
+ return _real.AlmostEqual(other._real) && _imag.AlmostEqual(other._imag);
+ }
+
+ ///
+ /// The hash code for the complex number.
+ ///
+ ///
+ /// The hash code of the complex number.
+ ///
+ ///
+ /// The hash code is calculated as
+ /// System.Math.Exp(ComplexMath.Absolute(complexNumber)).
+ ///
+ public override int GetHashCode()
+ {
+ return _real.GetHashCode() ^ (-_imag.GetHashCode());
+ }
+
+ ///
+ /// Checks if two complex numbers are equal. Two complex numbers are equal if their
+ /// corresponding real and imaginary components are equal.
+ ///
+ ///
+ /// Returns true if the two objects are the same object, or if their corresponding
+ /// real and imaginary components are equal, false otherwise.
+ ///
+ ///
+ /// The complex number to compare to with.
+ ///
+ public override bool Equals(object obj)
+ {
+ return (obj is Complex) && Equals((Complex)obj);
+ }
+
+ #endregion
+
+ #region Operators
+
+ ///
+ /// Equality test.
+ ///
+ /// One of complex numbers to compare.
+ /// The other complex numbers to compare.
+ /// true if the real and imaginary components of the two complex numbers are equal; false otherwise.
+ public static bool operator ==(Complex complex1, Complex complex2)
+ {
+ return complex1.Equals(complex2);
+ }
+
+ ///
+ /// Inequality test.
+ ///
+ /// One of complex numbers to compare.
+ /// The other complex numbers to compare.
+ /// true if the real or imaginary components of the two complex numbers are not equal; false otherwise.
+ public static bool operator !=(Complex complex1, Complex complex2)
+ {
+ return !complex1.Equals(complex2);
+ }
+
+ ///
+ /// Unary addition.
+ ///
+ /// The complex number to operate on.
+ /// Returns the same complex number.
+ public static Complex operator +(Complex summand)
+ {
+ return summand;
+ }
+
+ ///
+ /// Unary minus.
+ ///
+ /// The complex number to operate on.
+ /// The negated value of the .
+ public static Complex operator -(Complex subtrahend)
+ {
+ return new Complex(-subtrahend._real, -subtrahend._imag);
+ }
+
+ /// Addition operator. Adds two complex numbers together.
+ /// The result of the addition.
+ /// One of the complex numbers to add.
+ /// The other complex numbers to add.
+ public static Complex operator +(Complex summand1, Complex summand2)
+ {
+ return new Complex(summand1._real + summand2._real, summand1._imag + summand2._imag);
+ }
+
+ /// Subtraction operator. Subtracts two complex numbers.
+ /// The result of the subtraction.
+ /// The complex number to subtract from.
+ /// The complex number to subtract.
+ public static Complex operator -(Complex minuend, Complex subtrahend)
+ {
+ return new Complex(minuend._real - subtrahend._real, minuend._imag - subtrahend._imag);
+ }
+
+ /// Addition operator. Adds a complex number and double together.
+ /// The result of the addition.
+ /// The complex numbers to add.
+ /// The double value to add.
+ public static Complex operator +(Complex summand1, double summand2)
+ {
+ return new Complex(summand1._real + summand2, summand1._imag);
+ }
+
+ /// Subtraction operator. Subtracts double value from a complex value.
+ /// The result of the subtraction.
+ /// The complex number to subtract from.
+ /// The double value to subtract.
+ public static Complex operator -(Complex minuend, double subtrahend)
+ {
+ return new Complex(minuend._real - subtrahend, minuend._imag);
+ }
+
+ /// Addition operator. Adds a complex number and double together.
+ /// The result of the addition.
+ /// The double value to add.
+ /// The complex numbers to add.
+ public static Complex operator +(double summand1, Complex summand2)
+ {
+ return new Complex(summand2._real + summand1, summand2._imag);
+ }
+
+ /// Subtraction operator. Subtracts complex value from a double value.
+ /// The result of the subtraction.
+ /// The double vale to subtract from.
+ /// The complex value to subtract.
+ public static Complex operator -(double minuend, Complex subtrahend)
+ {
+ return new Complex(minuend - subtrahend._real, -subtrahend._imag);
+ }
+
+ /// Multiplication operator. Multiplies two complex numbers.
+ /// The result of the multiplication.
+ /// One of the complex numbers to multiply.
+ /// The other complex number to multiply.
+ public static Complex operator *(Complex multiplicand, Complex multiplier)
+ {
+ return new Complex(
+ (multiplicand._real * multiplier._real) - (multiplicand._imag * multiplier._imag),
+ (multiplicand._real * multiplier._imag) + (multiplicand._imag * multiplier._real));
+ }
+
+ /// Multiplication operator. Multiplies a complex number with a double value.
+ /// The result of the multiplication.
+ /// The double value to multiply.
+ /// The complex number to multiply.
+ public static Complex operator *(double multiplicand, Complex multiplier)
+ {
+ return new Complex(multiplier._real * multiplicand, multiplier._imag * multiplicand);
+ }
+
+ /// Multiplication operator. Multiplies a complex number with a double value.
+ /// The result of the multiplication.
+ /// The complex number to multiply.
+ /// The double value to multiply.
+ public static Complex operator *(Complex multiplicand, double multiplier)
+ {
+ return new Complex(multiplicand._real * multiplier, multiplicand._imag * multiplier);
+ }
+
+ /// Division operator. Divides a complex number by another.
+ /// The result of the division.
+ /// The dividend.
+ /// The divisor.
+ public static Complex operator /(Complex dividend, Complex divisor)
+ {
+ if (dividend.IsZero() && divisor.IsZero())
+ {
+ return NaN;
+ }
+
+ if (divisor.IsZero())
+ {
+ return Infinity;
+ }
+
+ var modSquared = divisor.MagnitudeSquared;
+ return new Complex(
+ ((dividend._real * divisor._real) + (dividend._imag * divisor._imag)) / modSquared,
+ ((dividend._imag * divisor._real) - (dividend._real * divisor._imag)) / modSquared);
+ }
+
+ /// Division operator. Divides a double value by a complex number.
+ /// The result of the division.
+ /// The dividend.
+ /// The divisor.
+ public static Complex operator /(double dividend, Complex divisor)
+ {
+ if (dividend == 0.0d && divisor.IsZero())
+ {
+ return NaN;
+ }
+
+ if (divisor.IsZero())
+ {
+ return Infinity;
+ }
+
+ var zmod = divisor.MagnitudeSquared;
+ return new Complex(dividend * divisor._real / zmod, -dividend * divisor._imag / zmod);
+ }
+
+ /// Division operator. Divides a complex number by a double value.
+ /// The result of the division.
+ /// The dividend.
+ /// The divisor.
+ public static Complex operator /(Complex dividend, double divisor)
+ {
+ if (dividend.IsZero() && divisor == 0.0d)
+ {
+ return NaN;
+ }
+
+ if (divisor == 0.0d)
+ {
+ return Infinity;
+ }
+
+ return new Complex(dividend._real / divisor, dividend._imag / divisor);
+ }
+
+ ///
+ /// Unary addition.
+ ///
+ ///
+ /// Returns the same complex number.
+ ///
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ public Complex Plus()
+ {
+ return this;
+ }
+
+ ///
+ /// Unary minus.
+ ///
+ ///
+ /// The negated value of this complex number.
+ ///
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ public Complex Negate()
+ {
+ return -this;
+ }
+
+ ///
+ /// Adds a complex number to this one.
+ ///
+ ///
+ /// The result of the addition.
+ ///
+ ///
+ /// The other complex number to add.
+ ///
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ public Complex Add(Complex other)
+ {
+ return this + other;
+ }
+
+ ///
+ /// Subtracts a complex number from this one.
+ ///
+ ///
+ /// The result of the subtraction.
+ ///
+ ///
+ /// The other complex number to subtract from this one.
+ ///
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ public Complex Subtract(Complex other)
+ {
+ return this - other;
+ }
+
+ ///
+ /// Multiplies this complex number with this one.
+ ///
+ ///
+ /// The result of the multiplication.
+ ///
+ ///
+ /// The complex number to multiply.
+ ///
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ public Complex Multiply(Complex multiplier)
+ {
+ return this * multiplier;
+ }
+
+ ///
+ /// Divides this complex number by another.
+ ///
+ ///
+ /// The result of the division.
+ ///
+ ///
+ /// The divisor.
+ ///
+#if !PORTABLE
+ [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
+#endif
+ public Complex Divide(Complex divisor)
+ {
+ return this / divisor;
+ }
+
+ #endregion
+
+ #region IPrecisionSupport
+
+ ///
+ /// Returns a Norm of a value of this type, which is appropriate for measuring how
+ /// close this value is to zero.
+ ///
+ ///
+ /// A norm of this value.
+ ///
+ double IPrecisionSupport.Norm()
+ {
+ return MagnitudeSquared;
+ }
+
+ ///
+ /// Returns a Norm of the difference of two values of this type, which is
+ /// appropriate for measuring how close together these two values are.
+ ///
+ ///
+ /// The value to compare with.
+ ///
+ ///
+ /// A norm of the difference between this and the other value.
+ ///
+ double IPrecisionSupport.NormOfDifference(Complex otherValue)
+ {
+ return (this - otherValue).MagnitudeSquared;
+ }
+
+ #endregion
+
+ #region Parse Functions
+
+ ///
+ /// Creates a complex number based on a string. The string can be in the
+ /// following formats (without the quotes): 'n', 'ni', 'n +/- ni',
+ /// 'ni +/- n', 'n,n', 'n,ni,' '(n,n)', or '(n,ni)', where n is a double.
+ ///
+ ///
+ /// A complex number containing the value specified by the given string.
+ ///
+ ///
+ /// The string to parse.
+ ///
+ public static Complex Parse(string value)
+ {
+ return Parse(value, null);
+ }
+
+ ///
+ /// Creates a complex number based on a string. The string can be in the
+ /// following formats (without the quotes): 'n', 'ni', 'n +/- ni',
+ /// 'ni +/- n', 'n,n', 'n,ni,' '(n,n)', or '(n,ni)', where n is a double.
+ ///
+ ///
+ /// A complex number containing the value specified by the given string.
+ ///
+ ///
+ /// the string to parse.
+ ///
+ ///
+ /// An that supplies culture-specific
+ /// formatting information.
+ ///
+ public static Complex Parse(string value, IFormatProvider formatProvider)
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(value);
+ }
+
+ value = value.Trim();
+ if (value.Length == 0)
+ {
+ throw new FormatException();
+ }
+
+ // strip out parens
+ if (value.StartsWith("(", StringComparison.Ordinal))
+ {
+ if (!value.EndsWith(")", StringComparison.Ordinal))
+ {
+ throw new FormatException();
+ }
+
+ value = value.Substring(1, value.Length - 2).Trim();
+ }
+
+ // keywords
+ var numberFormatInfo = formatProvider.GetNumberFormatInfo();
+ var textInfo = formatProvider.GetTextInfo();
+ var keywords =
+ new[]
+ {
+ textInfo.ListSeparator, numberFormatInfo.NaNSymbol,
+ numberFormatInfo.NegativeInfinitySymbol, numberFormatInfo.PositiveInfinitySymbol,
+ "+", "-", "i", "j"
+ };
+
+ // lexing
+ var tokens = new LinkedList();
+ GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
+ var token = tokens.First;
+
+ // parse the left part
+ bool isLeftPartImaginary;
+ var leftPart = ParsePart(ref token, out isLeftPartImaginary, formatProvider);
+ if (token == null)
+ {
+ return isLeftPartImaginary ? new Complex(0, leftPart) : new Complex(leftPart, 0);
+ }
+
+ // parse the right part
+ if (token.Value == textInfo.ListSeparator)
+ {
+ // format: real,imag
+ token = token.Next;
+
+ if (isLeftPartImaginary)
+ {
+ // left must not contain 'i', right doesn't matter.
+ throw new FormatException();
+ }
+
+ bool isRightPartImaginary;
+ var rightPart = ParsePart(ref token, out isRightPartImaginary, formatProvider);
+
+ return new Complex(leftPart, rightPart);
+ }
+ else
+ {
+ // format: real + imag
+ bool isRightPartImaginary;
+ var rightPart = ParsePart(ref token, out isRightPartImaginary, formatProvider);
+
+ if (!(isLeftPartImaginary ^ isRightPartImaginary))
+ {
+ // either left or right part must contain 'i', but not both.
+ throw new FormatException();
+ }
+
+ return isLeftPartImaginary ? new Complex(rightPart, leftPart) : new Complex(leftPart, rightPart);
+ }
+ }
+
+ ///
+ /// Parse a part (real or complex) from a complex number.
+ ///
+ /// Start Token.
+ /// Is set to true if the part identified itself as being imaginary.
+ ///
+ /// An that supplies culture-specific
+ /// formatting information.
+ ///
+ /// Resulting part as double.
+ ///
+ private static double ParsePart(ref LinkedListNode token, out bool imaginary, IFormatProvider format)
+ {
+ imaginary = false;
+ if (token == null)
+ {
+ throw new FormatException();
+ }
+
+ // handle prefix modifiers
+ if (token.Value == "+")
+ {
+ token = token.Next;
+
+ if (token == null)
+ {
+ throw new FormatException();
+ }
+ }
+
+ var negative = false;
+ if (token.Value == "-")
+ {
+ negative = true;
+ token = token.Next;
+
+ if (token == null)
+ {
+ throw new FormatException();
+ }
+ }
+
+ // handle prefix imaginary symbol
+ if (String.Compare(token.Value, "i", StringComparison.OrdinalIgnoreCase) == 0
+ || String.Compare(token.Value, "j", StringComparison.OrdinalIgnoreCase) == 0)
+ {
+ imaginary = true;
+ token = token.Next;
+
+ if (token == null)
+ {
+ return negative ? -1 : 1;
+ }
+ }
+
+#if PORTABLE
+ var value = GlobalizationHelper.ParseSingle(ref token);
+#else
+ var value = GlobalizationHelper.ParseSingle(ref token, format.GetCultureInfo());
+#endif
+
+ // handle suffix imaginary symbol
+ if (token != null && (String.Compare(token.Value, "i", StringComparison.OrdinalIgnoreCase) == 0
+ || String.Compare(token.Value, "j", StringComparison.OrdinalIgnoreCase) == 0))
+ {
+ if (imaginary)
+ {
+ // only one time allowed: either prefix or suffix, or neither.
+ throw new FormatException();
+ }
+
+ imaginary = true;
+ token = token.Next;
+ }
+
+ return negative ? -value : value;
+ }
+
+ ///
+ /// Converts the string representation of a complex number to a single-precision complex number equivalent.
+ /// A return value indicates whether the conversion succeeded or failed.
+ ///
+ ///
+ /// A string containing a complex number to convert.
+ ///
+ ///
+ /// The parsed value.
+ ///
+ ///
+ /// If the conversion succeeds, the result will contain a complex number equivalent to value.
+ /// Otherwise the result will contain complex32.Zero. This parameter is passed uninitialized
+ ///
+ public static bool TryParse(string value, out Complex result)
+ {
+ return TryParse(value, null, out result);
+ }
+
+ ///
+ /// Converts the string representation of a complex number to single-precision complex number equivalent.
+ /// A return value indicates whether the conversion succeeded or failed.
+ ///
+ ///
+ /// A string containing a complex number to convert.
+ ///
+ ///
+ /// An that supplies culture-specific formatting information about value.
+ ///
+ ///
+ /// The parsed value.
+ ///
+ ///
+ /// If the conversion succeeds, the result will contain a complex number equivalent to value.
+ /// Otherwise the result will contain complex32.Zero. This parameter is passed uninitialized
+ ///
+ public static bool TryParse(string value, IFormatProvider formatProvider, out Complex result)
+ {
+ bool ret;
+ try
+ {
+ result = Parse(value, formatProvider);
+ ret = true;
+ }
+ catch (ArgumentNullException)
+ {
+ result = _zero;
+ ret = false;
+ }
+ catch (FormatException)
+ {
+ result = _zero;
+ ret = false;
+ }
+
+ return ret;
+ }
+
+ #endregion
+
+ #region Conversion
+
+ ///
+ /// Explicit conversion of a real decimal to a Complex.
+ ///
+ /// The decimal value to convert.
+ /// The result of the conversion.
+ public static explicit operator Complex(decimal value)
+ {
+ return new Complex((double)value, 0.0d);
+ }
+
+ ///
+ /// Explicit conversion of a Complex to a Complex.
+ ///
+ /// The decimal value to convert.
+ /// The result of the conversion.
+ public static explicit operator Complex(Complex32 value)
+ {
+ return new Complex((double)value.Real, (double)value.Imaginary);
+ }
+
+ ///
+ /// Implicit conversion of a real byte to a Complex.
+ ///
+ /// The byte value to convert.
+ /// The result of the conversion.
+ public static implicit operator Complex(byte value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a real short to a Complex.
+ ///
+ /// The short value to convert.
+ /// The result of the conversion.
+ public static implicit operator Complex(short value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a signed byte to a Complex.
+ ///
+ /// The signed byte value to convert.
+ /// The result of the conversion.
+ [CLSCompliant(false)]
+ public static implicit operator Complex(sbyte value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a unsgined real short to a Complex.
+ ///
+ /// The unsgined short value to convert.
+ /// The result of the conversion.
+ [CLSCompliant(false)]
+ public static implicit operator Complex(ushort value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a real int to a Complex.
+ ///
+ /// The int value to convert.
+ /// The result of the conversion.
+ public static implicit operator Complex(int value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a real long to a Complex.
+ ///
+ /// The long value to convert.
+ /// The result of the conversion.
+ public static implicit operator Complex(long value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a real uint to a Complex.
+ ///
+ /// The uint value to convert.
+ /// The result of the conversion.
+ [CLSCompliant(false)]
+ public static implicit operator Complex(uint value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a real ulong to a Complex.
+ ///
+ /// The ulong value to convert.
+ /// The result of the conversion.
+ [CLSCompliant(false)]
+ public static implicit operator Complex(ulong value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a real double to a Complex.
+ ///
+ /// The double value to convert.
+ /// The result of the conversion.
+ public static implicit operator Complex(double value)
+ {
+ return new Complex(value, 0.0d);
+ }
+
+ ///
+ /// Implicit conversion of a real float to a Complex.
+ ///
+ /// The double value to convert.
+ /// The result of the conversion.
+ public static explicit operator Complex(float value)
+ {
+ return new Complex((double)value, 0.0d);
+ }
+
+ ///
+ /// Converts this Complex to a .
+ ///
+ /// A with the same values as this Complex.
+ public Complex ToComplex()
+ {
+ return new Complex(_real, _imag);
+ }
+
+ #endregion
+
+ ///
+ /// Gets the absolute value (or magnitude) of a complex number.
+ ///
+ /// A complex number.
+ /// The absolute value (or magnitude) of a complex number.
+ public static double Abs(Complex value)
+ {
+ return value.Magnitude;
+ }
+
+ ///
+ /// Trigonometric Arc Cosine of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The arc cosine of a complex number.
+ ///
+ public static Complex Acos(Complex value)
+ {
+ return (Complex)value.ToComplex().InverseCosine();
+ }
+
+ ///
+ /// Trigonometric Arc Sine of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The arc sine of a complex number.
+ ///
+ public static Complex Asin(Complex value)
+ {
+ return (Complex)value.ToComplex().InverseSine();
+ }
+
+ ///
+ /// Trigonometric Arc Tangent of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The arc tangent of a complex number.
+ ///
+ public static Complex Atan(Complex value)
+ {
+ return (Complex)value.ToComplex().InverseTangent();
+ }
+
+ ///
+ /// Trigonometric Cosine of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The cosine of a complex number.
+ ///
+ public static Complex Cos(Complex value)
+ {
+ return (Complex)value.ToComplex().Cosine();
+ }
+
+ ///
+ /// Trigonometric Sine of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The Sine of a complex number.
+ ///
+ public static Complex Sin(Complex value)
+ {
+ return (Complex)value.ToComplex().Sine();
+ }
+
+ ///
+ /// Trigonometric Tangent of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The tangent of a complex number.
+ ///
+ public static Complex Tan(Complex value)
+ {
+ return (Complex)value.ToComplex().Tangent();
+ }
+
+ ///
+ /// Trigonometric Hyperbolic Cosine of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The hyperbolic cosine of a complex number.
+ ///
+ public static Complex Cosh(Complex value)
+ {
+ return (Complex)value.ToComplex().HyperbolicCosine();
+ }
+
+ ///
+ /// Trigonometric Hyperbolic Sine of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The hyperbolic sine of a complex number.
+ ///
+ public static Complex Sinh(Complex value)
+ {
+ return (Complex)value.ToComplex().HyperbolicSine();
+ }
+
+ ///
+ /// Trigonometric Hyperbolic Tangent of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The hyperbolic tangent of a complex number.
+ ///
+ public static Complex Tanh(Complex value)
+ {
+ return (Complex)value.ToComplex().HyperbolicTangent();
+ }
+
+ ///
+ /// Exponential of a Complex number (exp(x), E^x).
+ ///
+ /// A complex number.
+ ///
+ /// The exponential of a complex number.
+ ///
+ public static Complex Exp(Complex value)
+ {
+ return (Complex)value.ToComplex().Exponential();
+ }
+
+ ///
+ /// Constructs a Complex from its magnitude and phase.
+ ///
+ ///
+ /// Must be non-negative.
+ ///
+ ///
+ /// Real number.
+ ///
+ ///
+ /// A new Complex from the given values.
+ ///
+ ///
+ public static Complex FromPolarCoordinates(double magnitude, double phase)
+ {
+ return WithModulusArgument(magnitude, phase);
+ }
+
+ ///
+ /// Natural Logarithm of a Complex number (exp(x), E^x).
+ ///
+ /// A complex number.
+ ///
+ /// The natural logarithm of a complex number.
+ ///
+ public static Complex Log(Complex value)
+ {
+ return (Complex)value.ToComplex().NaturalLogarithm();
+ }
+
+ ///
+ /// Returns the logarithm of a specified complex number in a specified base
+ ///
+ /// A complex number.
+ /// The base of the logarithm.
+ /// The logarithm of value in base baseValue.
+ public static Complex Log(Complex value, double baseValue)
+ {
+ if (baseValue == 1.0)
+ {
+ return double.NaN;
+ }
+
+ return (Complex)(value.ToComplex().NaturalLogarithm() / Math.Log(baseValue, Math.E));
+ }
+
+ ///
+ /// Returns the base-10 logarithm of a specified complex number in a specified base
+ ///
+ /// A complex number.
+ /// The base-10 logarithm of the complex number.
+ public static Complex Log10(Complex value)
+ {
+ return Log(value, 10);
+ }
+
+ ///
+ /// Raise this a Complexnumber to the given value.
+ ///
+ /// A complex number.
+ /// The exponent.
+ ///
+ /// The complex number raised to the given exponent.
+ ///
+ public static Complex Pow(Complex value, Complex power)
+ {
+ return value.Power(power);
+ }
+
+ ///
+ /// Raise this a Complexnumber to the given value.
+ ///
+ /// A complex number.
+ /// The exponent.
+ ///
+ /// The complex number raised to the given exponent.
+ ///
+ public static Complex Pow(Complex value, double power)
+ {
+ return value.Power(power);
+ }
+
+ ///
+ /// Returns the multiplicative inverse of a complex number.
+ ///
+ /// A complex number.
+ /// The reciprocal of value.
+ /// If value is , the method returns . Otherwise, it returns the result of the expression / value.
+ public static Complex Reciprocal(Complex value)
+ {
+ if (value.IsZero())
+ {
+ return _zero;
+ }
+
+ return 1.0d / value;
+ }
+
+ ///
+ /// The Square Root (power 1/2) of a Complex number.
+ ///
+ /// A complex number.
+ ///
+ /// The square root of a complex number.
+ ///
+ public static Complex Sqrt(Complex value)
+ {
+ return value.SquareRoot();
+ }
+ }
+#endif
+}
\ No newline at end of file
diff --git a/src/Numerics/ComplexExtensions.cs b/src/Numerics/ComplexExtensions.cs
index 71f5ba58..fe217e97 100644
--- a/src/Numerics/ComplexExtensions.cs
+++ b/src/Numerics/ComplexExtensions.cs
@@ -497,7 +497,7 @@ namespace MathNet.Numerics
}
}
-#if SILVERLIGHT
+#if PORTABLE
var value = GlobalizationHelper.ParseDouble(ref token);
#else
var value = GlobalizationHelper.ParseDouble(ref token, format.GetCultureInfo());
diff --git a/src/Numerics/Control.cs b/src/Numerics/Control.cs
index fbcca5a8..7c6d165d 100644
--- a/src/Numerics/Control.cs
+++ b/src/Numerics/Control.cs
@@ -32,19 +32,16 @@ namespace MathNet.Numerics
{
using System;
using Algorithms.LinearAlgebra;
- using Threading;
///
/// Sets parameters for the library.
///
public static class Control
{
-#if !SILVERLIGHT
///
/// Initial number of threads to use;
///
private static int _numberOfThreads = Environment.ProcessorCount;
-#endif
///
/// Initial block size for the native linear algebra provider.
@@ -110,20 +107,11 @@ namespace MathNet.Numerics
/// The Silverlight version of the library defaults to one thread.
public static int NumberOfParallelWorkerThreads
{
-#if SILVERLIGHT
- get { return ThreadQueue.ThreadCount; }
- set { ThreadQueue.Start(value); }
-#else
- get
- {
- return _numberOfThreads;
- }
-
+ get { return _numberOfThreads; }
set
{ // instead of throwing an out of range exception, simply normalize
_numberOfThreads = Math.Max(1, Math.Min(1024, value));
}
-#endif
}
///
@@ -133,11 +121,7 @@ namespace MathNet.Numerics
/// The block size. Must be at least 32.
public static int BlockSize
{
- get
- {
- return _blockSize;
- }
-
+ get { return _blockSize; }
set
{
if (_blockSize > 31)
@@ -153,11 +137,7 @@ namespace MathNet.Numerics
/// The order. Default is 64.
public static int ParallelizeOrder
{
- get
- {
- return _parallelizeOrder;
- }
-
+ get { return _parallelizeOrder; }
set
{
if (_parallelizeOrder > 2)
@@ -173,11 +153,7 @@ namespace MathNet.Numerics
/// Number of elements. Default is 300.
public static int ParallelizeElements
{
- get
- {
- return _parallelizeElements;
- }
-
+ get { return _parallelizeElements; }
set
{
if (_parallelizeElements > 2)
diff --git a/src/Numerics/GlobalizationHelper.cs b/src/Numerics/GlobalizationHelper.cs
index 2072244f..8e5b9068 100644
--- a/src/Numerics/GlobalizationHelper.cs
+++ b/src/Numerics/GlobalizationHelper.cs
@@ -127,7 +127,7 @@ namespace MathNet.Numerics
}
}
-#if SILVERLIGHT
+#if PORTABLE
///
/// Globalized Parsing: Parse a double number
///
diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
index f69f806f..f707adc5 100644
--- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
@@ -807,11 +807,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(
- 0,
- Count,
- (index, localData) => Math.Max(localData, Data[index].Magnitude),
- Math.Max);
+ return CommonParallel.Aggregate(Data, (i, v) => v.Magnitude, Math.Max, 0d);
}
var sum = 0.0;
diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
index 51172498..24e957b6 100644
--- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
@@ -268,7 +268,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(Data[i].GetHashCode());
#else
hash ^= BitConverter.DoubleToInt64Bits(Data[i].GetHashCode());
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs
index 99ffad1c..1e305933 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs
@@ -38,7 +38,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// Defines the base interface for iterators that help control an iterative calculation.
///
public interface IIterator
-#if !SILVERLIGHT
+#if !PORTABLE
: ICloneable
#endif
{
@@ -101,7 +101,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
///
void ResetToPrecalculationState();
-#if SILVERLIGHT
+#if PORTABLE
IIterator Clone();
#endif
}
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs
index 0fc67ea6..ed96d564 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs
@@ -96,7 +96,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
///
private static readonly ICalculationStatus RunningStatus = new CalculationRunning();
-#if SILVERLIGHT
+#if PORTABLE
private static readonly Dictionary> SolverSetups = new Dictionary>();
#else
///
@@ -125,6 +125,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
LoadSolverInformationFromAssembly(Assembly.GetExecutingAssembly(), typesToExclude);
}
+#if !PORTABLE
///
/// Loads the available objects from the assembly specified by the file location.
///
@@ -171,6 +172,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// Now we can load the solver information.
LoadSolverInformationFromAssembly(assembly, typesToExclude);
}
+#endif
///
/// Loads the available objects from the assembly specified by the assembly name.
@@ -291,6 +293,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
{
continue;
}
+#if !PORTABLE
catch (MethodAccessException)
{
continue;
@@ -299,6 +302,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
{
continue;
}
+#endif
catch (MemberAccessException)
{
continue;
@@ -556,7 +560,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
throw new Exception("IIterativeSolverSetup objects not found");
}
-#if SILVERLIGHT
+#if PORTABLE
foreach (var setup in SolverSetups.OrderBy(solver => solver.Key, new DoubleComparer()).Select(pair => pair.Value).SelectMany(setups => setups))
#else
foreach (var setup in SolverSetups.Select(pair => pair.Value).SelectMany(setups => setups))
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs
index 3e8916fb..a973ed26 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs
@@ -311,7 +311,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
return new Iterator(stopCriteria);
}
- #if !SILVERLIGHT
+ #if !PORTABLE
///
/// Creates a deep clone of the current iterator.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs
index 3f0cc784..3c37e941 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs
@@ -378,7 +378,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
return new DivergenceStopCriterium(_maximumRelativeIncrease, _minimumNumberOfIterations);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clone this object
///
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs
index 176280ba..8714fe85 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs
@@ -186,7 +186,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
return new FailureStopCriterium();
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs
index 90237143..34835820 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs
@@ -34,7 +34,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
/// The base interface for classes that provide stop criteria for iterative calculations.
///
public interface IIterationStopCriterium
-#if !SILVERLIGHT
+#if !PORTABLE
: ICloneable
#endif
{
@@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
///
StopLevel StopLevel { get; }
-#if SILVERLIGHT
+#if PORTABLE
IIterationStopCriterium Clone();
#endif
}
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs
index 1ecabc32..7332905c 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs
@@ -212,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
return new IterationCountStopCriterium(_maximumNumberOfIterations);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs
index 15471b3e..6c38c644 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs
@@ -394,7 +394,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
return new ResidualStopCriterium(_maximum, _minimumIterationsBelowMaximum);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
index a4203773..d76968a2 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
@@ -843,7 +843,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(_nonZeroValues[i].Magnitude);
#else
hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].Magnitude);
diff --git a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
index 7d9b5492..fdb48569 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
@@ -1090,7 +1090,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(0, NonZerosCount, (index, localData) => Math.Max(localData, _nonZeroValues[index].Magnitude), Math.Max);
+ return CommonParallel.Aggregate(0, NonZerosCount, i => _nonZeroValues[i].Magnitude, Math.Max, 0d);
}
var sum = 0.0;
@@ -1406,7 +1406,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(this._nonZeroValues[i].GetHashCode());
#else
hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].GetHashCode());
diff --git a/src/Numerics/LinearAlgebra/Complex/Vector.cs b/src/Numerics/LinearAlgebra/Complex/Vector.cs
index 6ca78ff0..21eb5ea5 100644
--- a/src/Numerics/LinearAlgebra/Complex/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Vector.cs
@@ -316,11 +316,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(
- 0,
- Count,
- (index, localData) => Math.Max(localData, At(index).Magnitude),
- Math.Max);
+ return CommonParallel.Aggregate(0, Count, i => At(i).Magnitude, Math.Max, 0d);
}
var sum = 0.0;
diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
index a3092b02..ce5c9eba 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
@@ -860,11 +860,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(
- 0,
- Count,
- (index, localData) => Math.Max(localData, Data[index].Magnitude),
- Common.Max);
+ return CommonParallel.Aggregate(Data, (i, v) => v.Magnitude, Math.Max, 0f);
}
var sum = 0.0;
diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
index 78fd384d..335fe87a 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
@@ -273,7 +273,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(Data[i].GetHashCode());
#else
hash ^= BitConverter.DoubleToInt64Bits(Data[i].GetHashCode());
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs
index 23b0c110..405b1197 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs
@@ -38,7 +38,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// Defines the base interface for iterators that help control an iterative calculation.
///
public interface IIterator
-#if !SILVERLIGHT
+#if !PORTABLE
: ICloneable
#endif
{
@@ -101,7 +101,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
///
void ResetToPrecalculationState();
-#if SILVERLIGHT
+#if PORTABLE
IIterator Clone();
#endif
}
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs
index 087ba3f3..af845551 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs
@@ -93,7 +93,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
///
private static readonly ICalculationStatus RunningStatus = new CalculationRunning();
-#if SILVERLIGHT
+#if PORTABLE
private static readonly Dictionary> SolverSetups = new Dictionary>();
#else
///
@@ -122,6 +122,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
LoadSolverInformationFromAssembly(Assembly.GetExecutingAssembly(), typesToExclude);
}
+#if !PORTABLE
///
/// Loads the available objects from the assembly specified by the file location.
///
@@ -168,6 +169,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// Now we can load the solver information.
LoadSolverInformationFromAssembly(assembly, typesToExclude);
}
+#endif
///
/// Loads the available objects from the assembly specified by the assembly name.
@@ -288,6 +290,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
{
continue;
}
+#if !PORTABLE
catch (MethodAccessException)
{
continue;
@@ -296,6 +299,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
{
continue;
}
+#endif
catch (MemberAccessException)
{
continue;
@@ -553,7 +557,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
throw new Exception("IIterativeSolverSetup objects not found");
}
-#if SILVERLIGHT
+#if PORTABLE
foreach (var setup in SolverSetups.OrderBy(solver => solver.Key, new DoubleComparer()).Select(pair => pair.Value).SelectMany(setups => setups))
#else
foreach (var setup in SolverSetups.Select(pair => pair.Value).SelectMany(setups => setups))
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs
index 3002f188..3b5f2591 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs
@@ -311,7 +311,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
return new Iterator(stopCriteria);
}
- #if !SILVERLIGHT
+#if !PORTABLE
///
/// Creates a deep clone of the current iterator.
///
@@ -320,6 +320,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
{
return Clone();
}
- #endif
+#endif
}
}
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs
index cbe6f37e..6a3fd1ee 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs
@@ -378,7 +378,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
return new DivergenceStopCriterium(_maximumRelativeIncrease, _minimumNumberOfIterations);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clone this object
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs
index 8ab3a39f..f733dca3 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs
@@ -186,7 +186,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
return new FailureStopCriterium();
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs
index 8853629a..7deab9e7 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs
@@ -34,7 +34,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
/// The base interface for classes that provide stop criteria for iterative calculations.
///
public interface IIterationStopCriterium
-#if !SILVERLIGHT
+#if !PORTABLE
: ICloneable
#endif
{
@@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
///
StopLevel StopLevel { get; }
-#if SILVERLIGHT
+#if PORTABLE
IIterationStopCriterium Clone();
#endif
}
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs
index 451fcb32..84db0e05 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs
@@ -212,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
return new IterationCountStopCriterium(_maximumNumberOfIterations);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs
index 1ada26d7..88312e59 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs
@@ -394,7 +394,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
return new ResidualStopCriterium(_maximum, _minimumIterationsBelowMaximum);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
index 1ec92341..11d9cfd6 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
@@ -844,7 +844,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(_nonZeroValues[i].Magnitude);
#else
hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].Magnitude);
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
index 753ffedf..69c32a76 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
@@ -1120,7 +1120,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(0, NonZerosCount, (index, localData) => Math.Max(localData, _nonZeroValues[index].Magnitude), Common.Max);
+ return CommonParallel.Aggregate(0, NonZerosCount, i => _nonZeroValues[i].Magnitude, Math.Max, 0f);
}
var sum = 0.0;
@@ -1436,7 +1436,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(this._nonZeroValues[i].GetHashCode());
#else
hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].GetHashCode());
diff --git a/src/Numerics/LinearAlgebra/Complex32/Vector.cs b/src/Numerics/LinearAlgebra/Complex32/Vector.cs
index 77a66db6..c76eecbd 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Vector.cs
@@ -316,11 +316,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(
- 0,
- Count,
- (index, localData) => Math.Max(localData, At(index).Magnitude),
- Common.Max);
+ return CommonParallel.Aggregate(0, Count, i => At(i).Magnitude, Math.Max, 0f);
}
var sum = 0.0;
diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
index 74f145a5..689f01fc 100644
--- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
@@ -942,11 +942,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(
- 0,
- Count,
- (index, localData) => Math.Max(localData, Math.Abs(Data[index])),
- Math.Max);
+ return CommonParallel.Aggregate(Data, (i, v) => Math.Abs(v), Math.Max, 0d);
}
var sum = 0.0;
diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
index 7da0f0ba..1c8527b2 100644
--- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
@@ -267,7 +267,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(Data[i]);
#else
hash ^= BitConverter.DoubleToInt64Bits(Data[i]);
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs
index 3f68df69..3a500db8 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs
@@ -38,7 +38,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// Defines the base interface for iterators that help control an iterative calculation.
///
public interface IIterator
-#if !SILVERLIGHT
+#if !PORTABLE
: ICloneable
#endif
{
@@ -101,7 +101,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
///
void ResetToPrecalculationState();
-#if SILVERLIGHT
+#if PORTABLE
IIterator Clone();
#endif
}
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs
index fcdd0492..9c80e771 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs
@@ -31,7 +31,6 @@
namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
{
using System;
- using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -91,7 +90,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
///
private static readonly ICalculationStatus RunningStatus = new CalculationRunning();
-#if SILVERLIGHT
+#if PORTABLE
private static readonly Dictionary> SolverSetups = new Dictionary>();
#else
///
@@ -120,6 +119,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
LoadSolverInformationFromAssembly(Assembly.GetExecutingAssembly(), typesToExclude);
}
+#if !PORTABLE
///
/// Loads the available objects from the assembly specified by the file location.
///
@@ -166,6 +166,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
// Now we can load the solver information.
LoadSolverInformationFromAssembly(assembly, typesToExclude);
}
+#endif
///
/// Loads the available objects from the assembly specified by the assembly name.
@@ -286,6 +287,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
{
continue;
}
+#if !PORTABLE
catch (MethodAccessException)
{
continue;
@@ -294,6 +296,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
{
continue;
}
+#endif
catch (MemberAccessException)
{
continue;
@@ -551,7 +554,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
throw new Exception("IIterativeSolverSetup objects not found");
}
-#if SILVERLIGHT
+#if PORTABLE
foreach (var setup in SolverSetups.OrderBy(solver => solver.Key, new DoubleComparer()).Select(pair => pair.Value).SelectMany(setups => setups))
#else
foreach (var setup in SolverSetups.Select(pair => pair.Value).SelectMany(setups => setups))
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs
index 307b41fa..4d318928 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs
@@ -311,7 +311,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
return new Iterator(stopCriteria);
}
- #if !SILVERLIGHT
+#if !PORTABLE
///
/// Creates a deep clone of the current iterator.
///
@@ -320,6 +320,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
{
return Clone();
}
- #endif
+#endif
}
}
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs
index 5356827a..e36fd566 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs
@@ -378,7 +378,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium
return new DivergenceStopCriterium(_maximumRelativeIncrease, _minimumNumberOfIterations);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clone this object
///
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs
index dd52ce1e..75267b66 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs
@@ -186,7 +186,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium
return new FailureStopCriterium();
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs
index 95a9824d..f207ba5a 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs
@@ -34,7 +34,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium
/// The base interface for classes that provide stop criteria for iterative calculations.
///
public interface IIterationStopCriterium
-#if !SILVERLIGHT
+#if !PORTABLE
: ICloneable
#endif
{
@@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium
///
StopLevel StopLevel { get; }
-#if SILVERLIGHT
+#if PORTABLE
IIterationStopCriterium Clone();
#endif
}
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs
index 8331418a..e42c3d68 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs
@@ -212,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium
return new IterationCountStopCriterium(_maximumNumberOfIterations);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs
index e4549885..712828b9 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs
@@ -394,7 +394,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium
return new ResidualStopCriterium(_maximum, _minimumIterationsBelowMaximum);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
index 1a20251d..c43f6072 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
@@ -855,7 +855,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(_nonZeroValues[i]);
#else
hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i]);
diff --git a/src/Numerics/LinearAlgebra/Double/SparseVector.cs b/src/Numerics/LinearAlgebra/Double/SparseVector.cs
index fb2c9d5f..dc142180 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseVector.cs
@@ -1149,7 +1149,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(0, NonZerosCount, (index, localData) => Math.Max(localData, Math.Abs(_nonZeroValues[index])), Math.Max);
+ return CommonParallel.Aggregate(0, NonZerosCount, i => Math.Abs(_nonZeroValues[i]), Math.Max, 0d);
}
var sum = 0.0;
@@ -1466,7 +1466,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(this._nonZeroValues[i].GetHashCode());
#else
hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].GetHashCode());
diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs
index da12ab27..9098a52d 100644
--- a/src/Numerics/LinearAlgebra/Double/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Double/Vector.cs
@@ -318,11 +318,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(
- 0,
- Count,
- (index, localData) => Math.Max(localData, Math.Abs(At(index))),
- Math.Max);
+ return CommonParallel.Aggregate(0, Count, i => Math.Abs(At(i)), Math.Max, 0d);
}
var sum = 0.0;
diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.cs
index de09f0b8..1c0ed835 100644
--- a/src/Numerics/LinearAlgebra/Generic/Matrix.cs
+++ b/src/Numerics/LinearAlgebra/Generic/Matrix.cs
@@ -41,7 +41,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// Supported data types are double, single, , and .
[Serializable]
public abstract partial class Matrix :
-#if SILVERLIGHT
+#if PORTABLE
IFormattable, IEquatable>
#else
IFormattable, IEquatable>, ICloneable
@@ -1335,7 +1335,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
#region Implemented Interfaces
-#if !SILVERLIGHT
+#if !PORTABLE
#region ICloneable
@@ -1493,7 +1493,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
var col = i % ColumnCount;
var row = (i - col) / RowCount;
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(this[row, col].GetHashCode());
#else
hash ^= BitConverter.DoubleToInt64Bits(this[row, col].GetHashCode());
diff --git a/src/Numerics/LinearAlgebra/Generic/Vector.cs b/src/Numerics/LinearAlgebra/Generic/Vector.cs
index 717ee750..9a005a19 100644
--- a/src/Numerics/LinearAlgebra/Generic/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Generic/Vector.cs
@@ -42,7 +42,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// Supported data types are double, single, , and .
[Serializable]
public abstract class Vector :
-#if SILVERLIGHT
+#if PORTABLE
IFormattable, IEnumerable, IEquatable>
#else
IFormattable, IEnumerable, IEquatable>, ICloneable
@@ -1391,7 +1391,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
#region Implemented Interfaces
-#if !SILVERLIGHT
+#if !PORTABLE
#region ICloneable
@@ -1583,7 +1583,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(this[i].GetHashCode());
#else
hash ^= BitConverter.DoubleToInt64Bits(this[i].GetHashCode());
diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs
index 915da6df..2a1cc810 100644
--- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs
@@ -942,11 +942,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(
- 0,
- Count,
- (index, localData) => Math.Max(localData, Math.Abs(Data[index])),
- Common.Max);
+ return CommonParallel.Aggregate(Data, (i, v) => Math.Abs(v), Math.Max, 0f);
}
var sum = 0.0;
diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
index de0bb4c0..946817bb 100644
--- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
@@ -267,7 +267,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(Data[i]);
#else
hash ^= BitConverter.DoubleToInt64Bits(Data[i]);
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs
index 446a02ed..e4f30b7b 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs
@@ -38,7 +38,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// Defines the base interface for iterators that help control an iterative calculation.
///
public interface IIterator
-#if !SILVERLIGHT
+#if !PORTABLE
: ICloneable
#endif
{
@@ -101,7 +101,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
///
void ResetToPrecalculationState();
-#if SILVERLIGHT
+#if PORTABLE
IIterator Clone();
#endif
}
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs
index fd1c1614..6005d94d 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs
@@ -93,7 +93,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
///
private static readonly ICalculationStatus RunningStatus = new CalculationRunning();
-#if SILVERLIGHT
+#if PORTABLE
private static readonly Dictionary> SolverSetups = new Dictionary>();
#else
///
@@ -122,6 +122,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
LoadSolverInformationFromAssembly(Assembly.GetExecutingAssembly(), typesToExclude);
}
+#if !PORTABLE
///
/// Loads the available objects from the assembly specified by the file location.
///
@@ -168,6 +169,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
// Now we can load the solver information.
LoadSolverInformationFromAssembly(assembly, typesToExclude);
}
+#endif
///
/// Loads the available objects from the assembly specified by the assembly name.
@@ -288,6 +290,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
{
continue;
}
+#if !PORTABLE
catch (MethodAccessException)
{
continue;
@@ -296,6 +299,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
{
continue;
}
+#endif
catch (MemberAccessException)
{
continue;
@@ -553,7 +557,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
throw new Exception("IIterativeSolverSetup objects not found");
}
-#if SILVERLIGHT
+#if PORTABLE
foreach (var setup in SolverSetups.OrderBy(solver => solver.Key, new DoubleComparer()).Select(pair => pair.Value).SelectMany(setups => setups))
#else
foreach (var setup in SolverSetups.Select(pair => pair.Value).SelectMany(setups => setups))
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs
index f2fe30c6..7d07607e 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs
@@ -311,7 +311,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
return new Iterator(stopCriteria);
}
- #if !SILVERLIGHT
+#if !PORTABLE
///
/// Creates a deep clone of the current iterator.
///
@@ -320,6 +320,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
{
return Clone();
}
- #endif
+#endif
}
}
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs
index f9ee03f6..c9dc9aa5 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs
@@ -378,7 +378,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium
return new DivergenceStopCriterium(_maximumRelativeIncrease, _minimumNumberOfIterations);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clone this object
///
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs
index e8408fcd..12cfa6ab 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs
@@ -186,7 +186,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium
return new FailureStopCriterium();
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs
index 4125546e..0ff9d0ce 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs
@@ -34,7 +34,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium
/// The base interface for classes that provide stop criteria for iterative calculations.
///
public interface IIterationStopCriterium
-#if !SILVERLIGHT
+#if !PORTABLE
: ICloneable
#endif
{
@@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium
///
StopLevel StopLevel { get; }
-#if SILVERLIGHT
+#if PORTABLE
IIterationStopCriterium Clone();
#endif
}
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs
index e82fb1a0..5f4126b3 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs
@@ -212,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium
return new IterationCountStopCriterium(_maximumNumberOfIterations);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs
index 78ce43b6..54e98cd8 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs
@@ -394,7 +394,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium
return new ResidualStopCriterium(_maximum, _minimumIterationsBelowMaximum);
}
-#if !SILVERLIGHT
+#if !PORTABLE
///
/// Clones the current and its settings.
///
diff --git a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
index 2f02cb9e..78d47de6 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
@@ -838,7 +838,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(_nonZeroValues[i]);
#else
hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i]);
diff --git a/src/Numerics/LinearAlgebra/Single/SparseVector.cs b/src/Numerics/LinearAlgebra/Single/SparseVector.cs
index 5d036854..5333d290 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseVector.cs
@@ -1159,7 +1159,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (Double.IsPositiveInfinity(p))
{
- return CommonParallel.Select(0, NonZerosCount, (index, localData) => Math.Max(localData, Math.Abs(_nonZeroValues[index])), Common.Max);
+ return CommonParallel.Aggregate(0, NonZerosCount, i => Math.Abs(_nonZeroValues[i]), Math.Max, 0f);
}
var sum = 0.0;
@@ -1476,7 +1476,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
long hash = 0;
for (var i = 0; i < hashNum; i++)
{
-#if SILVERLIGHT
+#if PORTABLE
hash ^= Precision.DoubleToInt64Bits(this._nonZeroValues[i].GetHashCode());
#else
hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].GetHashCode());
diff --git a/src/Numerics/LinearAlgebra/Single/Vector.cs b/src/Numerics/LinearAlgebra/Single/Vector.cs
index 2dfcdea8..f5655156 100644
--- a/src/Numerics/LinearAlgebra/Single/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Single/Vector.cs
@@ -319,11 +319,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (float.IsPositiveInfinity((float)p))
{
- return CommonParallel.Select(
- 0,
- Count,
- (index, localData) => Math.Max(localData, Math.Abs(At(index))),
- Common.Max);
+ return CommonParallel.Aggregate(0, Count, i => Math.Abs(At(i)), Math.Max, 0f);
}
var sum = 0.0;
diff --git a/src/Numerics/NumberTheory/IntegerTheory.Euclid.Big.cs b/src/Numerics/NumberTheory/IntegerTheory.Euclid.Big.cs
index 685efc54..aec35941 100644
--- a/src/Numerics/NumberTheory/IntegerTheory.Euclid.Big.cs
+++ b/src/Numerics/NumberTheory/IntegerTheory.Euclid.Big.cs
@@ -28,13 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+#if SYSNUMERICS
namespace MathNet.Numerics.NumberTheory
{
using System;
using System.Collections.Generic;
using System.Numerics;
- ///
+ ///
/// Number theory utility functions for integers.
///
public static partial class IntegerTheory
@@ -47,7 +48,7 @@ namespace MathNet.Numerics.NumberTheory
/// Greatest common divisor gcd(a,b)
public static BigInteger GreatestCommonDivisor(BigInteger a, BigInteger b)
{
- return BigInteger.GreatestCommonDivisor(a, b);
+ return BigInteger.GreatestCommonDivisor(a, b);
}
///
@@ -55,7 +56,7 @@ namespace MathNet.Numerics.NumberTheory
///
/// List of Integers.
/// Greatest common divisor gcd(list of integers)
- public static BigInteger GreatestCommonDivisor(IList integers)
+ public static BigInteger GreatestCommonDivisor(IList integers)
{
if (null == integers)
{
@@ -82,114 +83,115 @@ namespace MathNet.Numerics.NumberTheory
///
/// List of Integers.
/// Greatest common divisor gcd(list of integers)
- public static BigInteger GreatestCommonDivisor(params BigInteger[] integers)
+ public static BigInteger GreatestCommonDivisor(params BigInteger[] integers)
{
- return GreatestCommonDivisor((IList)integers);
+ return GreatestCommonDivisor((IList)integers);
}
- ///
- /// Computes the extended greatest common divisor, such that a*x + b*y = gcd(a,b).
- ///
- /// First Integer: a.
- /// Second Integer: b.
- /// Resulting x, such that a*x + b*y = gcd(a,b).
- /// Resulting y, such that a*x + b*y = gcd(a,b)
- /// Greatest common divisor gcd(a,b)
- ///
- ///
- /// long x,y,d;
- /// d = Fn.GreatestCommonDivisor(45,18,out x, out y);
- /// -> d == 9 && x == 1 && y == -2
- ///
- /// The gcd of 45 and 18 is 9: 18 = 2*9, 45 = 5*9. 9 = 1*45 -2*18, therefore x=1 and y=-2.
- ///
- public static BigInteger ExtendedGreatestCommonDivisor(
- BigInteger a,
- BigInteger b,
- out BigInteger x,
- out BigInteger y)
- {
- BigInteger mp = BigInteger.One, np = BigInteger.Zero, m = BigInteger.Zero, n = BigInteger.One;
-
- while (!b.IsZero)
- {
- BigInteger rem;
- BigInteger quot = BigInteger.DivRem(a, b, out rem);
- a = b;
- b = rem;
-
- BigInteger tmp = m;
- m = mp - (quot * m);
- mp = tmp;
-
- tmp = n;
- n = np - (quot * n);
- np = tmp;
- }
-
- if (a >= BigInteger.Zero)
- {
- x = mp;
- y = np;
- return a;
- }
-
- x = -mp;
- y = -np;
- return -a;
- }
-
- ///
- /// Returns the least common multiple (lcm) of two big integers.
- ///
- /// First Integer: a.
- /// Second Integer: b.
- /// Least common multiple lcm(a,b)
- public static BigInteger LeastCommonMultiple(BigInteger a, BigInteger b)
- {
- if (a.IsZero || b.IsZero)
- {
- return BigInteger.Zero;
- }
-
- return BigInteger.Abs((a / BigInteger.GreatestCommonDivisor(a, b)) * b);
- }
-
- ///
- /// Returns the least common multiple (lcm) of a set of big integers.
- ///
- /// List of Integers.
- /// Least common multiple lcm(list of integers)
- public static BigInteger LeastCommonMultiple(IList integers)
- {
- if (null == integers)
- {
- throw new ArgumentNullException("integers");
- }
-
- if (integers.Count == 0)
- {
- return 1;
- }
-
- var lcm = BigInteger.Abs(integers[0]);
-
- for (int i = 1; i < integers.Count; i++)
- {
- lcm = LeastCommonMultiple(lcm, integers[i]);
- }
-
- return lcm;
- }
-
- ///
- /// Returns the least common multiple (lcm) of a set of big integers.
- ///
- /// List of Integers.
- /// Least common multiple lcm(list of integers)
- public static BigInteger LeastCommonMultiple(params BigInteger[] integers)
- {
- return LeastCommonMultiple((IList)integers);
- }
- }
+ ///
+ /// Computes the extended greatest common divisor, such that a*x + b*y = gcd(a,b).
+ ///
+ /// First Integer: a.
+ /// Second Integer: b.
+ /// Resulting x, such that a*x + b*y = gcd(a,b).
+ /// Resulting y, such that a*x + b*y = gcd(a,b)
+ /// Greatest common divisor gcd(a,b)
+ ///
+ ///
+ /// long x,y,d;
+ /// d = Fn.GreatestCommonDivisor(45,18,out x, out y);
+ /// -> d == 9 && x == 1 && y == -2
+ ///
+ /// The gcd of 45 and 18 is 9: 18 = 2*9, 45 = 5*9. 9 = 1*45 -2*18, therefore x=1 and y=-2.
+ ///
+ public static BigInteger ExtendedGreatestCommonDivisor(
+ BigInteger a,
+ BigInteger b,
+ out BigInteger x,
+ out BigInteger y)
+ {
+ BigInteger mp = BigInteger.One, np = BigInteger.Zero, m = BigInteger.Zero, n = BigInteger.One;
+
+ while (!b.IsZero)
+ {
+ BigInteger rem;
+ BigInteger quot = BigInteger.DivRem(a, b, out rem);
+ a = b;
+ b = rem;
+
+ BigInteger tmp = m;
+ m = mp - (quot * m);
+ mp = tmp;
+
+ tmp = n;
+ n = np - (quot * n);
+ np = tmp;
+ }
+
+ if (a >= BigInteger.Zero)
+ {
+ x = mp;
+ y = np;
+ return a;
+ }
+
+ x = -mp;
+ y = -np;
+ return -a;
+ }
+
+ ///
+ /// Returns the least common multiple (lcm) of two big integers.
+ ///
+ /// First Integer: a.
+ /// Second Integer: b.
+ /// Least common multiple lcm(a,b)
+ public static BigInteger LeastCommonMultiple(BigInteger a, BigInteger b)
+ {
+ if (a.IsZero || b.IsZero)
+ {
+ return BigInteger.Zero;
+ }
+
+ return BigInteger.Abs((a / BigInteger.GreatestCommonDivisor(a, b)) * b);
+ }
+
+ ///
+ /// Returns the least common multiple (lcm) of a set of big integers.
+ ///
+ /// List of Integers.
+ /// Least common multiple lcm(list of integers)
+ public static BigInteger LeastCommonMultiple(IList integers)
+ {
+ if (null == integers)
+ {
+ throw new ArgumentNullException("integers");
+ }
+
+ if (integers.Count == 0)
+ {
+ return 1;
+ }
+
+ var lcm = BigInteger.Abs(integers[0]);
+
+ for (int i = 1; i < integers.Count; i++)
+ {
+ lcm = LeastCommonMultiple(lcm, integers[i]);
+ }
+
+ return lcm;
+ }
+
+ ///
+ /// Returns the least common multiple (lcm) of a set of big integers.
+ ///
+ /// List of Integers.
+ /// Least common multiple lcm(list of integers)
+ public static BigInteger LeastCommonMultiple(params BigInteger[] integers)
+ {
+ return LeastCommonMultiple((IList)integers);
+ }
+ }
}
+#endif
diff --git a/src/Numerics/NumberTheory/IntegerTheory.Euclid.cs b/src/Numerics/NumberTheory/IntegerTheory.Euclid.cs
index de3b2b1b..6b04d2fe 100644
--- a/src/Numerics/NumberTheory/IntegerTheory.Euclid.cs
+++ b/src/Numerics/NumberTheory/IntegerTheory.Euclid.cs
@@ -117,8 +117,9 @@ namespace MathNet.Numerics.NumberTheory
while (b != 0)
{
long rem;
-#if SILVERLIGHT
- var quot = SilverlightUtilities.DivRem(a, b, out rem);
+#if PORTABLE
+ rem = a / b;
+ var quot = a % b;
#else
long quot = Math.DivRem(a, b, out rem);
#endif
diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj
index 7674503f..36a3c06e 100644
--- a/src/Numerics/Numerics.csproj
+++ b/src/Numerics/Numerics.csproj
@@ -40,7 +40,7 @@
full
false
..\..\out\debug\Net40\
- TRACE;DEBUG
+ TRACE;DEBUG;SYSNUMERICS
prompt
4
@@ -51,7 +51,7 @@
pdbonly
true
..\..\out\lib\Net40\
- TRACE
+ TRACE;SYSNUMERICS
prompt
4
..\..\out\lib\Net40\MathNet.Numerics.xml
@@ -96,6 +96,7 @@
+
@@ -394,6 +395,7 @@
+
diff --git a/src/Numerics/Permutation.cs b/src/Numerics/Permutation.cs
index bc1abf14..0e5d93fb 100644
--- a/src/Numerics/Permutation.cs
+++ b/src/Numerics/Permutation.cs
@@ -149,7 +149,7 @@ namespace MathNet.Numerics
{
if (idx[i] != i)
{
-#if !SILVERLIGHT
+#if !PORTABLE
int q = Array.FindIndex(idx, i + 1, x => x == i);
#else
int q = -1;
diff --git a/src/Numerics/Precision.cs b/src/Numerics/Precision.cs
index 16af911b..25ab0844 100644
--- a/src/Numerics/Precision.cs
+++ b/src/Numerics/Precision.cs
@@ -186,14 +186,14 @@ namespace MathNet.Numerics
// truncating a negative number will give us a magnitude that is off by 1
if (magnitude < 0)
{
-#if SILVERLIGHT
+#if PORTABLE
return (int)Truncate(magnitude - 1);
#else
return (int)Math.Truncate(magnitude - 1);
#endif
}
-#if SILVERLIGHT
+#if PORTABLE
return (int)Truncate(magnitude);
#else
return (int)Math.Truncate(magnitude);
@@ -223,14 +223,14 @@ namespace MathNet.Numerics
// truncating a negative number will give us a magnitude that is off by 1
if (magnitude < 0)
{
-#if SILVERLIGHT
+#if PORTABLE
return (int)Truncate(magnitude - 1);
#else
return (int)Math.Truncate(magnitude - 1);
#endif
}
-#if SILVERLIGHT
+#if PORTABLE
return (int)Truncate(magnitude);
#else
return (int)Math.Truncate(magnitude);
@@ -261,7 +261,7 @@ namespace MathNet.Numerics
///
private static long GetLongFromDouble(double value)
{
-#if SILVERLIGHT
+#if PORTABLE
return DoubleToInt64Bits(value);
#else
return BitConverter.DoubleToInt64Bits(value);
@@ -364,7 +364,7 @@ namespace MathNet.Numerics
// Note that not all long values can be translated into double values. There's a whole bunch of them
// which return weird values like infinity and NaN
-#if SILVERLIGHT
+#if PORTABLE
return Int64BitsToDouble(intValue);
#else
return BitConverter.Int64BitsToDouble(intValue);
@@ -434,7 +434,7 @@ namespace MathNet.Numerics
// Note that not all long values can be translated into double values. There's a whole bunch of them
// which return weird values like infinity and NaN
-#if SILVERLIGHT
+#if PORTABLE
return Int64BitsToDouble(intValue);
#else
return BitConverter.Int64BitsToDouble(intValue);
@@ -581,7 +581,7 @@ namespace MathNet.Numerics
// Got underflow, which can be fixed by splitting the calculation into two bits
// first get the remainder of the intValue after subtracting it from the long.MinValue
// and add that to the ulpsDifference. That way we'll turn positive without underflow
-#if SILVERLIGHT
+#if PORTABLE
topRangeEnd =Int64BitsToDouble(maxNumbersBetween + (long.MinValue - intValue));
#else
topRangeEnd = BitConverter.Int64BitsToDouble(maxNumbersBetween + (long.MinValue - intValue));
@@ -590,7 +590,7 @@ namespace MathNet.Numerics
else
{
// No problems here, move along.
-#if SILVERLIGHT
+#if PORTABLE
topRangeEnd = Int64BitsToDouble(intValue - maxNumbersBetween);
#else
topRangeEnd = BitConverter.Int64BitsToDouble(intValue - maxNumbersBetween);
@@ -607,7 +607,7 @@ namespace MathNet.Numerics
{
// intValue is negative. Adding the positive ulpsDifference means that it gets less negative.
// However due to the conversion way this means that the actual double value gets more negative :-S
-#if SILVERLIGHT
+#if PORTABLE
bottomRangeEnd =Int64BitsToDouble(intValue + maxNumbersBetween);
#else
bottomRangeEnd = BitConverter.Int64BitsToDouble(intValue + maxNumbersBetween);
@@ -626,7 +626,7 @@ namespace MathNet.Numerics
else
{
// No troubles here
-#if SILVERLIGHT
+#if PORTABLE
topRangeEnd = Int64BitsToDouble(intValue + maxNumbersBetween);
#else
topRangeEnd = BitConverter.Int64BitsToDouble(intValue + maxNumbersBetween);
@@ -638,7 +638,7 @@ namespace MathNet.Numerics
{
// No problems here. IntValue is larger than ulpsDifference so we'll end up with a
// positive number.
-#if SILVERLIGHT
+#if PORTABLE
bottomRangeEnd =Int64BitsToDouble(intValue - maxNumbersBetween);
#else
bottomRangeEnd = BitConverter.Int64BitsToDouble(intValue - maxNumbersBetween);
@@ -648,7 +648,7 @@ namespace MathNet.Numerics
{
// Int value is bigger than zero but smaller than the ulpsDifference. So we'll need to deal with
// the reversal at the negative end
-#if SILVERLIGHT
+#if PORTABLE
bottomRangeEnd = Int64BitsToDouble(long.MinValue + (maxNumbersBetween - intValue));
#else
bottomRangeEnd = BitConverter.Int64BitsToDouble(long.MinValue + (maxNumbersBetween - intValue));
@@ -1772,7 +1772,7 @@ namespace MathNet.Numerics
return double.NaN;
}
-#if SILVERLIGHT
+#if PORTABLE
long signed64 = DoubleToInt64Bits(value);
#else
long signed64 = BitConverter.DoubleToInt64Bits(value);
@@ -1781,7 +1781,7 @@ namespace MathNet.Numerics
if (signed64 == 0)
{
signed64++;
-#if SILVERLIGHT
+#if PORTABLE
return Int64BitsToDouble(signed64) - value;
#else
return BitConverter.Int64BitsToDouble(signed64) - value;
@@ -1790,14 +1790,14 @@ namespace MathNet.Numerics
if (signed64-- < 0)
{
-#if SILVERLIGHT
+#if PORTABLE
return Int64BitsToDouble(signed64) - value;
#else
return BitConverter.Int64BitsToDouble(signed64) - value;
#endif
}
-#if SILVERLIGHT
+#if PORTABLE
return value - Int64BitsToDouble(signed64);
#else
return value - BitConverter.Int64BitsToDouble(signed64);
@@ -1826,7 +1826,7 @@ namespace MathNet.Numerics
return BitConverter.ToInt32(BitConverter.GetBytes(value), 0);
}
-#if SILVERLIGHT
+#if PORTABLE
internal static long DoubleToInt64Bits(double value)
{
return BitConverter.ToInt64(BitConverter.GetBytes(value), 0);
diff --git a/src/Numerics/Properties/Resources1.Designer.cs b/src/Numerics/Properties/Resources1.Designer.cs
index 5ba402b7..be1a723f 100644
--- a/src/Numerics/Properties/Resources1.Designer.cs
+++ b/src/Numerics/Properties/Resources1.Designer.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.488
+// Runtime Version:4.0.30319.269
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
diff --git a/src/Numerics/Random/SystemCrypto.cs b/src/Numerics/Random/SystemCrypto.cs
index f99f4c81..96234201 100644
--- a/src/Numerics/Random/SystemCrypto.cs
+++ b/src/Numerics/Random/SystemCrypto.cs
@@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
-// Copyright (c) 2009-2010 Math.NET
+// Copyright (c) 2009-2012 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -28,6 +28,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+#if !PORTABLE
namespace MathNet.Numerics.Random
{
using System;
@@ -97,4 +98,5 @@ namespace MathNet.Numerics.Random
return BitConverter.ToUInt32(bytes, 0) * mReciprocal;
}
}
-}
\ No newline at end of file
+}
+#endif
diff --git a/src/Numerics/SerializableAttribute.cs b/src/Numerics/SerializableAttribute.cs
new file mode 100644
index 00000000..adbcf375
--- /dev/null
+++ b/src/Numerics/SerializableAttribute.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace MathNet.Numerics
+{
+#if PORTABLE
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
+ public class SerializableAttribute : Attribute
+ {
+ }
+#endif
+}
diff --git a/src/Numerics/Sorting.cs b/src/Numerics/Sorting.cs
index 16432304..e8e79f53 100644
--- a/src/Numerics/Sorting.cs
+++ b/src/Numerics/Sorting.cs
@@ -165,6 +165,7 @@ namespace MathNet.Numerics
throw new ArgumentNullException("comparer");
}
+#if !PORTABLE
// array case
var keysArray = keys as TKey[];
var itemsArray = items as TItem[];
@@ -173,6 +174,7 @@ namespace MathNet.Numerics
Array.Sort(keysArray, itemsArray, comparer);
return;
}
+#endif
// local sort implementation
QuickSort(keys, items, comparer, 0, keys.Count - 1);
diff --git a/src/Numerics/Statistics/Histogram.cs b/src/Numerics/Statistics/Histogram.cs
index 465147d8..1c438ee2 100644
--- a/src/Numerics/Statistics/Histogram.cs
+++ b/src/Numerics/Statistics/Histogram.cs
@@ -41,7 +41,7 @@ namespace MathNet.Numerics.Statistics
///
[Serializable]
public class Bucket :
-#if SILVERLIGHT
+#if PORTABLE
IComparable
#else
IComparable, ICloneable
diff --git a/src/Numerics/Threading/CommonParallel.cs b/src/Numerics/Threading/CommonParallel.cs
index 25a45d8b..70050612 100644
--- a/src/Numerics/Threading/CommonParallel.cs
+++ b/src/Numerics/Threading/CommonParallel.cs
@@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
-// Copyright (c) 2009-2011 Math.NET
+// Copyright (c) 2009-2012 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -31,10 +31,14 @@
namespace MathNet.Numerics.Threading
{
using System;
+ using System.Threading.Tasks;
-#if !SILVERLIGHT
+#if !PORTABLE
using System.Collections.Concurrent;
- using System.Threading.Tasks;
+ using System.Collections.Generic;
+#else
+ using System.Linq;
+ using MathNet.Numerics.Properties;
#endif
///
@@ -43,7 +47,7 @@ namespace MathNet.Numerics.Threading
public static class CommonParallel
{
///
- /// Executes a for loop in which iterations may run in parallel.
+ /// Executes a for loop in which iterations may run in parallel.
///
/// The start index, inclusive.
/// The end index, exclusive.
@@ -52,26 +56,11 @@ namespace MathNet.Numerics.Threading
/// At least one invocation of the body threw an exception.
public static void For(int fromInclusive, int toExclusive, Action body)
{
- var parallel = true;
- if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
+ if (body == null)
{
- parallel = false;
+ throw new ArgumentNullException("body");
}
- For(fromInclusive, toExclusive, body, parallel);
- }
-
- ///
- /// Executes a for loop in which iterations may run in parallel.
- ///
- /// The start index, inclusive.
- /// The end index, exclusive.
- /// The body to be invoked for each iteration.
- /// Use multiple threads.
- /// The argument is null.
- /// At least one invocation of the body threw an exception.
- public static void For(int fromInclusive, int toExclusive, Action body, bool parallel)
- {
// Special case: no action
if (fromInclusive >= toExclusive)
{
@@ -85,286 +74,154 @@ namespace MathNet.Numerics.Threading
return;
}
- // Common case
- if (parallel)
- {
-#if SILVERLIGHT
- Parallel.For(fromInclusive, toExclusive, body);
-#else
- Parallel.ForEach(
- Partitioner.Create(fromInclusive, toExclusive),
- new ParallelOptions
- {
- MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads
- },
- (range, loopState) =>
- {
- for (var i = range.Item1; i < range.Item2; i++)
- {
- body(i);
- }
- });
-#endif
- }
- else
+ // Special case: straight execution without parallelism
+ if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
{
for (var index = fromInclusive; index < toExclusive; index++)
{
body(index);
}
+ return;
}
- }
-/* ///
- /// Aggregates a function over a loop.
- ///
- /// Starting index of the loop.
- /// Ending index of the loop
- /// The function to aggregate.
- /// The sum of the function over the loop.
- public static double Aggregate(int fromInclusive, int toExclusive, Func body)
- {
- var sync = new object();
- var sum = 0.0;
-
-#if SILVERLIGHT
- Parallel.For(
- fromInclusive,
- toExclusive,
- () => 0.0,
- (i, localData) => localData += body(i),
- localResult =>
- {
- lock (sync)
- {
- sum += localResult;
- }
- });
-#else
+ // Common case
+#if PORTABLE
+ var tasks = new Task[Control.NumberOfParallelWorkerThreads];
+ var size = (toExclusive - fromInclusive) / tasks.Length;
- if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
- {
- for (var index = fromInclusive; index < toExclusive; index++)
- {
- sum += body(index);
- }
- }
- else
+ // partition the jobs into separate sets for each but the last worked thread
+ for (var i = 0; i < tasks.Length - 1; i++)
{
- Parallel.ForEach(
- Partitioner.Create(fromInclusive, toExclusive),
- new ParallelOptions { MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads },
- () => 0.0,
- (range, loopState, localData) =>
- {
- for (var i = range.Item1; i < range.Item2; i++)
- {
- localData += body(i);
- }
+ var start = fromInclusive + (i * size);
+ var stop = fromInclusive + ((i + 1) * size);
- return localData;
- },
- localResult =>
+ tasks[i] = Task.Factory.StartNew(() =>
{
- lock (sync)
+ for (int j = start; j < stop; j++)
{
- sum += localResult;
+ body(j);
}
});
}
-#endif
- return sum;
- }
- ///
- /// Aggregates a function over a loop.
- ///
- /// Starting index of the loop.
- /// Ending index of the loop
- /// The function to aggregate.
- /// The sum of the function over the loop.
- public static float Aggregate(int fromInclusive, int toExclusive, Func body)
- {
- var sync = new object();
- var sum = 0.0f;
-
-#if SILVERLIGHT
- Parallel.For(
- fromInclusive,
- toExclusive,
- () => 0.0f,
- (i, localData) => localData += body(i),
- localResult =>
+ // add another set for last worker thread
+ tasks[tasks.Length - 1] = Task.Factory.StartNew(() =>
{
- lock (sync)
+ for (int j = fromInclusive + ((tasks.Length - 1) * size); j < toExclusive; j++)
{
- sum += localResult;
+ body(j);
}
});
-#else
- if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
- {
- for (var index = fromInclusive; index < toExclusive; index++)
+ Task.WaitAll(tasks);
+#else
+ Parallel.ForEach(
+ Partitioner.Create(fromInclusive, toExclusive),
+ new ParallelOptions
{
- sum += body(index);
- }
- }
- else
- {
- Parallel.ForEach(
- Partitioner.Create(fromInclusive, toExclusive),
- new ParallelOptions { MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads },
- () => 0.0f,
- (range, loopState, localData) =>
- {
- for (var i = range.Item1; i < range.Item2; i++)
- {
- localData += body(i);
- }
-
- return localData;
- },
- localResult =>
+ MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads
+ },
+ (range, loopState) =>
+ {
+ for (var i = range.Item1; i < range.Item2; i++)
{
- lock (sync)
- {
- sum += localResult;
- }
- });
- }
+ body(i);
+ }
+ });
#endif
- return sum;
}
///
- /// Aggregates a function over a loop for Complex data type.
+ /// Executes a for loop in which iterations may run in parallel.
///
- /// Starting index of the loop.
- /// Ending index of the loop
- /// The function to aggregate.
- /// The sum of the function over the loop.
- public static Complex Aggregate(int fromInclusive, int toExclusive, Func body)
+ /// The array to iterate over.
+ /// The body to be invoked for each iteration.
+ /// The argument is null.
+ /// At least one invocation of the body threw an exception.
+ public static void For(T[] array, Action body)
{
- var sync = new object();
- var sum = Complex.Zero;
-
-#if SILVERLIGHT
- Parallel.For(
- fromInclusive,
- toExclusive,
- () => Complex.Zero,
- (i, localData) => localData += body(i),
- localResult =>
- {
- lock (sync)
- {
- sum += localResult;
- }
- });
-#else
+ if (body == null)
+ {
+ throw new ArgumentNullException("body");
+ }
+
+ // Special case: no action
+ if (array == null || array.Length == 0)
+ {
+ return;
+ }
+ // Special case: single action, inline
+ if (array.Length == 0)
+ {
+ body(0, array[0]);
+ return;
+ }
+
+ // Special case: straight execution without parallelism
if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
{
- for (var index = fromInclusive; index < toExclusive; index++)
+ // efficient since the compiler can drop the range checks
+ for (int i = 0; i < array.Length; i++)
{
- sum += body(index);
+ body(i, array[i]);
}
+ return;
}
- else
+
+ // Common case
+#if PORTABLE
+ var tasks = new Task[Control.NumberOfParallelWorkerThreads];
+ var size = array.Length / tasks.Length;
+
+ // partition the jobs into separate sets for each but the last worked thread
+ for (var i1 = 0; i1 < tasks.Length - 1; i1++)
{
- Parallel.ForEach(
- Partitioner.Create(fromInclusive, toExclusive),
- new ParallelOptions { MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads },
- () => Complex.Zero,
- (range, loopState, localData) =>
- {
- for (var i = range.Item1; i < range.Item2; i++)
- {
- localData += body(i);
- }
+ var start = (i1 * size);
+ var stop = ((i1 + 1) * size);
- return localData;
- },
- localResult =>
+ tasks[i1] = Task.Factory.StartNew(() =>
{
- lock (sync)
+ for (int j = start; j < stop; j++)
{
- sum += localResult;
+ body(j, array[j]);
}
});
}
-#endif
- return sum;
- }
- ///
- /// Aggregates a function over a loop for Complex32 data type.
- ///
- /// Starting index of the loop.
- /// Ending index of the loop
- /// The function to aggregate.
- /// The sum of the function over the loop.
- public static Complex32 Aggregate(int fromInclusive, int toExclusive, Func body)
- {
- var sync = new object();
- var sum = Complex32.Zero;
-
-#if SILVERLIGHT
- Parallel.For(
- fromInclusive,
- toExclusive,
- () => Complex32.Zero,
- (i, localData) => localData += body(i),
- localResult =>
+ // add another set for last worker thread
+ tasks[tasks.Length - 1] = Task.Factory.StartNew(() =>
{
- lock (sync)
+ for (int j = ((tasks.Length - 1) * size); j < array.Length; j++)
{
- sum += localResult;
+ body(j, array[j]);
}
});
-#else
- if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
- {
- for (var index = fromInclusive; index < toExclusive; index++)
+ Task.WaitAll(tasks);
+#else
+ Parallel.ForEach(
+ Partitioner.Create(0, array.Length),
+ new ParallelOptions
{
- sum += body(index);
- }
- }
- else
- {
- Parallel.ForEach(
- Partitioner.Create(fromInclusive, toExclusive),
- new ParallelOptions { MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads },
- () => Complex32.Zero,
- (range, loopState, localData) =>
- {
- for (var i = range.Item1; i < range.Item2; i++)
- {
- localData += body(i);
- }
-
- return localData;
- },
- localResult =>
+ MaxDegreeOfParallelism = Control.NumberOfParallelWorkerThreads
+ },
+ (range, loopState) =>
+ {
+ for (var i = range.Item1; i < range.Item2; i++)
{
- lock (sync)
- {
- sum += localResult;
- }
- });
- }
+ body(i, array[i]);
+ }
+ });
#endif
- return sum;
- }*/
+ }
///
/// Executes each of the provided actions inside a discrete, asynchronous task.
///
/// An array of actions to execute.
/// The actions array contains a null element.
- /// An action threw an exception.
+ /// At least one invocation of the actions threw an exception.
public static void Invoke(params Action[] actions)
{
// Special case: no action
@@ -381,10 +238,21 @@ namespace MathNet.Numerics.Threading
}
// Common case
- var maxThreads = Control.DisableParallelization ? 1 : Control.NumberOfParallelWorkerThreads;
-#if SILVERLIGHT
- Parallel.Invoke(actions);
+#if PORTABLE
+ var tasks = new Task[actions.Length];
+ for (var i = 0; i < tasks.Length; i++)
+ {
+ Action action = actions[i];
+ if (action == null)
+ {
+ throw new ArgumentException(String.Format(Resources.ArgumentItemNull, "actions"), "actions");
+ }
+
+ tasks[i] = Task.Factory.StartNew(action);
+ }
+ Task.WaitAll(tasks);
#else
+ var maxThreads = Control.DisableParallelization ? 1 : Control.NumberOfParallelWorkerThreads;
Parallel.Invoke(
new ParallelOptions
{
@@ -399,105 +267,275 @@ namespace MathNet.Numerics.Threading
///
/// Starting index of the loop.
/// Ending index of the loop
- /// The function to select items over a subset.
- /// The function to select the item of selection from the subsets.
+ /// The function to select items over a subset.
+ /// The function to select the item of selection from the subsets.
/// The selected value.
- public static double Select(int fromInclusive, int toExclusive, Func body, Func localFinally)
- {
- double ret = 0;
- var syncLock = new object();
+ public static T Aggregate(int fromInclusive, int toExclusive, Func select, Func reduce)
+ {
+ if (select == null)
+ {
+ throw new ArgumentNullException("select");
+ }
+ if (reduce == null)
+ {
+ throw new ArgumentNullException("reduce");
+ }
-#if SILVERLIGHT
- Parallel.For(
- fromInclusive,
- toExclusive,
- () => 0.0,
- (i, localData) => localData = body(i, localData),
- localResult =>
+ // Special case: no action
+ if (fromInclusive >= toExclusive)
+ {
+ return reduce(new T[0]);
+ }
+
+ // Special case: single action, inline
+ if (fromInclusive == (toExclusive - 1))
+ {
+ return reduce(new [] { select(fromInclusive) });
+ }
+
+ // Special case: straight execution without parallelism
+ if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
+ {
+ var mapped = new T[toExclusive - fromInclusive];
+ for (int k = 0; k < mapped.Length; k++)
{
- lock (syncLock)
+ mapped[k] = select(k + fromInclusive);
+ }
+ return reduce(mapped);
+ }
+
+#if PORTABLE
+ var tasks = new Task[Control.NumberOfParallelWorkerThreads];
+ var size = (toExclusive - fromInclusive) / tasks.Length;
+
+ // partition the jobs into separate sets for each but the last worked thread
+ for (var i = 0; i < tasks.Length - 1; i++)
+ {
+ var start = fromInclusive + (i * size);
+ var stop = fromInclusive + ((i + 1) * size);
+
+ tasks[i] = Task.Factory.StartNew(() =>
+ {
+ var mapped = new T[stop - start];
+ for (int k = 0; k < mapped.Length; k++)
+ {
+ mapped[k] = select(k + start);
+ }
+ return reduce(mapped);
+ });
+ }
+
+ // add another set for last worker thread
+ tasks[tasks.Length - 1] = Task.Factory.StartNew(() =>
+ {
+ var start = fromInclusive + ((tasks.Length - 1) * size);
+ var mapped = new T[toExclusive - start];
+ for (int k = 0; k < mapped.Length; k++)
{
- ret = localFinally(ret, localResult);
+ mapped[k] = select(k + start);
}
+ return reduce(mapped);
});
+
+ return Task.Factory
+ .ContinueWhenAll(tasks, tsk => reduce(tsk.Select(t => t.Result).ToArray()))
+ .Result;
#else
+ var intermediateResults = new List();
+ var syncLock = new object();
var maxThreads = Control.DisableParallelization ? 1 : Control.NumberOfParallelWorkerThreads;
Parallel.ForEach(
Partitioner.Create(fromInclusive, toExclusive),
new ParallelOptions { MaxDegreeOfParallelism = maxThreads },
- () => 0.0,
+ () => new List(),
(range, loop, localData) =>
{
- for (var i = range.Item1; i < range.Item2; i++)
+ var mapped = new T[range.Item2 - range.Item1];
+ for (int k = 0; k < mapped.Length; k++)
{
- localData = body(i, localData);
+ mapped[k] = select(k + range.Item1);
}
-
+ localData.Add(reduce(mapped));
return localData;
- },
+ },
localResult =>
{
lock (syncLock)
{
- ret = localFinally(ret, localResult);
+ intermediateResults.Add(reduce(localResult.ToArray()));
}
});
+ return reduce(intermediateResults.ToArray());
#endif
-
- return ret;
- }
+ }
///
/// Selects an item (such as Max or Min).
///
- /// Starting index of the loop.
- /// Ending index of the loop
- /// The function to select items over a subset.
- /// The function to select the item of selection from the subsets.
+ /// The array to iterate over.
+ /// The function to select items over a subset.
+ /// The function to select the item of selection from the subsets.
/// The selected value.
- public static float Select(int fromInclusive, int toExclusive, Func body, Func localFinally)
+ public static U Aggregate(T[] array, Func select, Func reduce)
{
- float ret = 0;
- var syncLock = new object();
+ if (select == null)
+ {
+ throw new ArgumentNullException("select");
+ }
+ if (reduce == null)
+ {
+ throw new ArgumentNullException("reduce");
+ }
-#if SILVERLIGHT
- Parallel.For(
- fromInclusive,
- toExclusive,
- () => 0.0f,
- (i, localData) => localData = body(i, localData),
- localResult =>
+ // Special case: no action
+ if (array == null || array.Length == 0)
+ {
+ return reduce(new U[0]);
+ }
+
+ // Special case: single action, inline
+ if (array.Length == 1)
+ {
+ return reduce(new[] { select(0, array[0]) });
+ }
+
+ // Special case: straight execution without parallelism
+ if (Control.DisableParallelization || Control.NumberOfParallelWorkerThreads < 2)
+ {
+ var mapped = new U[array.Length];
+ for (int k = 0; k < mapped.Length; k++)
{
- lock (syncLock)
+ mapped[k] = select(k, array[k]);
+ }
+ return reduce(mapped);
+ }
+
+#if PORTABLE
+ var tasks = new Task[Control.NumberOfParallelWorkerThreads];
+ var size = array.Length / tasks.Length;
+
+ // partition the jobs into separate sets for each but the last worked thread
+ for (var i = 0; i < tasks.Length - 1; i++)
+ {
+ var start = (i * size);
+ var stop = ((i + 1) * size);
+
+ tasks[i] = Task.Factory.StartNew(() =>
+ {
+ var mapped = new U[stop - start];
+ for (int k = 0; k < mapped.Length; k++)
+ {
+ mapped[k] = select(k + start, array[k + start]);
+ }
+ return reduce(mapped);
+ });
+ }
+
+ // add another set for last worker thread
+ tasks[tasks.Length - 1] = Task.Factory.StartNew(() =>
+ {
+ var start = ((tasks.Length - 1) * size);
+ var mapped = new U[array.Length - start];
+ for (int k = 0; k < mapped.Length; k++)
{
- ret = localFinally(ret, localResult);
+ mapped[k] = select(k + start, array[k + start]);
}
+ return reduce(mapped);
});
+
+ return Task.Factory
+ .ContinueWhenAll(tasks, tsk => reduce(tsk.Select(t => t.Result).ToArray()))
+ .Result;
#else
+ var intermediateResults = new List();
+ var syncLock = new object();
var maxThreads = Control.DisableParallelization ? 1 : Control.NumberOfParallelWorkerThreads;
Parallel.ForEach(
- Partitioner.Create(fromInclusive, toExclusive),
+ Partitioner.Create(0, array.Length),
new ParallelOptions { MaxDegreeOfParallelism = maxThreads },
- () => 0.0f,
+ () => new List(),
(range, loop, localData) =>
{
- for (var i = range.Item1; i < range.Item2; i++)
+ var mapped = new U[range.Item2 - range.Item1];
+ for (int k = 0; k < mapped.Length; k++)
{
- localData = body(i, localData);
+ mapped[k] = select(k + range.Item1, array[k + range.Item1]);
}
-
+ localData.Add(reduce(mapped));
return localData;
},
localResult =>
{
lock (syncLock)
{
- ret = localFinally(ret, localResult);
+ intermediateResults.Add(reduce(localResult.ToArray()));
}
});
+ return reduce(intermediateResults.ToArray());
#endif
+ }
- return ret;
+ ///
+ /// Selects an item (such as Max or Min).
+ ///
+ /// Starting index of the loop.
+ /// Ending index of the loop
+ /// The function to select items over a subset.
+ /// The function to select the item of selection from the subsets.
+ /// Default result of the reduce function on an empty set.
+ /// The selected value.
+ public static T Aggregate(int fromInclusive, int toExclusive, Func select, Func reducePair, T reduceDefault)
+ {
+ return Aggregate(fromInclusive, toExclusive, select, results =>
+ {
+ if (results == null || results.Length == 0)
+ {
+ return reduceDefault;
+ }
+
+ if (results.Length == 1)
+ {
+ return results[0];
+ }
+
+ T result = results[0];
+ for (int i = 1; i < results.Length; i++)
+ {
+ result = reducePair(result, results[i]);
+ }
+ return result;
+ });
+ }
+
+ ///
+ /// Selects an item (such as Max or Min).
+ ///
+ /// The array to iterate over.
+ /// The function to select items over a subset.
+ /// The function to select the item of selection from the subsets.
+ /// Default result of the reduce function on an empty set.
+ /// The selected value.
+ public static U Aggregate(T[] array, Func select, Func reducePair, U reduceDefault)
+ {
+ return Aggregate(array, select, results =>
+ {
+ if (results == null || results.Length == 0)
+ {
+ return reduceDefault;
+ }
+
+ if (results.Length == 1)
+ {
+ return results[0];
+ }
+
+ U result = results[0];
+ for (int i = 1; i < results.Length; i++)
+ {
+ result = reducePair(result, results[i]);
+ }
+ return result;
+ });
}
}
}
\ No newline at end of file
diff --git a/src/Portable/Portable.csproj b/src/Portable/Portable.csproj
new file mode 100644
index 00000000..27eeda98
--- /dev/null
+++ b/src/Portable/Portable.csproj
@@ -0,0 +1,1028 @@
+
+
+
+
+ 10.0
+ Debug
+ AnyCPU
+ {D877F358-A2D2-4CC3-A921-8AA5CF6187E8}
+ Library
+ Properties
+ MathNet.Numerics
+ MathNet.Numerics
+ v4.0
+ Profile42
+ 512
+ {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+
+
+ true
+ full
+ false
+ ..\..\out\debug\Portable\
+ TRACE;DEBUG;PORTABLE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ ..\..\out\lib\Portable\
+ TRACE;PORTABLE
+ prompt
+ 4
+ ..\..\out\lib\Portable\MathNet.Numerics.XML
+
+
+
+
+ Properties\Resources.resx
+ ResXFileCodeGenerator
+ Resources1.Designer.cs
+
+
+
+
+ Algorithms\LinearAlgebra\ILinearAlgebraProvider.cs
+
+
+ Algorithms\LinearAlgebra\ILinearAlgebraProviderOfT.cs
+
+
+ Algorithms\LinearAlgebra\ManagedLinearAlgebraProvider.Complex.cs
+
+
+ Algorithms\LinearAlgebra\ManagedLinearAlgebraProvider.Complex32.cs
+
+
+ Algorithms\LinearAlgebra\ManagedLinearAlgebraProvider.Double.cs
+
+
+ Algorithms\LinearAlgebra\ManagedLinearAlgebraProvider.Single.cs
+
+
+ ArrayExtensions.cs
+
+
+ Combinatorics.cs
+
+
+ Complex32.cs
+
+
+ Complex64.cs
+
+
+ ComplexExtensions.cs
+
+
+ Constants.cs
+
+
+ Control.cs
+
+
+ Distributions\Continuous\Beta.cs
+
+
+ Distributions\Continuous\Cauchy.cs
+
+
+ Distributions\Continuous\Chi.cs
+
+
+ Distributions\Continuous\ChiSquare.cs
+
+
+ Distributions\Continuous\ContinuousUniform.cs
+
+
+ Distributions\Continuous\Erlang.cs
+
+
+ Distributions\Continuous\Exponential.cs
+
+
+ Distributions\Continuous\FisherSnedecor.cs
+
+
+ Distributions\Continuous\Gamma.cs
+
+
+ Distributions\Continuous\InverseGamma.cs
+
+
+ Distributions\Continuous\Laplace.cs
+
+
+ Distributions\Continuous\LogNormal.cs
+
+
+ Distributions\Continuous\Normal.cs
+
+
+ Distributions\Continuous\Pareto.cs
+
+
+ Distributions\Continuous\Rayleigh.cs
+
+
+ Distributions\Continuous\Stable.cs
+
+
+ Distributions\Continuous\StudentT.cs
+
+
+ Distributions\Continuous\Weibull.cs
+
+
+ Distributions\Discrete\Bernoulli.cs
+
+
+ Distributions\Discrete\Binomial.cs
+
+
+ Distributions\Discrete\Categorical.cs
+
+
+ Distributions\Discrete\ConwayMaxwellPoisson.cs
+
+
+ Distributions\Discrete\DiscreteUniform.cs
+
+
+ Distributions\Discrete\Geometric.cs
+
+
+ Distributions\Discrete\Hypergeometric.cs
+
+
+ Distributions\Discrete\NegativeBinomial.cs
+
+
+ Distributions\Discrete\Poisson.cs
+
+
+ Distributions\Discrete\Zipf.cs
+
+
+ Distributions\IContinuousDistribution.cs
+
+
+ Distributions\IDiscreteDistribution.cs
+
+
+ Distributions\IDistribution.cs
+
+
+ Distributions\Multivariate\Dirichlet.cs
+
+
+ Distributions\Multivariate\InverseWishart.cs
+
+
+ Distributions\Multivariate\MatrixNormal.cs
+
+
+ Distributions\Multivariate\Multinomial.cs
+
+
+ Distributions\Multivariate\NormalGamma.cs
+
+
+ Distributions\Multivariate\Wishart.cs
+
+
+ GlobalizationHelper.cs
+
+
+ IntegralTransforms\Algorithms\DiscreteFourierTransform.Bluestein.cs
+
+
+ IntegralTransforms\Algorithms\DiscreteFourierTransform.Naive.cs
+
+
+ IntegralTransforms\Algorithms\DiscreteFourierTransform.Options.cs
+
+
+ IntegralTransforms\Algorithms\DiscreteFourierTransform.RadixN.cs
+
+
+ IntegralTransforms\Algorithms\DiscreteHartleyTransform.Naive.cs
+
+
+ IntegralTransforms\Algorithms\DiscreteHartleyTransform.Options.cs
+
+
+ IntegralTransforms\FourierOptions.cs
+
+
+ IntegralTransforms\HartleyOptions.cs
+
+
+ IntegralTransforms\Transform.cs
+
+
+ Integration\Algorithms\DoubleExponentialTransformation.cs
+
+
+ Integration\Algorithms\NewtonCotesTrapeziumRule.cs
+
+
+ Integration\Algorithms\SimpsonRule.cs
+
+
+ Integration\Integrate.cs
+
+
+ Interpolation\Algorithms\AkimaSplineInterpolation.cs
+
+
+ Interpolation\Algorithms\BarycentricInterpolation.cs
+
+
+ Interpolation\Algorithms\BulirschStoerRationalInterpolation.cs
+
+
+ Interpolation\Algorithms\CubicHermiteSplineInterpolation.cs
+
+
+ Interpolation\Algorithms\CubicSplineInterpolation.cs
+
+
+ Interpolation\Algorithms\EquidistantPolynomialInterpolation.cs
+
+
+ Interpolation\Algorithms\FloaterHormannRationalInterpolation.cs
+
+
+ Interpolation\Algorithms\LinearSplineInterpolation.cs
+
+
+ Interpolation\Algorithms\NevillePolynomialInterpolation.cs
+
+
+ Interpolation\Algorithms\SplineInterpolation.cs
+
+
+ Interpolation\IInterpolation.cs
+
+
+ Interpolation\Interpolate.cs
+
+
+ Interpolation\SplineBoundaryCondition.cs
+
+
+ IPrecisionSupport.cs
+
+
+ LinearAlgebra\Complex32\DenseMatrix.cs
+
+
+ LinearAlgebra\Complex32\DenseVector.cs
+
+
+ LinearAlgebra\Complex32\DiagonalMatrix.cs
+
+
+ LinearAlgebra\Complex32\ExtensionMethods.cs
+
+
+ LinearAlgebra\Complex32\Factorization\Cholesky.cs
+
+
+ LinearAlgebra\Complex32\Factorization\DenseCholesky.cs
+
+
+ LinearAlgebra\Complex32\Factorization\DenseEvd.cs
+
+
+ LinearAlgebra\Complex32\Factorization\DenseGramSchmidt.cs
+
+
+ LinearAlgebra\Complex32\Factorization\DenseLU.cs
+
+
+ LinearAlgebra\Complex32\Factorization\DenseQR.cs
+
+
+ LinearAlgebra\Complex32\Factorization\DenseSvd.cs
+
+
+ LinearAlgebra\Complex32\Factorization\Evd.cs
+
+
+ LinearAlgebra\Complex32\Factorization\GramSchmidt.cs
+
+
+ LinearAlgebra\Complex32\Factorization\LU.cs
+
+
+ LinearAlgebra\Complex32\Factorization\QR.cs
+
+
+ LinearAlgebra\Complex32\Factorization\Svd.cs
+
+
+ LinearAlgebra\Complex32\Factorization\UserCholesky.cs
+
+
+ LinearAlgebra\Complex32\Factorization\UserEvd.cs
+
+
+ LinearAlgebra\Complex32\Factorization\UserGramSchmidt.cs
+
+
+ LinearAlgebra\Complex32\Factorization\UserLU.cs
+
+
+ LinearAlgebra\Complex32\Factorization\UserQR.cs
+
+
+ LinearAlgebra\Complex32\Factorization\UserSvd.cs
+
+
+ LinearAlgebra\Complex32\Matrix.cs
+
+
+ LinearAlgebra\Complex32\Solvers\IIterativeSolver.cs
+
+
+ LinearAlgebra\Complex32\Solvers\IIterativeSolverSetup.cs
+
+
+ LinearAlgebra\Complex32\Solvers\IIterator.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Iterative\BiCgStab.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Iterative\CompositeSolver.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Iterative\GpBiCg.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Iterative\MlkBiCgStab.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Iterative\TFQMR.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Iterator.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Preconditioners\Diagonal.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Preconditioners\Ilutp.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Preconditioners\IlutpElementSorter.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Preconditioners\IncompleteLU.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Preconditioners\IPreConditioner.cs
+
+
+ LinearAlgebra\Complex32\Solvers\Preconditioners\UnitPreconditioner.cs
+
+
+ LinearAlgebra\Complex32\Solvers\StopCriterium\DivergenceStopCriterium.cs
+
+
+ LinearAlgebra\Complex32\Solvers\StopCriterium\FailureStopCriterium.cs
+
+
+ LinearAlgebra\Complex32\Solvers\StopCriterium\IIterationStopCriterium.cs
+
+
+ LinearAlgebra\Complex32\Solvers\StopCriterium\IterationCountStopCriterium.cs
+
+
+ LinearAlgebra\Complex32\Solvers\StopCriterium\ResidualStopCriterium.cs
+
+
+ LinearAlgebra\Complex32\SparseMatrix.cs
+
+
+ LinearAlgebra\Complex32\SparseVector.cs
+
+
+ LinearAlgebra\Complex32\Vector.cs
+
+
+ LinearAlgebra\Complex\DenseMatrix.cs
+
+
+ LinearAlgebra\Complex\DenseVector.cs
+
+
+ LinearAlgebra\Complex\DiagonalMatrix.cs
+
+
+ LinearAlgebra\Complex\ExtensionMethods.cs
+
+
+ LinearAlgebra\Complex\Factorization\Cholesky.cs
+
+
+ LinearAlgebra\Complex\Factorization\DenseCholesky.cs
+
+
+ LinearAlgebra\Complex\Factorization\DenseEvd.cs
+
+
+ LinearAlgebra\Complex\Factorization\DenseGramSchmidt.cs
+
+
+ LinearAlgebra\Complex\Factorization\DenseLU.cs
+
+
+ LinearAlgebra\Complex\Factorization\DenseQR.cs
+
+
+ LinearAlgebra\Complex\Factorization\DenseSvd.cs
+
+
+ LinearAlgebra\Complex\Factorization\Evd.cs
+
+
+ LinearAlgebra\Complex\Factorization\GramSchmidt.cs
+
+
+ LinearAlgebra\Complex\Factorization\LU.cs
+
+
+ LinearAlgebra\Complex\Factorization\QR.cs
+
+
+ LinearAlgebra\Complex\Factorization\Svd.cs
+
+
+ LinearAlgebra\Complex\Factorization\UserCholesky.cs
+
+
+ LinearAlgebra\Complex\Factorization\UserEvd.cs
+
+
+ LinearAlgebra\Complex\Factorization\UserGramSchmidt.cs
+
+
+ LinearAlgebra\Complex\Factorization\UserLU.cs
+
+
+ LinearAlgebra\Complex\Factorization\UserQR.cs
+
+
+ LinearAlgebra\Complex\Factorization\UserSvd.cs
+
+
+ LinearAlgebra\Complex\Matrix.cs
+
+
+ LinearAlgebra\Complex\Solvers\IIterativeSolver.cs
+
+
+ LinearAlgebra\Complex\Solvers\IIterativeSolverSetup.cs
+
+
+ LinearAlgebra\Complex\Solvers\IIterator.cs
+
+
+ LinearAlgebra\Complex\Solvers\Iterative\BiCgStab.cs
+
+
+ LinearAlgebra\Complex\Solvers\Iterative\CompositeSolver.cs
+
+
+ LinearAlgebra\Complex\Solvers\Iterative\GpBiCg.cs
+
+
+ LinearAlgebra\Complex\Solvers\Iterative\MlkBiCgStab.cs
+
+
+ LinearAlgebra\Complex\Solvers\Iterative\TFQMR.cs
+
+
+ LinearAlgebra\Complex\Solvers\Iterator.cs
+
+
+ LinearAlgebra\Complex\Solvers\Preconditioners\Diagonal.cs
+
+
+ LinearAlgebra\Complex\Solvers\Preconditioners\Ilutp.cs
+
+
+ LinearAlgebra\Complex\Solvers\Preconditioners\IlutpElementSorter.cs
+
+
+ LinearAlgebra\Complex\Solvers\Preconditioners\IncompleteLU.cs
+
+
+ LinearAlgebra\Complex\Solvers\Preconditioners\IPreConditioner.cs
+
+
+ LinearAlgebra\Complex\Solvers\Preconditioners\UnitPreconditioner.cs
+
+
+ LinearAlgebra\Complex\Solvers\StopCriterium\DivergenceStopCriterium.cs
+
+
+ LinearAlgebra\Complex\Solvers\StopCriterium\FailureStopCriterium.cs
+
+
+ LinearAlgebra\Complex\Solvers\StopCriterium\IIterationStopCriterium.cs
+
+
+ LinearAlgebra\Complex\Solvers\StopCriterium\IterationCountStopCriterium.cs
+
+
+ LinearAlgebra\Complex\Solvers\StopCriterium\ResidualStopCriterium.cs
+
+
+ LinearAlgebra\Complex\SparseMatrix.cs
+
+
+ LinearAlgebra\Complex\SparseVector.cs
+
+
+ LinearAlgebra\Complex\Vector.cs
+
+
+ LinearAlgebra\Double\DenseMatrix.cs
+
+
+ LinearAlgebra\Double\DenseVector.cs
+
+
+ LinearAlgebra\Double\DiagonalMatrix.cs
+
+
+ LinearAlgebra\Double\ExtensionMethods.cs
+
+
+ LinearAlgebra\Double\Factorization\Cholesky.cs
+
+
+ LinearAlgebra\Double\Factorization\DenseCholesky.cs
+
+
+ LinearAlgebra\Double\Factorization\DenseEvd.cs
+
+
+ LinearAlgebra\Double\Factorization\DenseGramSchmidt.cs
+
+
+ LinearAlgebra\Double\Factorization\DenseLU.cs
+
+
+ LinearAlgebra\Double\Factorization\DenseQR.cs
+
+
+ LinearAlgebra\Double\Factorization\DenseSvd.cs
+
+
+ LinearAlgebra\Double\Factorization\Evd.cs
+
+
+ LinearAlgebra\Double\Factorization\GramSchmidt.cs
+
+
+ LinearAlgebra\Double\Factorization\LU.cs
+
+
+ LinearAlgebra\Double\Factorization\QR.cs
+
+
+ LinearAlgebra\Double\Factorization\Svd.cs
+
+
+ LinearAlgebra\Double\Factorization\UserCholesky.cs
+
+
+ LinearAlgebra\Double\Factorization\UserEvd.cs
+
+
+ LinearAlgebra\Double\Factorization\UserGramSchmidt.cs
+
+
+ LinearAlgebra\Double\Factorization\UserLU.cs
+
+
+ LinearAlgebra\Double\Factorization\UserQR.cs
+
+
+ LinearAlgebra\Double\Factorization\UserSvd.cs
+
+
+ LinearAlgebra\Double\Matrix.cs
+
+
+ LinearAlgebra\Double\Solvers\IIterativeSolver.cs
+
+
+ LinearAlgebra\Double\Solvers\IIterativeSolverSetup.cs
+
+
+ LinearAlgebra\Double\Solvers\IIterator.cs
+
+
+ LinearAlgebra\Double\Solvers\Iterative\BiCgStab.cs
+
+
+ LinearAlgebra\Double\Solvers\Iterative\CompositeSolver.cs
+
+
+ LinearAlgebra\Double\Solvers\Iterative\GpBiCg.cs
+
+
+ LinearAlgebra\Double\Solvers\Iterative\MlkBiCgStab.cs
+
+
+ LinearAlgebra\Double\Solvers\Iterative\TFQMR.cs
+
+
+ LinearAlgebra\Double\Solvers\Iterator.cs
+
+
+ LinearAlgebra\Double\Solvers\Preconditioners\Diagonal.cs
+
+
+ LinearAlgebra\Double\Solvers\Preconditioners\Ilutp.cs
+
+
+ LinearAlgebra\Double\Solvers\Preconditioners\IlutpElementSorter.cs
+
+
+ LinearAlgebra\Double\Solvers\Preconditioners\IncompleteLU.cs
+
+
+ LinearAlgebra\Double\Solvers\Preconditioners\IPreConditioner.cs
+
+
+ LinearAlgebra\Double\Solvers\Preconditioners\UnitPreconditioner.cs
+
+
+ LinearAlgebra\Double\Solvers\StopCriterium\DivergenceStopCriterium.cs
+
+
+ LinearAlgebra\Double\Solvers\StopCriterium\FailureStopCriterium.cs
+
+
+ LinearAlgebra\Double\Solvers\StopCriterium\IIterationStopCriterium.cs
+
+
+ LinearAlgebra\Double\Solvers\StopCriterium\IterationCountStopCriterium.cs
+
+
+ LinearAlgebra\Double\Solvers\StopCriterium\ResidualStopCriterium.cs
+
+
+ LinearAlgebra\Double\SparseMatrix.cs
+
+
+ LinearAlgebra\Double\SparseVector.cs
+
+
+ LinearAlgebra\Double\Vector.cs
+
+
+ LinearAlgebra\Generic\Common.cs
+
+
+ LinearAlgebra\Generic\Factorization\Cholesky.cs
+
+
+ LinearAlgebra\Generic\Factorization\Evd.cs
+
+
+ LinearAlgebra\Generic\Factorization\GramSchmidt.cs
+
+
+ LinearAlgebra\Generic\Factorization\LU.cs
+
+
+ LinearAlgebra\Generic\Factorization\QR.cs
+
+
+ LinearAlgebra\Generic\Factorization\Svd.cs
+
+
+ LinearAlgebra\Generic\ISolver.cs
+
+
+ LinearAlgebra\Generic\Matrix.Arithmetic.cs
+
+
+ LinearAlgebra\Generic\Matrix.cs
+
+
+ LinearAlgebra\Generic\Solvers\Status\CalculationCancelled.cs
+
+
+ LinearAlgebra\Generic\Solvers\Status\CalculationConverged.cs
+
+
+ LinearAlgebra\Generic\Solvers\Status\CalculationDiverged.cs
+
+
+ LinearAlgebra\Generic\Solvers\Status\CalculationFailure.cs
+
+
+ LinearAlgebra\Generic\Solvers\Status\CalculationIndetermined.cs
+
+
+ LinearAlgebra\Generic\Solvers\Status\CalculationRunning.cs
+
+
+ LinearAlgebra\Generic\Solvers\Status\CalculationStoppedWithoutConvergence.cs
+
+
+ LinearAlgebra\Generic\Solvers\Status\ICalculationStatus.cs
+
+
+ LinearAlgebra\Generic\Solvers\StopCriterium\StopLevel.cs
+
+
+ LinearAlgebra\Generic\Vector.cs
+
+
+ LinearAlgebra\Single\DenseMatrix.cs
+
+
+ LinearAlgebra\Single\DenseVector.cs
+
+
+ LinearAlgebra\Single\DiagonalMatrix.cs
+
+
+ LinearAlgebra\Single\ExtensionMethods.cs
+
+
+ LinearAlgebra\Single\Factorization\Cholesky.cs
+
+
+ LinearAlgebra\Single\Factorization\DenseCholesky.cs
+
+
+ LinearAlgebra\Single\Factorization\DenseEvd.cs
+
+
+ LinearAlgebra\Single\Factorization\DenseGramSchmidt.cs
+
+
+ LinearAlgebra\Single\Factorization\DenseLU.cs
+
+
+ LinearAlgebra\Single\Factorization\DenseQR.cs
+
+
+ LinearAlgebra\Single\Factorization\DenseSvd.cs
+
+
+ LinearAlgebra\Single\Factorization\Evd.cs
+
+
+ LinearAlgebra\Single\Factorization\GramSchmidt.cs
+
+
+ LinearAlgebra\Single\Factorization\LU.cs
+
+
+ LinearAlgebra\Single\Factorization\QR.cs
+
+
+ LinearAlgebra\Single\Factorization\Svd.cs
+
+
+ LinearAlgebra\Single\Factorization\UserCholesky.cs
+
+
+ LinearAlgebra\Single\Factorization\UserEvd.cs
+
+
+ LinearAlgebra\Single\Factorization\UserGramSchmidt.cs
+
+
+ LinearAlgebra\Single\Factorization\UserLU.cs
+
+
+ LinearAlgebra\Single\Factorization\UserQR.cs
+
+
+ LinearAlgebra\Single\Factorization\UserSvd.cs
+
+
+ LinearAlgebra\Single\Matrix.cs
+
+
+ LinearAlgebra\Single\Solvers\IIterativeSolver.cs
+
+
+ LinearAlgebra\Single\Solvers\IIterativeSolverSetup.cs
+
+
+ LinearAlgebra\Single\Solvers\IIterator.cs
+
+
+ LinearAlgebra\Single\Solvers\Iterative\BiCgStab.cs
+
+
+ LinearAlgebra\Single\Solvers\Iterative\CompositeSolver.cs
+
+
+ LinearAlgebra\Single\Solvers\Iterative\GpBiCg.cs
+
+
+ LinearAlgebra\Single\Solvers\Iterative\MlkBiCgStab.cs
+
+
+ LinearAlgebra\Single\Solvers\Iterative\TFQMR.cs
+
+
+ LinearAlgebra\Single\Solvers\Iterator.cs
+
+
+ LinearAlgebra\Single\Solvers\Preconditioners\Diagonal.cs
+
+
+ LinearAlgebra\Single\Solvers\Preconditioners\Ilutp.cs
+
+
+ LinearAlgebra\Single\Solvers\Preconditioners\IlutpElementSorter.cs
+
+
+ LinearAlgebra\Single\Solvers\Preconditioners\IncompleteLU.cs
+
+
+ LinearAlgebra\Single\Solvers\Preconditioners\IPreConditioner.cs
+
+
+ LinearAlgebra\Single\Solvers\Preconditioners\UnitPreconditioner.cs
+
+
+ LinearAlgebra\Single\Solvers\StopCriterium\DivergenceStopCriterium.cs
+
+
+ LinearAlgebra\Single\Solvers\StopCriterium\FailureStopCriterium.cs
+
+
+ LinearAlgebra\Single\Solvers\StopCriterium\IIterationStopCriterium.cs
+
+
+ LinearAlgebra\Single\Solvers\StopCriterium\IterationCountStopCriterium.cs
+
+
+ LinearAlgebra\Single\Solvers\StopCriterium\ResidualStopCriterium.cs
+
+
+ LinearAlgebra\Single\SparseMatrix.cs
+
+
+ LinearAlgebra\Single\SparseVector.cs
+
+
+ LinearAlgebra\Single\Vector.cs
+
+
+ NumberTheory\IntegerTheory.cs
+
+
+ NumberTheory\IntegerTheory.Euclid.Big.cs
+
+
+ NumberTheory\IntegerTheory.Euclid.cs
+
+
+ Permutation.cs
+
+
+ Precision.cs
+
+
+ Properties\Resources1.Designer.cs
+ Resources.resx
+ True
+ True
+
+
+ Random\AbstractRandomNumberGenerator.cs
+
+
+ Random\Mcg31m1.cs
+
+
+ Random\Mcg59.cs
+
+
+ Random\MersenneTwister.cs
+
+
+ Random\Mrg32k3a.cs
+
+
+ Random\Palf.cs
+
+
+ Random\SystemCrypto.cs
+
+
+ Random\SystemRandomExtensions.cs
+
+
+ Random\WH1982.cs
+
+
+ Random\WH2006.cs
+
+
+ Random\Xorshift.cs
+
+
+ SerializableAttribute.cs
+
+
+ Signals\SignalGenerator.Chebyshev.cs
+
+
+ Signals\SignalGenerator.Equidistant.cs
+
+
+ Signals\SignalGenerator.Random.cs
+
+
+ Sorting.cs
+
+
+ SpecialFunctions.cs
+
+
+ SpecialFunctions\Beta.cs
+
+
+ SpecialFunctions\Erf.cs
+
+
+ SpecialFunctions\Factorial.cs
+
+
+ SpecialFunctions\Gamma.cs
+
+
+ SpecialFunctions\Stability.cs
+
+
+ Statistics\Correlation.cs
+
+
+ Statistics\DescriptiveStatistics.cs
+
+
+ Statistics\Histogram.cs
+
+
+ Statistics\MCMC\MCMCSampler.cs
+
+
+ Statistics\MCMC\MetropolisHastingsSampler.cs
+
+
+ Statistics\MCMC\MetropolisSampler.cs
+
+
+ Statistics\MCMC\RejectionSampler.cs
+
+
+ Statistics\MCMC\UnivariateSliceSampler.cs
+
+
+ Statistics\Percentile.cs
+
+
+ Statistics\Statistics.cs
+
+
+ Threading\CommonParallel.cs
+
+
+ Trigonometry.cs
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Silverlight/SilverlightUtilities.cs b/src/Portable/Properties/AssemblyInfo.cs
similarity index 54%
rename from src/Silverlight/SilverlightUtilities.cs
rename to src/Portable/Properties/AssemblyInfo.cs
index 8c21ea20..6f6280db 100644
--- a/src/Silverlight/SilverlightUtilities.cs
+++ b/src/Portable/Properties/AssemblyInfo.cs
@@ -1,9 +1,9 @@
-//
+//
// 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
+// http://mathnet.opensourcedotnet.info
+//
+// Copyright (c) 2002-2012 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
@@ -12,8 +12,10 @@
// 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
@@ -24,24 +26,21 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-namespace MathNet.Numerics
-{
- ///
- /// Contains methods missing from Silverlight.
- ///
- public static class SilverlightUtilities
- {
- ///
- /// Calculates the quotient of two 64-bit signed integers and also returns the remainder in an output parameter.
- ///
- /// The dividend.
- /// The divisor.
- /// The remainder.
- /// The quotient of the specified numbers.
- public static long DivRem(long a, long b, out long result)
- {
- result = a % b;
- return a / b;
- }
- }
-}
+using System;
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+
+[assembly: AssemblyTitle("Math.NET Numerics - Portable Edition")]
+[assembly: AssemblyDescription("Math.NET Numerics, providing methods and algorithms for numerical computations in science, engineering and every day use.")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Math.NET Project")]
+[assembly: AssemblyProduct("Math.NET Numerics")]
+[assembly: AssemblyCopyright("Copyright © Math.NET Project")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: CLSCompliant(true)]
+[assembly: InternalsVisibleTo("SilverlightUnitTests")]
+[assembly: NeutralResourcesLanguage("en")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
diff --git a/src/Silverlight/Properties/AssemblyInfo.cs b/src/Silverlight/Properties/AssemblyInfo.cs
index 2441b7f8..8c7ece37 100644
--- a/src/Silverlight/Properties/AssemblyInfo.cs
+++ b/src/Silverlight/Properties/AssemblyInfo.cs
@@ -2,7 +2,7 @@
// Math.NET Numerics, part of the Math.NET Project
// http://mathnet.opensourcedotnet.info
//
-// Copyright (c) 2009 Math.NET
+// Copyright (c) 2002-2012 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
diff --git a/src/Silverlight/SerializableAttribute.cs b/src/Silverlight/SerializableAttribute.cs
deleted file mode 100644
index 3cab6ee9..00000000
--- a/src/Silverlight/SerializableAttribute.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System;
-
-namespace MathNet.Numerics
-{
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
- public class SerializableAttribute : Attribute
- {
- }
-}
diff --git a/src/Silverlight/Silverlight.csproj b/src/Silverlight/Silverlight.csproj
index 0847df2d..221f846c 100644
--- a/src/Silverlight/Silverlight.csproj
+++ b/src/Silverlight/Silverlight.csproj
@@ -44,7 +44,7 @@
full
false
..\..\out\debug\SL4\
- DEBUG;TRACE;SILVERLIGHT
+ TRACE;DEBUG;SILVERLIGHT;PORTABLE
true
true
prompt
@@ -106,6 +106,9 @@
Complex32.cs
+
+ Complex64.cs
+
ComplexExtensions.cs
@@ -976,6 +979,9 @@
Random\Xorshift.cs
+
+ SerializableAttribute.cs
+
Signals\SignalGenerator.Chebyshev.cs
@@ -1043,13 +1049,6 @@
Trigonometry.cs
-
-
-
-
-
-
-
diff --git a/src/Silverlight/Threading/AggregateException.cs b/src/Silverlight/Threading/AggregateException.cs
deleted file mode 100644
index b1d6d042..00000000
--- a/src/Silverlight/Threading/AggregateException.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// http://mathnet.opensourcedotnet.info
-// Copyright (c) 2009 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.Threading
-{
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
-
- ///
- /// Represents multiple errors that occur during application execution.
- ///
- public class AggregateException : Exception
- {
- ///
- /// List of the aggregated exceptions.
- ///
- private readonly IList _exceptions = new List();
-
- ///
- /// Initializes a new instance of the AggregateException class with a specified error message and references to the inner exceptions that are the cause of this exception.
- ///
- /// The exceptions that are the cause of the current exception.
- public AggregateException(IEnumerable exceptions)
- {
- foreach (var exception in exceptions)
- {
- this._exceptions.Add(exception);
- }
- }
-
- ///
- /// Gets a read-only collection of the Exception instances that caused the current exception.
- ///
- /// A read-only collection of the Exception instances that caused the current exception
- public ReadOnlyCollection InnerExceptions
- {
- get
- {
- return new ReadOnlyCollection(this._exceptions);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Silverlight/Threading/Parallel.cs b/src/Silverlight/Threading/Parallel.cs
deleted file mode 100644
index 9c266a29..00000000
--- a/src/Silverlight/Threading/Parallel.cs
+++ /dev/null
@@ -1,485 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// http://mathnet.opensourcedotnet.info
-//
-// Copyright (c) 2009 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.Threading
-{
- using System;
- using System.Collections.Generic;
- using Properties;
-
- ///
- /// Provides support for parallel loops.
- ///
- internal static class Parallel
- {
- ///
- /// The amount to scale the foreach buffer after each iteration.
- ///
- private const int ScalingFactor = 2;
-
- ///
- /// The maximum size of the foreach buffer.
- ///
- private const int MaxBlockSize = 65536;
-
- ///
- /// The initial size of the for each buffer.
- ///
- private const int IntialBlockSize = 1024;
-
- ///
- /// Executes a for loop in which iterations may run in parallel.
- ///
- /// The start index, inclusive.
- /// The end index, exclusive.
- /// The body to be invoked for each iteration.
- /// The argument is null.
- /// At least one invocation of the body threw an exception.
- public static void For(int fromInclusive, int toExclusive, Action body)
- {
- if (body == null)
- {
- throw new ArgumentNullException("body");
- }
-
- // fast forward execution if it's only one or none items
- var count = toExclusive - fromInclusive;
- if (count <= 1)
- {
- if (count == 1)
- {
- body(fromInclusive);
- }
-
- return;
- }
-
- // fast forward execution in case parallelization is disabled
- if (Control.DisableParallelization
- || ThreadQueue.ThreadCount <= 1
- || ThreadQueue.IsInWorkerThread)
- {
- for (int i = fromInclusive; i < toExclusive; i++)
- {
- body(i);
- }
-
- return;
- }
-
- var actions = new Action[ThreadQueue.ThreadCount];
- var size = count / actions.Length;
-
- // partition the jobs into separate sets for each but the last worked thread
- for (var i = 0; i < actions.Length - 1; i++)
- {
- var start = fromInclusive + (i * size);
- var stop = fromInclusive + ((i + 1) * size);
-
- actions[i] =
- () =>
- {
- for (int j = start; j < stop; j++)
- {
- body(j);
- }
- };
- }
-
- // add another set for last worker thread
- actions[actions.Length - 1] =
- () =>
- {
- for (int i = fromInclusive + ((actions.Length - 1) * size); i < toExclusive; i++)
- {
- body(i);
- }
- };
-
- Invoke(actions);
- }
-
- ///
- /// Executes a for loop in which iterations may run in parallel.
- ///
- /// The type of the thread-local data.
- /// The start index, inclusive.
- /// The end index, exclusive.
- /// The function delegate that returns the initial state of the local data for each thread.
- /// The delegate that is invoked once per iteration.
- /// The delegate that performs a final action on the local state of each thread.
- public static void For(int fromInclusive, int toExclusive, Func localInit, Func body, Action localFinally)
- {
- var count = toExclusive - fromInclusive;
- var tasks = new Task[ThreadQueue.ThreadCount];
- var size = count / tasks.Length;
-
- // fast forward execution if it's only one or none items
- if (count <= 1)
- {
- if (count == 1)
- {
- localFinally(body(fromInclusive, localInit()));
- }
-
- return;
- }
-
- // fast forward execution in case parallelization is disabled
- if (Control.DisableParallelization
- || ThreadQueue.ThreadCount <= 1
- || ThreadQueue.IsInWorkerThread)
- {
- var localresult = localInit();
- for (var i = fromInclusive; i < toExclusive; i++)
- {
- localresult = body(i, localresult);
- }
-
- localFinally(localresult);
- return;
- }
-
- // partition the jobs into separate sets for each but the last worked thread
- for (var i = 0; i < tasks.Length - 1; i++)
- {
- var start = fromInclusive + (i * size);
- var stop = fromInclusive + ((i + 1) * size);
- tasks[i] = new Task(
- localData =>
- {
- var localresult = (T)localData;
- for (var j = start; j < stop; j++)
- {
- localresult = body(j, localresult);
- }
-
- return localresult;
- },
- localInit());
- ThreadQueue.Enqueue(tasks[i]);
- }
-
- // add another set for last worker thread
- tasks[tasks.Length - 1] = new Task(
- localData =>
- {
- var localresult = (T)localData;
- for (var i = fromInclusive + ((tasks.Length - 1) * size); i < toExclusive; i++)
- {
- localresult = body(i, localresult);
- }
-
- return localresult;
- },
- localInit());
-
- ThreadQueue.Enqueue(tasks[tasks.Length - 1]);
- if (tasks.Length <= 0)
- {
- return;
- }
-
- WaitForTasksToComplete(tasks);
-
- foreach (var t in tasks)
- {
- localFinally(t.Result);
- }
-
- CollectExceptions(tasks);
- }
-
- ///
- /// Executes a for each operation on an IEnumerable{T} in which iterations may run in parallel.
- ///
- /// The type of the data in the source.
- /// An enumerable data source.
- /// The delegate that is invoked once per iteration.
- public static void ForEach(IEnumerable source, Action body)
- {
- if (body == null)
- {
- throw new ArgumentNullException("body");
- }
-
- // fast forward execution in case parallelization is disabled
- if (Control.DisableParallelization
- || ThreadQueue.ThreadCount <= 1
- || ThreadQueue.IsInWorkerThread)
- {
- foreach (var item in source)
- {
- body(item);
- }
-
- return;
- }
-
- // source is a IList, call For instead.
- if (source is IList)
- {
- var list = (IList)source;
- For(0, list.Count, i => body(list[i]));
- return;
- }
-
- var maxBlockSize = IntialBlockSize;
- var tasks = new List();
-
- var enumerator = source.GetEnumerator();
- while (enumerator.MoveNext())
- {
- var pos = 0;
- var list = new T[maxBlockSize];
- list[pos++] = enumerator.Current;
-
- var count = 1;
- while (count < maxBlockSize && enumerator.MoveNext())
- {
- list[pos++] = enumerator.Current;
- count++;
- }
-
- var task = new Task(
- () =>
- {
- for (var i = 0; i < pos; i++)
- {
- body(list[i]);
- }
- });
-
- ThreadQueue.Enqueue(task);
- tasks.Add(task);
- maxBlockSize = Math.Min(MaxBlockSize, maxBlockSize * ScalingFactor);
- }
-
- if (tasks.Count > 0)
- {
- WaitForTasksToComplete(tasks.ToArray());
- CollectExceptions(tasks);
- }
- }
-
- ///
- /// Executes a for each operation on an IEnumerable{TSource in which iterations may run in parallel.
- ///
- /// The type of the data in the source.
- /// The type of the thread-local data.
- /// An enumerable data source.
- /// The function delegate that returns the initial state of the local data for each thread.
- /// The delegate that is invoked once per iteration.
- /// The delegate that performs a final action on the local state of each thread.
- public static void ForEach(IEnumerable source, Func localInit, Func body, Action localFinally)
- {
- if (body == null)
- {
- throw new ArgumentNullException("body");
- }
-
- // fast forward execution in case parallelization is disabled
- if (Control.DisableParallelization
- || ThreadQueue.ThreadCount <= 1
- || ThreadQueue.IsInWorkerThread)
- {
- var localResult = localInit();
- foreach (var item in source)
- {
- localResult = body(item, localResult);
- }
-
- localFinally(localResult);
- return;
- }
-
- // source is a IList, call For instead.
- if (source is IList)
- {
- var list = (IList)source;
- For(0, list.Count, localInit, (i, local) => body(list[i], local), localFinally);
- return;
- }
-
- var maxBlockSize = IntialBlockSize;
- var tasks = new List>();
-
- var enumerator = source.GetEnumerator();
- while (enumerator.MoveNext())
- {
- var pos = 0;
- var list = new TSource[maxBlockSize];
- list[pos++] = enumerator.Current;
-
- var count = 1;
- while (count < maxBlockSize && enumerator.MoveNext())
- {
- list[pos++] = enumerator.Current;
- count++;
- }
-
- var task = new Task(
- localData =>
- {
- var localresult = localData;
- for (var i = 0; i < pos; i++)
- {
- localresult = body(list[i], (TLocal)localresult);
- }
-
- return (TLocal)localresult;
- },
- localInit());
-
- ThreadQueue.Enqueue(task);
- tasks.Add(task);
- maxBlockSize = Math.Min(MaxBlockSize, maxBlockSize * ScalingFactor);
- }
-
- if (tasks.Count <= 0)
- {
- return;
- }
-
- var taskArray = tasks.ToArray();
- WaitForTasksToComplete(taskArray);
-
- for (var i = 0; i < taskArray.Length; i++)
- {
- localFinally(tasks[i].Result);
- }
-
- CollectExceptions(taskArray);
- }
-
- ///
- /// Executes each of the provided actions inside a discrete, asynchronous task.
- ///
- /// An array of actions to execute.
- /// The argument is null.
- /// The actions array contains a null element.
- /// An action threw an exception.
- public static void Run(params Action[] actions)
- {
- if (actions == null)
- {
- throw new ArgumentNullException("actions");
- }
-
- // fast forward execution if it's only one or none items
- if (actions.Length <= 1)
- {
- if (actions.Length == 1)
- {
- actions[0]();
- }
-
- return;
- }
-
- // fast forward execution in case parallelization is disabled
- if (Control.DisableParallelization
- || ThreadQueue.ThreadCount <= 1
- || ThreadQueue.IsInWorkerThread)
- {
- for (var i = 0; i < actions.Length; i++)
- {
- actions[i]();
- }
-
- return;
- }
-
- Invoke(actions);
- }
-
- ///
- /// Executes each of the provided actions inside a discrete, asynchronous task.
- ///
- /// An array of actions to execute.
- /// The actions array contains a null element.
- /// An action threw an exception.
- internal static void Invoke(params Action[] actions)
- {
- // create a job for each action
- var tasks = new Task[actions.Length];
- for (var i = 0; i < tasks.Length; i++)
- {
- Action action = actions[i];
- if (action == null)
- {
- throw new ArgumentException(String.Format(Resources.ArgumentItemNull, "actions"), "actions");
- }
-
- tasks[i] = new Task(action);
- }
-
- // run the jobs
- ThreadQueue.Enqueue(tasks);
-
- WaitForTasksToComplete(tasks);
-
- CollectExceptions(tasks);
- }
-
- ///
- /// Waits for tasks to complete.
- ///
- /// The tasks.
- private static void WaitForTasksToComplete(Task[] tasks)
- {
- foreach (var task in tasks)
- {
- task.Wait();
- }
- }
-
- ///
- /// Collects the exceptions and dispose tasks.
- ///
- /// The tasks.
- private static void CollectExceptions(IEnumerable tasks)
- {
- // collect all thrown exceptions and dispose the jobs
- var exceptions = new List();
- foreach (var task in tasks)
- {
- if (task.IsFaulted)
- {
- exceptions.Add(task.Exception);
- }
- }
-
- // throw the aggregated exceptions, if any
- if (exceptions.Count > 0)
- {
- throw new AggregateException(exceptions);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Silverlight/Threading/Task.cs b/src/Silverlight/Threading/Task.cs
deleted file mode 100644
index 2f330837..00000000
--- a/src/Silverlight/Threading/Task.cs
+++ /dev/null
@@ -1,128 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// http://mathnet.opensourcedotnet.info
-//
-// Copyright (c) 2009 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.Threading
-{
- using System;
- using System.Threading;
-
- ///
- /// Internal Parallel Task Handle.
- ///
- internal class Task
- {
- ///
- /// Delegate to the task's action.
- ///
- private readonly System.Action _body;
-
- ///
- /// Initializes a new instance of the Task class.
- ///
- /// Delegate to the task's action.
- public Task(Action body)
- {
- if (body == null)
- {
- throw new ArgumentNullException("body");
- }
-
- _body = body;
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- protected Task()
- {
- }
-
- ///
- /// Gets a value indicating whether the task completed due to an unhandled exception.
- ///
- ///
- /// true if this task completed due to an unhandled exception; otherwise, false.
- ///
- public bool IsFaulted
- {
- get { return Exception != null; }
- }
-
- ///
- /// Gets a value indicating whether this task has completed.
- ///
- ///
- /// true if this task has completed; otherwise, false.
- ///
- public bool IsCompleted
- {
- get;
- private set;
- }
-
- ///
- /// Gets or sets the exception thrown by the task, if any.
- ///
- public Exception Exception { get; set; }
-
- ///
- /// Run the task.
- ///
- public void Compute()
- {
- try
- {
- DoCompute();
- IsCompleted = true;
- }
- catch (Exception e)
- {
- Exception = e;
- }
- }
-
- ///
- /// Runs the actual task.
- ///
- protected virtual void DoCompute()
- {
- _body();
- }
-
- ///
- /// Waits for the task to complete execution.
- ///
- public void Wait()
- {
- while (!IsCompleted && !IsFaulted)
- {
- Thread.Sleep(0);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Silverlight/Threading/TaskOfT.cs b/src/Silverlight/Threading/TaskOfT.cs
deleted file mode 100644
index 2cef39c2..00000000
--- a/src/Silverlight/Threading/TaskOfT.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// http://mathnet.opensourcedotnet.info
-//
-// Copyright (c) 2009 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.Threading
-{
- using System;
-
- ///
- /// Internal Generic Parallel Task Handle.
- ///
- /// The type of the result.
- internal class Task : Task
- {
- ///
- /// Delegate to the task's action.
- ///
- private readonly Func