Quansight-Labs / numpy.net

A port of NumPy to .Net
BSD 3-Clause "New" or "Revised" License
128 stars 14 forks source link

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

Closed Happypig375 closed 2 years ago

Happypig375 commented 2 years ago

but this library returns false.

Happypig375 commented 2 years ago

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

Happypig375 commented 2 years ago

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

Happypig375 commented 2 years ago

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

Happypig375 commented 2 years ago

This library should check functions for empty arrays

Happypig375 commented 2 years ago

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

KevinBaselinesw commented 2 years ago

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.

Happypig375 commented 2 years ago

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.

KevinBaselinesw commented 2 years ago

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.

Happypig375 commented 2 years ago

np.stack still throws for empty array

KevinBaselinesw commented 2 years ago

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;
    }
Happypig375 commented 2 years ago

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([]))