def f(x1, x2): try: if x1._rank() == 2 and x2._rank() == 2: # pylint: disable=protected-access # Fast path for known ranks. return gen_math_ops.mat_mul(x1, x2) return np_utils.cond( math_ops.equal(np_utils.tf_rank(x2), 1), lambda: math_ops.tensordot(x1, x2, axes=1), lambda: np_utils.cond( # pylint: disable=g-long-lambda math_ops.equal(np_utils.tf_rank(x1), 1), lambda: math_ops.tensordot( # pylint: disable=g-long-lambda x1, x2, axes=[[0], [-2]]), lambda: math_ops.matmul(x1, x2))) except errors.InvalidArgumentError as err: raise ValueError(str(err)).with_traceback(sys.exc_info()[2])
def f(x1, x2): try: if x1.shape.rank == 2 and x2.shape.rank == 2: # Fast path for known ranks. return math_ops.matmul(x1, x2) return np_utils.cond( math_ops.equal(np_utils.tf_rank(x2), 1), lambda: math_ops.tensordot(x1, x2, axes=1), lambda: np_utils.cond( # pylint: disable=g-long-lambda math_ops.equal(np_utils.tf_rank(x1), 1), lambda: math_ops.tensordot( # pylint: disable=g-long-lambda x1, x2, axes=[[0], [-2]]), lambda: math_ops.matmul(x1, x2))) except errors.InvalidArgumentError as err: six.reraise(ValueError, ValueError(str(err)), sys.exc_info()[2])