From 564f58909e828651a3d4415e4047690fa573738c Mon Sep 17 00:00:00 2001 From: ArgusMagnus Date: Fri, 3 Feb 2017 12:08:50 +0100 Subject: [PATCH] Changed project to .NETStandard library (v1.3) --- FFTW.NET.sln | 36 ++++++++--- FFTW.NET/AlignedArray.cs | 15 ++--- FFTW.NET/BufferPool.cs | 18 +++--- FFTW.NET/DFT.cs | 8 +-- FFTW.NET/FFTW.NET.csproj | 96 +++++++---------------------- FFTW.NET/FftwInterop.tt | 4 +- FFTW.NET/FftwPlanC2C.cs | 8 +-- FFTW.NET/FftwPlanRC.cs | 18 +++--- FFTW.NET/IPinnedArray.cs | 29 +++++---- FFTW.NET/PinnedArray.cs | 1 - FFTW.NET/Properties/AssemblyInfo.cs | 36 ----------- FFTW.NET/Utils.cs | 25 ++++++++ TestApp/TestApp.csproj | 2 +- 13 files changed, 126 insertions(+), 170 deletions(-) delete mode 100644 FFTW.NET/Properties/AssemblyInfo.cs create mode 100644 FFTW.NET/Utils.cs diff --git a/FFTW.NET.sln b/FFTW.NET.sln index 8dd54ea..104f6da 100644 --- a/FFTW.NET.sln +++ b/FFTW.NET.sln @@ -1,10 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26127.3 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FFTW.NET", "FFTW.NET\FFTW.NET.csproj", "{4503AC9C-F2E2-4E6B-8C34-01FC8F5EBC58}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C70D1EED-A6CF-48D4-A689-D21FE0A46AEB}" @@ -14,20 +12,42 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FFTW.NET", "FFTW.NET\FFTW.NET.csproj", "{09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4503AC9C-F2E2-4E6B-8C34-01FC8F5EBC58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4503AC9C-F2E2-4E6B-8C34-01FC8F5EBC58}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4503AC9C-F2E2-4E6B-8C34-01FC8F5EBC58}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4503AC9C-F2E2-4E6B-8C34-01FC8F5EBC58}.Release|Any CPU.Build.0 = Release|Any CPU {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Debug|x64.ActiveCfg = Debug|Any CPU + {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Debug|x64.Build.0 = Debug|Any CPU + {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Debug|x86.ActiveCfg = Debug|Any CPU + {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Debug|x86.Build.0 = Debug|Any CPU {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Release|Any CPU.Build.0 = Release|Any CPU + {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Release|x64.ActiveCfg = Release|Any CPU + {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Release|x64.Build.0 = Release|Any CPU + {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Release|x86.ActiveCfg = Release|Any CPU + {FF3AE58A-D8C5-4660-A253-6DFD46EEB8E6}.Release|x86.Build.0 = Release|Any CPU + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Debug|x64.ActiveCfg = Debug|x64 + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Debug|x64.Build.0 = Debug|x64 + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Debug|x86.ActiveCfg = Debug|x86 + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Debug|x86.Build.0 = Debug|x86 + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Release|Any CPU.Build.0 = Release|Any CPU + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Release|x64.ActiveCfg = Release|x64 + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Release|x64.Build.0 = Release|x64 + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Release|x86.ActiveCfg = Release|x86 + {09D24CC5-7C95-44E4-8E08-FDB6A4AA002C}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FFTW.NET/AlignedArray.cs b/FFTW.NET/AlignedArray.cs index 928558f..f62d3ce 100644 --- a/FFTW.NET/AlignedArray.cs +++ b/FFTW.NET/AlignedArray.cs @@ -19,11 +19,10 @@ public class AlignedArray : IPinnedArray readonly PinnedGCHandle _pin; readonly int _alignment; readonly IntPtr _alignedPtr; - readonly long _length; + readonly int _length; readonly int[] _lengths; - public long LongLength => _length; - public int Length => checked((int)_length); + public int Length => _length; public bool IsDisposed => !_pin.IsAllocated; public int Rank => _lengths.Length; @@ -33,20 +32,18 @@ public AlignedArray(byte[] buffer, int alignment, params int[] lengths) { _buffer = buffer; _alignment = alignment; - _length = 1; - foreach (var n in lengths) - _length *= n; + _length = Utils.GetTotalSize(lengths); _lengths = lengths; - if (_length > buffer.LongLength / Marshal.SizeOf()) + if (_length > buffer.Length / Marshal.SizeOf()) throw new ArgumentException($"Buffer is to small to hold array of size {nameof(lengths)}", nameof(buffer)); _pin = PinnedGCHandle.Pin(buffer); long value = _pin.Pointer.ToInt64(); - long offset = alignment - (value % alignment); + int offset = alignment - (int)(value % alignment); _alignedPtr = new IntPtr(value + offset); - long maxLength = (_buffer.LongLength - offset) / Marshal.SizeOf(); + int maxLength = (_buffer.Length - offset) / Marshal.SizeOf(); if (_length > maxLength) { diff --git a/FFTW.NET/BufferPool.cs b/FFTW.NET/BufferPool.cs index 36d035f..928b5b7 100644 --- a/FFTW.NET/BufferPool.cs +++ b/FFTW.NET/BufferPool.cs @@ -14,12 +14,12 @@ namespace FFTW.NET public class BufferPool where T : struct { readonly List _buffers = new List(); - long _minSize; + int _minSize; /// /// Minimum size a buffer must have to be added to the pool. /// - public long MinSizeToPool + public int MinSizeToPool { get { return _minSize; } set @@ -34,16 +34,16 @@ public long MinSizeToPool /// Minimum size a buffer must have to be added to the pool. /// /// - public BufferPool(long minSizeToPool = 0) + public BufferPool(int minSizeToPool = 0) { MinSizeToPool = minSizeToPool; } - public Container RequestBuffer(long minSize) => Container.Get(this, minSize); + public Container RequestBuffer(int minSize) => Container.Get(this, minSize); struct BufferItem { - readonly long _size; + readonly int _size; readonly WeakReference _buffer; public long Size => _size; @@ -51,7 +51,7 @@ struct BufferItem internal BufferItem(T[] buffer) { - _size = buffer.LongLength; + _size = buffer.Length; _buffer = new WeakReference(buffer); } } @@ -69,7 +69,7 @@ private Container(BufferPool bufferPool, T[] buffer) _bufferPool = bufferPool; } - internal static Container Get(BufferPool bufferPool, long minSize) + internal static Container Get(BufferPool bufferPool, int minSize) { if (minSize < bufferPool.MinSizeToPool) return new Container(bufferPool, new T[minSize]); @@ -96,7 +96,7 @@ public void Dispose() if (_buffer == null) return; - if (_buffer.LongLength < _bufferPool.MinSizeToPool) + if (_buffer.Length < _bufferPool.MinSizeToPool) { _buffer = null; return; @@ -106,7 +106,7 @@ public void Dispose() { for (int i = 0; i < _bufferPool._buffers.Count; i++) { - if (_buffer.LongLength >= _bufferPool._buffers[i].Size) + if (_buffer.Length >= _bufferPool._buffers[i].Size) { _bufferPool._buffers.Insert(i, new BufferItem(_buffer)); _buffer = null; diff --git a/FFTW.NET/DFT.cs b/FFTW.NET/DFT.cs index 821c224..ecec3be 100644 --- a/FFTW.NET/DFT.cs +++ b/FFTW.NET/DFT.cs @@ -89,13 +89,13 @@ static void Transform(IPinnedArray input, IPinnedArray output, } else { - using (var bufferContainer = _bufferPool.RequestBuffer(input.LongLength*Marshal.SizeOf()+MemoryAlignment)) + using (var bufferContainer = _bufferPool.RequestBuffer(input.Length * Marshal.SizeOf() + MemoryAlignment)) using (var buffer = new AlignedArrayComplex(bufferContainer.Buffer, MemoryAlignment, input.GetSize())) using (var plan = FftwPlanC2C.Create(buffer, buffer, input.Rank, input.GetSize(), direction, plannerFlags, nThreads)) { input.CopyTo(plan.Input); plan.Execute(); - plan.Output.CopyTo(output, 0, 0, input.LongLength); + plan.Output.CopyTo(output, 0, 0, input.Length); } } } @@ -128,7 +128,7 @@ public static void FFT(IPinnedArray input, IPinnedArray output, /// If with no plan can be created /// and is not specified, we use /// a different buffer to avoid overwriting the input - using (var bufferContainer = _bufferPool.RequestBuffer(input.LongLength * sizeof(double) + MemoryAlignment)) + using (var bufferContainer = _bufferPool.RequestBuffer(input.Length * sizeof(double) + MemoryAlignment)) using (var buffer = new AlignedArrayDouble(bufferContainer.Buffer, MemoryAlignment, input.GetSize())) using (var plan = FftwPlanRC.Create(buffer, output, DftDirection.Forwards, plannerFlags, nThreads)) { @@ -165,7 +165,7 @@ public static void IFFT(IPinnedArray input, IPinnedArray output /// If with no plan can be created /// and is not specified, we use /// a different buffer to avoid overwriting the input - using (var bufferContainer = _bufferPool.RequestBuffer(input.LongLength * Marshal.SizeOf() + MemoryAlignment)) + using (var bufferContainer = _bufferPool.RequestBuffer(input.Length * Marshal.SizeOf() + MemoryAlignment)) using (var buffer = new AlignedArrayComplex(bufferContainer.Buffer, MemoryAlignment, input.GetSize())) using (var plan = FftwPlanRC.Create(output, buffer, DftDirection.Backwards, plannerFlags, nThreads)) { diff --git a/FFTW.NET/FFTW.NET.csproj b/FFTW.NET/FFTW.NET.csproj index 4256edb..21a9e58 100644 --- a/FFTW.NET/FFTW.NET.csproj +++ b/FFTW.NET/FFTW.NET.csproj @@ -1,83 +1,33 @@ - - - + - Debug - AnyCPU - {4503AC9C-F2E2-4E6B-8C34-01FC8F5EBC58} - Library - Properties - FFTW.NET - FFTW.NET - v4.6.1 - 512 - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - true + netstandard1.3 + True + True + ArgusMagnus + + + C#/.NET Wrapper for FFTW (http://www.fftw.org/, native binaries are included). + Copyright 2017 + https://github.com/ArgusMagnus/FFTW.NET/blob/master/LICENSE + https://github.com/ArgusMagnus/FFTW.NET + Git + https://github.com/ArgusMagnus/FFTW.NET + FFTW FFTW.NET FFT - - - - - - - - - + + TextTemplatingFileGenerator + FftwInterop.g.cs + - - - - - - - - True + + + + True + True FftwInterop.tt - - - - - - - - - - - - - TextTemplatingFileGenerator - FftwInterop.g.cs - - - \ No newline at end of file diff --git a/FFTW.NET/FftwInterop.tt b/FFTW.NET/FftwInterop.tt index d335021..cfed273 100644 --- a/FFTW.NET/FftwInterop.tt +++ b/FFTW.NET/FftwInterop.tt @@ -98,7 +98,7 @@ foreach (string import in Imports) if (returnType == "void") { // --------------------------------------------------------- Code End ----------------------------------------------------- #> - if (Environment.Is64BitProcess) + if (Utils.Is64BitProcess) <#=name#>_x64(<#=args#>); else <#=name#>_x86(<#=args#>); @@ -107,7 +107,7 @@ foreach (string import in Imports) else { // --------------------------------------------------------- Code End ----------------------------------------------------- #> - if (Environment.Is64BitProcess) + if (Utils.Is64BitProcess) return <#=name#>_x64(<#=args#>); else return <#=name#>_x86(<#=args#>); diff --git a/FFTW.NET/FftwPlanC2C.cs b/FFTW.NET/FftwPlanC2C.cs index 7d13ca1..94f6350 100644 --- a/FFTW.NET/FftwPlanC2C.cs +++ b/FFTW.NET/FftwPlanC2C.cs @@ -47,14 +47,12 @@ protected override void VerifyRankAndSize(IPinnedArray input, IPinnedAr protected override void VerifyMinSize(IPinnedArray input, IPinnedArray output, int[] n) { - long size = 1; - foreach (var ni in n) - size *= ni; + int size = Utils.GetTotalSize(n); - if (input.LongLength < size) + if (input.Length < size) throw new ArgumentException($"{nameof(input)} is too small."); - if (output.LongLength < size) + if (output.Length < size) throw new ArgumentException($"{nameof(output)} is too small."); } diff --git a/FFTW.NET/FftwPlanRC.cs b/FFTW.NET/FftwPlanRC.cs index b5df2d1..97e9ef1 100644 --- a/FFTW.NET/FftwPlanRC.cs +++ b/FFTW.NET/FftwPlanRC.cs @@ -52,16 +52,20 @@ protected override void VerifyRankAndSize(IPinnedArray bufferReal, IPinn protected override void VerifyMinSize(IPinnedArray bufferReal, IPinnedArray bufferComplex, int[] n) { - long sizeReal = 1; - for (int i = 0; i < n.Length - 1; i++) - sizeReal *= n[i]; - long sizeComplex = sizeReal * (n[n.Length - 1] / 2 + 1); - sizeReal *= n[n.Length - 1]; + int sizeComplex; + int sizeReal = 1; + checked + { + for (int i = 0; i < n.Length - 1; i++) + sizeReal *= n[i]; + sizeComplex = sizeReal * (n[n.Length - 1] / 2 + 1); + sizeReal *= n[n.Length - 1]; + } - if (bufferReal.LongLength < sizeReal) + if (bufferReal.Length < sizeReal) throw new ArgumentException($"{nameof(bufferReal)} is too small."); - if (bufferComplex.LongLength < sizeComplex) + if (bufferComplex.Length < sizeComplex) throw new ArgumentException($"{nameof(bufferComplex)} is too small."); } diff --git a/FFTW.NET/IPinnedArray.cs b/FFTW.NET/IPinnedArray.cs index c99ea40..cd3e12c 100644 --- a/FFTW.NET/IPinnedArray.cs +++ b/FFTW.NET/IPinnedArray.cs @@ -16,7 +16,6 @@ public interface IPinnedArray : IDisposable { int Rank { get; } int Length { get; } - long LongLength { get; } IntPtr Pointer { get; } bool IsDisposed { get; } @@ -31,16 +30,16 @@ public interface IPinnedArray : IDisposable public static class IPinnedArrayExtensions { - public static void CopyTo(this IPinnedArray src, IPinnedArray dst, long srcIndex, long dstIndex, long count) + public static void CopyTo(this IPinnedArray src, IPinnedArray dst, int srcIndex, int dstIndex, int count) where T : struct { - if (count < 0 || count > src.LongLength) + if (count < 0 || count > src.Length) throw new ArgumentOutOfRangeException(nameof(count)); - if (count > dst.LongLength) + if (count > dst.Length) throw new ArgumentException(nameof(dst), "Destination is not large enough."); - if (srcIndex + count > src.LongLength) + if (srcIndex + count > src.Length) throw new ArgumentOutOfRangeException(nameof(srcIndex)); - if (dstIndex + count > src.LongLength) + if (dstIndex + count > src.Length) throw new ArgumentOutOfRangeException(nameof(dstIndex)); int sizeOfT = Marshal.SizeOf(); @@ -48,11 +47,11 @@ public static void CopyTo(this IPinnedArray src, IPinnedArray dst, long { void* pSrc = new IntPtr(src.Pointer.ToInt64() + srcIndex).ToPointer(); void* pDst = new IntPtr(dst.Pointer.ToInt64() + dstIndex).ToPointer(); - System.Buffer.MemoryCopy(pSrc, pDst, dst.LongLength * sizeOfT, count * sizeOfT); + System.Buffer.MemoryCopy(pSrc, pDst, (long)dst.Length * sizeOfT, (long)count * sizeOfT); } } - public static void CopyTo(this IPinnedArray src, IPinnedArray dst, int[] srcIndices, int[] dstIndices, long count) + public static void CopyTo(this IPinnedArray src, IPinnedArray dst, int[] srcIndices, int[] dstIndices, int count) where T : struct { if (srcIndices == null) @@ -60,22 +59,22 @@ public static void CopyTo(this IPinnedArray src, IPinnedArray dst, int[ if (dstIndices == null) throw new ArgumentNullException(nameof(dstIndices)); - long srcIndex = src.GetIndex(srcIndices); - long dstIndex = dst.GetIndex(dstIndices); + int srcIndex = src.GetIndex(srcIndices); + int dstIndex = dst.GetIndex(dstIndices); src.CopyTo(dst, srcIndex, dstIndex, count); } - public static void CopyTo(this IPinnedArray src, IPinnedArray dst) where T:struct + public static void CopyTo(this IPinnedArray src, IPinnedArray dst) where T : struct { - src.CopyTo(dst, 0, 0, dst.LongLength); + src.CopyTo(dst, 0, 0, dst.Length); } - public static long GetIndex(this IPinnedArray array, int[] indices) + public static int GetIndex(this IPinnedArray array, int[] indices) where T : struct { if (indices.Length != array.Rank) throw new ArgumentException($"Array of length {nameof(array.Rank)} = {array.Rank} expected.", nameof(indices)); - long index = indices[0]; + int index = indices[0]; for (int i = 1; i < indices.Length; i++) { index *= array.GetLength(i); @@ -84,4 +83,4 @@ public static long GetIndex(this IPinnedArray array, int[] indices) return index; } } -} +} \ No newline at end of file diff --git a/FFTW.NET/PinnedArray.cs b/FFTW.NET/PinnedArray.cs index 8e60e6f..d1efce9 100644 --- a/FFTW.NET/PinnedArray.cs +++ b/FFTW.NET/PinnedArray.cs @@ -27,7 +27,6 @@ public class PinnedArray : IPinnedArray public int Rank => _buffer.Rank; public Array Buffer => _buffer; public int Length => _buffer.Length; - public long LongLength => _buffer.LongLength; public IntPtr Pointer => _pin.Pointer; public bool IsDisposed => !_pin.IsAllocated; diff --git a/FFTW.NET/Properties/AssemblyInfo.cs b/FFTW.NET/Properties/AssemblyInfo.cs deleted file mode 100644 index ebc35eb..0000000 --- a/FFTW.NET/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("FFTW.NET")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("FFTW.NET")] -[assembly: AssemblyCopyright("Copyright © Tobias Meyer 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("4503ac9c-f2e2-4e6b-8c34-01fc8f5ebc58")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FFTW.NET/Utils.cs b/FFTW.NET/Utils.cs new file mode 100644 index 0000000..a1f00c1 --- /dev/null +++ b/FFTW.NET/Utils.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace FFTW.NET +{ + static class Utils + { + static readonly bool _is64Bit = IntPtr.Size == 8; + + public static bool Is64BitProcess => _is64Bit; + + public static int GetTotalSize(params int[] n) + { + int result = 1; + checked + { + foreach (var ni in n) + result *= ni; + } + return result; + } + } +} \ No newline at end of file diff --git a/TestApp/TestApp.csproj b/TestApp/TestApp.csproj index 78a158f..f295e26 100644 --- a/TestApp/TestApp.csproj +++ b/TestApp/TestApp.csproj @@ -50,7 +50,7 @@ - {4503ac9c-f2e2-4e6b-8c34-01fc8f5ebc58} + {09d24cc5-7c95-44e4-8e08-fdb6a4aa002c} FFTW.NET