From f2cbeb2baa368cd90c15792e4ea9c717bdc3f52d Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Sun, 16 Aug 2009 20:47:23 +0800 Subject: [PATCH] started sketching linear algebra algos. trying out the individual provider approach modified Resharper settings to match StyleCop on typeof spacing Signed-off-by: Marcus Cuda --- .gitignore | 1 + src/MathNet.Numerics.4.5.resharper | 922 ++---------------- src/Numerics/Algorithms/AlgorithmFactory.cs | 130 +++ .../LinearAlgebra/ILinearAlgebra.cs | 32 + .../LinearAlgebra/ManagedLinearAlgebra.cs | 33 + src/Numerics/Numerics.csproj | 6 +- src/Numerics/Properties/Resources.Designer.cs | 9 + src/Numerics/Properties/Resources.resx | 3 + 8 files changed, 269 insertions(+), 867 deletions(-) create mode 100644 src/Numerics/Algorithms/AlgorithmFactory.cs create mode 100644 src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebra.cs create mode 100644 src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebra.cs diff --git a/.gitignore b/.gitignore index f8c60a74..7d8be136 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ TestResult.xml coverage.* _ReSharper* *.marcus +*.bak diff --git a/src/MathNet.Numerics.4.5.resharper b/src/MathNet.Numerics.4.5.resharper index 020c580c..8b435c46 100644 --- a/src/MathNet.Numerics.4.5.resharper +++ b/src/MathNet.Numerics.4.5.resharper @@ -1,868 +1,62 @@ - - - - - SOLUTION - - - - - - en-US - false - Wikipedia -Cholesky -Bluestein -Chebyshev - - - - en-US - en-US - en-US - - en-US - - - Public Protected ProtectedInternal - Any - Maybe - Maybe - Any - - - - false - 120 - - - - - false - - - Any - Class - Maybe - Maybe - Any - - - Any - Enum - - Maybe - Maybe - Any - - - Any - EnumerationMember - - Maybe - Maybe - Any - - - - Classes, Enumerations, Enumeration values should be named in Pascal - - - _ - m_ - - Pascal - - - - - false - - - Public Internal Protected ProtectedInternal - Property - - Maybe - Maybe - Any - - - Public Internal Protected ProtectedInternal - Method - - Maybe - Maybe - Any - - - Public Internal Protected ProtectedInternal - Event - - Maybe - Maybe - Any - - - - Non private properties, methods, events should be in pascal. - - - _ - m_ - - Pascal - - - - - false - - - Private - Property - - Maybe - Maybe - Any - - - Private - Method - - Maybe - Maybe - Any - - - Private - Event - - Maybe - Maybe - Any - - - - Private properties, methods, events should be in pascal. - - - _ - m_ - - Pascal - - - - - false - - - Any - Field - - Maybe - Maybe - Any - - - - Fields should be underscore camel. - - _ - - - m_ - - Camel - - - - - false - - - Any - Variable - Maybe - Maybe - Any - - - Variable should be declared in camel. - - - _ - m_ - - Camel - - - - - false - - - Any - Parameter - Maybe - Maybe - Any - - - Function parameters should be in camel. - - - _ - m_ - - Camel - - - - - false - - - Any - Namespace - Maybe - Maybe - Any - - - Namespaces should be in Pascal. - - - _ - m_ - - Pascal - - - - - true - - - Any - Constant - Maybe - Maybe - Any - - - Constants should be in capital. - - - UpperCase - - - - - false - - - Any - Any - Maybe - Maybe - Any - - - - - Any - Constant - Maybe - Maybe - Any - - - Acronyms should not have more than 2 characters. - - - MatchesRegex - - - ^(?>(XML|SQL|[A-Z]{0,2})[A-Z]?([^A-Z]|$)|[^A-Z]+)*$ - - - false - - - Any - Any - Maybe - Maybe - Any - - - - - Any - Constant - - Maybe - Maybe - Any - - - Any - Field - - Maybe - Maybe - Any - - - Private - Method - - Maybe - Maybe - Any - - - None - Namespace - Maybe - Maybe - Any - - - Names should not have underscore character - - - NotMatchesRegex - - - (?<remove>_) - - - false - - - Any - Class - NUnit.Framework.TestFixtureAttribute - Maybe - Maybe - Any - - - TestFixtures should end with Test. - - - Test - - None - - Test - - - - - false - - - Any - Method - NUnit.Framework.TestAttribute - Maybe - Maybe - Any - - - Test methods should start with Test. - - Test - - - None - - - Test - - - - false - - - Any - Enum - Maybe - Maybe - Any - - - Enumerations should not end with Enum. - - - None - - - Enum - - - - false - - - Any - EnumerationMember - Maybe - Maybe - Any - - - Do not name enumerations reserved. - - - NotMatchesRegex - - - (?<remove>(reserved|Reserved)) - - - false - - - Any - Event - Maybe - Maybe - Any - - - Event should not have Before or After prefix. - - - Before - After - - None - - - - - false - - - Any - Enum - System.FlagsAttribute - Maybe - Maybe - Any - - - Flags enums should have plural names - - - None - - s - - - - - true - - - Any - Enum - Maybe - Maybe - Any - - - - - Any - Enum - System.FlagsAttribute - Maybe - Maybe - Any - - - Enums that are not flags should not have plural names - - - None - - - s - - - - false - - - Any - Class - System.Attribute - Maybe - Maybe - Any - - - Attribute should end with Attribute. - - - None - - Attribute - - - - - false - - - Any - Class - System.EventArgs - Maybe - Maybe - Any - - - EventArgs should end with EventArgs. - - - None - - EventArgs - - - - - false - - - Any - Class - System.Exception - Maybe - Maybe - Any - - - Exceptions should end with Exception. - - - None - - Exception - - - - - false - - - Any - Class - System.Collections.Stack - Maybe - Maybe - Any - - - Any - Class - System.Collections.Generic.Stack - - Maybe - Maybe - Any - - - - Stack should end with Collection or Stack. - - - None - - Collection - Stack - - - - - false - - - Any - Class - System.Collections.ICollection - Maybe - Maybe - Any - - - Any - Class - System.Collections.IEnumerable - Maybe - Maybe - Any - - - Any - Class - System.Collections.Generic.ICollection - Maybe - Maybe - Any - - - - - Any - Class - System.Collections.Stack - Maybe - Maybe - Any - - - Any - Class - System.Collections.Queue - Maybe - Maybe - Any - - - Any - Class - System.Collections.Generic.Stack - - Maybe - Maybe - Any - - - Collections should end with Collection. - - - None - - Collection - - - - - false - - - Any - Class - System.Collections.IDictionary - Maybe - Maybe - Any - - - Any - Class - System.Collections.Generic.IDictionary - Maybe - Maybe - Any - - - Dictionary should end with Dictionary. - - - None - - Dictionary - - - - - false - - - Any - Class - System.Collections.Queue - Maybe - Maybe - Any - - - Queue should end with Collection or Queue. - - - None - - Collection - Queue - - - - - false - - - Any - Interface - Maybe - Maybe - Any - - - Interfaces should be in Pascal and start with I. - - I - - - Pascal - - - - - - - - - Public Protected ProtectedInternal - Any - Maybe - Maybe - Any - - - - - (?#email)\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* - (?#url)http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)? - - - - - - NEXT_LINE - NEXT_LINE - ALWAYS_ADD - ALWAYS_ADD - ALWAYS_ADD - ALWAYS_ADD - ALWAYS_ADD - ALWAYS_ADD - True - True - 4 - NEXT_LINE - - public - protected - internal - private - new - abstract - virtual - override - sealed - static - readonly - extern - unsafe - volatile - - False - False - True - False - True - False - False - True - True - True - CHOP_IF_LONG - True - True - CHOP_ALWAYS - CHOP_IF_LONG - - - True - - - - - - - - - - - - - - - - - - - - - - - 4 - - - - - + + + + 4 + + public + protected + internal + private + new + abstract + virtual + override + sealed + static + readonly + extern + unsafe + volatile + + False + + - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Numerics/Algorithms/AlgorithmFactory.cs b/src/Numerics/Algorithms/AlgorithmFactory.cs new file mode 100644 index 00000000..4b32719f --- /dev/null +++ b/src/Numerics/Algorithms/AlgorithmFactory.cs @@ -0,0 +1,130 @@ +// +// 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. +// +using System; +using MathNet.Numerics.Algorithms.LinearAlgebra; + +namespace MathNet.Numerics.Algorithms +{ + /// + /// Enumerates the linear algebra providers. + /// + public enum LinearAlgebraProvider + { + /// + /// Managed provider + /// + Managed, + + /// + /// User defined provider + /// + UserDefined + +/* /// + /// Intel's Math Kernel Library (MKL) Provider + /// + Mkl, + + /// + /// Automatically Tuned Linear Algebra Software (ATLAS) Provider + /// + Atlas, + + /// + /// AMD Core Math Library (ACML) Provider + /// + Acml, + + /// + /// NVIDIA Compute Unified Device Architecture (CUDA) Provider + /// + Cuda, + */ + } + + /// + /// Lets users choose which algorithm providers to use. + /// + public static class AlgorithmFactory + { + /// + /// The current linear algebra provider - starts as the managed provider. + /// + private static Type _linearAlgebraProvider = typeof(ManagedLinearAlgebra); + + /// + /// The type of the user defined linear algebra provider. + /// + private static Type _userLinearAlgebraProvider; + + /// + /// Gets the linear algebra provider. + /// + /// The linear algebra provider. + public static ILinearAlgebra LinearAlgebra + { + get { return (ILinearAlgebra) Activator.CreateInstance(_linearAlgebraProvider); } + } + + /// + /// Sets the linear algebra provider to use. + /// + /// + /// The linear algebra provider to use. + /// + public static void SetLinearAlgebraProvider(LinearAlgebraProvider provider) + { + switch (provider) + { + case LinearAlgebraProvider.Managed: + _linearAlgebraProvider = typeof(ManagedLinearAlgebra); + break; + case LinearAlgebraProvider.UserDefined: + if (_userLinearAlgebraProvider == null) + { + throw new ArgumentException(); + } + + _linearAlgebraProvider = _userLinearAlgebraProvider; + break; + } + } + + /// + /// Registers the user defined linear algebra provider. + /// + /// + /// The user defined provider. + /// + public static void RegisterLinearAlgebraProvider(Type provider) + { + if (provider == null) + { + throw new ArgumentNullException("provider"); + } + + _userLinearAlgebraProvider = provider; + } + } +} \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebra.cs b/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebra.cs new file mode 100644 index 00000000..01b0c8cb --- /dev/null +++ b/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebra.cs @@ -0,0 +1,32 @@ +// +// 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.Algorithms.LinearAlgebra +{ + /// + /// Interface to linear algebra algorithms that work off 1-D arrays. + /// + public interface ILinearAlgebra + { + } +} diff --git a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebra.cs b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebra.cs new file mode 100644 index 00000000..42bcf138 --- /dev/null +++ b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebra.cs @@ -0,0 +1,33 @@ +// +// 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.Algorithms.LinearAlgebra +{ + /// + /// The managed linear algebra provider. + /// + internal class ManagedLinearAlgebra : ILinearAlgebra + { + } +} diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 02f0e614..72547be0 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -44,6 +44,9 @@ + + + @@ -123,9 +126,6 @@ MathNet.Numerics.snk - - -