Example #1
0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

"""Implementation for internal polymorphism `logical or` operations."""
from mindspore.ops.composite import base
from mindspore.ops import functional as F

# logical_or is a metagraph object which will generate function according to input type
# using ".register" decorator
logical_or = base.MultitypeFuncGraph("logical_or", True)


@logical_or.register("Number", "Number")
def _logical_or_scala(x, y):
    """
    Return logical or operation result of x and y.

    Args:
       x(Number): Number.
       y(Number): Number.

    Returns:
       bool, Return logical or operation result of x and y.
   """
    return F.bool_or(x.__bool__(), y.__bool__())
Example #2
0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Ungreater required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

"""Implementation for internal polymorphism `greater` operations."""
from mindspore.ops.composite import base
from mindspore.ops import functional as F

# greater is a metafuncgraph object which will determine if two objects are greater according to input type
# using ".register" decorator
greater = base.MultitypeFuncGraph("greater", True)


@greater.register("Number", "Number")
def _greater_scalar(x, y):
    """
    Determine whether two numbers are greater.

    Args:
       x(Number): Number.
       y(Number): Number.

    Returns:
       bool, if x > y return true, x <= y return false.
   """
    return F.scalar_gt(x, y)
Example #3
0
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Implementation for internal polymorphism `less_equal` operations."""
from mindspore.ops.composite import base
from mindspore.ops import functional as F

# less_equal is a metagraph object which will determine if two objects are less_equal according to input type
# using ".register" decorator
less_equal = base.MultitypeFuncGraph("less_equal", True)


@less_equal.register("Number", "Number")
def _less_equal_scala(x, y):
    """
    Determine whether x is less equal than y.

    Args:
       x(Number): Number.
       y(Number): Number.

    Returns:
       bool, if x <= y return true, x > y return false.
   """
    return F.scalar_le(x, y)
Example #4
0
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

"""Implementation for internal polymorphism `uadd` operations."""
from mindspore.ops.composite import base

# uadd is a metagraph object which will return operation result regarding input
# using ".register" decorator
uadd = base.MultitypeFuncGraph("uadd", True)

@uadd.register("Tensor")
@uadd.register("Number")
def _uadd_scala(x):
    return x
Example #5
0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

"""logical_and_impl"""
from mindspore.ops.composite import base
from mindspore.ops import functional as F

# logical_and is a metagraph object which will generate function according to input type
# using ".register" decorator
logical_and = base.MultitypeFuncGraph("logical_and")


@logical_and.register("Number", "Number")
def _logical_and_scala(x, y):
    """
    Return logical and operation result of x and y.

    Args:
       x(Number): Number.
       y(Number): Number.

    Returns:
       bool, Return logical and operation result of x and y.
   """
    return F.bool_and(x.__bool__(), y.__bool__())
Example #6
0
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""equal_impl"""
from mindspore.ops.composite import base
from mindspore.ops import functional as F

# less is a metafuncgraph object which will determine if two objects are less according to input type
# using ".register" decorator
less = base.MultitypeFuncGraph("less")


@less.register("Number", "Number")
def _less_scala(x, y):
    """
    Determine whether two numbers are less.

    Args:
       x(Number): Number.
       y(Number): Number.

    Returns:
       bool, if x < y return true, x >= y return false.
   """
    return F.scalar_lt(x, y)
Example #7
0
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""logical_not_impl"""
from mindspore.ops.composite import base
from mindspore.ops import functional as F

# logical_not is a metagraph object which will generate function according to input type
# using ".register" decorator
logical_not = base.MultitypeFuncGraph("logical_not")


@logical_not.register("Number")
def _logical_not_scala(x):
    """
    Return logical not operation result of x

    Args:
       x(Number): Number.

    Returns:
       bool, Return logical not operation result of x
   """
    return F.bool_not(x.__bool__())
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""greater_equal_impl"""
from mindspore.ops.composite import base
from mindspore.ops import functional as F

# greater_equal is a metagraph object which will determine if two objects are greater_equal according to input type
# using ".register" decorator
greater_equal = base.MultitypeFuncGraph("greater_equal")


@greater_equal.register("Number", "Number")
def _greater_equal_scala(x, y):
    """
    Determine whether x is greater equal than y.

    Args:
       x(Number): Number.
       y(Number): Number.

    Returns:
       bool, if x >= y return true, x < y return false.
   """
    return F.scalar_ge(x, y)