Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/tvm/relax/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class ShapeTypeNode : public TypeNode {

class ShapeType : public Type {
public:
// TODO(relax-team): remove the default value later.
TVM_DLL ShapeType(int ndim = kUnknownNDim, Span span = Span());
TVM_DLL ShapeType(int ndim, Span span = Span());

TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ShapeType, Type, ShapeTypeNode);
};
Expand Down
7 changes: 3 additions & 4 deletions python/tvm/relax/ty.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ class ShapeType(Type):

Parameters
----------
ndim : Optional[int]
The size of the shape.
ndim : int
The number of dimensions of the shape. Use -1 for unknown ndim.
"""

# TODO(relax-team): consider make ndim mandatory
def __init__(self, ndim: int = -1, span: Span = None) -> None:
def __init__(self, ndim: int, span: Span = None) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ndim parameter is now mandatory in the constructor. However, the class docstring (at line 34, just above this hunk) still describes ndim as Optional[int]. Please update the docstring to int to maintain consistency with the implementation.

self.__init_handle_by_constructor__(_ffi_api.ShapeType, ndim, span) # type: ignore


Expand Down
4 changes: 2 additions & 2 deletions tests/python/relax/test_ast_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_shape_expr():

def test_types():
printer = ASTPrinter()
assert strip_whitespace(printer.visit_type_(rx.ShapeType())) == "ShapeType(ndim=-1)"
assert strip_whitespace(printer.visit_type_(rx.ShapeType(ndim=-1))) == "ShapeType(ndim=-1)"
assert strip_whitespace(printer.visit_type_(rx.ShapeType(ndim=1))) == "ShapeType(ndim=1)"
object_type = rx.ObjectType()
assert strip_whitespace(printer.visit_type_(object_type)) == "ObjectType()"
Expand All @@ -266,7 +266,7 @@ def test_types():
assert strip_whitespace(printer.visit_type_(tensor_type)) == "TensorType(ndim=2,dtype=int32)"
unit_type = rx.TupleType([])
assert strip_whitespace(printer.visit_type_(unit_type)) == "TupleType(fields=[])"
tuple_type = rx.TupleType([rx.ShapeType(), object_type])
tuple_type = rx.TupleType([rx.ShapeType(ndim=-1), object_type])
assert_fields(
"TupleType",
{"fields": "[ShapeType(ndim=-1),ObjectType()]"},
Expand Down
4 changes: 2 additions & 2 deletions tests/python/relax/test_struct_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def test_object_struct_info():


def test_shape_type():
t0 = rx.ShapeType()
t1 = rx.ShapeType()
t0 = rx.ShapeType(ndim=-1)
t1 = rx.ShapeType(ndim=-1)
assert t0 == t1


Expand Down
Loading