forked from dmlc/nnvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PYTHON] Check in a symbolic construction interface in python, start … (
dmlc#4) * [PYTHON] Check in a symbolic construction interface in python, start add graph API * Graph API
- Loading branch information
Showing
18 changed files
with
1,145 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,5 @@ build | |
lib | ||
*~ | ||
dmlc-core | ||
cli_test | ||
cli_test | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
"""NNVM python API for ease of use and help new framework establish python API. """ | ||
from __future__ import absolute_import | ||
|
||
from . import base | ||
from . import symbol as sym | ||
from . import symbol | ||
|
||
__version__ = base.__version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# coding: utf-8 | ||
"""Attribute scoping support for symbolic API.""" | ||
from __future__ import absolute_import | ||
|
||
from .base import string_types | ||
|
||
class AttrScope(object): | ||
"""Attribute manager for scoping. | ||
User can also inherit this object to change naming behavior. | ||
Parameters | ||
---------- | ||
kwargs | ||
The attributes to set for all symbol creations in the scope. | ||
""" | ||
current = None | ||
|
||
def __init__(self, **kwargs): | ||
self._old_scope = None | ||
for value in kwargs.values(): | ||
if not isinstance(value, string_types): | ||
raise ValueError("Attributes need to be string") | ||
self._attr = kwargs | ||
|
||
def get(self, attr): | ||
""" | ||
Get the attribute dict given the attribute set by the symbol. | ||
Parameters | ||
---------- | ||
attr : dict of string to string | ||
The attribute passed in by user during symbol creation. | ||
Returns | ||
------- | ||
attr : dict of string to string | ||
Updated attributes to add other scope related attributes. | ||
""" | ||
if self._attr: | ||
ret = self._attr.copy() | ||
if attr: | ||
ret.update(attr) | ||
return ret | ||
else: | ||
return attr | ||
|
||
def __enter__(self): | ||
# pylint: disable=protected-access | ||
self._old_scope = AttrScope.current | ||
attr = AttrScope.current._attr.copy() | ||
attr.update(self._attr) | ||
self._attr = attr | ||
AttrScope.current = self | ||
return self | ||
|
||
def __exit__(self, ptype, value, trace): | ||
assert self._old_scope | ||
AttrScope.current = self._old_scope | ||
|
||
AttrScope.current = AttrScope() | ||
|
Oops, something went wrong.