tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] zhiics commented on a change in pull request #4862: [REFACTOR][PY] establish tvm.ir, migrate base, expr, type, adt
Date Tue, 11 Feb 2020 18:31:04 GMT
zhiics commented on a change in pull request #4862: [REFACTOR][PY] establish tvm.ir, migrate
base, expr, type, adt
URL: https://github.com/apache/incubator-tvm/pull/4862#discussion_r377817042
 
 

 ##########
 File path: python/tvm/ir/type.py
 ##########
 @@ -0,0 +1,205 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+"""Unified type system in the project."""
+from enum import IntEnum
+import tvm._ffi
+
+from .base import Node
+from . import _ffi_api
+
+
+class Type(Node):
+    """The base class of all types."""
+    def __eq__(self, other):
+        """Compare two types for structural equivalence."""
+        return bool(_ffi_api.type_alpha_equal(self, other))
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def same_as(self, other):
+        """Compares two Relay types by referential equality."""
+        return super().__eq__(other)
+
+
+class TypeKind(IntEnum):
+    """Possible kinds of TypeVars."""
+    Type = 0
+    ShapeVar = 1
+    BaseType = 2
+    Constraint = 4
+    AdtHandle = 5
+    TypeData = 6
+
+
+@tvm._ffi.register_object("relay.TypeVar")
+class TypeVar(Type):
+    """Type parameter in functions.
+
+    A type variable represents a type placeholder which will
+    be filled in later on. This allows the user to write
+    functions which are generic over types.
+
+    Parameters
+    ----------
+    name_hint: str
+        The name of the type variable. This name only acts as a hint, and
+        is not used for equality.
+
+    kind : Optional[TypeKind]
+        The kind of the type parameter.
+    """
+    def __init__(self, name_hint, kind=TypeKind.Type):
+        self.__init_handle_by_constructor__(
+            _ffi_api.TypeVar, name_hint, kind)
+
+    def __call__(self, *args):
+        """Create a type call from this type.
+
+        Parameters
+        ----------
+        args: List[Type]
+            The arguments to the type call.
+
+        Returns
+        -------
+        call: Type
+            The result type call.
+        """
+        # pylint: disable=import-outside-toplevel
+        from .type_relation import TypeCall
+        return TypeCall(self, args)
+
+
+@tvm._ffi.register_object("relay.GlobalTypeVar")
+class GlobalTypeVar(Type):
+    """A global type variable that is used for defining new types or type aliases.
+
+    Parameters
+    ----------
+    name_hint: str
+        The name of the type variable. This name only acts as a hint, and
+        is not used for equality.
+
+    kind : Optional[TypeKind]
+        The kind of the type parameter.
+    """
+    def __init__(self, name_hint, kind=TypeKind.AdtHandle):
+        self.__init_handle_by_constructor__(
+            _ffi_api.GlobalTypeVar, name_hint, kind)
+
+    def __call__(self, *args):
+        """Create a type call from this type.
+
+        Parameters
+        ----------
+        args: List[Type]
+            The arguments to the type call.
+
+        Returns
+        -------
+        call: Type
+            The result type call.
+        """
+        # pylint: disable=import-outside-toplevel
+        from .type_relation import TypeCall
+        return TypeCall(self, args)
+
+
+@tvm._ffi.register_object("relay.TupleType")
+class TupleType(Type):
+    """The type of tuple values.
+
+    Parameters
+    ----------
+    fields : List[Type]
+        The fields in the tuple
+    """
+
+    def __init__(self, fields):
+        self.__init_handle_by_constructor__(
+            _ffi_api.TupleType, fields)
+
+
+@tvm._ffi.register_object("relay.TypeConstraint")
+class TypeConstraint(Type):
+    """Abstract class representing a type constraint."""
+
+
+@tvm._ffi.register_object("relay.FuncType")
+class FuncType(Type):
+    """Function type.
+
+
 
 Review comment:
   extra line?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message