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

[Bug] np.random.choice raise Exception #466

Open QingtaoLi1 opened 2 years ago

QingtaoLi1 commented 2 years ago

Hi, when using np.random.choice, I got an Exception with message "Specified method is not supported.", and the stack trace is:

at NumSharp.NPTypeCodeExtensions.GetAccumulatingType(NPTypeCode typeCode) at NumSharp.Backends.DefaultEngine.cumsumelementwise(NDArray& arr, Nullable1 typeCode) at NumSharp.Backends.DefaultEngine.ReduceCumAdd(NDArray& arr, Nullable1 axis, Nullable1 typeCode) at NumSharp.np.cumsum(NDArray arr, Nullable1 axis, Nullable`1 typeCode)

QingtaoLi1 commented 2 years ago

It seems there is no UT for this function in this repo.

QingtaoLi1 commented 2 years ago

Besides, another argument replace is not used at all in both overrides.

QingtaoLi1 commented 2 years ago

I do a simple test on np.cumsum since it is in the stack trace:

    public static void RandomChoice()
    {
        var array = np.arange(1, 50265);
        var arrayDouble = 1.0 / array.astype(np.@double);
        var cumsum = np.cumsum(arrayDouble, typeCode: arrayDouble.typecode);  // OK
        var cumsum2 = np.cumsum(arrayDouble);                              // raise Exception mentioned above
    }

It looks like there's something wrong in the default typeCode. BTW, I'm using the latest NumSharp 0.30.0 version.

UCtreespring commented 2 years ago

相同的问题,你解决了吗?

QingtaoLi1 commented 2 years ago

目前发现的解决方案就是上面那样自己copy一个,加上typeCode就能跑了

UCtreespring commented 2 years ago

是我没有留意到那个“Ok”的注释,按照你的方案,我复制了官方Numsharp-master中的相关方法,添加了相关的typeCode参数,问题解决。非常感谢!