def not_equal(inputs, **kwargs): r"""Compute the element-wise not-equal comparison. .. math:: \text{out} = (\text{input1} \neq \text{input2}) Examples: ```python a = dragon.constant(2) b = dragon.constant(3) c = dragon.constant(3) print(dragon.math.not_equal([a, b])) print(dragon.math.not_equal([b, c])) ``` Parameters ---------- inputs : Sequence[dragon.Tensor] The input1 and input2 tensor. Returns ------- dragon.Tensor The output tensor. """ args = ArgHelper.parse(locals()) inputs = ops.remove_binary_scalar(inputs) op_lib = math_ops_lib.BinaryOp if context.executing_eagerly(): return op_lib.instantiate(op_type='NotEqual').apply(inputs) else: return op_lib.blend('NotEqual', **args)
def mul(inputs, **kwargs): r"""Compute the element-wise multiplication. .. math:: \text{out} = \text{input1} \times \text{input2} Examples: ```python a = dragon.constant(4) b = dragon.constant(2) print(dragon.math.mul([a, b])) print(a * b) # Equivalent operation ``` Parameters ---------- inputs : Sequence[dragon.Tensor] The input1 and input2 tensor. Returns ------- dragon.Tensor The output tensor. """ args = ArgHelper.parse(locals()) inputs = ops.remove_binary_scalar(inputs) op_lib = math_ops_lib.BinaryOp if context.executing_eagerly(): return op_lib.instantiate(op_type='Mul').apply(inputs) else: return op_lib.blend('Mul', **args)
def pow(inputs, **kwargs): r"""Compute the power of input. .. math:: \text{out} = \text{input}^{\text{exponent}} The two inputs should be broadcast to each other: ```python x = dragon.fill(shape=(1, 2), value=2) print(dragon.math.pow([x, x])) # [[4, 4]] print(dragon.math.pow([x, 3])) # [[8, 8]] print(dragon.math.pow([3, x])) # [[9, 9]] ``` Parameters ---------- inputs : Sequence[dragon.Tensor] The input and exponent tensor. Returns ------- dragon.Tensor The output tensor. """ args = ArgHelper.parse(locals()) inputs = ops.remove_binary_scalar(inputs) op_lib = math_ops_lib.BinaryOp if context.executing_eagerly(): return op_lib.instantiate(op_type='Pow').apply(inputs) else: return op_lib.blend('Pow', **args)
def minimum(inputs, **kwargs): r"""Compute the minimum value of given two inputs. .. math:: \text{out} = \min(\text{input1}, \text{input2}) Parameters ---------- inputs : Sequence[Union[dragon.Tensor, number]] The input1 and input2 tensor. Returns ------- dragon.Tensor The output tensor. """ args = ArgHelper.parse(locals()) inputs = ops.remove_binary_scalar(inputs) op_lib = math_ops_lib.BinaryOp if context.executing_eagerly(): return op_lib.instantiate(op_type='Minimum').apply(inputs) else: return op_lib.blend('Minimum', **args)
def _binary_op(a, b, op_type, outputs=(None,)): """Apply the binary operation.""" return math_ops_lib.BinaryOp \ .instantiate(op_type=op_type) \ .apply(ops.remove_binary_scalar([a, b]), outputs)
def _binary_op(a, b, op_type): """Apply the binary operator.""" a, b = ops.remove_binary_scalar([a, b]) return OpDef.apply(op_type, [a, b])