Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime][Object] expose runtime::String to Python #5212

Merged
merged 2 commits into from
Apr 2, 2020
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
6 changes: 3 additions & 3 deletions include/tvm/runtime/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,12 @@ class String : public ObjectRef {
#endif
}

TVM_DEFINE_OBJECT_REF_METHODS(String, ObjectRef, StringObj);

private:
/*! \return the internal StringObj pointer */
const StringObj* get() const { return operator->(); }

TVM_DEFINE_OBJECT_REF_METHODS(String, ObjectRef, StringObj);

private:
/*!
* \brief Compare two char sequence
*
Expand Down
18 changes: 18 additions & 0 deletions python/tvm/runtime/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,22 @@ def tuple_object(fields=None):
return _Tuple(*fields)


@tvm._ffi.register_object("runtime.String")
class String(Object):
"""The string object.

Parameters
----------
string : Str
The string used to construct a runtime String object

Returns
-------
ret : String
The created object.
"""
def __init__(self, string):
self.__init_handle_by_constructor__(_String, string)


tvm._ffi._init_api("tvm.runtime.container")
6 changes: 6 additions & 0 deletions src/runtime/container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ TVM_REGISTER_GLOBAL("runtime.container._ADT")
*rv = ADT(tag, fields);
});

TVM_REGISTER_GLOBAL("runtime.container._String")
.set_body_typed([](std::string str) {
return String(std::move(str));
});

TVM_REGISTER_OBJECT_TYPE(ADTObj);
TVM_REGISTER_OBJECT_TYPE(StringObj);
TVM_REGISTER_OBJECT_TYPE(ClosureObj);

} // namespace runtime
Expand Down