def subtract(x, biases): if isinstance(x, expr.Constant) and isinstance(biases, expr.Constant): return expr.Constant(subtract_fn.forward([x.value, biases.value])[0]) else: return expr.Apply(subtract_fn, [x, biases])
def softmax(x): if isinstance(x, expr.Constant): return expr.Constant(softmax_fn.forward([x.value])[0]) else: return expr.Apply(softmax_fn, [x])
def reshape(values, new_shape): if isinstance(values, expr.Constant): return expr.Constant(Reshape(new_shape).forward([values.value])) else: return expr.Apply(Reshape(new_shape), [values])
def mean(values, dims): if isinstance(values, expr.Constant): return expr.Constant(Mean(dims).forward(values.value)) else: return expr.Apply(Mean(dims), [values])
def squared_difference(x, weights): if isinstance(x, expr.Constant) and isinstance(weights, expr.Constant): return expr.Constant(squared_difference_fn.forward([x.value, weights.value])[0]) else: return expr.Apply(squared_difference_fn, [x, weights])
def sigmoid_cross_entropy(x, labels): if isinstance(x, expr.Constant) and isinstance(labels, expr.Constant): return expr.Constant( sigmoid_cross_entropy_fn.forward([x.value, labels.value])[0]) else: return expr.Apply(sigmoid_cross_entropy_fn, [x, labels])
def upsample(values, scale): if isinstance(values, expr.Constant): return expr.Constant(Upsample(scale).forward(values.value)) else: return expr.Apply(Upsample(scale), [values])
def add_biases(x, biases): if isinstance(x, expr.Constant) and isinstance(biases, expr.Constant): return expr.Constant(add_biases_fn.forward([x.value, biases.value])[0]) else: return expr.Apply(add_biases_fn, [x, biases])
def linear(x, weights): if isinstance(x, expr.Constant) and isinstance(weights, expr.Constant): return expr.Constant(linear_fn.forward([x.value, weights.value])[0]) else: return expr.Apply(linear_fn, [x, weights])
def sigmoid(x): if isinstance(x, expr.Constant): return expr.Constant(sigmoid_fn.forward([x.value])[0]) else: return expr.Apply(sigmoid_fn, [x])
def concat(args, axis): if all(lambda x: isinstance(expr.Constant), args): return expr.Constant( Concat(axis).forward(map(lambda x: x.value, args))) else: return expr.Apply(Concat(axis), [args])
def broadcast(x, shape=None): if isinstance(x, expr.Constant): return expr.Constant(Broadcast(shape).forward([x.value])[0]) else: return expr.Apply(Broadcast(shape), [x])