You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/06/08 00:44:12 UTC

[GitHub] spidyDev closed pull request #11189: Adding support for dict in infer_shape

spidyDev closed pull request #11189: Adding support for dict in  infer_shape
URL: https://github.com/apache/incubator-mxnet/pull/11189
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/python/mxnet/symbol/symbol.py b/python/mxnet/symbol/symbol.py
index fc1a71c203b..68b1891ad7f 100644
--- a/python/mxnet/symbol/symbol.py
+++ b/python/mxnet/symbol/symbol.py
@@ -1068,7 +1068,7 @@ def infer_shape_partial(self, *args, **kwargs):
 
     def _infer_shape_impl(self, partial, *args, **kwargs):
         """The actual implementation for calling shape inference API."""
-        # pylint: disable=too-many-locals
+        # pylint: disable=too-many-locals, too-many-nested-blocks
         if len(args) != 0 and len(kwargs) != 0:
             raise ValueError('Can only specify known argument \
                     shapes either by positional or kwargs way.')
@@ -1078,11 +1078,25 @@ def _infer_shape_impl(self, partial, *args, **kwargs):
             keys = c_array(ctypes.c_char_p, [])
             for i, s in enumerate(args):
                 if s is not None:
-                    if not isinstance(s, tuple):
-                        raise TypeError("Arguments need to be shapes (tuple), "
-                                        "but argument %d is %s." % (i, type(s)))
-                    sdata.extend(s)
-                indptr.append(len(sdata))
+                    if isinstance(s, dict):
+                        str_keys = []
+                        for k, v in s.items():
+                            if not isinstance(v, tuple):
+                                raise TypeError("Arguments need to be shapes (tuple), "
+                                                "but '%s' is %s." % (k, type(v)))
+                            if not isinstance(k, string_types):
+                                raise TypeError("Key should be of string type but is %s"
+                                                % (type(k)))
+                            str_keys.append(k)
+                            sdata.extend(v)
+                            indptr.append(len(sdata))
+                        keys = c_str_array(str_keys)
+                    else:
+                        if not isinstance(s, tuple):
+                            raise TypeError("Arguments need to be shapes (tuple), "
+                                            "but argument %d is %s." % (i, type(s)))
+                        sdata.extend(s)
+                        indptr.append(len(sdata))
         else:
             str_keys = []
             for k, v in kwargs.items():
@@ -1093,6 +1107,7 @@ def _infer_shape_impl(self, partial, *args, **kwargs):
                 sdata.extend(v)
                 indptr.append(len(sdata))
             keys = c_str_array(str_keys)
+
         arg_shape_size = mx_uint()
         arg_shape_ndim = ctypes.POINTER(mx_uint)()
         arg_shape_data = ctypes.POINTER(ctypes.POINTER(mx_uint))()


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services