Quansight-Labs/numpy.net

np.array_equal(new int[0], new int[0]) should output True

Happypig375 opened this issue · 11 comments

but this library returns false.

np.all(new int[0]) -> true
np.any(new int[0]) -> false
these two also should not throw.

np.sum(new int[0]) -> 0
np.prod(new int[0]) -> 1
these two also should not throw.

np.logical_and(new int[0], new int[0]) is supposed to return an empty array

This library should check functions for empty arrays

np.stack(new[]{new int[0], new int[0]}) should also output empty array

you have found some edge cases that I may not be handling in the same exact way as python/numpy. Are you working on an application that makes use of these empty arrays? Or are you just looking for ways to break NumpyDotNet?

What is the use case for these empty arrays? I can't think of any practical use for an empty array.

I am actually very busy with other things right now, so if you are just trying to break it I will attempt to resolve these issues when I get some free time. If you are really being blocked by them, let me know and I will try to get to them sooner.

I encountered this for np.array_equal with I was implementing the Apriori algorithm for association data mining. Here in the join step an elementwise equality check is done for a slice of items excluding the last item.
image
However, for the case where k = 2, the slice generates an empty array, causing the check for np.array_equal to return an invalid false.

You can fix this when you are free though, I can just work around this when an empty array is present. It's just surprising to reveal that empty arrays have issues with this library when testing other functions for empty arrays as well.

I generated a new release 0.9.76 to fix these empty array issues you have discovered.
Let me know if you have any more trouble.

np.stack still throws for empty array

Here is a unit test using np.stack that does not throw an exception. It does not produce the exact same result as python but no exception. Can you provide a np.stack call that does throw and exception?

    [TestMethod]
    public void test_HadrianTang_6()
    {

        var x = np.concatenate((new Int32[0], new Int32[0]));
        Assert.IsTrue(x.Size == 0);
        print(x);

        x = np.stack(new[] { new Int32[0], new Int32[0] });
        Assert.IsTrue(x.Size == 0);
        print(x);
   

        return;
    }

Ah sorry, it was this case

np.stack(new int[0][]);

but I found out that Python throws for this as well.

import numpy as np
print(np.stack([]))