SciSharp / NumSharp

High Performance Computation for N-D Tensors in .NET, similar API to NumPy.
https://github.com/SciSharp
Apache License 2.0
1.37k stars 192 forks source link

Unable to convert between types via numpy.astype #280

Closed Nucs closed 5 years ago

Nucs commented 5 years ago

Consider the following code:

a = np.array([1, 2, 3], dtype=np.int32)
a = a.astype(np.float64)

The following code in C# does not work:

np.array(1, 2, 3, 4, 5).astype(np.float64);

Exception:

Test method NumSharp.UnitTest.NpRandomUniformTests.Basic threw exception: 
System.NotImplementedException: _ChangeTypeOfArray from Int32 to Double
    at NumSharp.Backends.TypedArrayStorage._ChangeTypeOfArray(Array arrayVar, Type to_dtype) in C:\Users\Eli-PC\Desktop\NumSharp\src\NumSharp.Core\Backends\TypedArrayStorage.cs:line 135
   at NumSharp.Backends.TypedArrayStorage.SetData(Array values, Type dtype) in C:\Users\Eli-PC\Desktop\NumSharp\src\NumSharp.Core\Backends\TypedArrayStorage.cs:line 718
   at NumSharp.NDArray.astype(Type dtype, Boolean copy) in C:\Users\Eli-PC\Desktop\NumSharp\src\NumSharp.Core\Backends\NDArray.cs:line 132
   at NumSharp.UnitTest.NpRandomUniformTests.Basic() in C:\Users\Eli-PC\Desktop\NumSharp\test\NumSharp.UnitTest\Random\np.random.uniform.Test.cs:line 16
Nucs commented 5 years ago

I can fix it simply by adding support for all type conversions in _ChangeTypeOfArray like it is in python. Let me know if you want me to PR it.

Oceania2018 commented 5 years ago

No, thanks. I’ve already fixed that issue on my local.

Nucs commented 5 years ago

Was fixed in PR #287