-
Notifications
You must be signed in to change notification settings - Fork 2
Store default objects in python #41
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
Conversation
| """ | ||
| CppDevice.set_default(device.wrapped[0]) | ||
| global py_primitiv_default_device | ||
| py_primitiv_default_device = device |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required. The argument is typed statically, and it throws TypeError if a wrong argument is specified.
In [5]: Device.set_default({})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-558a1bb96fcd> in <module>()
----> 1 Device.set_default({})
TypeError: Argument 'device' has incorrect type (expected primitiv._device.Device, got dict)
|
|
||
| @staticmethod | ||
| def raw_input(shape, vector[float] data, Device device = None, Graph graph = None): | ||
| if device is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_cpp_something may return NULL and NULL is acceptable by C++ APIs (if they received NULLs, it is replaced to the C++-side default objects). This may confuse the overall behavior.
It is good to add some Python-side functions get_default_or_die, or adding an option to get_default to raise an exception if the Python-side default object is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. get_default() checks default object now.
Related to #39
This branch holds default objects in the python module instead of using set/get_default() of the core library.
I checked that it works fine on Windows 10.