SciSharp / NumSharp

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

np.argsort not sorting properly #405

Open tk4218 opened 4 years ago

tk4218 commented 4 years ago

I am attempting to call np.argsort() on the following array: [0.700656592845917, 0.651415288448334, 0.719015657901764] dtype = Double

The expected result should be: [1, 0, 2]

However, the actual result I'm getting is: [0, 2, 1]

This doesn't to produce a result that is sorted in any direction. I pulled in ndarray.argsort locally and changed line 31 - from: var data = Array; to: var data = ToArray<T>() (Also changing the declaration of the function to include where T : unmanaged)

And this seemed to work for me.

tk4218 commented 4 years ago

After trying things out for awhile, it seems I can get np.argsort to work if I pass a copy of the NDArray to it. It seems like the NDArray is being manipulated while sorting, causing the sort to misbehave.

It seems like np.argsort should be: nd.copy().argsort<T>(axis)

rather than: nd.argsort<t>(axis)