Skip to content

Checking if NDArray is null returns wrong results #935

Closed

Description

@Superpiffer

If I try to check if an NDArray is null, I get strange behavior:

NDArray n = null;
bool b1 = n is null;  // TRUE
bool b2 = n == null;  // FALSE!

I saw in NDArray.Operators.cs that if the second value is null, the result is false:

public static NDArray operator ==(NDArray lhs, NDArray rhs)
=> rhs is null ? Scalar(false) : new NDArray(math_ops.equal(lhs, rhs));

Is that a wanted behavior? I think that if both values are null, the result should be true.

Activity

  1. m0nzderr commented on Aug 5, 2022

    @m0nzderr

    Just got into this after migrating from the older version that used NumSharp. Almost had a heart attack by watching an expression if (x != null) throwing a NullReferenceException.
    It looks like it was an intended behavior, according to the implementation, but wait, this is not a Python anymore! Despite there is an "is" operator in C# now, this is not a common idiomatic form. No one should expect from "x == null" anything else except checking for null! In other words, let's not try to turn C# into a Python, please?

  2. Superpiffer commented on Feb 20, 2023

    @Superpiffer
    ContributorAuthor

    Solved 5821275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions