In the python interface of mxnet it seems to be impossible to distinguish between an array of unknown shape and an array with known shape of ():
a = mx.sym.var('a')
b = mx.sym.var('b')
(a + b).infer_shape_partial(b=())
([(), ()], [()], [])
In this case b is known to be a scalar, while a's shape is unknown.
Shouldn't it return something like ([None, ()], [None], [])?
If a is set to be a scalar, it returns an invalid result:
a = mx.sym.var('a')
b = mx.sym.var('b')
(a + b).infer_shape_partial(a=(), b=(1, 2))
([(1, 2), (1, 2)], [(1, 2)], [])
It identifies the shape of a as (1, 2), even though we set it to a scalar.
If we don't set the shape of a, it returns results, that aren't always true:
a = mx.sym.var('a')
b = mx.sym.var('b')
c = a + b
c.infer_shape_partial(b=(1, 2))
([(1, 2), (1, 2)], [(1, 2)], [])
# but a could also be a scalar:
a_ = mx.nd.zeros(())
b_ = mx.nd.zeros((1, 2))
func = c.bind(mx.cpu(), {'a': a_, 'b': b_})
func.forward()
Edit: Does it? It looks like it accesses memory out of bounds:
a = mx.sym.var('a')
b = mx.sym.var('b')
c = a + b
a_ = mx.nd.ones(())
b_ = mx.nd.ones((5))
func = c.bind(mx.cpu(), {'a': a_, 'b': b_})
func.forward()
func.outputs[0].asnumpy()
array([ 2.00000000e+00, 2.52435490e-29, 8.84247875e+05,
1.08446609e-19, -1.92860745e-26], dtype=float32)