当前位置: 首页>>代码示例>>Python>>正文


Python Utils.clean_split方法代码示例

本文整理汇总了Python中utils.Utils.clean_split方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.clean_split方法的具体用法?Python Utils.clean_split怎么用?Python Utils.clean_split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Utils的用法示例。


在下文中一共展示了Utils.clean_split方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_dimension

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import clean_split [as 别名]
    def parse_dimension(self, line):
        """Currently don't support arithmetic expressions"""
        dim_name, dim_value = Utils.clean_split(line, '=')
        dim_value = int(dim_value)  # Explicitly convert to int

        Log.log("{}: Registering dimension: {}".format(dim_name, dim_value))
        dimension = {
            'name': dim_name,
            'value': dim_value
        }
        return dimension
开发者ID:jpanikulam,项目名称:cvxbind,代码行数:13,代码来源:parse_cvxgen.py

示例2: consume_parameter

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import clean_split [as 别名]
    def consume_parameter(self, line):
        # -- Array handling
        # Is it an array?
        is_array = self.is_array(line)
        if is_array is not None:

            index_var, name = is_array

            # - Check if we have an initializer, like x[0] or something
            # Required to be 't', for now
            if index_var.isdigit() or (index_var != 't'):
                is_array_initializer = True
                array_bounds = index_var
            else:
                is_array_initializer = False
                array_bounds = self.get_array_bounds(line)

            Log.log("Registering array {} with indexing variable, {}".format(name, index_var))
            if is_array_initializer:
                Log.log("{}: Is an initializer".format(name))

        # -- Not an array
        else:
            array_bounds = None
            is_array_initializer = False
            name = Utils.clean_split(line, None, maxsplit=1)[0]
            Log.log("Registering non-array {}".format(name))

        # -- Get dimensions
        dimensions = self.get_dimensions(line)
        if dimensions is None:
            _type = 'scalar'
        elif dimensions['cols'] != '1':
            _type = 'matrix'
        else:
            _type = 'vector'
        if dimensions is not None:
            Log.log("{}: Registering dimensions as {}x{}".format(name, dimensions['rows'], dimensions['cols']))
        else:
            Log.log("{}: Registering as sclar".format(name))

        special = self.get_special(line)

        parameter = {
            'name': name,
            'dimensions': dimensions,
            'array_bounds': array_bounds,
            'type': _type,
            'special': special,
            'initializer': is_array_initializer
        }
        return parameter
开发者ID:jpanikulam,项目名称:cvxbind,代码行数:54,代码来源:parse_cvxgen.py

示例3: get_dimensions

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import clean_split [as 别名]
    def get_dimensions(self, line):
        stripped = line.strip()
        if '(' not in stripped:
            return None
        else:
            dimensions = stripped[stripped.find("(") + 1:stripped.find(")")]
            if ',' in dimensions:
                rows, cols = Utils.clean_split(dimensions, ',')
                dimension_data = {
                    'rows': rows,
                    'cols': cols
                }
            else:
                dimension_data = {
                    'rows': dimensions.strip(), 'cols': '1'
                }

            return dimension_data
开发者ID:jpanikulam,项目名称:cvxbind,代码行数:20,代码来源:parse_cvxgen.py

示例4: parse_parameter

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import clean_split [as 别名]
    def parse_parameter(self, line):
        '''
            dimension_expr: string expression for reflecting dimension
        TODO:
            - Should have used regex!
            - Don't do blind text-replacement for special structure flags
        '''
        split = Utils.clean_split(line, None, maxsplit=1)
        if len(split) == 1:
            name = split[0]
            _type = 'scalar'
            return {
                'name': name,
                'dimensions': None,
                'special': None,
                'array_bounds': None,
                'type': _type
            }

        name, second_half = split[:2]
        Log.log("{}: Found parameter or variable".format(name))

        # Handle special structure flags
        special_features = ['psd', 'nsd', 'diagonal', 'nonnegative']
        special = set()
        for special_feature in special_features:
            if special_feature in second_half:
                special.add(special_feature)
                Log.log("{}: Registering special behavior: {}".format(name, special))
                second_half = second_half.replace(special_feature, '')

        # Handle arrays
        is_array = self.is_array(line)
        if is_array:
            array_var, name = is_array
            array_expr = second_half.split(', ')[-1]
            second_half = second_half.split(', ' + array_expr)[0]

            array_expr = array_expr.split('=')[-1]
            lower_bound, upper_bound = array_expr.split('..')
            array_bounds = (lower_bound, upper_bound)  # Strings
            Log.log("{}: Registering array bounds expression: [{}...{}]".format(name, lower_bound, upper_bound))

        else:
            array_bounds = None

        # Dimensions
        dimensions = self.get_dimensions(line)
        if dimensions is None:
            _type = 'scalar'
        elif len(dimensions) == 2:
            _type = 'matrix'
        elif len(dimensions) == 1:
            _type = 'vector'

        Log.log("{}: Registering vector dimension: {}".format(name, dimensions))

        parameter = {
            'name': name,
            'dimensions': dimensions,
            'special': special,
            'array_bounds': array_bounds,
            'type': _type
        }
        return parameter
开发者ID:jpanikulam,项目名称:cvxbind,代码行数:67,代码来源:parse_cvxgen.py

示例5: get_array_bounds

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import clean_split [as 别名]
 def get_array_bounds(self, line):
     if '=' not in line:
         return None
     _, after_eq = Utils.clean_split(line, '=')
     upper, lower = Utils.clean_split(after_eq, '..')
     return (upper, lower)
开发者ID:jpanikulam,项目名称:cvxbind,代码行数:8,代码来源:parse_cvxgen.py


注:本文中的utils.Utils.clean_split方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。