Parses the parameter `split_shape`

        :param split_shape: The parameter `split_shape` from class initialization
        :type split_shape: int or (int, int)
        :return: A tuple of n
        :rtype: (int, int)
        :raises: ValueError
173368
def _parse_split_shape(split_shape):
        
        if isinstance(split_shape, int):
            return split_shape, split_shape
        if isinstance(split_shape, (tuple, list)):
            if len(split_shape) == 2 and isinstance(split_shape[0], int) and isinstance(split_shape[1], int):
                return split_shape[0], split_shape[1]
            raise ValueError("Content of split_shape {} must be 2 integers.".format(split_shape))
        raise ValueError("Split shape must be an int or a tuple of 2 integers.")
302835
def _split_index(params):
    
    if isinstance(params, list):
        return [params[0], _split_index(params[1])]
    elif isinstance(params, dict):
        if INDEX in params.keys():
            return _split_index(params[VALUE])
        result = dict()
        for key in params:
            result[key] = _split_index(params[key])
        return result
    else:
        return params
701219
def check_consistent_parameter_grouping(self):
        
        parameter_groups = {}
        if self.indices_per_axis is not None:
            parameter_groups["indices_per_axis"] = \
                {"self.indices_per_axis": self.indices_per_axis}
        if (self.split_size is not None) or (self.split_num_slices_per_axis is not None):
            parameter_groups["split_size"] = \
                {
                    "self.split_size": self.split_size,
                    "self.split_num_slices_per_axis": self.split_num_slices_per_axis,
            }
        if self.tile_shape is not None:
            parameter_groups["tile_shape"] = \
                {"self.tile_shape": self.tile_shape}
        if self.max_tile_bytes is not None:
            parameter_groups["max_tile_bytes"] = \
                {"self.max_tile_bytes": self.max_tile_bytes}
        if self.max_tile_shape is not None:
            if "max_tile_bytes" not in parameter_groups.keys():
                parameter_groups["max_tile_bytes"] = {}
            parameter_groups["max_tile_bytes"]["self.max_tile_shape"] = self.max_tile_shape
        if self.sub_tile_shape is not None:
            if "max_tile_bytes" not in parameter_groups.keys():
                parameter_groups["max_tile_bytes"] = {}
            parameter_groups["max_tile_bytes"]["self.sub_tile_shape"] = self.sub_tile_shape

        self.logger.debug("parameter_groups=%s", parameter_groups)

        if len(parameter_groups.keys()) > 1:
            group_keys = sorted(parameter_groups.keys())
            raise ValueError(
                "Got conflicting parameter groups specified, "
                +
                "should only specify one group to define the split:\n"
                +
                (
                    "\n".join(
                        [
                            (
                                ("Group %18s: " % ("'%s'" % group_key))
                                +
                                str(parameter_groups[group_key])
                            )
                            for group_key in group_keys
                        ]
                    )
                )
            )
        if len(parameter_groups.keys()) <= 0:
            raise ValueError(
                "No split parameters specified, need parameters from one of the groups: "
                +
                "'indices_per_axis', 'split_size', 'tile_shape' or 'max_tile_bytes'"
            )
119926
def _chunked_selector_output_shape(  # pylint: disable=invalid-name
    input_shapes, selector=None, **unused_kwargs):
  """"""
  # Read the main function below first, the shape logic just follows the ops.
  selector = selector or (lambda x: [] if x < 1 else [x-1])
  triples, _ = zip(*input_shapes)
  (query_shapes, key_shapes, value_shapes) = zip(*triples)
  result = []
  for i in range(len(input_shapes)):
    selected = selector(i)
    cur_key_shape, cur_value_shape = key_shapes[i], value_shapes[i]
    # Since keys and values are [batch, length, depth] we concatenate on axis=1.
    new_key_len = sum([key_shapes[j][1] for j in selected]) + cur_key_shape[1]
    new_key_shape = (cur_key_shape[0], new_key_len, cur_key_shape[2])
    new_value_len = sum(
        [value_shapes[j][1] for j in selected]) + cur_value_shape[1]
    new_value_shape = (cur_value_shape[0], new_value_len, cur_value_shape[2])
    # Masks are (1, query-len, key-len).
    new_mask_shape = (1, query_shapes[i][1], new_key_len)
    new_shape = ((query_shapes[i], new_key_shape, new_value_shape),
                 new_mask_shape)
    result.append(new_shape)
  return tuple(result)
531162
def parse(self, value):
        
        if self.required and value is None:
            raise ValueError("%s is required!" % self.name)
        elif self.ignored and value is not None:
            warn("%s is ignored for this class!" % self.name)
        elif not self.multi and isinstance(value, (list, tuple)):
            if len(value) > 1:
                raise ValueError(
                    "%s does not accept multiple values!" % self.name
                )
            return value[0]
        elif self.multi and value is not None:
            if not isinstance(value, (list, tuple)):
                return [value]
        return value
1369619
def _parse_geometry(geometry):
        
        if isinstance(geometry, str):
            geometry = shapely.wkt.loads(geometry)
        elif isinstance(geometry, dict):
            geometry = shapely.geometry.shape(geometry)
        elif not isinstance(geometry, shapely.geometry.base.BaseGeometry):
            raise TypeError('Unsupported geometry representation')

        if not isinstance(geometry, (shapely.geometry.Polygon, shapely.geometry.MultiPolygon)):
            raise ValueError('Supported geometry types are polygon and multipolygon, got {}'.format(type(geometry)))

        return geometry
1169296
def split(self, maxweight):
        
        # NB: can be called only after .set_weights() has been called
        idx = {ri: i for i, ri in enumerate(self.rup_indices)}
        for rup_indices in general.block_splitter(
                self.rup_indices, maxweight, lambda ri: self.weights[idx[ri]]):
            if rup_indices:
                # some indices may have weight 0 and are discarded
                rgetter = self.__class__(
                    self.filename, list(rup_indices), self.grp_id,
                    self.trt, self.samples, self.rlzs_by_gsim,
                    self.first_event)
                rgetter.weight = sum([self.weights[idx[ri]]
                                      for ri in rup_indices])
                yield rgetter
90002
def shlex_split(str_to_split: str) -> List[str]:
    
    return shlex.split(str_to_split, comments=False, posix=False)
1185177
def check_shape(meth):
    
    @wraps(meth)
    def wrapped_meth(self, val):
        if isinstance(val, (larray, numpy.ndarray)):
            if val.shape != self._shape:
                raise ValueError("shape mismatch: objects cannot be broadcast to a single shape")
        return meth(self, val)
    return wrapped_meth
895943
def parse(self, scode, args_chain=None, join_with=None, default=''):
        
        assert args_chain and isinstance(
            args_chain, (list, tuple)
        ) and isinstance(args_chain[0], (list, tuple)), ValueError(
            'args_chain type should be list of list, like: [["1-n", "html", "p", "html"], ["n-n", "html", "p", "text"]].'
        )
        for arg in args_chain:
            # py2 not support * unpack
            one_to_many, parser_name, parse_args = (arg[0], arg[1], arg[2:])
            assert self._re.match(
                '^[1n]-[1n]$',
                one_to_many), 'one_to_many should be one of 1-1, 1-n, n-n, n-1'
            input_count, output_count = one_to_many.split('-')
            parser = self._choose_parser(parser_name)
            # input data to parse.
            if input_count == 'n':
                scode = list(map(lambda item: parser(item, *parse_args), scode))
            if input_count == '1':
                if parser not in (self.jsonpath_parser, self.objectpath_parser,
                                  self.python_parser):
                    # json may remain multi-items
                    scode = get_one(scode, default=default)
                scode = parser(scode, *parse_args)
            # ensure result match n or 1 after parsing.
            if parser in (self.objectpath_parser,):
                # objectpath not need
                continue
            if output_count == '1':
                # 1-1 or n-1
                scode = get_one(scode, default=default)
            elif input_count == 'n':
                # n-n
                scode = [get_one(i, default=default) for i in scode]
            else:
                # 1-n
                scode = list(scode)
        if join_with:
            scode = join_with.join(map(str, scode))
        return scode
1280323
def laid_out_slice_num(self, tensor_shape):
    
    ret = self.slicewise(lambda: tf.to_int32(0))
    tensor_layout = self.tensor_layout(tensor_shape)
    for mesh_axis in tensor_layout.tensor_axis_to_mesh_axis:
      if mesh_axis is not None:
        def my_fn(x, pcoord, mesh_dim_size):
          return x * mesh_dim_size + pcoord
        ret = self.slicewise(
            my_fn, ret, self.laid_out_pcoord(mesh_axis),
            self.shape[mesh_axis].size)
    return ret
1210025
def slices(img, shape=[3, 4]):
    
    sh = np.asarray(shape)
    i_max = np.prod(sh)
    allimg = np.zeros(img.shape[-2:] * sh)

    for i in range(0, i_max):
        # i = 0
        islice = round((img.shape[0] / float(i_max)) * i)
        #         print(islice)
        imgi = img[islice, :, :]
        coords = index_to_coords(i, sh)
        aic = np.asarray(img.shape[-2:]) * coords

        allimg[aic[0]:aic[0] + imgi.shape[-2], aic[1]:aic[1] + imgi.shape[-1]] = imgi

    #     plt.imshow(imgi)
    #     print(imgi.shape)
    #     print(img.shape)
    return allimg
43100
def split_last_dimension(x, n):
  
  x_shape = common_layers.shape_list(x)
  m = x_shape[-1]
  if isinstance(m, int) and isinstance(n, int):
    assert m % n == 0
  return tf.reshape(x, x_shape[:-1] + [n, m // n])
847079
def shape2d(a):
    
    if type(a) == int:
        return [a, a]
    if isinstance(a, (list, tuple)):
        assert len(a) == 2
        return list(a)
    raise RuntimeError("Illegal shape: {}".format(a))
43656
def split_args(args):
    
    args_dict = {}
    for arg in args:
        split_arg = arg.split('=', 1)
        if len(split_arg) > 1:
            value = split_arg[1]
        else:
            value = True
        args_dict[split_arg[0]] = value
    return args_dict
393135
def parse_descriptor(descriptor: str) -> list:
    
    # States:
    #   10 == NORMAL,
    #   20 == OBJECT REFERENCE
    state = 10
    tokens = []
    token = []
    dimensions = 0
    for char in descriptor:
        if state == 10 and char == 'L':
            state = 20
        elif state == 10 and char == '[':
            dimensions += 1
        elif state == 10:
            tokens.append(JVMType(char, dimensions, _HUMAN_NAMES[char]))
            dimensions = 0
        elif state == 20 and char == ';':
            tokens.append(JVMType('L', dimensions, ''.join(token)))
            dimensions = 0
            state = 10
            del token[:]
        elif state == 20:
            token.append(char)
    return tokens
6059
def convert_to_shape(x):
  
  if x is None:
    return None
  if isinstance(x, Shape):
    return x
  if isinstance(x, str):
    x = _parse_string_to_list_of_pairs(x, seconds_to_int=True)
  return Shape(x)