Quansight-Labs / numpy.net

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

[Suggest] make Ndarray == closer to numpy #38

Closed ChengYen-Tang closed 1 year ago

ChengYen-Tang commented 1 year ago

There is no Equals method for ndarray in numpy, so I think in numpy.net if you want to compare ndarray instence, you should use Equals instead of ==.

  ndarray a1 = new ndarray();
  ndarray a2 = new ndarray();

a. Compare elements in two ndarrays
  ndarray result = a1 == a2;

b. Compare instance of two objects
  bool result = a1.Equals(a2);

c. Check ndarray is null
  bool result = a1 is null;
  bool result = a1 is not null; //need C# 7.0 or later
  --Solution--
  1. set <LangVersion>latest</LangVersion> in csproj
      https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version#c-language-version-reference
  2. bool result = !(a1 is null);

If you accept my proposal, but you are not free, I can assist you.

KevinBaselinesw commented 1 year ago

== is a special .NET case. If you override that, you also have to override != and that creates other problems in the code.

Try using np.equals() and np.array_equal() instead.

Also, I already overide ndarray.Equals()

ChengYen-Tang commented 1 year ago

What are the problems, can you explain? I think override != is a must

image