[Bug] np.random.choice raise Exception
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.cumsum_elementwise(NDArray& arr, Nullable
1 typeCode) at NumSharp.Backends.DefaultEngine.ReduceCumAdd(NDArray& arr, Nullable1 axis_, Nullable1 typeCode) at NumSharp.np.cumsum(NDArray arr, Nullable1 axis, Nullable`1 typeCode)
It seems there is no UT for this function in this repo.
Besides, another argument replace is not used at all in both overrides.
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.
相同的问题,你解决了吗?
目前发现的解决方案就是上面那样自己copy一个,加上typeCode就能跑了
是我没有留意到那个“Ok”的注释,按照你的方案,我复制了官方Numsharp-master中的相关方法,添加了相关的typeCode参数,问题解决。非常感谢!
This has been fixed. np.random.choice now works correctly:
np.random.seed(42);
var result = np.random.choice(5, 3, true);
// Result: [3, 4, 2]
The underlying cumsum issue that caused the NotSupportedException has been resolved.
Resolved via #600, #602, #603, #596.