Skip to content

Commit

Permalink
Changed project to .NETStandard library (v1.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArgusMagnus committed Feb 3, 2017
1 parent 25d66ec commit 564f589
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 170 deletions.
36 changes: 28 additions & 8 deletions FFTW.NET.sln
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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
Expand Down
15 changes: 6 additions & 9 deletions FFTW.NET/AlignedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ public class AlignedArray<T> : IPinnedArray<T>
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;

Expand All @@ -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<T>())
if (_length > buffer.Length / Marshal.SizeOf<T>())
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<T>();
int maxLength = (_buffer.Length - offset) / Marshal.SizeOf<T>();

if (_length > maxLength)
{
Expand Down
18 changes: 9 additions & 9 deletions FFTW.NET/BufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace FFTW.NET
public class BufferPool<T> where T : struct
{
readonly List<BufferItem> _buffers = new List<BufferItem>();
long _minSize;
int _minSize;

/// <summary>
/// Minimum size a buffer must have to be added to the pool.
/// </summary>
public long MinSizeToPool
public int MinSizeToPool
{
get { return _minSize; }
set
Expand All @@ -34,24 +34,24 @@ public long MinSizeToPool
/// Minimum size a buffer must have to be added to the pool.
/// </summary>
/// <param name="minSizeToPool"></param>
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<T[]> _buffer;

public long Size => _size;
public WeakReference<T[]> Buffer => _buffer;

internal BufferItem(T[] buffer)
{
_size = buffer.LongLength;
_size = buffer.Length;
_buffer = new WeakReference<T[]>(buffer);
}
}
Expand All @@ -69,7 +69,7 @@ private Container(BufferPool<T> bufferPool, T[] buffer)
_bufferPool = bufferPool;
}

internal static Container Get(BufferPool<T> bufferPool, long minSize)
internal static Container Get(BufferPool<T> bufferPool, int minSize)
{
if (minSize < bufferPool.MinSizeToPool)
return new Container(bufferPool, new T[minSize]);
Expand All @@ -96,7 +96,7 @@ public void Dispose()
if (_buffer == null)
return;

if (_buffer.LongLength < _bufferPool.MinSizeToPool)
if (_buffer.Length < _bufferPool.MinSizeToPool)
{
_buffer = null;
return;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions FFTW.NET/DFT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ static void Transform(IPinnedArray<Complex> input, IPinnedArray<Complex> output,
}
else
{
using (var bufferContainer = _bufferPool.RequestBuffer(input.LongLength*Marshal.SizeOf<Complex>()+MemoryAlignment))
using (var bufferContainer = _bufferPool.RequestBuffer(input.Length * Marshal.SizeOf<Complex>() + 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);
}
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public static void FFT(IPinnedArray<double> input, IPinnedArray<Complex> output,
/// If with <see cref="PlannerFlags.WisdomOnly"/> no plan can be created
/// and <see cref="PlannerFlags.Estimate"/> 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))
{
Expand Down Expand Up @@ -165,7 +165,7 @@ public static void IFFT(IPinnedArray<Complex> input, IPinnedArray<double> output
/// If with <see cref="PlannerFlags.WisdomOnly"/> no plan can be created
/// and <see cref="PlannerFlags.Estimate"/> is not specified, we use
/// a different buffer to avoid overwriting the input
using (var bufferContainer = _bufferPool.RequestBuffer(input.LongLength * Marshal.SizeOf<Complex>() + MemoryAlignment))
using (var bufferContainer = _bufferPool.RequestBuffer(input.Length * Marshal.SizeOf<Complex>() + MemoryAlignment))
using (var buffer = new AlignedArrayComplex(bufferContainer.Buffer, MemoryAlignment, input.GetSize()))
using (var plan = FftwPlanRC.Create(output, buffer, DftDirection.Backwards, plannerFlags, nThreads))
{
Expand Down
96 changes: 23 additions & 73 deletions FFTW.NET/FFTW.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,83 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4503AC9C-F2E2-4E6B-8C34-01FC8F5EBC58}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FFTW.NET</RootNamespace>
<AssemblyName>FFTW.NET</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFramework>netstandard1.3</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Authors>ArgusMagnus</Authors>
<Company />
<Product />
<Description>C#/.NET Wrapper for FFTW (http://www.fftw.org/, native binaries are included).</Description>
<Copyright>Copyright 2017</Copyright>
<PackageLicenseUrl>https://github.com/ArgusMagnus/FFTW.NET/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/ArgusMagnus/FFTW.NET</PackageProjectUrl>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/ArgusMagnus/FFTW.NET</RepositoryUrl>
<PackageTags>FFTW FFTW.NET FFT</PackageTags>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<None Update="FftwInterop.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>FftwInterop.g.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="AlignedArray.cs" />
<Compile Include="FftwArray.cs" />
<Compile Include="PinnedArray.cs" />
<Compile Include="BufferPool.cs" />
<Compile Include="DFT.cs" />
<Compile Include="FftwInterop.cs" />
<Compile Include="FftwInterop.g.cs">
<AutoGen>True</AutoGen>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="FftwInterop.g.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>FftwInterop.tt</DependentUpon>
</Compile>
<Compile Include="FftwPlan.cs" />
<Compile Include="FftwPlanC2C.cs" />
<Compile Include="FftwPlanRC.cs" />
<Compile Include="IPinnedArray.cs" />
<Compile Include="PinnedGCHandle.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<Content Include="FftwInterop.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>FftwInterop.g.cs</LastGenOutput>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
4 changes: 2 additions & 2 deletions FFTW.NET/FftwInterop.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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#>);
Expand All @@ -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#>);
Expand Down
8 changes: 3 additions & 5 deletions FFTW.NET/FftwPlanC2C.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ protected override void VerifyRankAndSize(IPinnedArray<Complex> input, IPinnedAr

protected override void VerifyMinSize(IPinnedArray<Complex> input, IPinnedArray<Complex> 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.");
}

Expand Down
18 changes: 11 additions & 7 deletions FFTW.NET/FftwPlanRC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,20 @@ protected override void VerifyRankAndSize(IPinnedArray<double> bufferReal, IPinn

protected override void VerifyMinSize(IPinnedArray<double> bufferReal, IPinnedArray<Complex> 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.");
}

Expand Down
Loading

0 comments on commit 564f589

Please sign in to comment.