The actual implementation for calling shape inference API.
771379
def _infer_shape_impl(self, partial, *args, **kwargs):
        """"""
        # pylint: disable=too-many-locals
        if len(args) != 0 and len(kwargs) != 0:
            raise ValueError('Can only specify known argument \
                    shapes either by positional or kwargs way.')
        sdata = []
        indptr = [0]
        if len(args) != 0:
            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))
        else:
            str_keys = []
            for k, v in kwargs.items():
                if not isinstance(v, tuple):
                    raise TypeError("Arguments need to be shapes (tuple), "
                                    "but '%s' is %s." % (k, type(v)))
                str_keys.append(k)
                sdata.extend(v)
                indptr.append(len(sdata))
            keys = c_str_array(str_keys)
        arg_shape_size = mx_uint()
        arg_shape_ndim = ctypes.POINTER(mx_int)()
        arg_shape_data = ctypes.POINTER(ctypes.POINTER(mx_int))()
        out_shape_size = mx_uint()
        out_shape_ndim = ctypes.POINTER(mx_int)()
        out_shape_data = ctypes.POINTER(ctypes.POINTER(mx_int))()
        aux_shape_size = mx_uint()
        aux_shape_ndim = ctypes.POINTER(mx_int)()
        aux_shape_data = ctypes.POINTER(ctypes.POINTER(mx_int))()
        complete = ctypes.c_int()
        if partial:
            infer_func = _LIB.MXSymbolInferShapePartialEx
        else:
            infer_func = _LIB.MXSymbolInferShapeEx
        check_call(infer_func(
            self.handle,
            mx_uint(len(indptr) - 1),
            keys,
            c_array_buf(mx_uint, array('I', indptr)),
            c_array_buf(mx_int, array('i', sdata)),
            ctypes.byref(arg_shape_size),
            ctypes.byref(arg_shape_ndim),
            ctypes.byref(arg_shape_data),
            ctypes.byref(out_shape_size),
            ctypes.byref(out_shape_ndim),
            ctypes.byref(out_shape_data),
            ctypes.byref(aux_shape_size),
            ctypes.byref(aux_shape_ndim),
            ctypes.byref(aux_shape_data),
            ctypes.byref(complete)))
        if complete.value != 0:
            arg_shapes = [tuple(arg_shape_data[i][:arg_shape_ndim[i]])
                          if arg_shape_ndim[i] >= 0 else None
                          for i in range(arg_shape_size.value)]
            out_shapes = [tuple(out_shape_data[i][:out_shape_ndim[i]])
                          if out_shape_ndim[i] >= 0 else None
                          for i in range(out_shape_size.value)]
            aux_shapes = [tuple(aux_shape_data[i][:aux_shape_ndim[i]])
                          if aux_shape_ndim[i] >= 0 else None
                          for i in range(aux_shape_size.value)]
            return (arg_shapes, out_shapes, aux_shapes)
        else:
            return (None, None, None)
635037
private static Shape createShape(SHAPE_TYPE shapeType,
                                     GraphicInfo graphicInfo) {
        if (SHAPE_TYPE.Rectangle.equals(shapeType)) {
            // source is rectangle
            return new Rectangle2D.Double(graphicInfo.getX(),
                                          graphicInfo.getY(),
                                          graphicInfo.getWidth(),
                                          graphicInfo.getHeight());
        } else if (SHAPE_TYPE.Rhombus.equals(shapeType)) {
            // source is rhombus
            Path2D.Double rhombus = new Path2D.Double();
            rhombus.moveTo(graphicInfo.getX(),
                           graphicInfo.getY() + graphicInfo.getHeight() / 2);
            rhombus.lineTo(graphicInfo.getX() + graphicInfo.getWidth() / 2,
                           graphicInfo.getY() + graphicInfo.getHeight());
            rhombus.lineTo(graphicInfo.getX() + graphicInfo.getWidth(),
                           graphicInfo.getY() + graphicInfo.getHeight() / 2);
            rhombus.lineTo(graphicInfo.getX() + graphicInfo.getWidth() / 2,
                           graphicInfo.getY());
            rhombus.lineTo(graphicInfo.getX(),
                           graphicInfo.getY() + graphicInfo.getHeight() / 2);
            rhombus.closePath();
            return rhombus;
        } else if (SHAPE_TYPE.Ellipse.equals(shapeType)) {
            // source is ellipse
            return new Ellipse2D.Double(graphicInfo.getX(),
                                        graphicInfo.getY(),
                                        graphicInfo.getWidth(),
                                        graphicInfo.getHeight());
        }
        // unknown source element, just do not correct coordinates
        return null;
    }
656121
def partial_shape(addr, full_shape):
    
    def size(x, max):
        if isinstance(x, (int, long, numpy.integer)):
            return None
        elif isinstance(x, slice):
            y = min(max, x.stop or max)  # slice limits can go past the bounds
            return 1 + (y - (x.start or 0) - 1) // (x.step or 1)
        elif isinstance(x, collections.Sized):
            if hasattr(x, 'dtype') and x.dtype == bool:
                return x.sum()
            else:
                return len(x)
        else:
            raise TypeError("Unsupported index type %s" % type(x))

    addr = full_address(addr, full_shape)
    if isinstance(addr, numpy.ndarray) and addr.dtype == bool:
        return (addr.sum(),)
    elif all(isinstance(x, collections.Sized) for x in addr):
        return (len(addr[0]),)
    else:
        shape = [size(x, max) for (x, max) in zip(addr, full_shape)]
        return tuple([x for x in shape if x is not None])
570311
def shapes(self):
        """"""
        shp = self.__getFileObj(self.shp)
        shp.seek(100)
        shapes = []
        while shp.tell() < self.shpLength:
            shapes.append(self.__shape())
        return shapes
892347
def calculate_gru_output_shapes(operator):
    '''
    
    '''
    check_input_and_output_numbers(operator, input_count_range=[1, 2], output_count_range=[1, 2])
    check_input_and_output_types(operator, good_input_types=[FloatTensorType])

    input_shape = operator.inputs[0].type.shape

    if len(input_shape) not in [2, 4]:
        raise RuntimeError('Input must be a [N, C]- or [N, C, 1, 1]-tensor')

    if operator.type == 'gru':
        params = operator.raw_operator.gru
    elif operator.type == 'simpleRecurrent':
        params = operator.raw_operator.simpleRecurrent
    else:
        raise RuntimeError('Only GRU and SimpleRNN are supported')

    # The following line is more accurate but it may break some tests
    # output_shape = ['None', params.outputVectorSize] if params.params.sequenceOutput else [2, params.outputVectorSize]
    output_shape = [input_shape[0] if params.sequenceOutput else 'None', params.outputVectorSize]  # 'None' should be 1
    state_shape = [1, params.outputVectorSize]

    # TODO: Changing input shapes of an operator is dangerous, this should be move to Topology's _fix_shapes function
    if len(operator.inputs) > 1:
        Y_h_in = operator.inputs[1]  # The initial hidden state of a single sequence
        Y_h_in.type.shape = state_shape

    operator.outputs[0].type.shape = output_shape
    if len(operator.outputs) > 1:
        operator.outputs[1].type.shape = state_shape
113599
def _check_shape(var, name, shape, shape2=None):
    """
    varshape = np.shape(var)
    if shape != varshape:
        if shape2:
            if shape2 != varshape:
                print('* ERROR   :: Parameter ' + name + ' has wrong shape!' +
                      ' : ' + str(varshape) + ' instead of ' + str(shape) +
                      'or' + str(shape2) + '.')
                raise ValueError(name)
        else:
            print('* ERROR   :: Parameter ' + name + ' has wrong shape! : ' +
                  str(varshape) + ' instead of ' + str(shape) + '.')
            raise ValueError(name)
984550
def _compute_texture_shape(self, size=1):
        

        # We should use this line but we may not have a GL context yet
        # linesize = gl.glGetInteger(gl.GL_MAX_TEXTURE_SIZE)
        linesize = 1024
        count = self._uniforms_float_count
        cols = 4 * linesize // int(count)
        rows = max(1, int(math.ceil(size / float(cols))))
        shape = rows, cols * (count // 4), count
        self._ushape = shape
        return shape
479286
function getShape(x,y,modules,options){

  //Get the surrounding modules matrix
  var mod_matrix = {};
  mod_matrix.topLeft = (x!=0 && y!=0 && modules[x-1][y-1]);
  mod_matrix.top = (y!=0 && modules[x][y-1]);
  mod_matrix.topRight = (x!=modules.length-1 && y!=0 && modules[x+1][y-1]);
  mod_matrix.left = (x!=0 && modules[x-1][y]);
  mod_matrix.right = (x!=modules.length-1 && modules[x+1][y]);
  mod_matrix.bottomLeft = (x!=0 && y!=modules.length-1 && modules[x-1][y+1]);
  mod_matrix.bottom = (y!=modules.length-1 && modules[x][y+1]);
  mod_matrix.bottomRight = (x!=modules.length-1 && y!=modules.length-1 && modules[x+1][y+1]);

  var surroundingCount = 0;
  if(mod_matrix.top){surroundingCount++;}
  if(mod_matrix.left){surroundingCount++;}
  if(mod_matrix.right){surroundingCount++;}
  if(mod_matrix.bottom){surroundingCount++;}

  //Find out box shape from surroundingCount and the orientation of those surrounding modules
  switch(surroundingCount){
    case 0:
      return getShapeZero(x,y,options,modules);
    case 1:
      return getShapeOne(x,y,options,modules,mod_matrix);
    case 2:
      return getShapeTwo(x,y,options,modules,mod_matrix);
    case 3:
      return getShapeThree(x,y,options,modules,mod_matrix);
    case 4:
      return getShapeFour(x,y,options,modules,mod_matrix);
    default:
      return getShapeZero(x,y,options,modules);
  }
      //This function checks that arrays a1 and a2 are the same:
      /*  a1.length==a2.length && a1.every(function(v,i) { return v === a2[i]}) */

}
408852
public void computeDescriptor( int cx , int cy , TupleDesc_F64 desc  ) {

		desc.fill(0);

		int widthPixels = widthSubregion*widthGrid;
		int radius = widthPixels/2;

		for (int i = 0; i < widthPixels; i++) {
			int angleIndex = (cy-radius+i)*savedAngle.width + (cx-radius);

			float subY = i/(float)widthSubregion;

			for (int j = 0; j < widthPixels; j++, angleIndex++ ) {
				float subX = j/(float)widthSubregion;

				double angle = savedAngle.data[angleIndex];

				float weightGaussian = gaussianWeight[i*widthPixels+j];
				float weightGradient = savedMagnitude.data[angleIndex];

				// trilinear interpolation intro descriptor
				trilinearInterpolation(weightGaussian*weightGradient,subX,subY,angle,desc);
			}
		}

		normalizeDescriptor(desc,maxDescriptorElementValue);
	}
1075964
def _getshapes_2d(center, max_radius, shape):
    """"""
    index_mean = shape * center
    index_radius = max_radius / 2.0 * np.array(shape)

    # Avoid negative indices
    min_idx = np.maximum(np.floor(index_mean - index_radius), 0).astype(int)
    max_idx = np.ceil(index_mean + index_radius).astype(int)
    idx = [slice(minx, maxx) for minx, maxx in zip(min_idx, max_idx)]
    shapes = [(idx[0], slice(None)),
              (slice(None), idx[1])]
    return tuple(idx), tuple(shapes)
591859
def _infer_shape(self, dimensions):
    
    # Size of input
    n = np.prod(dimensions)
    # Size of output where defined
    m = np.prod(abs(np.array(self._shape)))
    # Replace wildcard
    v = np.array(self._shape)
    v[v == -1] = n // m
    return tuple(v)
1221982
def dynamic_shape(self, max_elements):
        
        known = 1
        unknown_pos = -1
        for i, x in enumerate(self.shape):
            if x is not None:
                known *= x
            else:
                assert unknown_pos == -1, 'Shape has multiple unknown dimensions'
                unknown_pos = i
        if unknown_pos == -1:
            return self.shape
        else:
            shape = list(self.shape)
            if known == 0:
                shape[unknown_pos] = 0
            else:
                shape[unknown_pos] = max_elements // known
            return shape
697860
def shape(self, shape=None):
        """"""
        if shape is None:
            return self._shape
        data, color = self.renderer.manager.set_shape(self.model.id, shape)
        self.model.data = data
        self.color = color
        self._shape = shape
1277710
def shapes(self):
        """"""
        shapes = []
        curRes = self
        while curRes is not None:
            shapes.append(curRes.shape)
            curRes = curRes.nReservation
        return shapes
179139
function parseTMXShapes() {
         var i = 0;
         var shapes = []; // add an ellipse shape

         if (this.isEllipse === true) {
           // ellipse coordinates are the center position, so set default to the corresonding radius
           shapes.push(new me.Ellipse(this.width / 2, this.height / 2, this.width, this.height).rotate(this.rotation));
         } // add a polygon
         else if (this.isPolygon === true) {
             shapes.push(new me.Polygon(0, 0, this.points).rotate(this.rotation));
           } // add a polyline
           else if (this.isPolyLine === true) {
               var p = this.points;
               var p1, p2;
               var segments = p.length - 1;

               for (i = 0; i < segments; i++) {
                 // clone the value before, as [i + 1]
                 // is reused later by the next segment
                 p1 = new me.Vector2d(p[i].x, p[i].y);
                 p2 = new me.Vector2d(p[i + 1].x, p[i + 1].y);

                 if (this.rotation !== 0) {
                   p1 = p1.rotate(this.rotation);
                   p2 = p2.rotate(this.rotation);
                 }

                 shapes.push(new me.Line(0, 0, [p1, p2]));
               }
             } // it's a rectangle, returns a polygon object anyway
             else {
                 shapes.push(new me.Polygon(0, 0, [new me.Vector2d(), new me.Vector2d(this.width, 0), new me.Vector2d(this.width, this.height), new me.Vector2d(0, this.height)]).rotate(this.rotation));
               } // Apply isometric projection


         if (this.orientation === "isometric") {
           for (i = 0; i < shapes.length; i++) {
             shapes[i].toIso();
           }
         }

         return shapes;
       }
313676
function createShapeChecker(shapeTypes) {

    return createChainableChecker(function (data, dataName, componentName, fullDataName) {

        if (getDataType(shapeTypes) !== 'object') {
            throw new Error('[SAN ERROR] '
                + 'Data `' + fullDataName + '` of `' + componentName + '` has invalid '
                + 'DataType notation inside `shape`, expected `object`'
            );
        }

        var dataValue = data[dataName];
        var dataType = getDataType(dataValue);

        if (dataType !== 'object') {
            throw new Error('[SAN ERROR] '
                + 'Invalid ' + componentName + ' data `' + fullDataName + '` of type'
                + '(' + dataType + ' supplied to ' + componentName + ', '
                + 'expected object)'
            );
        }

        for (var shapeKeyName in shapeTypes) {
            /* istanbul ignore else  */
            if (shapeTypes.hasOwnProperty(shapeKeyName)) {
                var checker = shapeTypes[shapeKeyName];
                if (typeof checker === 'function') {
                    checker(dataValue, shapeKeyName, componentName, fullDataName + '.' + shapeKeyName);
                }
            }
        }

    });

}
1320004
def auto_locate_connectors(shapes, shape_hash)
      # Valid connector shapes.
      connector_shapes = {
        :straightConnector => 1,
        :Connector         => 1,
        :bentConnector     => 1,
        :curvedConnector   => 1,
        :line              => 1
      }

      shape_base = @type.chop.to_sym # Remove the number of segments from end of type.
      @connect = connector_shapes[shape_base] ? 1 : 0
      return if @connect == 0

      # Both ends have to be connected to size it.
      return if @start == 0 && @end == 0

      # Both ends need to provide info about where to connect.
      return if @start_side == 0 && @end_side == 0

      sid = @start
      eid = @end

      slink_id = shape_hash[sid] || 0
      sls      = shapes.fetch(slink_id, Shape.new)
      elink_id = shape_hash[eid] || 0
      els      = shapes.fetch(elink_id, Shape.new)

      # Assume shape connections are to the middle of an object, and
      # not a corner (for now).
      connect_type = @start_side + @end_side
      smidx        = sls.x_offset + sls.width / 2
      emidx        = els.x_offset + els.width / 2
      smidy        = sls.y_offset + sls.height / 2
      emidy        = els.y_offset + els.height / 2
      netx         = (smidx - emidx).abs
      nety         = (smidy - emidy).abs

      if connect_type == 'bt'
        sy = sls.y_offset + sls.height
        ey = els.y_offset

        @width = (emidx - smidx).to_i.abs
        @x_offset = [smidx, emidx].min.to_i
        @height =
          (els.y_offset - (sls.y_offset + sls.height)).to_i.abs
        @y_offset =
          [sls.y_offset + sls.height, els.y_offset].min.to_i
        @flip_h = smidx < emidx ? 1 : 0
        @rotation = 90

        if sy > ey
          @flip_v = 1

          # Create 3 adjustments for an end shape vertically above a
          # start @ Adjustments count from the upper left object.
          if @adjustments.empty?
            @adjustments = [-10, 50, 110]
          end
          @type = 'bentConnector5'
        end
      elsif connect_type == 'rl'
        @width =
          (els.x_offset - (sls.x_offset + sls.width)).to_i.abs
        @height = (emidy - smidy).to_i.abs
        @x_offset =
          [sls.x_offset + sls.width, els.x_offset].min
        @y_offset = [smidy, emidy].min

        @flip_h = 1 if smidx < emidx && smidy > emidy
        @flip_h = 1 if smidx > emidx && smidy < emidy

        if smidx > emidx
          # Create 3 adjustments for an end shape to the left of a
          # start @
          if @adjustments.empty?
            @adjustments = [-10, 50, 110]
          end
          @type = 'bentConnector5'
        end
      end
    end