dotnet / TorchSharp

A .NET library that provides access to the library that powers PyTorch.
MIT License
1.37k stars 177 forks source link

Sort out complex support #142

Closed dsyme closed 3 years ago

dsyme commented 4 years ago

Torch has support for ComplexFloat and ComplexDouble tensors.

I took a look at lighting this up for ComplexDouble using System.Numerics.Complex as the .NET in-memory interchange type. However I got a crash and disabled it - it should have "just worked" if the memory layouts are compatible - I'll double check what's going on.

The test CreateComplexDoubleTensorFromDataCheckStrides is commented out

dsyme commented 4 years ago

C# Complex.cs https://github.com/microsoft/referencesource/blob/master/System.Numerics/System/Numerics/Complex.cs

THe C++ std::complex https://en.cppreference.com/w/cpp/numeric/complex

They seem to have exactly the same memory layout, I'm not sure what's up.

NiklasGustafsson commented 3 years ago

I have added fairly complete support for complex numbers in the TorchSharp bindings. There was really no need to deal with the std::complex type in C++.