Skip to content

Conversation

@vbkaisetsu
Copy link
Contributor

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.

@vbkaisetsu vbkaisetsu requested a review from odashi July 18, 2018 22:51
"""
CppDevice.set_default(device.wrapped[0])
global py_primitiv_default_device
py_primitiv_default_device = device
Copy link
Member

Choose a reason for hiding this comment

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

Type check?

Copy link
Contributor Author

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:
Copy link
Member

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.

Copy link
Contributor Author

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.

@odashi odashi merged commit aebd0fb into develop Jul 20, 2018
@odashi odashi deleted the feature/store-default-object branch July 20, 2018 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants