[Arith] DetectLinearEquation is returning an empty container for unhandled `Expr`

DetectLinearEquation is an important utility method that is used in many places.

However, if it encounters Expr with a call to any other functions it fails to identify it as Non-Linear equation and instead of returning 0 as Coeff for the requested var, it returns an empty container.

If this empty container gets accessed as an Array, it can throw SegFaults.

E.g. following example:

   import tvm
    
    def test_basic():
        a = tvm.var("a")
        b = tvm.var("b")
        m = tvm.arith.DetectLinearEquation(a + tvm.expr.Select(b > 0, a, b), [a])
        print(m)
    
    
    test_basic()

Here we have a equation with a Select : a + Select(b>0, a, b).

DetectLinearEquation returns an empty Array for this example.

If DetectLinearEquation cannot handle this equation then, it should either:

  1. show some warning or
  2. another way is to classify this equation as a Non-linear equation and return 0 as Coeff of a.

So, currently, users have to make sure that Input passed to DetectLinearEquation is something that it can handle. But this is not something that can be guaranteed.

One way to fix this issue is checking for empty container every time using DetectLinearEquation.

However, is there a better way to handle this ?

@xqdan @derisavi-huawei