sequence
stringlengths
1.19k
35k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interev_mag'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'mags'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '8', 'type': 'tuple', 'children': ['9', '10']}, {'id': '9', 'type': 'float', 'children': [], 'value': '10.5'}; {'id': '10', 'type': 'float', 'children': [], 'value': '7.5'}, {'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '13', 'type': 'block', 'children': ['14', '20', '40', '54', '64', '74', '92', '100', '104', '108', '169', '183', '192', '201', '210', '228', '243', '252', '261', '275', '289', '307', '318']}; {'id': '14', 'type': 'import_statement', 'children': ['15']}, {'id': '15', 'type': 'aliased_import', 'children': ['16', '19']}; {'id': '16', 'type': 'dotted_name', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'matplotlib'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pyplot'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '23', 'type': 'list_comprehension', 'children': ['24', '31']}; {'id': '24', 'type': 'tuple', 'children': ['25', '28']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'mags'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'lambda', 'children': ['49', '51']}, {'id': '49', 'type': 'lambda_parameters', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '57', 'type': 'list_comprehension', 'children': ['58', '61']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'mags'}, {'id': '67', 'type': 'list_comprehension', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '79']}; {'id': '76', 'type': 'pattern_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'subplots'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86', '89']}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'sharey'}; {'id': '88', 'type': 'True', 'children': []}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'figsize'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ravel'}, {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pre_times'}, {'id': '103', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'post_times'}, {'id': '107', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '108', 'type': 'for_statement', 'children': ['109', '110', '117']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '117', 'type': 'block', 'children': ['118', '141']}; {'id': '118', 'type': 'if_statement', 'children': ['119', '122']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '>'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'pre_times'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '140'], 'value': '/'}; {'id': '130', 'type': 'parenthesized_expression', 'children': ['131'], 'value': '()'}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '135'], 'value': '-'}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '-'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '60'}, {'id': '141', 'type': 'if_statement', 'children': ['142', '150']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '<'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '149'], 'value': '-'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'post_times'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'binary_operator', 'children': ['158', '168'], 'value': '/'}; {'id': '158', 'type': 'parenthesized_expression', 'children': ['159'], 'value': '()'}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '165'], 'value': '-'}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '+'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '60'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '176']}, {'id': '171', 'type': 'attribute', 'children': ['172', '175']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'scatter'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'pre_times'}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'mags'}; {'id': '180', 'type': 'slice', 'children': ['181', '182']}, {'id': '181', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '182', 'type': 'colon', 'children': []}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '190']}, {'id': '185', 'type': 'attribute', 'children': ['186', '189']}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'set_title'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'string', 'children': [], 'value': "'Pre-event times'"}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '199']}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '197', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'Magnitude'"}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '208']}, {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'string', 'children': [], 'value': "'Time (Minutes)'"}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'setp'}, {'id': '215', 'type': 'argument_list', 'children': ['216', '225']}; {'id': '216', 'type': 'call', 'children': ['217', '224']}, {'id': '217', 'type': 'attribute', 'children': ['218', '223']}; {'id': '218', 'type': 'attribute', 'children': ['219', '222']}, {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '221', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'xaxis'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'get_majorticklabels'}; {'id': '224', 'type': 'argument_list', 'children': []}, {'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'rotation'}, {'id': '227', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '235']}; {'id': '230', 'type': 'attribute', 'children': ['231', '234']}, {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '233', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'scatter'}, {'id': '235', 'type': 'argument_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'pre_times'}, {'id': '237', 'type': 'subscript', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'mags'}, {'id': '239', 'type': 'slice', 'children': ['240', '241']}; {'id': '240', 'type': 'colon', 'children': []}, {'id': '241', 'type': 'unary_operator', 'children': ['242'], 'value': '-'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '250']}, {'id': '245', 'type': 'attribute', 'children': ['246', '249']}; {'id': '246', 'type': 'subscript', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '248', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'set_title'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'string', 'children': [], 'value': "'Post-event times'"}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '259']}; {'id': '254', 'type': 'attribute', 'children': ['255', '258']}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '257', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'Time (Minutes)'"}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '268']}, {'id': '263', 'type': 'attribute', 'children': ['264', '267']}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'autoscale'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '272']}, {'id': '269', 'type': 'keyword_argument', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'enable'}, {'id': '271', 'type': 'True', 'children': []}; {'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'tight'}; {'id': '274', 'type': 'True', 'children': []}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '282']}, {'id': '277', 'type': 'attribute', 'children': ['278', '281']}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '280', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'autoscale'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '286']}, {'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'enable'}, {'id': '285', 'type': 'True', 'children': []}; {'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'tight'}; {'id': '288', 'type': 'True', 'children': []}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'setp'}; {'id': '294', 'type': 'argument_list', 'children': ['295', '304']}, {'id': '295', 'type': 'call', 'children': ['296', '303']}; {'id': '296', 'type': 'attribute', 'children': ['297', '302']}, {'id': '297', 'type': 'attribute', 'children': ['298', '301']}; {'id': '298', 'type': 'subscript', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '300', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'xaxis'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'get_majorticklabels'}, {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'rotation'}; {'id': '306', 'type': 'integer', 'children': [], 'value': '30'}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '310', 'type': 'call', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': '_finalise_figure'}; {'id': '312', 'type': 'argument_list', 'children': ['313', '316']}, {'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '316', 'type': 'dictionary_splat', 'children': ['317']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '318', 'type': 'return_statement', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'fig'}
def interev_mag(times, mags, size=(10.5, 7.5), **kwargs): import matplotlib.pyplot as plt info = [(times[i], mags[i]) for i in range(len(times))] info.sort(key=lambda tup: tup[0]) times = [x[0] for x in info] mags = [x[1] for x in info] fig, axes = plt.subplots(1, 2, sharey=True, figsize=size) axes = axes.ravel() pre_times = [] post_times = [] for i in range(len(times)): if i > 0: pre_times.append((times[i] - times[i - 1]) / 60) if i < len(times) - 1: post_times.append((times[i + 1] - times[i]) / 60) axes[0].scatter(pre_times, mags[1:]) axes[0].set_title('Pre-event times') axes[0].set_ylabel('Magnitude') axes[0].set_xlabel('Time (Minutes)') plt.setp(axes[0].xaxis.get_majorticklabels(), rotation=30) axes[1].scatter(pre_times, mags[:-1]) axes[1].set_title('Post-event times') axes[1].set_xlabel('Time (Minutes)') axes[0].autoscale(enable=True, tight=True) axes[1].autoscale(enable=True, tight=True) plt.setp(axes[1].xaxis.get_majorticklabels(), rotation=30) fig = _finalise_figure(fig=fig, **kwargs) return fig
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pprint_blockers'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'blockers'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '86']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pprinted'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '28']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'blocker'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'blockers'}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '18', 'type': 'lambda', 'children': ['19', '21']}, {'id': '19', 'type': 'lambda_parameters', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '28', 'type': 'block', 'children': ['29', '36', '74']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '32', 'type': 'list', 'children': ['33'], 'value': '[blocker[0]]'}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'blocker'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '43']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '42'], 'value': '>'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'blocker'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '43', 'type': 'block', 'children': ['44', '51', '67']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "' (which is blocking '"}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'buf'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': "', which is blocking '"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'blocker'}; {'id': '64', 'type': 'slice', 'children': ['65', '66']}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'colon', 'children': []}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'buf'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'string', 'children': [], 'value': "')'"}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'pprinted'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "''"}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'buf'}; {'id': '86', 'type': 'return_statement', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'pprinted'}
def pprint_blockers(blockers): pprinted = [] for blocker in sorted(blockers, key=lambda x: tuple(reversed(x))): buf = [blocker[0]] if len(blocker) > 1: buf.append(' (which is blocking ') buf.append(', which is blocking '.join(blocker[1:])) buf.append(')') pprinted.append(''.join(buf)) return pprinted
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_document_summary'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'cite_sort'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'refresh'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '26', '69', '81', '95', '120']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'abstracts'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_abstracts'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'refresh'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'refresh'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'cite_sort'}; {'id': '28', 'type': 'block', 'children': ['29', '44', '59']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'counts'}; {'id': '32', 'type': 'list_comprehension', 'children': ['33', '41']}, {'id': '33', 'type': 'tuple', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'citedby_count'}, {'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'abstracts'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'counts'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '53']}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '52', 'type': 'True', 'children': []}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'abstracts'}; {'id': '62', 'type': 'list_comprehension', 'children': ['63', '66']}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'counts'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '72', 'type': 'None', 'children': []}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'abstracts'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '84', 'type': 'list', 'children': ['85'], 'value': "[u'{0} of {1} documents'.format(N, len(abstracts))]"}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': "u'{0} of {1} documents'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'abstracts'}, {'id': '95', 'type': 'for_statement', 'children': ['96', '97', '101']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'augmented_assignment', 'children': ['104', '105'], 'value': '+='}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '105', 'type': 'list', 'children': ['106'], 'value': "['{0:2d}. {1}\\n'.format(i + 1, str(abstracts[i]))]"}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'{0:2d}. {1}\\n'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '114']}, {'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '+'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'abstracts'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}
def get_document_summary(self, N=None, cite_sort=True, refresh=True): abstracts = self.get_abstracts(refresh=refresh) if cite_sort: counts = [(a, int(a.citedby_count)) for a in abstracts] counts.sort(reverse=True, key=itemgetter(1)) abstracts = [a[0] for a in counts] if N is None: N = len(abstracts) s = [u'{0} of {1} documents'.format(N, len(abstracts))] for i in range(N): s += ['{0:2d}. {1}\n'.format(i + 1, str(abstracts[i]))] return '\n'.join(s)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_match_version_string'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '23', '39', '74']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'matched'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_VERSION_STRING_REGEX'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'matched'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '29']}, {'id': '25', 'type': 'pattern_list', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'major'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'minor'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'micro'}, {'id': '29', 'type': 'expression_list', 'children': ['30', '33', '36']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '45', '65']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '44'], 'value': 'and'}, {'id': '41', 'type': 'boolean_operator', 'children': ['42', '43'], 'value': 'and'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'major'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'minor'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'micro'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '52']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50', '51']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'major'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'minor'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'micro'}; {'id': '52', 'type': 'expression_list', 'children': ['53', '57', '61']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'major'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'minor'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'micro'}, {'id': '65', 'type': 'else_clause', 'children': ['66']}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'raise_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'GnuPGVersionError'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'}; {'id': '72', 'type': 'string', 'children': [], 'value': '"Could not parse GnuPG version from: %r"'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'tuple', 'children': ['76', '77', '78']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'major'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'minor'}
def _match_version_string(version): matched = _VERSION_STRING_REGEX.match(version) g = matched.groups() major, minor, micro = g[0], g[2], g[4] if major and minor and micro: major, minor, micro = int(major), int(minor), int(micro) else: raise GnuPGVersionError("Could not parse GnuPG version from: %r" % version) return (major, minor, micro)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_help'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '9', '19', '57']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'help_text'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'\\nAvailable recipes:\\n\\n'"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'recipes'}; {'id': '12', 'type': 'call', 'children': ['13', '18']}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Config'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'get_registered_recipes'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'for_statement', 'children': ['20', '24', '38']}; {'id': '20', 'type': 'pattern_list', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'recipes'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '30', 'type': 'lambda', 'children': ['31', '33']}, {'id': '31', 'type': 'lambda_parameters', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '33', 'type': 'subscript', 'children': ['34', '37']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'augmented_assignment', 'children': ['41', '42'], 'value': '+='}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'help_text'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "' {0:<35s}{1:s}\\n'"}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '50']}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'contents'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'contents'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'short_description'"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'No description'"}, {'id': '57', 'type': 'return_statement', 'children': ['58']}
def generate_help(): help_text = '\nAvailable recipes:\n\n' recipes = config.Config.get_registered_recipes() for contents, _, _ in sorted(recipes, key=lambda k: k[0]['name']): help_text += ' {0:<35s}{1:s}\n'.format( contents['name'], contents.get('short_description', 'No description')) return help_text
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_to_csv'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'.dat'"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'overwrite'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'stride'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'chunksize'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '22', 'type': 'block', 'children': ['23', '26', '119', '130', '133', '185', '189', '196', '202', '217', '227', '322']}, {'id': '23', 'type': 'import_statement', 'children': ['24']}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '29', '68', '112']}, {'id': '27', 'type': 'not_operator', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '29', 'type': 'block', 'children': ['30', '36', '40']}; {'id': '30', 'type': 'assert_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'filenames'"}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '39', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '40', 'type': 'for_statement', 'children': ['41', '42', '45']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '45', 'type': 'block', 'children': ['46', '59']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '51']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '51', 'type': 'call', 'children': ['52', '57']}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'splitext'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '+'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'extension'}; {'id': '68', 'type': 'elif_clause', 'children': ['69', '74']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '74', 'type': 'block', 'children': ['75', '88']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'{stride}'"}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'stride'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '91', 'type': 'list_comprehension', 'children': ['92', '102']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': "'{itraj}'"}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'itraj'}; {'id': '102', 'type': 'for_in_clause', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'itraj'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'number_of_trajectories'}, {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'else_clause', 'children': ['113']}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'raise_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'string', 'children': [], 'value': '"filename should be str or None"'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '126']}, {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '%'}; {'id': '128', 'type': 'string', 'children': [], 'value': '"write_to_csv, filenames=%s"'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '130', 'type': 'import_statement', 'children': ['131']}, {'id': '131', 'type': 'dotted_name', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'errno'}, {'id': '133', 'type': 'for_statement', 'children': ['134', '135', '136']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'try_statement', 'children': ['138', '155']}; {'id': '138', 'type': 'block', 'children': ['139', '148']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '148', 'type': 'raise_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'OSError'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'EEXIST'}, {'id': '155', 'type': 'except_clause', 'children': ['156', '160']}; {'id': '156', 'type': 'as_pattern', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'OSError'}; {'id': '158', 'type': 'as_pattern_target', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '160', 'type': 'block', 'children': ['161', '184']}, {'id': '161', 'type': 'if_statement', 'children': ['162', '169', '174']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '166'], 'value': '=='}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'errno'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'EEXIST'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'if_statement', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'continue_statement', 'children': []}; {'id': '174', 'type': 'elif_clause', 'children': ['175', '182']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '179'], 'value': '=='}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'errno'}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'errno'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ENOENT'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'continue_statement', 'children': []}; {'id': '184', 'type': 'raise_statement', 'children': []}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '188', 'type': 'None', 'children': []}, {'id': '189', 'type': 'import_from_statement', 'children': ['190', '194']}; {'id': '190', 'type': 'dotted_name', 'children': ['191', '192', '193']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'pyemma'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': '_base'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'progress'}; {'id': '194', 'type': 'dotted_name', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'ProgressReporter'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'pg'}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ProgressReporter'}, {'id': '201', 'type': 'argument_list', 'children': []}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'it'}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'iterator'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211', '214']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'stride'}, {'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'chunk'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'chunksize'}; {'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'return_trajindex'}; {'id': '216', 'type': 'False', 'children': []}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'pg'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'it'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'n_chunks'}; {'id': '226', 'type': 'string', 'children': [], 'value': '"saving to csv"'}, {'id': '227', 'type': 'with_statement', 'children': ['228', '237']}; {'id': '228', 'type': 'with_clause', 'children': ['229', '231']}, {'id': '229', 'type': 'with_item', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'it'}, {'id': '231', 'type': 'with_item', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'pg'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '236', 'type': 'argument_list', 'children': []}, {'id': '237', 'type': 'block', 'children': ['238', '243']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'oldtraj'}, {'id': '241', 'type': 'unary_operator', 'children': ['242'], 'value': '-'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '243', 'type': 'for_statement', 'children': ['244', '245', '246']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '246', 'type': 'block', 'children': ['247', '298', '308', '314']}, {'id': '247', 'type': 'if_statement', 'children': ['248', '253']}; {'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': '!='}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'oldtraj'}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'current_trajindex'}, {'id': '253', 'type': 'block', 'children': ['254', '265', '273', '284', '292']}; {'id': '254', 'type': 'if_statement', 'children': ['255', '258']}, {'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': 'is'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '257', 'type': 'None', 'children': []}; {'id': '258', 'type': 'block', 'children': ['259']}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '264', 'type': 'argument_list', 'children': []}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'it'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'current_trajindex'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '280']}, {'id': '275', 'type': 'attribute', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'binary_operator', 'children': ['282', '283'], 'value': '%'}; {'id': '282', 'type': 'string', 'children': [], 'value': '"opening file %s for writing csv."'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '289', 'type': 'argument_list', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '291', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'oldtraj'}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'it'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'current_trajindex'}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'call', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'savetxt'}, {'id': '303', 'type': 'argument_list', 'children': ['304', '305', '306']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '306', 'type': 'dictionary_splat', 'children': ['307']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'flush'}, {'id': '313', 'type': 'argument_list', 'children': []}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'pg'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '319', 'type': 'argument_list', 'children': ['320', '321']}; {'id': '320', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '321', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '322', 'type': 'if_statement', 'children': ['323', '326']}, {'id': '323', 'type': 'comparison_operator', 'children': ['324', '325'], 'value': 'is'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '325', 'type': 'None', 'children': []}; {'id': '326', 'type': 'block', 'children': ['327']}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'close'}
def write_to_csv(self, filename=None, extension='.dat', overwrite=False, stride=1, chunksize=None, **kw): import os if not filename: assert hasattr(self, 'filenames') filenames = [] for f in self.filenames: base, _ = os.path.splitext(f) filenames.append(base + extension) elif isinstance(filename, str): filename = filename.replace('{stride}', str(stride)) filenames = [filename.replace('{itraj}', str(itraj)) for itraj in range(self.number_of_trajectories())] else: raise TypeError("filename should be str or None") self.logger.debug("write_to_csv, filenames=%s" % filenames) import errno for f in filenames: try: st = os.stat(f) raise OSError(errno.EEXIST) except OSError as e: if e.errno == errno.EEXIST: if overwrite: continue elif e.errno == errno.ENOENT: continue raise f = None from pyemma._base.progress import ProgressReporter pg = ProgressReporter() it = self.iterator(stride, chunk=chunksize, return_trajindex=False) pg.register(it.n_chunks, "saving to csv") with it, pg.context(): oldtraj = -1 for X in it: if oldtraj != it.current_trajindex: if f is not None: f.close() fn = filenames[it.current_trajindex] self.logger.debug("opening file %s for writing csv." % fn) f = open(fn, 'wb') oldtraj = it.current_trajindex np.savetxt(f, X, **kw) f.flush() pg.update(1, 0) if f is not None: f.close()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_distances'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'periodic'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'indices2'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '15', '22', '36', '45', '58']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '15', 'type': 'import_from_statement', 'children': ['16', '20']}; {'id': '16', 'type': 'relative_import', 'children': ['17', '18']}, {'id': '17', 'type': 'import_prefix', 'children': []}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'distances'}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'DistanceFeature'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_parse_pairwise_input'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30', '33']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'indices2'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'add_distances()'"}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_check_indices'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'DistanceFeature'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '54', '55']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'topology'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'periodic'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'periodic'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '__add_feature'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}
def add_distances(self, indices, periodic=True, indices2=None): r from .distances import DistanceFeature atom_pairs = _parse_pairwise_input( indices, indices2, self.logger, fname='add_distances()') atom_pairs = self._check_indices(atom_pairs) f = DistanceFeature(self.topology, atom_pairs, periodic=periodic) self.__add_feature(f)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_inverse_distances'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'periodic'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'indices2'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '20', '34', '43', '56']}, {'id': '13', 'type': 'import_from_statement', 'children': ['14', '18']}; {'id': '14', 'type': 'relative_import', 'children': ['15', '16']}, {'id': '15', 'type': 'import_prefix', 'children': []}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'distances'}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'InverseDistanceFeature'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_parse_pairwise_input'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28', '31']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'indices2'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'add_inverse_distances()'"}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_check_indices'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'InverseDistanceFeature'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '52', '53']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'topology'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'periodic'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'periodic'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '__add_feature'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}
def add_inverse_distances(self, indices, periodic=True, indices2=None): from .distances import InverseDistanceFeature atom_pairs = _parse_pairwise_input( indices, indices2, self.logger, fname='add_inverse_distances()') atom_pairs = self._check_indices(atom_pairs) f = InverseDistanceFeature(self.topology, atom_pairs, periodic=periodic) self.__add_feature(f)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_contacts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'indices2'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'threshold'}, {'id': '11', 'type': 'float', 'children': [], 'value': '0.3'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'periodic'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'count_contacts'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '21', '28', '42', '51', '64']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '21', 'type': 'import_from_statement', 'children': ['22', '26']}; {'id': '22', 'type': 'relative_import', 'children': ['23', '24']}, {'id': '23', 'type': 'import_prefix', 'children': []}; {'id': '24', 'type': 'dotted_name', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'distances'}; {'id': '26', 'type': 'dotted_name', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ContactFeature'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_parse_pairwise_input'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '36', '39']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'indices2'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'add_contacts()'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_check_indices'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ContactFeature'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '60', '61', '62', '63']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'topology'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'atom_pairs'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'periodic'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'count_contacts'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '__add_feature'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}
def add_contacts(self, indices, indices2=None, threshold=0.3, periodic=True, count_contacts=False): r from .distances import ContactFeature atom_pairs = _parse_pairwise_input( indices, indices2, self.logger, fname='add_contacts()') atom_pairs = self._check_indices(atom_pairs) f = ContactFeature(self.topology, atom_pairs, threshold, periodic, count_contacts) self.__add_feature(f)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'spd_eig'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'W'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'epsilon'}, {'id': '7', 'type': 'float', 'children': [], 'value': '1e-10'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'QR'"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'canonical_signs'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '26', '94', '104', '113', '129', '138', '149', '167', '179', '190', '199', '243']}, {'id': '15', 'type': 'assert_statement', 'children': ['16', '25']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'allclose'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'W'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'W'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'W is not a symmetric matrix'"}; {'id': '26', 'type': 'if_statement', 'children': ['27', '34', '52', '85']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '33'], 'value': '=='}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'string', 'children': [], 'value': "'qr'"}; {'id': '34', 'type': 'block', 'children': ['35', '43']}, {'id': '35', 'type': 'import_from_statement', 'children': ['36', '41']}; {'id': '36', 'type': 'relative_import', 'children': ['37', '38']}, {'id': '37', 'type': 'import_prefix', 'children': []}; {'id': '38', 'type': 'dotted_name', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'eig_qr'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'eig_qr'}, {'id': '41', 'type': 'dotted_name', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'eig_qr'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '48']}, {'id': '45', 'type': 'pattern_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'eig_qr'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'W'}; {'id': '52', 'type': 'elif_clause', 'children': ['53', '60']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '59'], 'value': '=='}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'string', 'children': [], 'value': "'schur'"}; {'id': '60', 'type': 'block', 'children': ['61', '67', '76']}, {'id': '61', 'type': 'import_from_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'dotted_name', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'scipy'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'linalg'}, {'id': '65', 'type': 'dotted_name', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'schur'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}, {'id': '69', 'type': 'pattern_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'S'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'schur'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'W'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_np'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'diag'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'S'}, {'id': '85', 'type': 'else_clause', 'children': ['86']}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'raise_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '+'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'method not implemented: '"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'pattern_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'V'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sort_by_norm'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'evmin'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_np'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '113', 'type': 'if_statement', 'children': ['114', '117']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '<'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'evmin'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'epsilon'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'epsilon'}, {'id': '125', 'type': 'binary_operator', 'children': ['126', '128'], 'value': '+'}; {'id': '126', 'type': 'unary_operator', 'children': ['127'], 'value': '-'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'evmin'}; {'id': '128', 'type': 'float', 'children': [], 'value': '1e-16'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'evnorms'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '141', 'type': 'subscript', 'children': ['142', '148']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'evnorms'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '-'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'searchsorted'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '166']}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'evnorms'}, {'id': '161', 'type': 'slice', 'children': ['162', '163', '164']}; {'id': '162', 'type': 'colon', 'children': []}, {'id': '163', 'type': 'colon', 'children': []}; {'id': '164', 'type': 'unary_operator', 'children': ['165'], 'value': '-'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'epsilon'}, {'id': '167', 'type': 'if_statement', 'children': ['168', '171']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': '=='}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'raise_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': '_ZeroRankError'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '%'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'All eigenvalues are smaller than %g, rank reduction would discard all dimensions.'"}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'epsilon'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'Vm'}; {'id': '182', 'type': 'subscript', 'children': ['183', '184', '186']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '184', 'type': 'slice', 'children': ['185']}, {'id': '185', 'type': 'colon', 'children': []}; {'id': '186', 'type': 'slice', 'children': ['187', '188', '189']}, {'id': '187', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '188', 'type': 'colon', 'children': []}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'sm'}, {'id': '193', 'type': 'subscript', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '195', 'type': 'slice', 'children': ['196', '197', '198']}; {'id': '196', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '197', 'type': 'colon', 'children': []}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '199', 'type': 'if_statement', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'canonical_signs'}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'for_statement', 'children': ['203', '204', '208']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '208', 'type': 'block', 'children': ['209', '227']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'jj'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'argmax'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': '_np'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224', '226']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'Vm'}; {'id': '224', 'type': 'slice', 'children': ['225']}, {'id': '225', 'type': 'colon', 'children': []}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'augmented_assignment', 'children': ['229', '234'], 'value': '*='}, {'id': '229', 'type': 'subscript', 'children': ['230', '231', '233']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'Vm'}, {'id': '231', 'type': 'slice', 'children': ['232']}; {'id': '232', 'type': 'colon', 'children': []}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '234', 'type': 'call', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'sign'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'subscript', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'Vm'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'jj'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '243', 'type': 'return_statement', 'children': ['244']}; {'id': '244', 'type': 'expression_list', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'sm'}
def spd_eig(W, epsilon=1e-10, method='QR', canonical_signs=False): assert _np.allclose(W.T, W), 'W is not a symmetric matrix' if method.lower() == 'qr': from .eig_qr.eig_qr import eig_qr s, V = eig_qr(W) elif method.lower() == 'schur': from scipy.linalg import schur S, V = schur(W) s = _np.diag(S) else: raise ValueError('method not implemented: ' + method) s, V = sort_by_norm(s, V) evmin = _np.min(s) if evmin < 0: epsilon = max(epsilon, -evmin + 1e-16) evnorms = _np.abs(s) n = _np.shape(evnorms)[0] m = n - _np.searchsorted(evnorms[::-1], epsilon) if m == 0: raise _ZeroRankError('All eigenvalues are smaller than %g, rank reduction would discard all dimensions.'%epsilon) Vm = V[:, 0:m] sm = s[0:m] if canonical_signs: for j in range(m): jj = _np.argmax(_np.abs(Vm[:, j])) Vm[:, j] *= _np.sign(Vm[jj, j]) return sm, Vm
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'eig_corr'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'C0'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'Ct'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '8', 'type': 'float', 'children': [], 'value': '1e-10'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'QR'"}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sign_maxelement'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '18', '34', '52', '95', '105', '115', '163']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'spd_inv_split'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25', '28', '31']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'C0'}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'epsilon'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'canonical_signs'}, {'id': '33', 'type': 'True', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Ct_trans'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_np'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '51']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'Ct'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '62', '78']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_np'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'allclose'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'Ct'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'Ct'}; {'id': '62', 'type': 'block', 'children': ['63', '69']}, {'id': '63', 'type': 'import_from_statement', 'children': ['64', '67']}; {'id': '64', 'type': 'dotted_name', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'scipy'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'linalg'}, {'id': '67', 'type': 'dotted_name', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'eigh'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '74']}, {'id': '71', 'type': 'pattern_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'R_trans'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'eigh'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'Ct_trans'}; {'id': '78', 'type': 'else_clause', 'children': ['79']}, {'id': '79', 'type': 'block', 'children': ['80', '86']}; {'id': '80', 'type': 'import_from_statement', 'children': ['81', '84']}, {'id': '81', 'type': 'dotted_name', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'scipy'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '84', 'type': 'dotted_name', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'eig'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '91']}; {'id': '88', 'type': 'pattern_list', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'R_trans'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'eig'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'Ct_trans'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}, {'id': '97', 'type': 'pattern_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'R_trans'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort_by_norm'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'R_trans'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'R_trans'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sign_maxelement'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'for_statement', 'children': ['119', '120', '128']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'subscript', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '128', 'type': 'block', 'children': ['129', '147']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'imax'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'argmax'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '_np'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144', '146']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '144', 'type': 'slice', 'children': ['145']}, {'id': '145', 'type': 'colon', 'children': []}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'augmented_assignment', 'children': ['149', '154'], 'value': '*='}, {'id': '149', 'type': 'subscript', 'children': ['150', '151', '153']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'R'}, {'id': '151', 'type': 'slice', 'children': ['152']}; {'id': '152', 'type': 'colon', 'children': []}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_np'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'sign'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'subscript', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'R'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'imax'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '163', 'type': 'return_statement', 'children': ['164']}; {'id': '164', 'type': 'expression_list', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'l'}
def eig_corr(C0, Ct, epsilon=1e-10, method='QR', sign_maxelement=False): r L = spd_inv_split(C0, epsilon=epsilon, method=method, canonical_signs=True) Ct_trans = _np.dot(_np.dot(L.T, Ct), L) if _np.allclose(Ct.T, Ct): from scipy.linalg import eigh l, R_trans = eigh(Ct_trans) else: from scipy.linalg import eig l, R_trans = eig(Ct_trans) l, R_trans = sort_by_norm(l, R_trans) R = _np.dot(L, R_trans) if sign_maxelement: for j in range(R.shape[1]): imax = _np.argmax(_np.abs(R[:, j])) R[:, j] *= _np.sign(R[imax, j]) return l, R
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortino_ratio'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'threshold'}, {'id': '7', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ddof'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '32']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'stdev'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'semi_stdev'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '26', '29']}, {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'threshold'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ddof'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ddof'}, {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '42'], 'value': '/'}; {'id': '34', 'type': 'parenthesized_expression', 'children': ['35'], 'value': '()'}, {'id': '35', 'type': 'binary_operator', 'children': ['36', '41'], 'value': '-'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'anlzd_ret'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'threshold'}
def sortino_ratio(self, threshold=0.0, ddof=0, freq=None): stdev = self.semi_stdev(threshold=threshold, ddof=ddof, freq=freq) return (self.anlzd_ret() - threshold) / stdev
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'columnId'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'Qt'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'AscendingOrder'}, {'id': '11', 'type': 'block', 'children': ['12', '20', '28', '38', '57', '65']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'layoutAboutToBeChanged'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'emit'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sortingAboutToStart'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'emit'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '31', 'type': 'subscript', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_dataFrame'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'columnId'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_dataFrame'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_values'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '54']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '56', 'type': 'True', 'children': []}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'layoutChanged'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'emit'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '72']}, {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sortingFinished'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'emit'}
def sort(self, columnId, order=Qt.AscendingOrder): self.layoutAboutToBeChanged.emit() self.sortingAboutToStart.emit() column = self._dataFrame.columns[columnId] self._dataFrame.sort_values(column, ascending=not bool(order), inplace=True) self.layoutChanged.emit() self.sortingFinished.emit()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'clf'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '29', '44', '60', '72', '83', '91', '95', '151']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'MPI'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'COMM_WORLD'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Get_rank'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'running activity-based voxel selection via Searchlight'"}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sl'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'distribute'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '41']}, {'id': '37', 'type': 'list', 'children': ['38'], 'value': '[self.data]'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'mask'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sl'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'broadcast'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'tuple', 'children': ['53', '56', '59']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'num_folds'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'clf'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '=='}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rank'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'string', 'children': [], 'value': "'data preparation done'"}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'result_volume'}, {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sl'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'run_searchlight'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_sfn'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'result_list'}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'result_volume'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'mask'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '94', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '99']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '=='}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '99', 'type': 'block', 'children': ['100', '127', '144']}; {'id': '100', 'type': 'for_statement', 'children': ['101', '104', '108']}, {'id': '101', 'type': 'pattern_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'result_list'}; {'id': '108', 'type': 'block', 'children': ['109', '118']}, {'id': '109', 'type': 'if_statement', 'children': ['110', '113']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '112', 'type': 'None', 'children': []}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'tuple', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '141']}, {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '135', 'type': 'lambda', 'children': ['136', '138']}; {'id': '136', 'type': 'lambda_parameters', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'tup'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '143', 'type': 'True', 'children': []}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'string', 'children': [], 'value': "'activity-based voxel selection via Searchlight is done'"}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'expression_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'result_volume'}
def run(self, clf): rank = MPI.COMM_WORLD.Get_rank() if rank == 0: logger.info( 'running activity-based voxel selection via Searchlight' ) self.sl.distribute([self.data], self.mask) self.sl.broadcast((self.labels, self.num_folds, clf)) if rank == 0: logger.info( 'data preparation done' ) result_volume = self.sl.run_searchlight(_sfn) result_list = result_volume[self.mask] results = [] if rank == 0: for idx, value in enumerate(result_list): if value is None: value = 0 results.append((idx, value)) results.sort(key=lambda tup: tup[1], reverse=True) logger.info( 'activity-based voxel selection via Searchlight is done' ) return result_volume, results
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'clf'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '62']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'MPI'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'COMM_WORLD'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Get_rank'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23', '49']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'master_rank'}, {'id': '23', 'type': 'block', 'children': ['24', '32']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_master'}, {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '46']}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '40', 'type': 'lambda', 'children': ['41', '43']}, {'id': '41', 'type': 'lambda_parameters', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'tup'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '48', 'type': 'True', 'children': []}, {'id': '49', 'type': 'else_clause', 'children': ['50']}; {'id': '50', 'type': 'block', 'children': ['51', '58']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_worker'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'clf'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '61', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'results'}
def run(self, clf): rank = MPI.COMM_WORLD.Get_rank() if rank == self.master_rank: results = self._master() results.sort(key=lambda tup: tup[1], reverse=True) else: self._worker(clf) results = [] return results
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'column_or_label'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'descending'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'distinct'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '22', '56', '68', '86']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_get_column'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'column_or_label'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24', '39']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'distinct'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}, {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'row_numbers'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'return_index'}; {'id': '38', 'type': 'True', 'children': []}, {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'row_numbers'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50', '53']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'mergesort'"}; {'id': '56', 'type': 'assert_statement', 'children': ['57', '67']}, {'id': '57', 'type': 'call', 'children': ['58', '66']}; {'id': '58', 'type': 'attribute', 'children': ['59', '65']}, {'id': '59', 'type': 'parenthesized_expression', 'children': ['60'], 'value': '()'}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '<'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'row_numbers'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'num_rows'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'row_numbers'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'descending'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'row_numbers'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'row_numbers'}, {'id': '81', 'type': 'slice', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'colon', 'children': []}, {'id': '83', 'type': 'colon', 'children': []}; {'id': '84', 'type': 'unary_operator', 'children': ['85'], 'value': '-'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '86', 'type': 'return_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'take'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}
def sort(self, column_or_label, descending=False, distinct=False): column = self._get_column(column_or_label) if distinct: _, row_numbers = np.unique(column, return_index=True) else: row_numbers = np.argsort(column, axis=0, kind='mergesort') assert (row_numbers < self.num_rows).all(), row_numbers if descending: row_numbers = np.array(row_numbers[::-1]) return self.take(row_numbers)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sub_expand'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '20', '89']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_build_graph'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '38']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'entity_index'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'string', 'children': [], 'value': "'entities'"}; {'id': '38', 'type': 'block', 'children': ['39', '47', '59']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'node_name'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'graph_key_from_tag'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'entity_index'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '52']}; {'id': '48', 'type': 'not_operator', 'children': ['49']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'node_name'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'entities'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'node_name'}; {'id': '58', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'augmented_assignment', 'children': ['61', '64'], 'value': '+='}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'entities'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'node_name'}; {'id': '64', 'type': 'list', 'children': ['65', '74', '88'], 'value': "[\n tag.get('entities', [])[entity_index],\n tag.get('entities', [])[entity_index].get('confidence'),\n tag\n ]"}, {'id': '65', 'type': 'subscript', 'children': ['66', '73']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'string', 'children': [], 'value': "'entities'"}; {'id': '72', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'entity_index'}; {'id': '74', 'type': 'call', 'children': ['75', '86']}, {'id': '75', 'type': 'attribute', 'children': ['76', '85']}; {'id': '76', 'type': 'subscript', 'children': ['77', '84']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'entities'"}, {'id': '83', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'entity_index'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'string', 'children': [], 'value': "'confidence'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '89', 'type': 'for_statement', 'children': ['90', '91', '99']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'clique'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get_cliques'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '98']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '99', 'type': 'block', 'children': ['100', '104', '220', '238']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '103', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '107']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'entity_name'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'clique'}, {'id': '107', 'type': 'block', 'children': ['108', '122', '130', '213']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'start_token'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'subscript', 'children': ['115', '121']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'entity_name'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': '"-"'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'old_tag'}, {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'entity_name'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '133', 'type': 'dictionary', 'children': ['134', '137', '148', '166', '174', '189', '204']}; {'id': '134', 'type': 'pair', 'children': ['135', '136']}, {'id': '135', 'type': 'string', 'children': [], 'value': "'start_token'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'start_token'}, {'id': '137', 'type': 'pair', 'children': ['138', '139']}; {'id': '138', 'type': 'string', 'children': [], 'value': "'entities'"}, {'id': '139', 'type': 'list', 'children': ['140'], 'value': '[entities.get(entity_name)[0]]'}; {'id': '140', 'type': 'subscript', 'children': ['141', '147']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'entity_name'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'pair', 'children': ['149', '150']}, {'id': '149', 'type': 'string', 'children': [], 'value': "'confidence'"}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '159'], 'value': '*'}, {'id': '151', 'type': 'subscript', 'children': ['152', '158']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'entities'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'entity_name'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'old_tag'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'string', 'children': [], 'value': "'confidence'"}, {'id': '165', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '166', 'type': 'pair', 'children': ['167', '168']}, {'id': '167', 'type': 'string', 'children': [], 'value': "'end_token'"}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'old_tag'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'string', 'children': [], 'value': "'end_token'"}; {'id': '174', 'type': 'pair', 'children': ['175', '176']}, {'id': '175', 'type': 'string', 'children': [], 'value': "'match'"}; {'id': '176', 'type': 'call', 'children': ['177', '187']}, {'id': '177', 'type': 'attribute', 'children': ['178', '186']}; {'id': '178', 'type': 'subscript', 'children': ['179', '185']}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'old_tag'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'string', 'children': [], 'value': "'entities'"}, {'id': '185', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'string', 'children': [], 'value': "'match'"}, {'id': '189', 'type': 'pair', 'children': ['190', '191']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'key'"}, {'id': '191', 'type': 'call', 'children': ['192', '202']}; {'id': '192', 'type': 'attribute', 'children': ['193', '201']}, {'id': '193', 'type': 'subscript', 'children': ['194', '200']}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'old_tag'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'string', 'children': [], 'value': "'entities'"}; {'id': '200', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '204', 'type': 'pair', 'children': ['205', '206']}, {'id': '205', 'type': 'string', 'children': [], 'value': "'from_context'"}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'old_tag'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '212']}, {'id': '211', 'type': 'string', 'children': [], 'value': "'from_context'"}; {'id': '212', 'type': 'False', 'children': []}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '225', 'type': 'argument_list', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '229', 'type': 'lambda', 'children': ['230', '232']}; {'id': '230', 'type': 'lambda_parameters', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'string', 'children': [], 'value': "'start_token'"}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'yield', 'children': ['240']}
def _sub_expand(self, tags): entities = {} graph = self._build_graph(tags) for tag in tags: for entity_index in xrange(len(tag.get('entities'))): node_name = graph_key_from_tag(tag, entity_index) if not node_name in entities: entities[node_name] = [] entities[node_name] += [ tag.get('entities', [])[entity_index], tag.get('entities', [])[entity_index].get('confidence'), tag ] for clique in get_cliques(list(entities), graph): result = [] for entity_name in clique: start_token = int(entity_name.split("-")[0]) old_tag = entities[entity_name][2] tag = { 'start_token': start_token, 'entities': [entities.get(entity_name)[0]], 'confidence': entities.get(entity_name)[1] * old_tag.get('confidence', 1.0), 'end_token': old_tag.get('end_token'), 'match': old_tag.get('entities')[0].get('match'), 'key': old_tag.get('entities')[0].get('key'), 'from_context': old_tag.get('from_context', False) } result.append(tag) result = sorted(result, key=lambda e: e.get('start_token')) yield result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_rank_results'}, {'id': '3', 'type': 'parameters', 'children': ['4', '12']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '9', 'type': 'type_parameter', 'children': ['10']}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '12', 'type': 'typed_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '14', 'type': 'type', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'SimAlgorithm'}; {'id': '16', 'type': 'type', 'children': ['17']}, {'id': '17', 'type': 'generic_type', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '19', 'type': 'type_parameter', 'children': ['20']}; {'id': '20', 'type': 'type', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '22', 'type': 'block', 'children': ['23', '45', '104']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorted_results'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '33']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '32', 'type': 'True', 'children': []}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '35', 'type': 'lambda', 'children': ['36', '38']}; {'id': '36', 'type': 'lambda_parameters', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '40', 'type': 'subscript', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'OwlSim2Api'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'method2key'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '45', 'type': 'if_statement', 'children': ['46', '52']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '51'], 'value': '>'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sorted_results'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '52', 'type': 'block', 'children': ['53', '57', '69']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'previous_score'}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted_results'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'subscript', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'OwlSim2Api'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'method2key'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted_results'}; {'id': '72', 'type': 'block', 'children': ['73', '88', '94']}, {'id': '73', 'type': 'if_statement', 'children': ['74', '83']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '>'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'previous_score'}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '78', 'type': 'subscript', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'OwlSim2Api'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'method2key'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'augmented_assignment', 'children': ['86', '87'], 'value': '+='}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'rank'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '93']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'rank'"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'previous_score'}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '99', 'type': 'subscript', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'OwlSim2Api'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'method2key'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '104', 'type': 'return_statement', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'sorted_results'}
def _rank_results(results: List[Dict], method: SimAlgorithm) -> List[Dict]: sorted_results = sorted( results, reverse=True, key=lambda k: k[OwlSim2Api.method2key[method]] ) if len(sorted_results) > 0: rank = 1 previous_score = sorted_results[0][OwlSim2Api.method2key[method]] for result in sorted_results: if previous_score > result[OwlSim2Api.method2key[method]]: rank += 1 result['rank'] = rank previous_score = result[OwlSim2Api.method2key[method]] return sorted_results
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_source_files'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '11', '15', '52']}; {'id': '6', 'type': 'assert_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'final'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'Call build() before using the graph.'"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '25']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'topological_sort'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32', '42']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'NodeSet'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '42', 'type': 'else_clause', 'children': ['43']}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'list', 'children': ['51'], 'value': '[node]'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'out'}
def sorted_source_files(self): assert self.final, 'Call build() before using the graph.' out = [] for node in nx.topological_sort(self.graph): if isinstance(node, NodeSet): out.append(node.nodes) else: out.append([node]) return list(reversed(out))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'expand_source_files'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cwd'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '56']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '20']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'expand_paths'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cwd'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '30', '39']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'augmented_assignment', 'children': ['33', '34'], 'value': '+='}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'collect_files'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '38', 'type': 'string', 'children': [], 'value': '".py"'}, {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '48']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'string', 'children': [], 'value': '".py"'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'out'}
def expand_source_files(filenames, cwd=None): out = [] for f in expand_paths(filenames, cwd): if os.path.isdir(f): out += collect_files(f, ".py") else: if f.endswith(".py"): out.append(f) return sorted(set(out))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '12', '33', '39', '45', '51', '58', '78', '99', '119', '133', '162', '181', '199', '224']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'cardinality'}, {'id': '17', 'type': 'call', 'children': ['18', '32']}; {'id': '18', 'type': 'attribute', 'children': ['19', '31']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'add_columns'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '30']}, {'id': '25', 'type': 'subscript', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sqla_expr'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_set_column_filter_expressions'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_set_global_filter_expression'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_set_sort_expressions'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_set_yadcf_data'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'list_splat', 'children': ['67']}, {'id': '67', 'type': 'list_comprehension', 'children': ['68', '69', '74']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'filter_expressions'}; {'id': '74', 'type': 'if_clause', 'children': ['75']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'cardinality_filtered'}, {'id': '83', 'type': 'call', 'children': ['84', '98']}; {'id': '84', 'type': 'attribute', 'children': ['85', '97']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'add_columns'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'attribute', 'children': ['91', '96']}, {'id': '91', 'type': 'subscript', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'sqla_expr'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '98', 'type': 'argument_list', 'children': []}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'list_splat', 'children': ['108']}; {'id': '108', 'type': 'list_comprehension', 'children': ['109', '110', '115']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '110', 'type': 'for_in_clause', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sort_expressions'}, {'id': '115', 'type': 'if_clause', 'children': ['116']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '118', 'type': 'None', 'children': []}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '131']}; {'id': '126', 'type': 'attribute', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'string', 'children': [], 'value': "'length'"}, {'id': '133', 'type': 'if_statement', 'children': ['134', '137', '147', '154']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '>='}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '147', 'type': 'elif_clause', 'children': ['148', '152']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': '=='}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '150', 'type': 'unary_operator', 'children': ['151'], 'value': '-'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'pass_statement', 'children': []}; {'id': '154', 'type': 'else_clause', 'children': ['155']}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'raise_statement', 'children': ['157']}, {'id': '157', 'type': 'parenthesized_expression', 'children': ['158'], 'value': '()'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'string', 'children': [], 'value': "'Length should be a positive integer or -1 to disable'"}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '179']}; {'id': '174', 'type': 'attribute', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'string', 'children': [], 'value': "'start'"}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'add_columns'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'list_splat', 'children': ['190']}; {'id': '190', 'type': 'list_comprehension', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'sqla_expr'}; {'id': '194', 'type': 'for_in_clause', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'column_names'}; {'id': '202', 'type': 'list_comprehension', 'children': ['203', '214']}, {'id': '203', 'type': 'conditional_expression', 'children': ['204', '207', '210'], 'value': 'if'}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'mData'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'mData'}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '214', 'type': 'for_in_clause', 'children': ['215', '218']}, {'id': '215', 'type': 'pattern_list', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '229', 'type': 'list_comprehension', 'children': ['230', '243']}; {'id': '230', 'type': 'dictionary_comprehension', 'children': ['231', '234']}, {'id': '231', 'type': 'pair', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '234', 'type': 'for_in_clause', 'children': ['235', '238']}, {'id': '235', 'type': 'pattern_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'column_names'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '243', 'type': 'for_in_clause', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '249', 'type': 'argument_list', 'children': []}
def run(self): query = self.query self.cardinality = query.add_columns(self.columns[0].sqla_expr).count() self._set_column_filter_expressions() self._set_global_filter_expression() self._set_sort_expressions() self._set_yadcf_data(query) query = query.filter( *[e for e in self.filter_expressions if e is not None]) self.cardinality_filtered = query.add_columns( self.columns[0].sqla_expr).count() query = query.order_by( *[e for e in self.sort_expressions if e is not None]) length = int(self.params.get('length')) if length >= 0: query = query.limit(length) elif length == -1: pass else: raise (ValueError( 'Length should be a positive integer or -1 to disable')) query = query.offset(int(self.params.get('start'))) query = query.add_columns(*[c.sqla_expr for c in self.columns]) column_names = [ col.mData if col.mData else str(i) for i, col in enumerate(self.columns) ] self.results = [{k: v for k, v in zip(column_names, row)} for row in query.all()]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'poll_events'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'while_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'started'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '19', '54', '83', '98']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'event_obj'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'try_statement', 'children': ['20', '32']}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'event_obj'}; {'id': '24', 'type': 'call', 'children': ['25', '30']}, {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_sl4a'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'eventWait'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'integer', 'children': [], 'value': '50000'}; {'id': '32', 'type': 'except_clause', 'children': ['33']}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'started'}; {'id': '38', 'type': 'block', 'children': ['39', '44', '53']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': '"Exception happened during polling."'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'traceback'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'format_exc'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'raise_statement', 'children': []}; {'id': '54', 'type': 'if_statement', 'children': ['55', '57', '59', '75']}, {'id': '55', 'type': 'not_operator', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'event_obj'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'continue_statement', 'children': []}, {'id': '59', 'type': 'elif_clause', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'not'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'event_obj'}, {'id': '63', 'type': 'block', 'children': ['64', '74']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': '"Received Malformed event {}"'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'event_obj'}; {'id': '74', 'type': 'continue_statement', 'children': []}, {'id': '75', 'type': 'else_clause', 'children': ['76']}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'event_obj'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '83', 'type': 'if_statement', 'children': ['84', '89']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'in'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'handlers'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'handle_subscribed_event'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'event_obj'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102', '112']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '=='}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'event_name'}, {'id': '101', 'type': 'string', 'children': [], 'value': '"EventDispatcherShutdown"'}; {'id': '102', 'type': 'block', 'children': ['103', '111']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '110']}, {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_sl4a'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'closeSl4aSession'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'break_statement', 'children': []}; {'id': '112', 'type': 'else_clause', 'children': ['113']}, {'id': '113', 'type': 'block', 'children': ['114', '122', '165']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'acquire'}, {'id': '121', 'type': 'argument_list', 'children': []}; {'id': '122', 'type': 'if_statement', 'children': ['123', '128', '140']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'in'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'event_name'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '138']}, {'id': '131', 'type': 'attribute', 'children': ['132', '137']}; {'id': '132', 'type': 'subscript', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'event_name'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'event_obj'}; {'id': '140', 'type': 'else_clause', 'children': ['141']}, {'id': '141', 'type': 'block', 'children': ['142', '150', '157']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Queue'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'put'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'event_obj'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '164']}, {'id': '159', 'type': 'subscript', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'event_dict'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'event_name'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '172']}, {'id': '167', 'type': 'attribute', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'lock'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'release'}
def poll_events(self): while self.started: event_obj = None event_name = None try: event_obj = self._sl4a.eventWait(50000) except: if self.started: print("Exception happened during polling.") print(traceback.format_exc()) raise if not event_obj: continue elif 'name' not in event_obj: print("Received Malformed event {}".format(event_obj)) continue else: event_name = event_obj['name'] if event_name in self.handlers: self.handle_subscribed_event(event_obj, event_name) if event_name == "EventDispatcherShutdown": self._sl4a.closeSl4aSession() break else: self.lock.acquire() if event_name in self.event_dict: self.event_dict[event_name].put(event_obj) else: q = queue.Queue() q.put(event_obj) self.event_dict[event_name] = q self.lock.release()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pop_events'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'regex_pattern'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '7', 'type': 'block', 'children': ['8', '19', '29', '65', '86']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '13']}, {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'started'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'IllegalStateError'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"Dispatcher needs to be started before popping."'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'deadline'}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '28'], 'value': '+'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '29', 'type': 'while_statement', 'children': ['30', '31']}; {'id': '30', 'type': 'True', 'children': []}, {'id': '31', 'type': 'block', 'children': ['32', '41', '58']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_match_and_pop'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'regex_pattern'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '56']}; {'id': '42', 'type': 'boolean_operator', 'children': ['43', '49'], 'value': 'or'}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '!='}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '55'], 'value': '>'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'deadline'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'break_statement', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sleep'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '72']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '71'], 'value': '=='}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'raise_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'queue'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'Empty'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': "'Timeout after {}s waiting for event: {}'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'regex_pattern'}; {'id': '86', 'type': 'return_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '93', 'type': 'lambda', 'children': ['94', '96']}; {'id': '94', 'type': 'lambda_parameters', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'event'}
def pop_events(self, regex_pattern, timeout): if not self.started: raise IllegalStateError( "Dispatcher needs to be started before popping.") deadline = time.time() + timeout while True: results = self._match_and_pop(regex_pattern) if len(results) != 0 or time.time() > deadline: break time.sleep(1) if len(results) == 0: raise queue.Empty('Timeout after {}s waiting for event: {}'.format( timeout, regex_pattern)) return sorted(results, key=lambda event: event['time'])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'children'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pvector'}, {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '20']}, {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_children'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'lambda', 'children': ['23', '25']}, {'id': '23', 'type': 'lambda_parameters', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'task_level'}
def children(self): return pvector( sorted(self._children.values(), key=lambda m: m.task_level))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_last_child_with_lineno'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '23', '41', '93']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ignored_fields'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'list', 'children': ['13', '14', '15', '16'], 'value': "['ctx', 'decorator_list', 'names', 'returns']"}, {'id': '13', 'type': 'string', 'children': [], 'value': "'ctx'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'decorator_list'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'names'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'returns'"}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_fields'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '31']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'Call'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '35', 'type': 'tuple', 'children': ['36', '37', '38', '39', '40']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'func'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'args'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'starargs'"}, {'id': '39', 'type': 'string', 'children': [], 'value': "'keywords'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'kwargs'"}, {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '47']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '47', 'type': 'block', 'children': ['48', '54', '68']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ignored_fields'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'continue_statement', 'children': []}; {'id': '54', 'type': 'try_statement', 'children': ['55', '64']}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'last_field'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '64', 'type': 'except_clause', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'continue_statement', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '76', '79']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'last_field'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ast'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'AST'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'last_field'}, {'id': '79', 'type': 'elif_clause', 'children': ['80', '87']}; {'id': '80', 'type': 'boolean_operator', 'children': ['81', '86'], 'value': 'and'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'last_field'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'last_field'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'last_field'}, {'id': '91', 'type': 'unary_operator', 'children': ['92'], 'value': '-'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'return_statement', 'children': ['94']}
def _get_last_child_with_lineno(node): ignored_fields = set(['ctx', 'decorator_list', 'names', 'returns']) fields = node._fields if isinstance(node, ast.Call): fields = ('func', 'args', 'starargs', 'keywords', 'kwargs') for name in reversed(fields): if name in ignored_fields: continue try: last_field = getattr(node, name) except AttributeError: continue if isinstance(last_field, ast.AST): return last_field elif isinstance(last_field, list) and last_field: return last_field[-1] return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_patched_ast'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'return_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'patch_ast'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '19', '20']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'source'}
def get_patched_ast(source, sorted_children=False): return patch_ast(ast.parse(source), source, sorted_children)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'patch_ast'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '19', '29', '37']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '16']}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'region'"}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'walker'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_PatchingASTWalker'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ast'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'call_for_nodes'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'walker'}, {'id': '37', 'type': 'return_statement', 'children': ['38']}
def patch_ast(node, source, sorted_children=False): if hasattr(node, 'region'): return node walker = _PatchingASTWalker(source, children=sorted_children) ast.call_for_nodes(node, walker) return node
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_ast'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'patched_ast_node'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '44']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'patched_ast_node'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted_children'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '24', '35']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ast'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'AST'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'write_ast'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '35', 'type': 'else_clause', 'children': ['36']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': "''"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}
def write_ast(patched_ast_node): result = [] for child in patched_ast_node.sorted_children: if isinstance(child, ast.AST): result.append(write_ast(child)) else: result.append(child) return ''.join(result)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_proposals'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'proposals'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'scopepref'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'typepref'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '21']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorter'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_ProposalSorter'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'proposals'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'scopepref'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'typepref'}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorter'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_sorted_proposal_list'}
def sorted_proposals(proposals, scopepref=None, typepref=None): sorter = _ProposalSorter(proposals, scopepref, typepref) return sorter.get_sorted_proposal_list()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_proposal_list'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '31', '35', '85']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'proposals'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'proposal'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'proposals'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '29']}; {'id': '18', 'type': 'attribute', 'children': ['19', '28']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'proposals'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'proposal'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'scope'}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'proposal'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '34', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '40']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'scope'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'scopepref'}; {'id': '40', 'type': 'block', 'children': ['41', '51', '67', '78']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'scope_proposals'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'proposals'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'scope'}; {'id': '50', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'scope_proposals'}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '56', '59']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'proposal'}; {'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'proposal'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'scope_proposals'}, {'id': '59', 'type': 'if_clause', 'children': ['60']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': 'in'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'proposal'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'typerank'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'scope_proposals'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_proposal_key'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'scope_proposals'}, {'id': '85', 'type': 'return_statement', 'children': ['86']}
def get_sorted_proposal_list(self): proposals = {} for proposal in self.proposals: proposals.setdefault(proposal.scope, []).append(proposal) result = [] for scope in self.scopepref: scope_proposals = proposals.get(scope, []) scope_proposals = [proposal for proposal in scope_proposals if proposal.type in self.typerank] scope_proposals.sort(key=self._proposal_key) result.extend(scope_proposals) return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_rank'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'criteria'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'condition'}, {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '25', '31', '42', '55', '61', '92', '106', '113']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '14', 'type': 'conditional_expression', 'children': ['15', '16', '22'], 'value': 'if'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'entity'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Projector'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'reference_entity'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'positions'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'members_position'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'biggest_entity_size'}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '41'], 'value': '+'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'filtered_criteria'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'condition'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'criteria'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'members_entity_id'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '64', 'type': 'call', 'children': ['65', '91']}, {'id': '65', 'type': 'attribute', 'children': ['66', '90']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'list_comprehension', 'children': ['72', '84']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'entity'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value_nth_person'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'filtered_criteria'}, {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'inf'}; {'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'biggest_entity_size'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'transpose'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'sorted_matrix'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '109', 'type': 'subscript', 'children': ['110', '111', '112']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'sorted_matrix'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '113', 'type': 'return_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'condition'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '121', 'type': 'unary_operator', 'children': ['122'], 'value': '-'}
def get_rank(self, entity, criteria, condition = True): entity = entity if not isinstance(entity, Projector) else entity.reference_entity positions = entity.members_position biggest_entity_size = np.max(positions) + 1 filtered_criteria = np.where(condition, criteria, np.inf) ids = entity.members_entity_id matrix = np.asarray([ entity.value_nth_person(k, filtered_criteria, default = np.inf) for k in range(biggest_entity_size) ]).transpose() sorted_matrix = np.argsort(np.argsort(matrix)) result = sorted_matrix[ids, positions] return np.where(condition, result, -1)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'value_nth_person'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'block', 'children': ['11', '20', '26', '34', '40', '54', '70']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '18']}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'members'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'check_array_compatible_with_entity'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'members_position'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'nb_persons_per_entity'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'nb_persons'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'members_map'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ordered_members_map'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'filled_array'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '61']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '>'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'nb_persons_per_entity'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '61', 'type': 'subscript', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'members_map'}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': '=='}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'positions'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'members_map'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'result'}
def value_nth_person(self, n, array, default = 0): self.members.check_array_compatible_with_entity(array) positions = self.members_position nb_persons_per_entity = self.nb_persons() members_map = self.ordered_members_map result = self.filled_array(default, dtype = array.dtype) result[nb_persons_per_entity > n] = array[members_map][positions[members_map] == n] return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_query_index'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'design_document_id'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'index_name'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'index_type'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'json'"}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'partitioned'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '19', 'type': 'block', 'children': ['20', '66', '72']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24', '39', '58']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '=='}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'index_type'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'JSON_INDEX_TYPE'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Index'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33', '34', '37']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'design_document_id'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'index_name'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'partitioned'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'partitioned'}, {'id': '37', 'type': 'dictionary_splat', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '39', 'type': 'elif_clause', 'children': ['40', '43']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '=='}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'index_type'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'TEXT_INDEX_TYPE'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'TextIndex'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52', '53', '56']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'design_document_id'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'index_name'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'partitioned'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'partitioned'}; {'id': '56', 'type': 'dictionary_splat', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '58', 'type': 'else_clause', 'children': ['59']}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'raise_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'CloudantArgumentError'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'integer', 'children': [], 'value': '103'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'index_type'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'create'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'index'}
def create_query_index( self, design_document_id=None, index_name=None, index_type='json', partitioned=False, **kwargs ): if index_type == JSON_INDEX_TYPE: index = Index(self, design_document_id, index_name, partitioned=partitioned, **kwargs) elif index_type == TEXT_INDEX_TYPE: index = TextIndex(self, design_document_id, index_name, partitioned=partitioned, **kwargs) else: raise CloudantArgumentError(103, index_type) index.create() return index
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_search_result'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ddoc_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'index_name'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'query_params'}, {'id': '9', 'type': 'block', 'children': ['10', '18']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ddoc'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'DesignDocument'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ddoc_id'}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_get_search_result'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '35']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'tuple', 'children': ['30', '33', '34']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ddoc'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'document_url'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'_search'"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'index_name'}, {'id': '35', 'type': 'dictionary_splat', 'children': ['36']}
def get_search_result(self, ddoc_id, index_name, **query_params): ddoc = DesignDocument(self, ddoc_id) return self._get_search_result( '/'.join((ddoc.document_url, '_search', index_name)), **query_params )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'predict_log_proba'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '26']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'jll'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_joint_log_likelihood'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'log_prob_x'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'logsumexp'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'jll'}, {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '-'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'jll'}, {'id': '29', 'type': 'attribute', 'children': ['30', '36']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'log_prob_x'}
def predict_log_proba(self, X): jll = self._joint_log_likelihood(X) log_prob_x = logsumexp(jll, axis=1) return jll - np.atleast_2d(log_prob_x).T
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorting_key_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'array1'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'array2'}, {'id': '7', 'type': 'block', 'children': ['8', '19', '28']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'concat_arrays'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'concatenate'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'list', 'children': ['17', '18'], 'value': '[array1, array2]'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'array1'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'array2'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'unique_values'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'concat_arrays'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}
def _get_sorting_key_values(self, array1, array2): concat_arrays = numpy.concatenate([array1, array2]) unique_values = numpy.unique(concat_arrays) return numpy.sort(unique_values)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortedneighbourhood'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '20', '27']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'indexer'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'SortedNeighbourhood'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '18']}; {'id': '16', 'type': 'list_splat', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '18', 'type': 'dictionary_splat', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'indexer'}, {'id': '27', 'type': 'return_statement', 'children': ['28']}
def sortedneighbourhood(self, *args, **kwargs): indexer = SortedNeighbourhood(*args, **kwargs) self.add(indexer) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_bst_from_sorted_values'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sorted_values'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '25', '34', '47', '62']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '12'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted_values'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'mid_index'}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '//'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted_values'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Node'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted_values'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'mid_index'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'left'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_build_bst_from_sorted_values'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted_values'}; {'id': '44', 'type': 'slice', 'children': ['45', '46']}, {'id': '45', 'type': 'colon', 'children': []}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'mid_index'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'right'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_build_bst_from_sorted_values'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted_values'}, {'id': '57', 'type': 'slice', 'children': ['58', '61']}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '+'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'mid_index'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'colon', 'children': []}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'root'}
def _build_bst_from_sorted_values(sorted_values): if len(sorted_values) == 0: return None mid_index = len(sorted_values) // 2 root = Node(sorted_values[mid_index]) root.left = _build_bst_from_sorted_values(sorted_values[:mid_index]) root.right = _build_bst_from_sorted_values(sorted_values[mid_index + 1:]) return root
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'holm'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pvals'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'alpha'}, {'id': '7', 'type': 'float', 'children': [], 'value': '.05'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '24', '32', '45', '54', '60', '68', '76', '98', '109', '120', '138', '149', '171']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'pvals'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pvals'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'shape_init'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pvals'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pvals'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pvals'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ravel'}, {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'num_nan'}, {'id': '35', 'type': 'call', 'children': ['36', '44']}; {'id': '36', 'type': 'attribute', 'children': ['37', '43']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'isnan'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pvals'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pvals_sortind'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'pvals'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pvals_sorted'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pvals'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pvals_sortind'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sortrevind'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'pvals_sortind'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ntests'}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '75'], 'value': '-'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pvals'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'num_nan'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'pvals_corr'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'diag'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '*'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'pvals_sorted'}; {'id': '86', 'type': 'subscript', 'children': ['87', '96', '97']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ntests'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'unary_operator', 'children': ['95'], 'value': '-'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'ellipsis', 'children': [], 'value': '...'}, {'id': '97', 'type': 'None', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'pvals_corr'}, {'id': '101', 'type': 'call', 'children': ['102', '107']}; {'id': '102', 'type': 'attribute', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'maximum'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'accumulate'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'pvals_corr'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'pvals_corr'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'clip'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'pvals_corr'}; {'id': '118', 'type': 'None', 'children': []}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'pvals_corr'}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'pvals_corr'}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'full'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'num_nan'}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'nan'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'pvals_corrected'}, {'id': '141', 'type': 'call', 'children': ['142', '147']}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'pvals_corr'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'sortrevind'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'shape_init'}, {'id': '149', 'type': 'with_statement', 'children': ['150', '160']}; {'id': '150', 'type': 'with_clause', 'children': ['151']}, {'id': '151', 'type': 'with_item', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'errstate'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'invalid'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'ignore'"}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'reject'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'less'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'pvals_corrected'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'alpha'}, {'id': '171', 'type': 'return_statement', 'children': ['172']}; {'id': '172', 'type': 'expression_list', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'reject'}
def holm(pvals, alpha=.05): pvals = np.asarray(pvals) shape_init = pvals.shape pvals = pvals.ravel() num_nan = np.isnan(pvals).sum() pvals_sortind = np.argsort(pvals) pvals_sorted = pvals[pvals_sortind] sortrevind = pvals_sortind.argsort() ntests = pvals.size - num_nan pvals_corr = np.diag(pvals_sorted * np.arange(ntests, 0, -1)[..., None]) pvals_corr = np.maximum.accumulate(pvals_corr) pvals_corr = np.clip(pvals_corr, None, 1) pvals_corr = np.append(pvals_corr, np.full(num_nan, np.nan)) pvals_corrected = pvals_corr[sortrevind].reshape(shape_init) with np.errstate(invalid='ignore'): reject = np.less(pvals_corrected, alpha) return reject, pvals_corrected
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_reverse_chronologically'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '13']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'measurements'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '22']}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '16', 'type': 'lambda', 'children': ['17', '19']}, {'id': '17', 'type': 'lambda_parameters', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def sort_reverse_chronologically(self): self.measurements.sort(key=lambda m: m.timestamp, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_dependencies'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '14', '19', '24', '28', '33', '107', '113', '119', '191', '205', '219']}, {'id': '9', 'type': 'import_from_statement', 'children': ['10', '12']}; {'id': '10', 'type': 'relative_import', 'children': ['11']}, {'id': '11', 'type': 'import_prefix', 'children': []}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'baseclass'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'collection'}, {'id': '17', 'type': 'list', 'children': ['18'], 'value': '[dist]'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '22', 'type': 'list', 'children': ['23'], 'value': '[dist]'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'edges'}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '31', 'type': 'list', 'children': ['32'], 'value': '[dist]'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '33', 'type': 'while_statement', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '35', 'type': 'block', 'children': ['36', '44']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'for_statement', 'children': ['45', '46', '52']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'prm'}; {'id': '52', 'type': 'block', 'children': ['53', '61', '72', '88']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'prm'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '70']}; {'id': '62', 'type': 'not_operator', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'baseclass'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'Dist'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'continue_statement', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '78']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '77'], 'value': 'not'}; {'id': '74', 'type': 'tuple', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'edges'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'tuple', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'not'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '92', 'type': 'block', 'children': ['93', '100']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'permanent_marks'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '112', 'type': 'argument_list', 'children': []}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'temporary_marks'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '118', 'type': 'argument_list', 'children': []}, {'id': '119', 'type': 'function_definition', 'children': ['120', '121', '123']}; {'id': '120', 'type': 'function_name', 'children': [], 'value': 'visit'}, {'id': '121', 'type': 'parameters', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '123', 'type': 'block', 'children': ['124', '130', '140', '147', '154', '170', '177', '184']}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'in'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'permanent_marks'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'return_statement', 'children': []}; {'id': '130', 'type': 'if_statement', 'children': ['131', '134']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'in'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'temporary_marks'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'raise_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'DependencyError'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'string', 'children': [], 'value': '"cycles in dependency structure."'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'temporary_marks'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '154', 'type': 'for_statement', 'children': ['155', '158', '159']}, {'id': '155', 'type': 'pattern_list', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'node1'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'node2'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'edges'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'if_statement', 'children': ['161', '164']}, {'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'is'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'node1'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'visit'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'node2'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'temporary_marks'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'permanent_marks'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '191', 'type': 'while_statement', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '193', 'type': 'block', 'children': ['194', '200']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '199', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'visit'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '205', 'type': 'if_statement', 'children': ['206', '208']}; {'id': '206', 'type': 'not_operator', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '219', 'type': 'return_statement', 'children': ['220']}
def sorted_dependencies(dist, reverse=False): from .. import baseclass collection = [dist] nodes = [dist] edges = [] pool = [dist] while pool: dist = pool.pop() for key in sorted(dist.prm): value = dist.prm[key] if not isinstance(value, baseclass.Dist): continue if (dist, value) not in edges: edges.append((dist, value)) if value not in nodes: nodes.append(value) pool.append(value) permanent_marks = set() temporary_marks = set() def visit(node): if node in permanent_marks: return if node in temporary_marks: raise DependencyError("cycles in dependency structure.") nodes.remove(node) temporary_marks.add(node) for node1, node2 in edges: if node1 is node: visit(node2) temporary_marks.remove(node) permanent_marks.add(node) pool.append(node) while nodes: node = nodes[0] visit(node) if not reverse: pool = list(reversed(pool)) return pool
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'orth_ttr'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'normed'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"GR"'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'retall'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}, {'id': '17', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '18', 'type': 'dictionary_splat_pattern', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kws'}; {'id': '20', 'type': 'block', 'children': ['21', '51', '86', '93', '215', '233', '245']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '28']}, {'id': '23', 'type': 'pattern_list', 'children': ['24', '25', '26', '27']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'chaospy'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'quad'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'generate_stieltjes'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38', '46', '49']}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'retall'}; {'id': '48', 'type': 'True', 'children': []}, {'id': '49', 'type': 'dictionary_splat', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'kws'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'normed'}, {'id': '53', 'type': 'block', 'children': ['54', '80']}; {'id': '54', 'type': 'for_statement', 'children': ['55', '58', '62']}, {'id': '55', 'type': 'pattern_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'polynomials'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '/'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77', '79']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'norms'}, {'id': '77', 'type': 'slice', 'children': ['78']}; {'id': '78', 'type': 'colon', 'children': []}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'norms'}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '**'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'norms'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '93', 'type': 'if_statement', 'children': ['94', '97', '203']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '>'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'block', 'children': ['98', '102', '106', '131', '172']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'mv_polynomials'}, {'id': '101', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'mv_norms'}, {'id': '105', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'bertran'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'bindex'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '119', '122', '125', '128']}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}, {'id': '131', 'type': 'for_statement', 'children': ['132', '133', '134']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '134', 'type': 'block', 'children': ['135', '145', '165']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '138', 'type': 'subscript', 'children': ['139', '144']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '145', 'type': 'for_statement', 'children': ['146', '147', '152']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '*'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '158', 'type': 'subscript', 'children': ['159', '164']}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'mv_polynomials'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '172', 'type': 'if_statement', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'retall'}; {'id': '174', 'type': 'block', 'children': ['175']}, {'id': '175', 'type': 'for_statement', 'children': ['176', '177', '178']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'mv_norms'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'prod'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'list_comprehension', 'children': ['191', '197']}, {'id': '191', 'type': 'subscript', 'children': ['192', '193', '194']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'norms'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '194', 'type': 'subscript', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '197', 'type': 'for_in_clause', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '203', 'type': 'else_clause', 'children': ['204']}; {'id': '204', 'type': 'block', 'children': ['205', '211']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'mv_norms'}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '210', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'mv_polynomials'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'polynomials'}; {'id': '218', 'type': 'call', 'children': ['219', '224']}, {'id': '219', 'type': 'attribute', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'chaospy'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'poly'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '231']}; {'id': '226', 'type': 'attribute', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'Poly'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'mv_polynomials'}, {'id': '233', 'type': 'if_statement', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'retall'}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'return_statement', 'children': ['237']}, {'id': '237', 'type': 'expression_list', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'mv_norms'}, {'id': '245', 'type': 'return_statement', 'children': ['246']}
def orth_ttr( order, dist, normed=False, sort="GR", retall=False, cross_truncation=1., **kws): polynomials, norms, _, _ = chaospy.quad.generate_stieltjes( dist=dist, order=numpy.max(order), retall=True, **kws) if normed: for idx, poly in enumerate(polynomials): polynomials[idx] = poly / numpy.sqrt(norms[:, idx]) norms = norms**0 dim = len(dist) if dim > 1: mv_polynomials = [] mv_norms = [] indices = chaospy.bertran.bindex( start=0, stop=order, dim=dim, sort=sort, cross_truncation=cross_truncation, ) for index in indices: poly = polynomials[index[0]][0] for idx in range(1, dim): poly = poly * polynomials[index[idx]][idx] mv_polynomials.append(poly) if retall: for index in indices: mv_norms.append( numpy.prod([norms[idx, index[idx]] for idx in range(dim)])) else: mv_norms = norms[0] mv_polynomials = polynomials polynomials = chaospy.poly.flatten(chaospy.poly.Poly(mv_polynomials)) if retall: return polynomials, numpy.array(mv_norms) return polynomials
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'orth_chol'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'normed'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"GR"'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}; {'id': '14', 'type': 'float', 'children': [], 'value': '1.'}, {'id': '15', 'type': 'dictionary_splat_pattern', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kws'}, {'id': '17', 'type': 'block', 'children': ['18', '25', '50', '57', '76', '91', '124', '139', '150', '157', '166', '190', '199', '205', '209', '220', '247', '267']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'chaospy'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'poly'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38', '41', '44', '47']}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cholmat'}; {'id': '60', 'type': 'call', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'chaospy'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'chol'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'gill_king'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'descriptives'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'Cov'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'cholmat_inv'}, {'id': '79', 'type': 'attribute', 'children': ['80', '90']}; {'id': '80', 'type': 'call', 'children': ['81', '86']}, {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'linalg'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'inv'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'cholmat'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '94']}; {'id': '92', 'type': 'not_operator', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'normed'}; {'id': '94', 'type': 'block', 'children': ['95', '113']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'diag_mesh'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '109']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'diag'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'cholmat_inv'}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'cholmat_inv'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'augmented_assignment', 'children': ['115', '116'], 'value': '/='}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'cholmat_inv'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'diag_mesh'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'cholmat_inv'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'coefs'}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'tuple', 'children': ['133', '136']}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '+'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '149']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143', '146']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'coefs'}, {'id': '143', 'type': 'slice', 'children': ['144', '145']}; {'id': '144', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '145', 'type': 'colon', 'children': []}; {'id': '146', 'type': 'slice', 'children': ['147', '148']}, {'id': '147', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '148', 'type': 'colon', 'children': []}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cholmat_inv'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '156']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154', '155']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'coefs'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '165']}, {'id': '159', 'type': 'subscript', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'coefs'}, {'id': '161', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '162', 'type': 'slice', 'children': ['163', '164']}, {'id': '163', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '164', 'type': 'colon', 'children': []}, {'id': '165', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'expected'}, {'id': '169', 'type': 'unary_operator', 'children': ['170'], 'value': '-'}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '188']}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '*'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'cholmat_inv'}, {'id': '177', 'type': 'call', 'children': ['178', '183']}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'descriptives'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'E'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '186', 'type': 'dictionary_splat', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'kws'}; {'id': '188', 'type': 'unary_operator', 'children': ['189'], 'value': '-'}, {'id': '189', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '198']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194', '197']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'coefs'}; {'id': '194', 'type': 'slice', 'children': ['195', '196']}, {'id': '195', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '196', 'type': 'colon', 'children': []}, {'id': '197', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'expected'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'coefs'}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'coefs'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '208', 'type': 'dictionary', 'children': []}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '217']}, {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '213', 'type': 'binary_operator', 'children': ['214', '216'], 'value': '*'}; {'id': '214', 'type': 'tuple', 'children': ['215']}, {'id': '215', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '217', 'type': 'subscript', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'coefs'}, {'id': '219', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '220', 'type': 'for_statement', 'children': ['221', '222', '226']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '222', 'type': 'call', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '226', 'type': 'block', 'children': ['227', '237']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '230', 'type': 'subscript', 'children': ['231', '236']}, {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '242']}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'coefs'}; {'id': '244', 'type': 'binary_operator', 'children': ['245', '246'], 'value': '+'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'polynomials'}; {'id': '250', 'type': 'call', 'children': ['251', '256']}, {'id': '251', 'type': 'attribute', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'chaospy'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'poly'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'Poly'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '258', '259', '266']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '259', 'type': 'subscript', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'coefs'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '263', 'type': 'slice', 'children': ['264', '265']}; {'id': '264', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '265', 'type': 'colon', 'children': []}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '267', 'type': 'return_statement', 'children': ['268']}
def orth_chol(order, dist, normed=True, sort="GR", cross_truncation=1., **kws): dim = len(dist) basis = chaospy.poly.basis( start=1, stop=order, dim=dim, sort=sort, cross_truncation=cross_truncation, ) length = len(basis) cholmat = chaospy.chol.gill_king(chaospy.descriptives.Cov(basis, dist)) cholmat_inv = numpy.linalg.inv(cholmat.T).T if not normed: diag_mesh = numpy.repeat(numpy.diag(cholmat_inv), len(cholmat_inv)) cholmat_inv /= diag_mesh.reshape(cholmat_inv.shape) coefs = numpy.empty((length+1, length+1)) coefs[1:, 1:] = cholmat_inv coefs[0, 0] = 1 coefs[0, 1:] = 0 expected = -numpy.sum( cholmat_inv*chaospy.descriptives.E(basis, dist, **kws), -1) coefs[1:, 0] = expected coefs = coefs.T out = {} out[(0,)*dim] = coefs[0] for idx in range(length): index = basis[idx].keys[0] out[index] = coefs[idx+1] polynomials = chaospy.poly.Poly(out, dim, coefs.shape[1:], float) return polynomials
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_key'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'binary_operator', 'children': ['13', '36'], 'value': '*'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '21'], 'value': '**'}; {'id': '14', 'type': 'parenthesized_expression', 'children': ['15'], 'value': '()'}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '20'], 'value': '+'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '32', '34']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '31'], 'value': '-'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'unary_operator', 'children': ['35'], 'value': '-'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}
def sort_key(val): return numpy.sum((max(val)+1)**numpy.arange(len(val)-1, -1, -1)*val)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'orth_gs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'normed'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"GR"'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}; {'id': '14', 'type': 'float', 'children': [], 'value': '1.'}, {'id': '15', 'type': 'dictionary_splat_pattern', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kws'}, {'id': '17', 'type': 'block', 'children': ['18', '27', '34', '81', '88', '95', '318']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '40', '75']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '40', 'type': 'block', 'children': ['41', '58']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '45']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Poly'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '61', 'type': 'call', 'children': ['62', '67']}; {'id': '62', 'type': 'attribute', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70', '71', '72']}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}, {'id': '75', 'type': 'else_clause', 'children': ['76']}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '91', 'type': 'list', 'children': ['92'], 'value': '[basis[0]]'}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '97', '207']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'normed'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'for_statement', 'children': ['99', '100', '108']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '108', 'type': 'block', 'children': ['109', '150', '169', '183', '198']}, {'id': '109', 'type': 'for_statement', 'children': ['110', '111', '115']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'idy'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '115', 'type': 'block', 'children': ['116', '136']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'orth'}, {'id': '119', 'type': 'call', 'children': ['120', '125']}; {'id': '120', 'type': 'attribute', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'descriptives'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'E'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '133', '134']}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '130'], 'value': '*'}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'polynomials'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'idy'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '134', 'type': 'dictionary_splat', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'kws'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '141']}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '145'], 'value': '-'}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '149'], 'value': '*'}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'polynomials'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'idy'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'orth'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'norms'}, {'id': '153', 'type': 'call', 'children': ['154', '159']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'descriptives'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'E'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '166', '167']}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '165'], 'value': '**'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '163', 'type': 'unary_operator', 'children': ['164'], 'value': '-'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '167', 'type': 'dictionary_splat', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'kws'}, {'id': '169', 'type': 'if_statement', 'children': ['170', '173']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '<='}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '173', 'type': 'block', 'children': ['174', '182']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181']}; {'id': '180', 'type': 'string', 'children': [], 'value': '"Warning: Polynomial cutoff at term %d"'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '182', 'type': 'break_statement', 'children': []}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '188', 'type': 'binary_operator', 'children': ['189', '192'], 'value': '/'}, {'id': '189', 'type': 'subscript', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'polynomials'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '207', 'type': 'else_clause', 'children': ['208']}; {'id': '208', 'type': 'block', 'children': ['209', '214']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '212', 'type': 'list', 'children': ['213'], 'value': '[1.]'}, {'id': '213', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '214', 'type': 'for_statement', 'children': ['215', '216', '224']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '220']}, {'id': '219', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '224', 'type': 'block', 'children': ['225', '270', '292', '309']}, {'id': '225', 'type': 'for_statement', 'children': ['226', '227', '231']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'idy'}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '231', 'type': 'block', 'children': ['232', '252']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'orth'}, {'id': '235', 'type': 'call', 'children': ['236', '241']}; {'id': '236', 'type': 'attribute', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'descriptives'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'E'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '249', '250']}; {'id': '242', 'type': 'binary_operator', 'children': ['243', '246'], 'value': '*'}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '246', 'type': 'subscript', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'polynomials'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'idy'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '250', 'type': 'dictionary_splat', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'kws'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '257']}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '257', 'type': 'binary_operator', 'children': ['258', '261'], 'value': '-'}; {'id': '258', 'type': 'subscript', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'basis'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '261', 'type': 'binary_operator', 'children': ['262', '267'], 'value': '/'}; {'id': '262', 'type': 'binary_operator', 'children': ['263', '266'], 'value': '*'}, {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'idy'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'orth'}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'norms'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'idy'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '282']}, {'id': '277', 'type': 'attribute', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'chaospy'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'descriptives'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '289', '290']}, {'id': '283', 'type': 'binary_operator', 'children': ['284', '288'], 'value': '**'}; {'id': '284', 'type': 'subscript', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'polynomials'}; {'id': '286', 'type': 'unary_operator', 'children': ['287'], 'value': '-'}, {'id': '287', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '288', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '290', 'type': 'dictionary_splat', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'kws'}; {'id': '292', 'type': 'if_statement', 'children': ['293', '299']}, {'id': '293', 'type': 'comparison_operator', 'children': ['294', '298'], 'value': '<='}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '296', 'type': 'unary_operator', 'children': ['297'], 'value': '-'}, {'id': '297', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '298', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '299', 'type': 'block', 'children': ['300', '308']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '305', 'type': 'argument_list', 'children': ['306', '307']}; {'id': '306', 'type': 'string', 'children': [], 'value': '"Warning: Polynomial cutoff at term %d"'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '308', 'type': 'break_statement', 'children': []}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'call', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}, {'id': '315', 'type': 'subscript', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'basis'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '318', 'type': 'return_statement', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '325']}; {'id': '320', 'type': 'attribute', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'Poly'}, {'id': '325', 'type': 'argument_list', 'children': ['326', '327', '330']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'polynomials'}, {'id': '327', 'type': 'keyword_argument', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '330', 'type': 'keyword_argument', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '332', 'type': 'tuple', 'children': ['333']}, {'id': '333', 'type': 'call', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '335', 'type': 'argument_list', 'children': ['336']}
def orth_gs(order, dist, normed=False, sort="GR", cross_truncation=1., **kws): logger = logging.getLogger(__name__) dim = len(dist) if isinstance(order, int): if order == 0: return chaospy.poly.Poly(1, dim=dim) basis = chaospy.poly.basis( 0, order, dim, sort, cross_truncation=cross_truncation) else: basis = order basis = list(basis) polynomials = [basis[0]] if normed: for idx in range(1, len(basis)): for idy in range(idx): orth = chaospy.descriptives.E( basis[idx]*polynomials[idy], dist, **kws) basis[idx] = basis[idx] - polynomials[idy]*orth norms = chaospy.descriptives.E(polynomials[-1]**2, dist, **kws) if norms <= 0: logger.warning("Warning: Polynomial cutoff at term %d", idx) break basis[idx] = basis[idx] / numpy.sqrt(norms) polynomials.append(basis[idx]) else: norms = [1.] for idx in range(1, len(basis)): for idy in range(idx): orth = chaospy.descriptives.E( basis[idx]*polynomials[idy], dist, **kws) basis[idx] = basis[idx] - polynomials[idy] * orth / norms[idy] norms.append( chaospy.descriptives.E(polynomials[-1]**2, dist, **kws)) if norms[-1] <= 0: logger.warning("Warning: Polynomial cutoff at term %d", idx) break polynomials.append(basis[idx]) return chaospy.poly.Poly(polynomials, dim=dim, shape=(len(polynomials),))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'basis'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"G"'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}; {'id': '16', 'type': 'float', 'children': [], 'value': '1.'}, {'id': '17', 'type': 'block', 'children': ['18', '36', '48', '60', '73', '105', '156', '211', '222', '237', '243', '247', '274', '289', '295', '299', '326']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}, {'id': '25', 'type': 'pattern_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '28', 'type': 'expression_list', 'children': ['29', '35']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '69', '72']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'chaospy'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'bertran'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'bindex'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '94', '102', '103', '104']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '*'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'cross_truncation'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '111', '125']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': '=='}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'bellow'}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '124'], 'value': '>='}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '122', 'type': 'unary_operator', 'children': ['123'], 'value': '-'}, {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '125', 'type': 'else_clause', 'children': ['126']}; {'id': '126', 'type': 'block', 'children': ['127', '141']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '140'], 'value': '*'}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ones'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'bellow'}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '154']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': '>='}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '-'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'unary_operator', 'children': ['155'], 'value': '-'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '162', '180']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': '=='}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '161', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'above'}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '175'], 'value': '<='}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '173', 'type': 'unary_operator', 'children': ['174'], 'value': '-'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '179', 'type': 'argument_list', 'children': []}; {'id': '180', 'type': 'else_clause', 'children': ['181']}, {'id': '181', 'type': 'block', 'children': ['182', '196']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '185', 'type': 'binary_operator', 'children': ['186', '195'], 'value': '*'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'above'}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '203', 'type': 'argument_list', 'children': ['204', '209']}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '208'], 'value': '>='}, {'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '-'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '209', 'type': 'unary_operator', 'children': ['210'], 'value': '-'}; {'id': '210', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'subscript', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '219', 'type': 'binary_operator', 'children': ['220', '221'], 'value': '*'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'above'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'bellow'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '234']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '242']}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '241', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '246', 'type': 'dictionary', 'children': []}, {'id': '247', 'type': 'for_statement', 'children': ['248', '249', '250']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '250', 'type': 'block', 'children': ['251', '258', '264']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '263']}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'assignment', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '267', 'type': 'call', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'roll'}, {'id': '271', 'type': 'argument_list', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '273', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '281', 'type': 'argument_list', 'children': ['282', '286']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '294']}, {'id': '291', 'type': 'subscript', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '293', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '294', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '298', 'type': 'dictionary', 'children': []}, {'id': '299', 'type': 'for_statement', 'children': ['300', '301', '302']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'I'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '302', 'type': 'block', 'children': ['303', '310', '316']}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '306', 'type': 'call', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'assignment', 'children': ['312', '315']}; {'id': '312', 'type': 'subscript', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'I'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'assignment', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'roll'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '325', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '326', 'type': 'return_statement', 'children': ['327']}, {'id': '327', 'type': 'call', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'Poly'}, {'id': '329', 'type': 'argument_list', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'A'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'dim'}
def basis(start, stop=None, dim=1, sort="G", cross_truncation=1.): if stop is None: start, stop = numpy.array(0), start start = numpy.array(start, dtype=int) stop = numpy.array(stop, dtype=int) dim = max(start.size, stop.size, dim) indices = numpy.array(chaospy.bertran.bindex( numpy.min(start), 2*numpy.max(stop), dim, sort, cross_truncation)) if start.size == 1: bellow = numpy.sum(indices, -1) >= start else: start = numpy.ones(dim, dtype=int)*start bellow = numpy.all(indices-start >= 0, -1) if stop.size == 1: above = numpy.sum(indices, -1) <= stop.item() else: stop = numpy.ones(dim, dtype=int)*stop above = numpy.all(stop-indices >= 0, -1) pool = list(indices[above*bellow]) arg = numpy.zeros(len(pool), dtype=int) arg[0] = 1 poly = {} for idx in pool: idx = tuple(idx) poly[idx] = arg arg = numpy.roll(arg, 1) x = numpy.zeros(len(pool), dtype=int) x[0] = 1 A = {} for I in pool: I = tuple(I) A[I] = x x = numpy.roll(x,1) return Poly(A, dim)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_transform'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'transformations'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted_t'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '26']}, {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def sorted(self, key=None, reverse=False): return self._transform(transformations.sorted_t(key=key, reverse=reverse))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetCredentials'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '15', '18', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'package_name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'scopes'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'client_id'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'client_secret'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'user_agent'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'credentials_filename'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'api_key'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'oauth2client_args'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'dictionary_splat_pattern', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwds'}, {'id': '23', 'type': 'block', 'children': ['24', '33', '61', '81', '94', '105', '112']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'scopes'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'NormalizeScopes'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'scopes'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'client_info'}; {'id': '36', 'type': 'dictionary', 'children': ['37', '40', '43', '54']}, {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'client_id'"}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'client_id'}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': "'client_secret'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'client_secret'}, {'id': '43', 'type': 'pair', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'scope'"}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'scopes'}; {'id': '54', 'type': 'pair', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'user_agent'"}; {'id': '56', 'type': 'boolean_operator', 'children': ['57', '58'], 'value': 'or'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'user_agent'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '%'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'%s-generated/0.1'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'package_name'}, {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_CREDENTIALS_METHODS'}; {'id': '64', 'type': 'block', 'children': ['65', '74']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'credentials'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'client_info'}; {'id': '72', 'type': 'dictionary_splat', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'kwds'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'credentials'}, {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'credentials'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'credentials_filename'}; {'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'or'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'credentials_filename'}; {'id': '86', 'type': 'call', 'children': ['87', '92']}, {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'expanduser'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'~/.apitools.token'"}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'credentials'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'CredentialsFromFile'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'credentials_filename'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'client_info'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'oauth2client_args'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'oauth2client_args'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'is'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'credentials'}; {'id': '108', 'type': 'None', 'children': []}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'return_statement', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'credentials'}; {'id': '112', 'type': 'raise_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'CredentialsError'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}
def GetCredentials(package_name, scopes, client_id, client_secret, user_agent, credentials_filename=None, api_key=None, client=None, oauth2client_args=None, **kwds): scopes = util.NormalizeScopes(scopes) client_info = { 'client_id': client_id, 'client_secret': client_secret, 'scope': ' '.join(sorted(scopes)), 'user_agent': user_agent or '%s-generated/0.1' % package_name, } for method in _CREDENTIALS_METHODS: credentials = method(client_info, **kwds) if credentials is not None: return credentials credentials_filename = credentials_filename or os.path.expanduser( '~/.apitools.token') credentials = CredentialsFromFile(credentials_filename, client_info, oauth2client_args=oauth2client_args) if credentials is not None: return credentials raise exceptions.CredentialsError('Could not create valid credentials')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_graph'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '100'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'slices'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'include_inf'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'exact'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '32', '133', '150']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '26']}; {'id': '22', 'type': 'not_operator', 'children': ['23']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'is_sorted'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'raise_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"Not a sorted queue"'}; {'id': '32', 'type': 'with_statement', 'children': ['33', '50']}, {'id': '33', 'type': 'with_clause', 'children': ['34']}; {'id': '34', 'type': 'with_item', 'children': ['35']}, {'id': '35', 'type': 'as_pattern', 'children': ['36', '48']}; {'id': '36', 'type': 'call', 'children': ['37', '44']}, {'id': '37', 'type': 'attribute', 'children': ['38', '43']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'connections'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'redis'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pipeline'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'transaction'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'exact'}; {'id': '48', 'type': 'as_pattern_target', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '50', 'type': 'block', 'children': ['51', '64', '98', '125']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'old_div'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '63']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '-'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'slices'}; {'id': '64', 'type': 'for_statement', 'children': ['65', '66', '71']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'slices'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'zcount'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '81', '87']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'redis_key'}, {'id': '81', 'type': 'parenthesized_expression', 'children': ['82'], 'value': '()'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '+'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '*'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '%'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"(%s"'}, {'id': '89', 'type': 'parenthesized_expression', 'children': ['90'], 'value': '()'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '92', 'type': 'binary_operator', 'children': ['93', '97'], 'value': '*'}, {'id': '93', 'type': 'parenthesized_expression', 'children': ['94'], 'value': '()'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'include_inf'}; {'id': '100', 'type': 'block', 'children': ['101', '112']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'zcount'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '110', '111']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'redis_key'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '111', 'type': 'string', 'children': [], 'value': '"+inf"'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'zcount'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '121', '122']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'redis_key'}, {'id': '121', 'type': 'string', 'children': [], 'value': '"-inf"'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '%'}, {'id': '123', 'type': 'string', 'children': [], 'value': '"(%s"'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '132', 'type': 'argument_list', 'children': []}, {'id': '133', 'type': 'if_statement', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'include_inf'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'return_statement', 'children': ['137']}, {'id': '137', 'type': 'binary_operator', 'children': ['138', '144'], 'value': '+'}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '140', 'type': 'slice', 'children': ['141', '143']}, {'id': '141', 'type': 'unary_operator', 'children': ['142'], 'value': '-'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '143', 'type': 'colon', 'children': []}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '146', 'type': 'slice', 'children': ['147', '148']}, {'id': '147', 'type': 'colon', 'children': []}; {'id': '148', 'type': 'unary_operator', 'children': ['149'], 'value': '-'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'return_statement', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'data'}
def get_sorted_graph( self, start=0, stop=100, slices=100, include_inf=False, exact=False): if not self.is_sorted: raise Exception("Not a sorted queue") with context.connections.redis.pipeline(transaction=exact) as pipe: interval = old_div(float(stop - start), slices) for i in range(0, slices): pipe.zcount(self.redis_key, (start + i * interval), "(%s" % (start + (i + 1) * interval)) if include_inf: pipe.zcount(self.redis_key, stop, "+inf") pipe.zcount(self.redis_key, "-inf", "(%s" % start) data = pipe.execute() if include_inf: return data[-1:] + data[:-1] return data
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_threads'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'querystring'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'newest_first'"}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'exclude_tags'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '19', '28', '39', '53']}, {'id': '13', 'type': 'assert_statement', 'children': ['14']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'in'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_sort_orders'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'querystring'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'set_sort'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_sort_orders'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'exclude_tags'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'exclude_tags'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'exclude_tag'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'async_'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'search_threads'}; {'id': '62', 'type': 'parenthesized_expression', 'children': ['63'], 'value': '()'}, {'id': '63', 'type': 'lambda', 'children': ['64', '66']}; {'id': '64', 'type': 'lambda_parameters', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_thread_id'}
def get_threads(self, querystring, sort='newest_first', exclude_tags=None): assert sort in self._sort_orders q = self.query(querystring) q.set_sort(self._sort_orders[sort]) if exclude_tags: for tag in exclude_tags: q.exclude_tag(tag) return self.async_(q.search_threads, (lambda a: a.get_thread_id()))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nd_sort_samples'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'samples'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '22', '41']}; {'id': '6', 'type': 'assert_statement', 'children': ['7']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '14'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'samples'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cKDTree'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '27']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'samples'}, {'id': '41', 'type': 'return_statement', 'children': ['42']}
def nd_sort_samples(samples): assert len(samples.shape) == 2 tree = cKDTree(samples) d, i = tree.query(samples[0], k=len(samples)) return i
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetVolumeIdentifiers'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'volume_system'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '36']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'volume_identifiers'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'volume'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'volume_system'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '16', 'type': 'block', 'children': ['17', '26']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'volume_identifier'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'volume'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'identifier'"}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'if_statement', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'volume_identifier'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'volume_identifiers'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'volume_identifier'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}
def GetVolumeIdentifiers(self, volume_system): volume_identifiers = [] for volume in volume_system.volumes: volume_identifier = getattr(volume, 'identifier', None) if volume_identifier: volume_identifiers.append(volume_identifier) return sorted(volume_identifiers)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'topological_order_dfs'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '17', '25', '127']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'times_seen'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '24'], 'value': '*'}, {'id': '21', 'type': 'list', 'children': ['22'], 'value': '[-1]'}; {'id': '22', 'type': 'unary_operator', 'children': ['23'], 'value': '-'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '31']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '39']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': '=='}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'times_seen'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'block', 'children': ['40', '46', '51']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'times_seen'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'to_visit'}, {'id': '49', 'type': 'list', 'children': ['50'], 'value': '[start]'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '51', 'type': 'while_statement', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'to_visit'}, {'id': '53', 'type': 'block', 'children': ['54', '61', '67']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'to_visit'}, {'id': '59', 'type': 'unary_operator', 'children': ['60'], 'value': '-'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '76', '90']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': '=='}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'times_seen'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '76', 'type': 'block', 'children': ['77', '83']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'to_visit'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '82', 'type': 'argument_list', 'children': []}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '90', 'type': 'else_clause', 'children': ['91']}, {'id': '91', 'type': 'block', 'children': ['92', '100', '106']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'times_seen'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'augmented_assignment', 'children': ['102', '105'], 'value': '+='}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'times_seen'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '113']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '=='}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'times_seen'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '111', 'type': 'unary_operator', 'children': ['112'], 'value': '-'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '113', 'type': 'block', 'children': ['114', '120']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '119']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'times_seen'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'to_visit'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '127', 'type': 'return_statement', 'children': ['128']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '130', 'type': 'slice', 'children': ['131', '132', '133']}, {'id': '131', 'type': 'colon', 'children': []}; {'id': '132', 'type': 'colon', 'children': []}, {'id': '133', 'type': 'unary_operator', 'children': ['134'], 'value': '-'}
def topological_order_dfs(graph): n = len(graph) order = [] times_seen = [-1] * n for start in range(n): if times_seen[start] == -1: times_seen[start] = 0 to_visit = [start] while to_visit: node = to_visit[-1] children = graph[node] if times_seen[node] == len(children): to_visit.pop() order.append(node) else: child = children[times_seen[node]] times_seen[node] += 1 if times_seen[child] == -1: times_seen[child] = 0 to_visit.append(child) return order[::-1]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'topological_order'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '24', '40', '54', '58', '102']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'V'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'indeg'}, {'id': '19', 'type': 'list_comprehension', 'children': ['20', '21']}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'V'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'for_statement', 'children': ['29', '30', '33']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'neighbor'}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'augmented_assignment', 'children': ['36', '39'], 'value': '+='}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'indeg'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'neighbor'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Q'}, {'id': '43', 'type': 'list_comprehension', 'children': ['44', '45', '48']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '48', 'type': 'if_clause', 'children': ['49']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': '=='}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'indeg'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'while_statement', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'Q'}; {'id': '60', 'type': 'block', 'children': ['61', '69', '76']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Q'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '68', 'type': 'argument_list', 'children': []}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '81']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'neighbor'}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '81', 'type': 'block', 'children': ['82', '88']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'augmented_assignment', 'children': ['84', '87'], 'value': '-='}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'indeg'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'neighbor'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '94']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '=='}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'indeg'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'neighbor'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'Q'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'neighbor'}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'order'}
def topological_order(graph): V = range(len(graph)) indeg = [0 for _ in V] for node in V: for neighbor in graph[node]: indeg[neighbor] += 1 Q = [node for node in V if indeg[node] == 0] order = [] while Q: node = Q.pop() order.append(node) for neighbor in graph[node]: indeg[neighbor] -= 1 if indeg[neighbor] == 0: Q.append(neighbor) return order
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'interval_tree'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '26', '30', '34', '38', '79', '93', '107', '114', '121']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': '=='}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'center'}; {'id': '16', 'type': 'subscript', 'children': ['17', '25']}, {'id': '17', 'type': 'subscript', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '//'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'intervals'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '29', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'R'}, {'id': '33', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'intervals'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'if_statement', 'children': ['43', '48', '56', '70']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': '<='}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'center'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '56', 'type': 'elif_clause', 'children': ['57', '62']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '<'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'center'}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'I'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'R'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '70', 'type': 'else_clause', 'children': ['71']}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'I'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'by_low'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '84', 'type': 'generator_expression', 'children': ['85', '90']}, {'id': '85', 'type': 'tuple', 'children': ['86', '89']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'by_high'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '98', 'type': 'generator_expression', 'children': ['99', '104']}, {'id': '99', 'type': 'tuple', 'children': ['100', '103']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '104', 'type': 'for_in_clause', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'I'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'IL'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'interval_tree'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'IR'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'interval_tree'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'R'}, {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': '_Node'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126', '127', '128', '129']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'center'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'by_low'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'by_high'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'IL'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'IR'}
def interval_tree(intervals): if intervals == []: return None center = intervals[len(intervals) // 2][0] L = [] R = [] C = [] for I in intervals: if I[1] <= center: L.append(I) elif center < I[0]: R.append(I) else: C.append(I) by_low = sorted((I[0], I) for I in C) by_high = sorted((I[1], I) for I in C) IL = interval_tree(L) IR = interval_tree(R) return _Node(center, by_low, by_high, IL, IR)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_type'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'block', 'children': ['7', '18']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '15']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '14'], 'value': '=='}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'string', 'children': [], 'value': "'hiddenservices'"}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'FilesystemOnionService'}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'subscript', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'parsers'}
def get_type(self, name): if name.lower() == 'hiddenservices': return FilesystemOnionService return type(self.parsers[name])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'schwarz'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'A'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'iterations'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'subdomain'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'inv_subblock_ptr'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sweep'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'forward'"}, {'id': '25', 'type': 'block', 'children': ['26', '42', '48', '62', '78', '192']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '32']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'make_system'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37', '38']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '40', 'type': 'list', 'children': ['41'], 'value': "['csr']"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'csr'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sort_indices'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'if_statement', 'children': ['49', '56']}, {'id': '49', 'type': 'boolean_operator', 'children': ['50', '53'], 'value': 'and'}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'subdomain'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'raise_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': '"inv_subblock must be None if subdomain is None"'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '69', '70']}; {'id': '64', 'type': 'tuple_pattern', 'children': ['65', '66', '67', '68']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'subdomain'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'inv_subblock_ptr'}, {'id': '69', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'schwarz_parameters'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '75', '76', '77']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'subdomain'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'inv_subblock_ptr'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82', '99', '122', '185']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '=='}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sweep'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'forward'"}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '89']}, {'id': '85', 'type': 'pattern_list', 'children': ['86', '87', '88']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'row_start'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'row_stop'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'row_step'}, {'id': '89', 'type': 'expression_list', 'children': ['90', '91', '98']}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '97'], 'value': '-'}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '99', 'type': 'elif_clause', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '=='}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sweep'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'backward'"}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '110']}; {'id': '106', 'type': 'pattern_list', 'children': ['107', '108', '109']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'row_start'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'row_stop'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'row_step'}; {'id': '110', 'type': 'expression_list', 'children': ['111', '118', '120']}, {'id': '111', 'type': 'binary_operator', 'children': ['112', '117'], 'value': '-'}; {'id': '112', 'type': 'subscript', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '118', 'type': 'unary_operator', 'children': ['119'], 'value': '-'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'unary_operator', 'children': ['121'], 'value': '-'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'elif_clause', 'children': ['123', '126']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '=='}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sweep'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'symmetric'"}; {'id': '126', 'type': 'block', 'children': ['127', '184']}, {'id': '127', 'type': 'for_statement', 'children': ['128', '129', '133']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'iter'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'iterations'}, {'id': '133', 'type': 'block', 'children': ['134', '159']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'schwarz'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140', '141', '144', '147', '150', '153', '156']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'A'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'iterations'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'subdomain'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'subdomain'}, {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}, {'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'inv_subblock_ptr'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'inv_subblock_ptr'}; {'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'sweep'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'forward'"}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'schwarz'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164', '165', '166', '169', '172', '175', '178', '181']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'iterations'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'subdomain'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'subdomain'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}, {'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}; {'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'inv_subblock_ptr'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'inv_subblock_ptr'}, {'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'sweep'}, {'id': '183', 'type': 'string', 'children': [], 'value': "'backward'"}; {'id': '184', 'type': 'return_statement', 'children': []}, {'id': '185', 'type': 'else_clause', 'children': ['186']}; {'id': '186', 'type': 'block', 'children': ['187']}, {'id': '187', 'type': 'raise_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'string', 'children': [], 'value': '"valid sweep directions are \'forward\',\\\n \'backward\', and \'symmetric\'"'}; {'id': '192', 'type': 'for_statement', 'children': ['193', '194', '198']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'iterations'}; {'id': '198', 'type': 'block', 'children': ['199']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'amg_core'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'overlapping_schwarz_csr'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '208', '211', '214', '215', '216', '217', '218', '219', '220', '227', '232', '233', '234']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'A'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'indptr'}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'A'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'inv_subblock'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'inv_subblock_ptr'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'subdomain'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}; {'id': '220', 'type': 'binary_operator', 'children': ['221', '226'], 'value': '-'}, {'id': '221', 'type': 'subscript', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'subdomain_ptr'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '225', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '226', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '227', 'type': 'subscript', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '231', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'row_start'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'row_stop'}
def schwarz(A, x, b, iterations=1, subdomain=None, subdomain_ptr=None, inv_subblock=None, inv_subblock_ptr=None, sweep='forward'): A, x, b = make_system(A, x, b, formats=['csr']) A.sort_indices() if subdomain is None and inv_subblock is not None: raise ValueError("inv_subblock must be None if subdomain is None") (subdomain, subdomain_ptr, inv_subblock, inv_subblock_ptr) = \ schwarz_parameters(A, subdomain, subdomain_ptr, inv_subblock, inv_subblock_ptr) if sweep == 'forward': row_start, row_stop, row_step = 0, subdomain_ptr.shape[0]-1, 1 elif sweep == 'backward': row_start, row_stop, row_step = subdomain_ptr.shape[0]-2, -1, -1 elif sweep == 'symmetric': for iter in range(iterations): schwarz(A, x, b, iterations=1, subdomain=subdomain, subdomain_ptr=subdomain_ptr, inv_subblock=inv_subblock, inv_subblock_ptr=inv_subblock_ptr, sweep='forward') schwarz(A, x, b, iterations=1, subdomain=subdomain, subdomain_ptr=subdomain_ptr, inv_subblock=inv_subblock, inv_subblock_ptr=inv_subblock_ptr, sweep='backward') return else: raise ValueError("valid sweep directions are 'forward',\ 'backward', and 'symmetric'") for iter in range(iterations): amg_core.overlapping_schwarz_csr(A.indptr, A.indices, A.data, x, b, inv_subblock, inv_subblock_ptr, subdomain, subdomain_ptr, subdomain_ptr.shape[0]-1, A.shape[0], row_start, row_stop, row_step)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_stdlib_path'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5']}, {'id': '5', 'type': 'if_statement', 'children': ['6', '13', '25']}; {'id': '6', 'type': 'comparison_operator', 'children': ['7', '10'], 'value': '>='}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'version_info'}; {'id': '10', 'type': 'tuple', 'children': ['11', '12']}, {'id': '11', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '7'}, {'id': '13', 'type': 'block', 'children': ['14', '17']}; {'id': '14', 'type': 'import_statement', 'children': ['15']}, {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sysconfig'}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'subscript', 'children': ['19', '24']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sysconfig'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_paths'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'string', 'children': [], 'value': "'stdlib'"}, {'id': '25', 'type': 'else_clause', 'children': ['26']}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'prefix'}
def get_stdlib_path(): if sys.version_info >= (2, 7): import sysconfig return sysconfig.get_paths()['stdlib'] else: return os.path.join(sys.prefix, 'lib')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'exists_case_sensitive'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '53']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '28']}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '27'], 'value': 'and'}, {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'platform'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'win'"}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '28', 'type': 'block', 'children': ['29', '42']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}, {'id': '31', 'type': 'pattern_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'directory'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '34', 'type': 'call', 'children': ['35', '40']}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'listdir'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'directory'}, {'id': '53', 'type': 'return_statement', 'children': ['54']}
def exists_case_sensitive(path): result = os.path.exists(path) if sys.platform.startswith('win') and result: directory, basename = os.path.split(path) result = basename in os.listdir(directory) return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_comments'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'comments'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'original_string'}; {'id': '8', 'type': 'string', 'children': [], 'value': '""'}, {'id': '9', 'type': 'ERROR', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}, {'id': '11', 'type': 'boolean_operator', 'children': ['12', '13'], 'value': 'and'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'comments'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"{0}\n "'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '21', '22'], 'value': 'or'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'comments'}, {'id': '21', 'type': 'ERROR', 'children': []}
def _add_comments(self, comments, original_string=""): return comments and "{0} "; ".join(comments)) or original_string
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_priority_key'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pep8_result'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '20', '25', '35']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '9', 'type': 'list', 'children': ['10', '11', '12', '13', '14', '15'], 'value': "[\n 'e701',\n 'e702',\n 'e225', 'e231',\n 'e201',\n 'e262'\n ]"}; {'id': '10', 'type': 'string', 'children': [], 'value': "'e701'"}, {'id': '11', 'type': 'string', 'children': [], 'value': "'e702'"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'e225'"}, {'id': '13', 'type': 'string', 'children': [], 'value': "'e231'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'e201'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'e262'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'middle_index'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '10000'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'lowest_priority'}, {'id': '23', 'type': 'list', 'children': ['24'], 'value': "[\n 'e501'\n ]"}; {'id': '24', 'type': 'string', 'children': [], 'value': "'e501'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pep8_result'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'try_statement', 'children': ['36', '44']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'except_clause', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'try_statement', 'children': ['48', '60']}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '59'], 'value': '+'}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'middle_index'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lowest_priority'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'except_clause', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'return_statement', 'children': ['64']}
def _priority_key(pep8_result): priority = [ 'e701', 'e702', 'e225', 'e231', 'e201', 'e262' ] middle_index = 10000 lowest_priority = [ 'e501' ] key = pep8_result['id'].lower() try: return priority.index(key) except ValueError: try: return middle_index + lowest_priority.index(key) + 1 except ValueError: return middle_index
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'git_hook'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '6', 'type': 'False', 'children': []}, {'id': '7', 'type': 'block', 'children': ['8', '12', '19', '23', '76']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'diff_cmd'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD"'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'files_modified'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_lines'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'diff_cmd'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'files_modified'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '34']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'string', 'children': [], 'value': "'.py'"}; {'id': '34', 'type': 'block', 'children': ['35', '41', '48', '67']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'staged_cmd'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '%'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"git show :%s"'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'staged_contents'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_output'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'staged_cmd'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'SortImports'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '57', '64']}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'file_contents'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'staged_contents'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'check'}; {'id': '66', 'type': 'True', 'children': []}, {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'incorrectly_sorted'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'augmented_assignment', 'children': ['74', '75'], 'value': '+='}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}, {'id': '77', 'type': 'conditional_expression', 'children': ['78', '79', '80'], 'value': 'if'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'strict'}
def git_hook(strict=False): diff_cmd = "git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD" files_modified = get_lines(diff_cmd) errors = 0 for filename in files_modified: if filename.endswith('.py'): staged_cmd = "git show :%s" % filename staged_contents = get_output(staged_cmd) sort = SortImports( file_path=filename, file_contents=staged_contents.decode(), check=True ) if sort.incorrectly_sorted: errors += 1 return errors if strict else 0
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_all_fix_names'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fixer_pkg'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'remove_prefix'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '20', '33', '37', '87']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'pkg'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '__import__'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17', '18']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'fixer_pkg'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'list', 'children': ['19'], 'value': '["*"]'}, {'id': '19', 'type': 'string', 'children': [], 'value': '"*"'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'fixer_dir'}, {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dirname'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pkg'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '__file__'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'fix_names'}; {'id': '36', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '48']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'fixer_dir'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'if_statement', 'children': ['50', '63']}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '57'], 'value': 'and'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': '"fix_"'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'endswith'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': '".py"'}, {'id': '63', 'type': 'block', 'children': ['64', '75']}; {'id': '64', 'type': 'if_statement', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'remove_prefix'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '72', 'type': 'slice', 'children': ['73', '74']}, {'id': '73', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '74', 'type': 'colon', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'fix_names'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '83', 'type': 'slice', 'children': ['84', '85']}; {'id': '84', 'type': 'colon', 'children': []}, {'id': '85', 'type': 'unary_operator', 'children': ['86'], 'value': '-'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '87', 'type': 'return_statement', 'children': ['88']}
def get_all_fix_names(fixer_pkg, remove_prefix=True): pkg = __import__(fixer_pkg, [], [], ["*"]) fixer_dir = os.path.dirname(pkg.__file__) fix_names = [] for name in sorted(os.listdir(fixer_dir)): if name.startswith("fix_") and name.endswith(".py"): if remove_prefix: name = name[4:] fix_names.append(name[:-3]) return fix_names
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '40']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'unsorted'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '10', 'type': 'generator_expression', 'children': ['11', '14', '25']}, {'id': '11', 'type': 'subscript', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '-'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '25', 'type': 'if_clause', 'children': ['26']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'operator'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'le'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '+'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'resort'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'unsorted'}
def check(self): for unsorted in iter(self[i] for i in range(len(self) - 2) if not operator.le(self[i], self[i + 1])): self.resort(unsorted)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_list_order'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sortlist'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'reflist'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'fltr'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'slemap'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '59', '96']}; {'id': '16', 'type': 'function_definition', 'children': ['17', '18', '20']}, {'id': '17', 'type': 'function_name', 'children': [], 'value': 'keyfunc'}; {'id': '18', 'type': 'parameters', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '20', 'type': 'block', 'children': ['21', '33']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'slemap'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'rle'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'slemap'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37', '45']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'in'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'rle'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'reflist'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'reflist'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'rle'}, {'id': '45', 'type': 'else_clause', 'children': ['46']}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '55'], 'value': '+'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'reflist'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'fltr'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'if_statement', 'children': ['63', '64', '81']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'slemap'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '80']}, {'id': '71', 'type': 'lambda', 'children': ['72', '74']}; {'id': '72', 'type': 'lambda_parameters', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': 'in'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'slemap'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'reflist'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sortlist'}, {'id': '81', 'type': 'else_clause', 'children': ['82']}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '95']}, {'id': '89', 'type': 'lambda', 'children': ['90', '92']}; {'id': '90', 'type': 'lambda_parameters', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'in'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'reflist'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '96', 'type': 'return_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '104']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sortlist'}, {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'keyfunc'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def sort_by_list_order(sortlist, reflist, reverse=False, fltr=False, slemap=None): def keyfunc(entry): if slemap is not None: rle = slemap(entry) if rle in reflist: return reflist.index(rle) else: return sortlist.index(entry) + len(reflist) if fltr: if slemap: sortlist = filter(lambda x: slemap(x) in reflist, sortlist) else: sortlist = filter(lambda x: x in reflist, sortlist) return sorted(sortlist, key=keyfunc, reverse=reverse)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'strategy'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '71']}; {'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']}, {'id': '11', 'type': 'function_name', 'children': [], 'value': 'decorator'}; {'id': '12', 'type': 'parameters', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '14', 'type': 'block', 'children': ['15', '25', '48', '63', '69']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keep_name'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'string', 'children': [], 'value': '"keep_name"'}; {'id': '24', 'type': 'False', 'children': []}, {'id': '25', 'type': 'if_statement', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '27', 'type': 'block', 'children': ['28', '38']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '38', 'type': 'raise_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': '"Unknown keyword argument \'{}\'"'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '51']}, {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'keep_name'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'return_statement', 'children': ['72']}
def strategy(self, *names, **kwargs): def decorator(func): keep_name = kwargs.pop("keep_name", False) if kwargs: key = next(iter(kwargs)) raise TypeError("Unknown keyword argument '{}'".format(key)) if not keep_name: func.__name__ = str(names[0]) self[names] = func return self return decorator
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'humansort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '5', 'type': 'block', 'children': ['6', '9', '48', '57']}; {'id': '6', 'type': 'import_statement', 'children': ['7']}, {'id': '7', 'type': 'dotted_name', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': 'alphanum_key'}, {'id': '11', 'type': 'parameters', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '13', 'type': 'block', 'children': ['14', '33']}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '18']}, {'id': '15', 'type': 'function_name', 'children': [], 'value': 'tryint'}; {'id': '16', 'type': 'parameters', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '18', 'type': 'block', 'children': ['19', '31']}, {'id': '19', 'type': 'if_statement', 'children': ['20', '25']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isdigit'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '33', 'type': 'return_statement', 'children': ['34']}; {'id': '34', 'type': 'list_comprehension', 'children': ['35', '39']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'tryint'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"([0-9]+)"'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'alphanum_key'}, {'id': '57', 'type': 'return_statement', 'children': ['58']}
def humansort(l): import re def alphanum_key(s): def tryint(s): if s.isdigit(): return int(s) return s return [tryint(c) for c in re.split("([0-9]+)", s)] l.sort(key=alphanum_key) return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '25']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '10', 'type': 'string', 'children': [], 'value': "''"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'agent'}, {'id': '13', 'type': 'string', 'children': [], 'value': "''"}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'scanner'}; {'id': '16', 'type': 'string', 'children': [], 'value': "''"}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '19', 'type': 'string', 'children': [], 'value': "''"}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'language'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'en'"}, {'id': '23', 'type': 'list_splat_pattern', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '25', 'type': 'dictionary_splat_pattern', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '27', 'type': 'block', 'children': ['28', '49', '59']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '31', 'type': 'binary_operator', 'children': ['32', '33'], 'value': '%'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'/library/sections?name=%s&type=%s&agent=%s&scanner=%s&language=%s&location=%s'"}, {'id': '33', 'type': 'tuple', 'children': ['34', '38', '39', '40', '44', '45']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'quote_plus'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'quote_plus'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'scanner'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'language'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'quote_plus'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'urlencode'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_server'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '70', 'type': 'attribute', 'children': ['71', '76']}, {'id': '71', 'type': 'attribute', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_server'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_session'}
def add(self, name='', type='', agent='', scanner='', location='', language='en', *args, **kwargs): part = '/library/sections?name=%s&type=%s&agent=%s&scanner=%s&language=%s&location=%s' % ( quote_plus(name), type, agent, quote_plus(scanner), language, quote_plus(location)) if kwargs: part += urlencode(kwargs) return self._server.query(part, method=self._server._session.post)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'all'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '26', '36']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sortStr'}; {'id': '14', 'type': 'string', 'children': [], 'value': "''"}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sortStr'}, {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'?sort='"}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '%'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'/library/sections/%s/all%s'"}, {'id': '31', 'type': 'tuple', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sortStr'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'fetchItems'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '43', 'type': 'dictionary_splat', 'children': ['44']}
def all(self, sort=None, **kwargs): sortStr = '' if sort is not None: sortStr = '?sort=' + sort key = '/library/sections/%s/all%s' % (self.key, sortStr) return self.fetchItems(key, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'as_sorted_list'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '5', 'type': 'block', 'children': ['6', '29']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '12'], 'value': '>'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '23', 'type': 'lambda', 'children': ['24', '26']}; {'id': '24', 'type': 'lambda_parameters', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'number'}, {'id': '29', 'type': 'return_statement', 'children': ['30']}
def as_sorted_list(options): if len(options) > 0: options = sorted(options, key=lambda o: o.number) return options
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'df_all'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'phot'}; {'id': '6', 'type': 'block', 'children': ['7', '30']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'concat'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'list_comprehension', 'children': ['16', '22']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'to_df'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_filenames'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'phot'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'df'}
def df_all(self, phot): df = pd.concat([self.to_df(f) for f in self.get_filenames(phot)]) return df
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'searchsorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '18', '22', '31', '90']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'R'}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '-'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '25', 'type': 'binary_operator', 'children': ['26', '30'], 'value': '//'}; {'id': '26', 'type': 'parenthesized_expression', 'children': ['27'], 'value': '()'}, {'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '+'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '31', 'type': 'while_statement', 'children': ['32', '34']}; {'id': '32', 'type': 'not_operator', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'done'}; {'id': '34', 'type': 'block', 'children': ['35', '72', '81']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '41', '48', '61']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': '<'}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '+'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'elif_clause', 'children': ['49', '54']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': '>'}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'arr'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '-'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'elif_clause', 'children': ['62', '67']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '66'], 'value': '=='}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '71', 'type': 'True', 'children': []}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '80'], 'value': '//'}; {'id': '76', 'type': 'parenthesized_expression', 'children': ['77'], 'value': '()'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '+'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '85']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '>'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'R'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'done'}, {'id': '89', 'type': 'True', 'children': []}; {'id': '90', 'type': 'return_statement', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'L'}
def searchsorted(arr, N, x): L = 0 R = N-1 done = False m = (L+R)//2 while not done: if arr[m] < x: L = m + 1 elif arr[m] > x: R = m - 1 elif arr[m] == x: done = True m = (L+R)//2 if L>R: done = True return L
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_plot_spectrogram'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node_idx'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '14', '23', '38', '48', '65', '74', '90', '104', '133', '147', '157', '174', '182', '201', '218', '235', '241', '302', '309', '311']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '9', 'type': 'import_from_statement', 'children': ['10', '12']}; {'id': '10', 'type': 'dotted_name', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'pygsp'}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '20']}; {'id': '16', 'type': 'pattern_list', 'children': ['17', '18', '19']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'qtg'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_import_qtg'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'if_statement', 'children': ['24', '30']}; {'id': '24', 'type': 'not_operator', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'spectr'"}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'features'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'compute_spectrogram'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'M'}, {'id': '41', 'type': 'subscript', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'spectr'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'spectr'}, {'id': '51', 'type': 'conditional_expression', 'children': ['52', '59', '62'], 'value': 'if'}; {'id': '52', 'type': 'subscript', 'children': ['53', '56', '57']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'spectr'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'node_idx'}, {'id': '57', 'type': 'slice', 'children': ['58']}; {'id': '58', 'type': 'colon', 'children': []}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'node_idx'}, {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'spectr'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'spectr'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ravel'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'spectr'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '79']}; {'id': '76', 'type': 'pattern_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'min_spec'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'max_spec'}, {'id': '79', 'type': 'expression_list', 'children': ['80', '85']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'spectr'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '84', 'type': 'argument_list', 'children': []}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'spectr'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'list', 'children': ['99', '100', '101', '102', '103'], 'value': '[0., 0.25, 0.5, 0.75, 1.]'}, {'id': '99', 'type': 'float', 'children': [], 'value': '0.'}; {'id': '100', 'type': 'float', 'children': [], 'value': '0.25'}, {'id': '101', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '102', 'type': 'float', 'children': [], 'value': '0.75'}, {'id': '103', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '107', 'type': 'list', 'children': ['108', '113', '118', '123', '128'], 'value': '[[20, 133, 212, 255], [53, 42, 135, 255], [48, 174, 170, 255],\n [210, 184, 87, 255], [249, 251, 14, 255]]'}; {'id': '108', 'type': 'list', 'children': ['109', '110', '111', '112'], 'value': '[20, 133, 212, 255]'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '133'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '212'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '255'}, {'id': '113', 'type': 'list', 'children': ['114', '115', '116', '117'], 'value': '[53, 42, 135, 255]'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '53'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '42'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '135'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '255'}; {'id': '118', 'type': 'list', 'children': ['119', '120', '121', '122'], 'value': '[48, 174, 170, 255]'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '48'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '174'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '170'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '255'}, {'id': '123', 'type': 'list', 'children': ['124', '125', '126', '127'], 'value': '[210, 184, 87, 255]'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '210'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '184'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '87'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '255'}; {'id': '128', 'type': 'list', 'children': ['129', '130', '131', '132'], 'value': '[249, 251, 14, 255]'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '249'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '251'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '14'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '255'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ubyte'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'qtg'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ColorMap'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'spectr'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '170'], 'value': '/'}, {'id': '161', 'type': 'parenthesized_expression', 'children': ['162'], 'value': '()'}; {'id': '162', 'type': 'binary_operator', 'children': ['163', '169'], 'value': '-'}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'spectr'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'astype'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'min_spec'}; {'id': '170', 'type': 'parenthesized_expression', 'children': ['171'], 'value': '()'}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '-'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'max_spec'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'min_spec'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'qtg'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'GraphicsWindow'}, {'id': '181', 'type': 'argument_list', 'children': []}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'setWindowTitle'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'string', 'children': [], 'value': '"Spectrogram of {}"'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '__repr__'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'string', 'children': [], 'value': "'frequencies {}:{:.2f}:{:.2f}'"}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '210', '215']}, {'id': '209', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '214'], 'value': '/'}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'lmax'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'M'}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'lmax'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'addPlot'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '228', 'type': 'dictionary', 'children': ['229', '232']}, {'id': '229', 'type': 'pair', 'children': ['230', '231']}; {'id': '230', 'type': 'string', 'children': [], 'value': "'bottom'"}, {'id': '231', 'type': 'string', 'children': [], 'value': "'nodes'"}; {'id': '232', 'type': 'pair', 'children': ['233', '234']}, {'id': '233', 'type': 'string', 'children': [], 'value': "'left'"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'setAspectLocked'}; {'id': '240', 'type': 'argument_list', 'children': []}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'spi'}; {'id': '244', 'type': 'call', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'qtg'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ScatterPlotItem'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '263', '284', '287', '290', '293']}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'repeat'}, {'id': '253', 'type': 'argument_list', 'children': ['254', '262']}; {'id': '254', 'type': 'call', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'M'}, {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'ravel'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'tile'}; {'id': '272', 'type': 'argument_list', 'children': ['273', '279']}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'M'}, {'id': '279', 'type': 'tuple', 'children': ['280', '281']}; {'id': '280', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'pxMode'}; {'id': '286', 'type': 'False', 'children': []}, {'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'symbol'}, {'id': '289', 'type': 'string', 'children': [], 'value': "'s'"}; {'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '292', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'brush'}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '299', 'type': 'argument_list', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'spectr'}, {'id': '301', 'type': 'string', 'children': [], 'value': "'qcolor'"}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'call', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'addItem'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'spi'}, {'id': '309', 'type': 'global_statement', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': '_qtg_windows'}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '316']}, {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': '_qtg_windows'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'w'}
def _plot_spectrogram(G, node_idx): r from pygsp import features qtg, _, _ = _import_qtg() if not hasattr(G, 'spectr'): features.compute_spectrogram(G) M = G.spectr.shape[1] spectr = G.spectr[node_idx, :] if node_idx is not None else G.spectr spectr = np.ravel(spectr) min_spec, max_spec = spectr.min(), spectr.max() pos = np.array([0., 0.25, 0.5, 0.75, 1.]) color = [[20, 133, 212, 255], [53, 42, 135, 255], [48, 174, 170, 255], [210, 184, 87, 255], [249, 251, 14, 255]] color = np.array(color, dtype=np.ubyte) cmap = qtg.ColorMap(pos, color) spectr = (spectr.astype(float) - min_spec) / (max_spec - min_spec) w = qtg.GraphicsWindow() w.setWindowTitle("Spectrogram of {}".format(G.__repr__(limit=4))) label = 'frequencies {}:{:.2f}:{:.2f}'.format(0, G.lmax/M, G.lmax) v = w.addPlot(labels={'bottom': 'nodes', 'left': label}) v.setAspectLocked() spi = qtg.ScatterPlotItem(np.repeat(np.arange(G.N), M), np.ravel(np.tile(np.arange(M), (1, G.N))), pxMode=False, symbol='s', size=1, brush=cmap.map(spectr, 'qcolor')) v.addItem(spi) global _qtg_windows _qtg_windows.append(w)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_omega_scan_config'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'channellist'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '35']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '16', '21']}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'fobj'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'FILE_LIKE'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'else_clause', 'children': ['22']}; {'id': '22', 'type': 'block', 'children': ['23', '31']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '34', 'type': 'True', 'children': []}, {'id': '35', 'type': 'try_statement', 'children': ['36', '90']}; {'id': '36', 'type': 'block', 'children': ['37', '47']}, {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43', '46']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '43', 'type': 'ERROR', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'\n print('"}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'for_statement', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'channel'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'channellist'}; {'id': '50', 'type': 'block', 'children': ['51', '74', '82']}, {'id': '51', 'type': 'if_statement', 'children': ['52', '57']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '!='}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'channel'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '57', 'type': 'block', 'children': ['58', '64']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'channel'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '71']}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '%'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'\\n[%s]'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': '""'}, {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'print_omega_channel'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'channel'}, {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '90', 'type': 'finally_clause', 'children': ['91']}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'fobj'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'close'}
def write_omega_scan_config(channellist, fobj, header=True): if isinstance(fobj, FILE_LIKE): close = False else: fobj = open(fobj, 'w') close = True try: if header: print(' print(' group = None for channel in channellist: if channel.group != group: group = channel.group print('\n[%s]' % group, file=fobj) print("", file=fobj) print_omega_channel(channel, file=fobj) finally: if close: fobj.close()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'coalesce'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '22', '28', '35', '153', '159']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '14', 'type': 'lambda', 'children': ['15', '17']}, {'id': '15', 'type': 'lambda_parameters', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 't0'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'while_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '<'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '39', 'type': 'block', 'children': ['40', '46', '50', '149']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'this'}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '+='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '65', '141']}, {'id': '51', 'type': 'boolean_operator', 'children': ['52', '55'], 'value': 'and'}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '<'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '64'], 'value': '=='}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'this'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'is_contiguous'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'while_statement', 'children': ['67', '79']}, {'id': '67', 'type': 'boolean_operator', 'children': ['68', '71'], 'value': 'and'}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '<'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'this'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'is_contiguous'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '79', 'type': 'block', 'children': ['80', '137']}; {'id': '80', 'type': 'try_statement', 'children': ['81', '97']}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'this'}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'this'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '97', 'type': 'except_clause', 'children': ['98', '102']}; {'id': '98', 'type': 'as_pattern', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '100', 'type': 'as_pattern_target', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'if_statement', 'children': ['104', '110', '134']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'in'}, {'id': '105', 'type': 'string', 'children': [], 'value': "'cannot resize this array'"}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '110', 'type': 'block', 'children': ['111', '119']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'this'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'this'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '118', 'type': 'argument_list', 'children': []}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'this'}; {'id': '122', 'type': 'assignment', 'children': ['123', '126']}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'this'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '134', 'type': 'else_clause', 'children': ['135']}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'raise_statement', 'children': []}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'augmented_assignment', 'children': ['139', '140'], 'value': '+='}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '148']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'this'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'augmented_assignment', 'children': ['151', '152'], 'value': '+='}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '153', 'type': 'delete_statement', 'children': ['154']}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'slice', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '158', 'type': 'colon', 'children': []}, {'id': '159', 'type': 'return_statement', 'children': ['160']}
def coalesce(self): self.sort(key=lambda ts: ts.t0.value) i = j = 0 N = len(self) while j < N: this = self[j] j += 1 if j < N and this.is_contiguous(self[j]) == 1: while j < N and this.is_contiguous(self[j]): try: this = self[i] = this.append(self[j]) except ValueError as exc: if 'cannot resize this array' in str(exc): this = this.copy() this = self[i] = this.append(self[j]) else: raise j += 1 else: self[i] = this i += 1 del self[i:] return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_cache'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cachefile'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'coltype'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'LIGOTimeGPS'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'segment'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '52', '68', '81', '93']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '22']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cachefile'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'FILE_LIKE'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'with_statement', 'children': ['24', '37']}; {'id': '24', 'type': 'with_clause', 'children': ['25']}, {'id': '25', 'type': 'with_item', 'children': ['26']}; {'id': '26', 'type': 'as_pattern', 'children': ['27', '35']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '34']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cachefile'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'r'"}, {'id': '35', 'type': 'as_pattern_target', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'fobj'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'read_cache'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43', '46', '49']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'fobj'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'coltype'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'coltype'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'segment'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'segment'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'cache'}, {'id': '55', 'type': 'list_comprehension', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_iter_cache'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'cachefile'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'gpstype'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'coltype'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'segment'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sieve'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'segment'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'segment'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '93', 'type': 'return_statement', 'children': ['94']}
def read_cache(cachefile, coltype=LIGOTimeGPS, sort=None, segment=None): if not isinstance(cachefile, FILE_LIKE): with open(file_path(cachefile), 'r') as fobj: return read_cache(fobj, coltype=coltype, sort=sort, segment=segment) cache = [x.path for x in _iter_cache(cachefile, gpstype=coltype)] if segment: cache = sieve(cache, segment=segment) if sort: cache.sort(key=sort) return cache
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_learned_skills'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '6', 'type': 'block', 'children': ['7', '23', '30']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'skills'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'skill'}; {'id': '12', 'type': 'for_in_clause', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'skill'}; {'id': '14', 'type': 'subscript', 'children': ['15', '22']}, {'id': '15', 'type': 'subscript', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'user_data'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'language_data'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'skills'"}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_compute_dependency_order'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'skills'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'list_comprehension', 'children': ['32', '33', '47']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'skill'}, {'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'skill'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'skills'}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '41', 'type': 'lambda', 'children': ['42', '44']}; {'id': '42', 'type': 'lambda_parameters', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'skill'}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'skill'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'dependency_order'"}, {'id': '47', 'type': 'if_clause', 'children': ['48']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'skill'}
def get_learned_skills(self, lang): skills = [skill for skill in self.user_data.language_data[lang]['skills']] self._compute_dependency_order(skills) return [skill for skill in sorted(skills, key=lambda skill: skill['dependency_order']) if skill['learned']]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'combine_adjacent_lines'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'line_numbers'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '14', '21', '27', '31', '92']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'combine_template'}, {'id': '9', 'type': 'string', 'children': [], 'value': '"{0}-{1}"'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'combined_list'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'line_numbers'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'line_numbers'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '38']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'line_number'}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'line_numbers'}, {'id': '35', 'type': 'slice', 'children': ['36', '37']}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'colon', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'if_statement', 'children': ['40', '49', '54']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '48'], 'value': '=='}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '47'], 'value': '+'}; {'id': '42', 'type': 'parenthesized_expression', 'children': ['43'], 'value': '()'}, {'id': '43', 'type': 'conditional_expression', 'children': ['44', '45', '46'], 'value': 'if'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'line_number'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'line_number'}; {'id': '54', 'type': 'else_clause', 'children': ['55']}, {'id': '55', 'type': 'block', 'children': ['56', '84', '88']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '58', '72']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'combined_list'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'combine_template'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'combined_list'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'line_number'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '91', 'type': 'None', 'children': []}; {'id': '92', 'type': 'return_statement', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'combined_list'}
def combine_adjacent_lines(line_numbers): combine_template = "{0}-{1}" combined_list = [] line_numbers.append(None) start = line_numbers[0] end = None for line_number in line_numbers[1:]: if (end if end else start) + 1 == line_number: end = line_number else: if end: combined_list.append(combine_template.format(start, end)) else: combined_list.append(str(start)) start = line_number end = None return combined_list
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_menus'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '11']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '19']}, {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'subscript', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '19', 'type': 'block', 'children': ['20', '38']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '29']}; {'id': '22', 'type': 'attribute', 'children': ['23', '28']}, {'id': '23', 'type': 'subscript', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'lambda', 'children': ['33', '35']}, {'id': '33', 'type': 'lambda_parameters', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'weight'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '45']}; {'id': '40', 'type': 'subscript', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '45', 'type': 'True', 'children': []}
def sort_menus(c): for name in c.items: if not c.sorted[name]: c.items[name].sort(key=lambda x: x.weight) c.sorted[name] = True
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_frequency_order_transform'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sets'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '33', '52', '71', '78']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"Applying frequency order transform on tokens..."'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'counts'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '32']}; {'id': '20', 'type': 'attribute', 'children': ['21', '31']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Counter'}, {'id': '23', 'type': 'generator_expression', 'children': ['24', '25', '28']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sets'}; {'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'most_common'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '38', 'type': 'generator_expression', 'children': ['39', '42']}, {'id': '39', 'type': 'tuple', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '48']}, {'id': '43', 'type': 'pattern_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '45', 'type': 'tuple_pattern', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'counts'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sets'}, {'id': '55', 'type': 'list_comprehension', 'children': ['56', '68']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'list_comprehension', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sets'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'string', 'children': [], 'value': '"Done applying frequency order."'}; {'id': '78', 'type': 'return_statement', 'children': ['79']}, {'id': '79', 'type': 'expression_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sets'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'order'}
def _frequency_order_transform(sets): logging.debug("Applying frequency order transform on tokens...") counts = reversed(Counter(token for s in sets for token in s).most_common()) order = dict((token, i) for i, (token, _) in enumerate(counts)) sets = [np.sort([order[token] for token in s]) for s in sets] logging.debug("Done applying frequency order.") return sets, order
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_numpy_vectors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '13', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'variable_order'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'index_dtype'}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'int64'}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort_indices'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '28', '34', '41', '48', '60', '72', '84', '248', '326']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'linear'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'quadratic'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'num_variables'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'linear'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'num_interactions'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'irow'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'num_interactions'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'index_dtype'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'icol'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'num_interactions'}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'index_dtype'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'qdata'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'num_interactions'}, {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '88', '161']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'is'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'variable_order'}, {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'block', 'children': ['89', '126']}, {'id': '89', 'type': 'try_statement', 'children': ['90', '115']}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ldata'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'fromiter'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '109', '112']}, {'id': '99', 'type': 'generator_expression', 'children': ['100', '103']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'num_variables'}, {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'num_variables'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '115', 'type': 'except_clause', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'raise_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'parenthesized_expression', 'children': ['123'], 'value': '()'}, {'id': '123', 'type': 'concatenated_string', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': '"if \'variable_order\' is not provided, binary quadratic model must be "'}, {'id': '125', 'type': 'string', 'children': [], 'value': '"index labeled [0, ..., N-1]"'}; {'id': '126', 'type': 'for_statement', 'children': ['127', '134', '142']}, {'id': '127', 'type': 'pattern_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '129', 'type': 'tuple_pattern', 'children': ['130', '133']}; {'id': '130', 'type': 'tuple_pattern', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '141', 'type': 'argument_list', 'children': []}; {'id': '142', 'type': 'block', 'children': ['143', '149', '155']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '148']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'irow'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '154']}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'icol'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'qdata'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'bias'}, {'id': '161', 'type': 'else_clause', 'children': ['162']}; {'id': '162', 'type': 'block', 'children': ['163', '194', '209']}, {'id': '163', 'type': 'try_statement', 'children': ['164', '186']}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ldata'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'fromiter'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '180', '183']}, {'id': '173', 'type': 'generator_expression', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '177', 'type': 'for_in_clause', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'variable_order'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'num_variables'}, {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '186', 'type': 'except_clause', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'raise_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'string', 'children': [], 'value': '"provided \'variable_order\' does not match binary quadratic model"'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'label_to_idx'}, {'id': '197', 'type': 'dictionary_comprehension', 'children': ['198', '201']}; {'id': '198', 'type': 'pair', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '201', 'type': 'for_in_clause', 'children': ['202', '205']}; {'id': '202', 'type': 'pattern_list', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'variable_order'}, {'id': '209', 'type': 'for_statement', 'children': ['210', '217', '225']}; {'id': '210', 'type': 'pattern_list', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '212', 'type': 'tuple_pattern', 'children': ['213', '216']}, {'id': '213', 'type': 'tuple_pattern', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'bias'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'quadratic'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '224', 'type': 'argument_list', 'children': []}, {'id': '225', 'type': 'block', 'children': ['226', '234', '242']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '231']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'irow'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'label_to_idx'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '239']}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'icol'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'label_to_idx'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '247']}; {'id': '244', 'type': 'subscript', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'qdata'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '248', 'type': 'if_statement', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'sort_indices'}; {'id': '250', 'type': 'block', 'children': ['251', '257', '280', '291']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'swaps'}; {'id': '254', 'type': 'comparison_operator', 'children': ['255', '256'], 'value': '>'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'irow'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'icol'}, {'id': '257', 'type': 'if_statement', 'children': ['258', '263']}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'swaps'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '262', 'type': 'argument_list', 'children': []}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'assignment', 'children': ['266', '273']}; {'id': '266', 'type': 'pattern_list', 'children': ['267', '270']}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'irow'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'swaps'}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'icol'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'swaps'}, {'id': '273', 'type': 'expression_list', 'children': ['274', '277']}; {'id': '274', 'type': 'subscript', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'icol'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'swaps'}, {'id': '277', 'type': 'subscript', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'irow'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'swaps'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'lexsort'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'tuple', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'irow'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'icol'}, {'id': '291', 'type': 'if_statement', 'children': ['292', '307']}; {'id': '292', 'type': 'not_operator', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '306']}; {'id': '294', 'type': 'attribute', 'children': ['295', '305']}, {'id': '295', 'type': 'parenthesized_expression', 'children': ['296'], 'value': '()'}; {'id': '296', 'type': 'comparison_operator', 'children': ['297', '298'], 'value': '=='}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '306', 'type': 'argument_list', 'children': []}, {'id': '307', 'type': 'block', 'children': ['308', '314', '320']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'irow'}, {'id': '311', 'type': 'subscript', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'irow'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'assignment', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'icol'}, {'id': '317', 'type': 'subscript', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'icol'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'qdata'}, {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'qdata'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '326', 'type': 'return_statement', 'children': ['327']}, {'id': '327', 'type': 'expression_list', 'children': ['328', '329', '333']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'ldata'}, {'id': '329', 'type': 'tuple', 'children': ['330', '331', '332']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'irow'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'icol'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'qdata'}, {'id': '333', 'type': 'call', 'children': ['334', '339']}; {'id': '334', 'type': 'attribute', 'children': ['335', '338']}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'ldata'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '339', 'type': 'argument_list', 'children': ['340']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'}
def to_numpy_vectors(self, variable_order=None, dtype=np.float, index_dtype=np.int64, sort_indices=False): linear = self.linear quadratic = self.quadratic num_variables = len(linear) num_interactions = len(quadratic) irow = np.empty(num_interactions, dtype=index_dtype) icol = np.empty(num_interactions, dtype=index_dtype) qdata = np.empty(num_interactions, dtype=dtype) if variable_order is None: try: ldata = np.fromiter((linear[v] for v in range(num_variables)), count=num_variables, dtype=dtype) except KeyError: raise ValueError(("if 'variable_order' is not provided, binary quadratic model must be " "index labeled [0, ..., N-1]")) for idx, ((u, v), bias) in enumerate(quadratic.items()): irow[idx] = u icol[idx] = v qdata[idx] = bias else: try: ldata = np.fromiter((linear[v] for v in variable_order), count=num_variables, dtype=dtype) except KeyError: raise ValueError("provided 'variable_order' does not match binary quadratic model") label_to_idx = {v: idx for idx, v in enumerate(variable_order)} for idx, ((u, v), bias) in enumerate(quadratic.items()): irow[idx] = label_to_idx[u] icol[idx] = label_to_idx[v] qdata[idx] = bias if sort_indices: swaps = irow > icol if swaps.any(): irow[swaps], icol[swaps] = icol[swaps], irow[swaps] order = np.lexsort((irow, icol)) if not (order == range(len(order))).all(): irow = irow[order] icol = icol[order] qdata = qdata[order] return ldata, (irow, icol, qdata), ldata.dtype.type(self.offset)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_samples_bqm'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'samples_like'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'bqm'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '17', '26']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'samples_like'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'as_samples'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'samples_like'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'energies'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'bqm'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'energies'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'samples_like'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'from_samples'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '36', '41']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'samples_like'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'energy'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'energies'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'vartype'}, {'id': '41', 'type': 'dictionary_splat', 'children': ['42']}
def from_samples_bqm(cls, samples_like, bqm, **kwargs): samples_like = as_samples(samples_like) energies = bqm.energies(samples_like) return cls.from_samples(samples_like, energy=energies, vartype=bqm.vartype, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'samples'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted_by'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'energy'"}, {'id': '11', 'type': 'block', 'children': ['12', '30', '68']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'subscript', 'children': ['19', '27']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'samples'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorted_by'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted_by'}, {'id': '27', 'type': 'slice', 'children': ['28', '29']}; {'id': '28', 'type': 'colon', 'children': []}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34', '43']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted_by'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sample'}, {'id': '43', 'type': 'else_clause', 'children': ['44']}; {'id': '44', 'type': 'block', 'children': ['45', '58']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'subscript', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted_by'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'samples'}, {'id': '61', 'type': 'subscript', 'children': ['62', '67']}; {'id': '62', 'type': 'attribute', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sample'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'SamplesArray'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'samples'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'variables'}
def samples(self, n=None, sorted_by='energy'): if n is not None: return self.samples(sorted_by=sorted_by)[:n] if sorted_by is None: samples = self.record.sample else: order = np.argsort(self.record[sorted_by]) samples = self.record.sample[order] return SamplesArray(samples, self.variables)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'append_variables'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'samples_like'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort_labels'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '19', '26', '75', '81', '101', '110', '125']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '15']}; {'id': '12', 'type': 'pattern_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'as_samples'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'samples_like'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'num_samples'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '34', '36', '60']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '33'], 'value': '=='}; {'id': '28', 'type': 'subscript', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'samples'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'num_samples'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'pass_statement', 'children': []}; {'id': '36', 'type': 'elif_clause', 'children': ['37', '46']}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '45'], 'value': 'and'}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '44'], 'value': '=='}, {'id': '39', 'type': 'subscript', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'num_samples'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'num_samples'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '60', 'type': 'else_clause', 'children': ['61']}, {'id': '61', 'type': 'block', 'children': ['62', '70']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '65', 'type': 'parenthesized_expression', 'children': ['66'], 'value': '()'}; {'id': '66', 'type': 'concatenated_string', 'children': ['67', '68', '69']}, {'id': '67', 'type': 'string', 'children': [], 'value': '"mismatched shape. The samples to append should either be "'}; {'id': '68', 'type': 'string', 'children': [], 'value': '"a single sample or should match the length of the sample "'}, {'id': '69', 'type': 'string', 'children': [], 'value': '"set. Empty sample sets cannot be appended to."'}; {'id': '70', 'type': 'raise_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'variables'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '91']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '84', 'type': 'generator_expression', 'children': ['85', '88']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'in'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '91', 'type': 'block', 'children': ['92', '96']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '95', 'type': 'string', 'children': [], 'value': '"Appended samples cannot contain variables in sample set"'}; {'id': '96', 'type': 'raise_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'new_variables'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '109'], 'value': '+'}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'variables'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'new_samples'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'hstack'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'tuple', 'children': ['119', '124']}, {'id': '119', 'type': 'attribute', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'samples'}, {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '133']}, {'id': '127', 'type': 'attribute', 'children': ['128', '132']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'from_samples'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '137', '140', '150', '153']}; {'id': '134', 'type': 'tuple', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'new_samples'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'new_variables'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'sort_labels'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'sort_labels'}, {'id': '153', 'type': 'dictionary_splat', 'children': ['154']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}
def append_variables(self, samples_like, sort_labels=True): samples, labels = as_samples(samples_like) num_samples = len(self) if samples.shape[0] == num_samples: pass elif samples.shape[0] == 1 and num_samples: samples = np.repeat(samples, num_samples, axis=0) else: msg = ("mismatched shape. The samples to append should either be " "a single sample or should match the length of the sample " "set. Empty sample sets cannot be appended to.") raise ValueError(msg) variables = self.variables if any(v in variables for v in labels): msg = "Appended samples cannot contain variables in sample set" raise ValueError(msg) new_variables = list(variables) + labels new_samples = np.hstack((self.record.sample, samples)) return type(self).from_samples((new_samples, new_variables), self.vartype, info=copy.deepcopy(self.info), sort_labels=sort_labels, **self.data_vectors)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'slice'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'slice_args'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '20', '41', '61', '99']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted_by'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'sorted_by'"}, {'id': '19', 'type': 'string', 'children': [], 'value': "'energy'"}; {'id': '20', 'type': 'if_statement', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'raise_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'concatenated_string', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'slice got an unexpected '"}, {'id': '31', 'type': 'string', 'children': [], 'value': "'keyword argument {!r}'"}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'subscript', 'children': ['35', '40']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'popitem'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '43', '52']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'slice_args'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'selector'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'slice'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'list_splat', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'slice_args'}; {'id': '52', 'type': 'else_clause', 'children': ['53']}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'selector'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'slice'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'None', 'children': []}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65', '74']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted_by'}; {'id': '64', 'type': 'None', 'children': []}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '69', 'type': 'subscript', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'selector'}; {'id': '74', 'type': 'else_clause', 'children': ['75']}, {'id': '75', 'type': 'block', 'children': ['76', '89']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sort_indices'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sorted_by'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort_indices'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'selector'}, {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '105']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107', '110', '118']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}
def slice(self, *slice_args, **kwargs): sorted_by = kwargs.pop('sorted_by', 'energy') if kwargs: raise TypeError('slice got an unexpected ' 'keyword argument {!r}'.format(kwargs.popitem()[0])) if slice_args: selector = slice(*slice_args) else: selector = slice(None) if sorted_by is None: record = self.record[selector] else: sort_indices = np.argsort(self.record[sorted_by]) record = self.record[sort_indices[selector]] return type(self)(record, self.variables, copy.deepcopy(self.info), self.vartype)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'describe_features'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'traj'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '58']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'n_f'}; {'id': '10', 'type': 'subscript', 'children': ['11', '19']}, {'id': '11', 'type': 'attribute', 'children': ['12', '18']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'partial_transform'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'traj'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'zippy'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '33', '40', '47']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"N/A"'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'n_f'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'repeat'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"N/A"'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'n_f'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"N/A"'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'n_f'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'repeat'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '57']}; {'id': '52', 'type': 'tuple', 'children': ['53', '54', '55', '56']}, {'id': '53', 'type': 'string', 'children': [], 'value': '"N/A"'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"N/A"'}, {'id': '55', 'type': 'string', 'children': [], 'value': '"N/A"'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"N/A"'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'n_f'}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dict_maker'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}
def describe_features(self, traj): n_f = self.partial_transform(traj).shape[1] zippy=zip(itertools.repeat("N/A", n_f), itertools.repeat("N/A", n_f), itertools.repeat("N/A", n_f), itertools.repeat(("N/A","N/A","N/A","N/A"), n_f)) return dict_maker(zippy)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_mapped_populations'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'mdl1'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'mdl2'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '64']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'return_vect'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'mdl1'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'n_states_'}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '26']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'mdl1'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'n_states_'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'try_statement', 'children': ['28', '61']}; {'id': '28', 'type': 'block', 'children': ['29', '43', '51']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'mdl1_unmapped'}; {'id': '32', 'type': 'subscript', 'children': ['33', '42']}, {'id': '33', 'type': 'subscript', 'children': ['34', '41']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'mdl1'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'inverse_transform'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'list', 'children': ['40'], 'value': '[i]'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'mdl2_mapped'}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'mdl2'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'mapping_'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'mdl1_unmapped'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '56']}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'return_vect'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'mdl2'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'populations_'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'mdl2_mapped'}, {'id': '61', 'type': 'except_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'pass_statement', 'children': []}; {'id': '64', 'type': 'return_statement', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'return_vect'}
def _mapped_populations(mdl1, mdl2): return_vect = np.zeros(mdl1.n_states_) for i in range(mdl1.n_states_): try: mdl1_unmapped = mdl1.inverse_transform([i])[0][0] mdl2_mapped = mdl2.mapping_[mdl1_unmapped] return_vect[i] = mdl2.populations_[mdl2_mapped] except: pass return return_vect
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'distance_upper_bound'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '17', 'type': 'block', 'children': ['18', '34']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'pattern_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cdists'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'cinds'}, {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_kdtree'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32', '33']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'distance_upper_bound'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'expression_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'cdists'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_split_indices'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}
def query(self, x, k=1, p=2, distance_upper_bound=np.inf): cdists, cinds = self._kdtree.query(x, k, p, distance_upper_bound) return cdists, self._split_indices(cinds)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_fn_list'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fn_list'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '30']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'dt_list'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'get_dt_list'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'fn_list'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'fn_list_sort'}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '18', 'type': 'for_in_clause', 'children': ['19', '22']}, {'id': '19', 'type': 'tuple_pattern', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dt'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dt_list'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'fn_list'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'fn_list_sort'}
def sort_fn_list(fn_list): dt_list = get_dt_list(fn_list) fn_list_sort = [fn for (dt,fn) in sorted(zip(dt_list,fn_list))] return fn_list_sort
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '5', 'type': 'block', 'children': ['6', '19']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ips'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '11', 'type': 'generator_expression', 'children': ['12', '16']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'normalize_ip'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ip'}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ip'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'list_comprehension', 'children': ['21', '25']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'clean_ip'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ip'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ips'}
def sort(iterable): ips = sorted(normalize_ip(ip) for ip in iterable) return [clean_ip(ip) for ip in ips]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'glob'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '25']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'file_glob'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'BASE_NAME'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20', '23', '24']}, {'id': '19', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '23', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '24', 'type': 'string', 'children': [], 'value': "'.*'"}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'file_glob'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'lambda', 'children': ['33', '35']}, {'id': '33', 'type': 'lambda_parameters', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'splitext'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}
def glob(self): file_glob = glob.glob(BASE_NAME.format('*', self.num, '*', '.*')) return sorted(file_glob, key=lambda f: os.path.splitext(f))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'event'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'interface_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'address'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'value_key'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '9', 'type': 'block', 'children': ['10', '30', '57', '84']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'LOG'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '%'}, {'id': '17', 'type': 'string', 'children': [], 'value': '"RPCFunctions.event: interface_id = %s, address = %s, value_key = %s, value = %s"'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20', '21', '26']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'interface_id'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'address'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'value_key'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '49']}; {'id': '32', 'type': 'attribute', 'children': ['33', '48']}, {'id': '33', 'type': 'subscript', 'children': ['34', '47']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'devices_all'}; {'id': '38', 'type': 'subscript', 'children': ['39', '45']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'interface_id'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '45', 'type': 'unary_operator', 'children': ['46'], 'value': '-'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '56']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'interface_id'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'value_key'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'eventcallback'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'eventcallback'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '71', '74', '81']}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'interface_id'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'interface_id'}, {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'address'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value_key'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'value_key'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'True', 'children': []}
def event(self, interface_id, address, value_key, value): LOG.debug("RPCFunctions.event: interface_id = %s, address = %s, value_key = %s, value = %s" % ( interface_id, address, value_key.upper(), str(value))) self.devices_all[interface_id.split( '-')[-1]][address].event(interface_id, value_key.upper(), value) if self.eventcallback: self.eventcallback(interface_id=interface_id, address=address, value_key=value_key.upper(), value=value) return True
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_isolated_cpus'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '12', '19', '27', '37', '67']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sysfs_path'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'devices/system/cpu/isolated'"}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'isolated'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'read_first_line'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'isolated'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'parse_cpu_list'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'isolated'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cmdline'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'read_first_line'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'proc_path'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'cmdline'"}, {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cmdline'}, {'id': '39', 'type': 'block', 'children': ['40', '50']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "r'\\bisolcpus=([^ ]+)'"}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cmdline'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '52', 'type': 'block', 'children': ['53', '62']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'parse_cpu_list'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'isolated'}, {'id': '67', 'type': 'return_statement', 'children': ['68']}
def get_isolated_cpus(): path = sysfs_path('devices/system/cpu/isolated') isolated = read_first_line(path) if isolated: return parse_cpu_list(isolated) cmdline = read_first_line(proc_path('cmdline')) if cmdline: match = re.search(r'\bisolcpus=([^ ]+)', cmdline) if match: isolated = match.group(1) return parse_cpu_list(isolated) return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'framesToFrameRange'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'frames'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'zfill'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'compress'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '28', '35', '41', '57', '66']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'compress'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'frames'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'unique'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '27']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'frames'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'frames'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '38']}; {'id': '36', 'type': 'not_operator', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': "''"}, {'id': '41', 'type': 'if_statement', 'children': ['42', '48']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '47'], 'value': '=='}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'frames'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pad'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56']}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'frames'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'zfill'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'string', 'children': [], 'value': "','"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'FrameSet'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'framesToFrameRanges'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'frames'}
def framesToFrameRange(frames, sort=True, zfill=0, compress=False): if compress: frames = unique(set(), frames) frames = list(frames) if not frames: return '' if len(frames) == 1: return pad(frames[0], zfill) if sort: frames.sort() return ','.join(FrameSet.framesToFrameRanges(frames, zfill))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_normalize_request_parameters'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'oauth_params'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '14', '24', '34', '44', '66', '95', '99', '138', '163', '169']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''\n This process normalizes the request parameters as detailed in the OAuth\n 1.0 spec.\n Additionally we apply a `Content-Type` header to the request of the\n `FORM_URLENCODE` type if the `Content-Type` was previously set, i.e. if\n this is a `POST` or `PUT` request. This ensures the correct header is\n set as per spec.\n Finally we sort the parameters in preparation for signing and return\n a URL encoded string of all normalized parameters.\n :param oauth_params: OAuth params to sign with.\n :type oauth_params: dict\n :param req_kwargs: Request kwargs to normalize.\n :type req_kwargs: dict\n '''"}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'normalized'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'params'"}, {'id': '23', 'type': 'dictionary', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'data'"}, {'id': '33', 'type': 'dictionary', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'headers'"}, {'id': '43', 'type': 'dictionary', 'children': []}; {'id': '44', 'type': 'for_statement', 'children': ['45', '48', '53']}, {'id': '45', 'type': 'pattern_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'augmented_assignment', 'children': ['61', '62'], 'value': '+='}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'normalized'}; {'id': '62', 'type': 'list', 'children': ['63'], 'value': '[(k, v)]'}, {'id': '63', 'type': 'tuple', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '77']}, {'id': '67', 'type': 'boolean_operator', 'children': ['68', '71', '72'], 'value': 'and'}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'Content-Type'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '71', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '76'], 'value': '=='}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'Content-Type'"}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'FORM_URLENCODED'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'for_statement', 'children': ['79', '82', '87']}, {'id': '79', 'type': 'pattern_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '+='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'normalized'}, {'id': '91', 'type': 'list', 'children': ['92'], 'value': '[(k, v)]'}; {'id': '92', 'type': 'tuple', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'all_normalized'}; {'id': '98', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '99', 'type': 'for_statement', 'children': ['100', '101', '102']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'normalized'}; {'id': '102', 'type': 'block', 'children': ['103', '109', '131']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'pattern_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '121']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '115'], 'value': 'and'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'is_basestring'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '115', 'type': 'not_operator', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'bytes'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'augmented_assignment', 'children': ['133', '134'], 'value': '+='}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'all_normalized'}; {'id': '134', 'type': 'list', 'children': ['135'], 'value': '[(k, v)]'}, {'id': '135', 'type': 'tuple', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '138', 'type': 'for_statement', 'children': ['139', '142', '147']}, {'id': '139', 'type': 'pattern_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'oauth_params'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '146', 'type': 'argument_list', 'children': []}, {'id': '147', 'type': 'block', 'children': ['148', '156']}; {'id': '148', 'type': 'if_statement', 'children': ['149', '154']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': 'in'}; {'id': '150', 'type': 'tuple', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'all_normalized'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'continue_statement', 'children': []}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'augmented_assignment', 'children': ['158', '159'], 'value': '+='}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'all_normalized'}, {'id': '159', 'type': 'list', 'children': ['160'], 'value': '[(k, v)]'}; {'id': '160', 'type': 'tuple', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'all_normalized'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'id': '169', 'type': 'return_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '186']}, {'id': '171', 'type': 'attribute', 'children': ['172', '184', '185']}; {'id': '172', 'type': 'call', 'children': ['173', '181']}, {'id': '173', 'type': 'attribute', 'children': ['174', '179', '180']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'urlencode'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'all_normalized'}; {'id': '178', 'type': 'True', 'children': []}, {'id': '179', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': "'+'"}, {'id': '183', 'type': 'string', 'children': [], 'value': "'%20'"}; {'id': '184', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188']}, {'id': '187', 'type': 'string', 'children': [], 'value': "'%7E'"}
def _normalize_request_parameters(self, oauth_params, req_kwargs): ''' This process normalizes the request parameters as detailed in the OAuth 1.0 spec. Additionally we apply a `Content-Type` header to the request of the `FORM_URLENCODE` type if the `Content-Type` was previously set, i.e. if this is a `POST` or `PUT` request. This ensures the correct header is set as per spec. Finally we sort the parameters in preparation for signing and return a URL encoded string of all normalized parameters. :param oauth_params: OAuth params to sign with. :type oauth_params: dict :param req_kwargs: Request kwargs to normalize. :type req_kwargs: dict ''' normalized = [] params = req_kwargs.get('params', {}) data = req_kwargs.get('data', {}) headers = req_kwargs.get('headers', {}) for k, v in params.items(): if v is not None: normalized += [(k, v)] if 'Content-Type' in headers and \ headers['Content-Type'] == FORM_URLENCODED: for k, v in data.items(): normalized += [(k, v)] all_normalized = [] for t in normalized: k, v = t if is_basestring(v) and not isinstance(v, bytes): v = v.encode('utf-8') all_normalized += [(k, v)] for k, v in oauth_params.items(): if (k, v) in all_normalized: continue all_normalized += [(k, v)] all_normalized.sort() return urlencode(all_normalized, True)\ .replace('+', '%20')\ .replace('%7E', '~')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_summary'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'block', 'children': ['7', '33', '49', '130', '148']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'show_output'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14', '20', '26', '32']}, {'id': '13', 'type': 'string', 'children': [], 'value': '"%s%s%s%s"'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"Created"'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ljust'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"Last modified"'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ljust'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': '"Owner"'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ljust'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'integer', 'children': [], 'value': '23'}; {'id': '32', 'type': 'string', 'children': [], 'value': '"Name"'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_zk'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'stat_map'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '55', '67', '97']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '54'], 'value': '=='}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '61']}; {'id': '58', 'type': 'pattern_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '61', 'type': 'expression_list', 'children': ['62', '63']}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '67', 'type': 'elif_clause', 'children': ['68', '73']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': '>'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '79']}; {'id': '76', 'type': 'pattern_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '79', 'type': 'expression_list', 'children': ['80', '81']}; {'id': '80', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '81', 'type': 'conditional_expression', 'children': ['82', '85', '93'], 'value': 'if'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': '<'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '97', 'type': 'else_clause', 'children': ['98']}; {'id': '98', 'type': 'block', 'children': ['99', '123']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '102', 'type': 'conditional_expression', 'children': ['103', '111', '122'], 'value': 'if'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '108'], 'value': '+'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '118'], 'value': '<'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'offs'}, {'id': '133', 'type': 'conditional_expression', 'children': ['134', '135', '140'], 'value': 'if'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': '=='}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '139', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '147'], 'value': '+'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '148', 'type': 'for_statement', 'children': ['149', '150', '155']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '155', 'type': 'block', 'children': ['156', '164']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'pattern_list', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'stat'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'show_output'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '184', '197', '208']}; {'id': '170', 'type': 'string', 'children': [], 'value': '"%s%s%s%s"'}, {'id': '171', 'type': 'call', 'children': ['172', '182']}; {'id': '172', 'type': 'attribute', 'children': ['173', '181']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'ctime'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'created'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ljust'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '184', 'type': 'call', 'children': ['185', '195']}, {'id': '185', 'type': 'attribute', 'children': ['186', '194']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ctime'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'stat'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'last_modified'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'ljust'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'integer', 'children': [], 'value': '32'}, {'id': '197', 'type': 'call', 'children': ['198', '206']}; {'id': '198', 'type': 'attribute', 'children': ['199', '205']}, {'id': '199', 'type': 'parenthesized_expression', 'children': ['200'], 'value': '()'}; {'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '%'}, {'id': '201', 'type': 'string', 'children': [], 'value': '"0x%x"'}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ephemeralOwner'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'ljust'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'integer', 'children': [], 'value': '23'}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '210', 'type': 'slice', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'offs'}
def do_summary(self, params): self.show_output("%s%s%s%s", "Created".ljust(32), "Last modified".ljust(32), "Owner".ljust(23), "Name") results = sorted(self._zk.stat_map(params.path)) if params.top == 0: start, end = 0, len(results) elif params.top > 0: start, end = 0, params.top if params.top < len(results) else len(results) else: start = len(results) + params.top if abs(params.top) < len(results) else 0 end = len(results) offs = 1 if params.path == "/" else len(params.path) + 1 for i in range(start, end): path, stat = results[i] self.show_output( "%s%s%s%s", time.ctime(stat.created).ljust(32), time.ctime(stat.last_modified).ljust(32), ("0x%x" % stat.ephemeralOwner).ljust(23), path[offs:] )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_json_count_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'block', 'children': ['7', '37', '49', '56', '130', '154', '170', '251', '272', '297']}, {'id': '7', 'type': 'try_statement', 'children': ['8', '18']}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Keys'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '18', 'type': 'except_clause', 'children': ['19', '25']}, {'id': '19', 'type': 'as_pattern', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Keys'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Bad'}, {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '25', 'type': 'block', 'children': ['26', '36']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'show_output'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '36', 'type': 'return_statement', 'children': []}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path_map'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'PathMap'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_zk'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '56', 'type': 'for_statement', 'children': ['57', '60', '65']}, {'id': '57', 'type': 'pattern_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'path_map'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'try_statement', 'children': ['67', '89', '108']}, {'id': '67', 'type': 'block', 'children': ['68', '83']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'Keys'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '80']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'json_deserialize'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'augmented_assignment', 'children': ['85', '88'], 'value': '+='}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '89', 'type': 'except_clause', 'children': ['90', '94']}; {'id': '90', 'type': 'as_pattern', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'BadJSON'}; {'id': '92', 'type': 'as_pattern_target', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'if_statement', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'report_errors'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'show_output'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': '"Path %s has bad JSON."'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '108', 'type': 'except_clause', 'children': ['109', '115']}, {'id': '109', 'type': 'as_pattern', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'Keys'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'Missing'}, {'id': '113', 'type': 'as_pattern_target', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'report_errors'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'show_output'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129']}, {'id': '127', 'type': 'string', 'children': [], 'value': '"Path %s is missing key %s."'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '141', '149']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '140', 'type': 'argument_list', 'children': []}, {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '143', 'type': 'lambda', 'children': ['144', '146']}; {'id': '144', 'type': 'lambda_parameters', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '157', 'type': 'list_comprehension', 'children': ['158', '159', '162']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '159', 'type': 'for_in_clause', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '162', 'type': 'if_clause', 'children': ['163']}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '167'], 'value': '>='}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'minfreq'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '176', '188', '218']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': '=='}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '175', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '182']}, {'id': '179', 'type': 'pattern_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '182', 'type': 'expression_list', 'children': ['183', '184']}, {'id': '183', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '188', 'type': 'elif_clause', 'children': ['189', '194']}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '193'], 'value': '>'}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '193', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}, {'id': '197', 'type': 'pattern_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '200', 'type': 'expression_list', 'children': ['201', '202']}, {'id': '201', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '202', 'type': 'conditional_expression', 'children': ['203', '206', '214'], 'value': 'if'}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '206', 'type': 'comparison_operator', 'children': ['207', '210'], 'value': '<'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '218', 'type': 'else_clause', 'children': ['219']}, {'id': '219', 'type': 'block', 'children': ['220', '244']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '223', 'type': 'conditional_expression', 'children': ['224', '232', '243'], 'value': 'if'}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '229'], 'value': '+'}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '239'], 'value': '<'}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'top'}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '243', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '251', 'type': 'if_statement', 'children': ['252', '262']}; {'id': '252', 'type': 'boolean_operator', 'children': ['253', '259'], 'value': 'and'}, {'id': '253', 'type': 'comparison_operator', 'children': ['254', '258'], 'value': '>'}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'print_path'}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'show_output'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '272', 'type': 'for_statement', 'children': ['273', '274', '279']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '274', 'type': 'call', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '279', 'type': 'block', 'children': ['280', '288']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '285']}; {'id': '282', 'type': 'pattern_list', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'frequency'}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'show_output'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '295', '296']}; {'id': '294', 'type': 'string', 'children': [], 'value': '"%s = %d"'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'frequency'}, {'id': '297', 'type': 'if_statement', 'children': ['298', '304']}; {'id': '298', 'type': 'comparison_operator', 'children': ['299', '303'], 'value': '=='}, {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '303', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '304', 'type': 'block', 'children': ['305']}, {'id': '305', 'type': 'return_statement', 'children': ['306']}
def do_json_count_values(self, params): try: Keys.validate(params.keys) except Keys.Bad as ex: self.show_output(str(ex)) return path_map = PathMap(self._zk, params.path) values = defaultdict(int) for path, data in path_map.get(): try: value = Keys.value(json_deserialize(data), params.keys) values[value] += 1 except BadJSON as ex: if params.report_errors: self.show_output("Path %s has bad JSON.", path) except Keys.Missing as ex: if params.report_errors: self.show_output("Path %s is missing key %s.", path, ex) results = sorted(values.items(), key=lambda item: item[1], reverse=params.reverse) results = [r for r in results if r[1] >= params.minfreq] if params.top == 0: start, end = 0, len(results) elif params.top > 0: start, end = 0, params.top if params.top < len(results) else len(results) else: start = len(results) + params.top if abs(params.top) < len(results) else 0 end = len(results) if len(results) > 0 and params.print_path: self.show_output(params.path) for i in range(start, end): value, frequency = results[i] self.show_output("%s = %d", value, frequency) if len(results) == 0: return False
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_json_dupes_for_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'block', 'children': ['7', '37', '49', '60', '160', '164', '233', '244']}, {'id': '7', 'type': 'try_statement', 'children': ['8', '18']}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Keys'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '18', 'type': 'except_clause', 'children': ['19', '25']}, {'id': '19', 'type': 'as_pattern', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Keys'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Bad'}, {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '25', 'type': 'block', 'children': ['26', '36']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'show_output'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '36', 'type': 'return_statement', 'children': []}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path_map'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'PathMap'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_zk'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dupes_by_path'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'lambda', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '60', 'type': 'for_statement', 'children': ['61', '64', '69']}, {'id': '61', 'type': 'pattern_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'path_map'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '68', 'type': 'argument_list', 'children': []}, {'id': '69', 'type': 'block', 'children': ['70', '79', '91']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '75']}; {'id': '72', 'type': 'pattern_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '89']}; {'id': '80', 'type': 'not_operator', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'continue_statement', 'children': []}, {'id': '91', 'type': 'try_statement', 'children': ['92', '119', '138']}; {'id': '92', 'type': 'block', 'children': ['93', '108']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'Keys'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '105']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'json_deserialize'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '117']}; {'id': '110', 'type': 'attribute', 'children': ['111', '116']}, {'id': '111', 'type': 'subscript', 'children': ['112', '115']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'dupes_by_path'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '119', 'type': 'except_clause', 'children': ['120', '124']}; {'id': '120', 'type': 'as_pattern', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'BadJSON'}; {'id': '122', 'type': 'as_pattern_target', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'if_statement', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'report_errors'}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'show_output'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'string', 'children': [], 'value': '"Path %s has bad JSON."'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '138', 'type': 'except_clause', 'children': ['139', '145']}, {'id': '139', 'type': 'as_pattern', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'Keys'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'Missing'}, {'id': '143', 'type': 'as_pattern_target', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ex'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'report_errors'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'show_output'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159']}, {'id': '157', 'type': 'string', 'children': [], 'value': '"Path %s is missing key %s."'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'dupes'}, {'id': '163', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '164', 'type': 'for_statement', 'children': ['165', '168', '173']}, {'id': '165', 'type': 'pattern_list', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'paths_by_value'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'dupes_by_path'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '172', 'type': 'argument_list', 'children': []}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'for_statement', 'children': ['175', '178', '183']}, {'id': '175', 'type': 'pattern_list', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'paths_by_value'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '182', 'type': 'argument_list', 'children': []}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'if_statement', 'children': ['185', '191']}, {'id': '185', 'type': 'comparison_operator', 'children': ['186', '190'], 'value': '>'}; {'id': '186', 'type': 'call', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '191', 'type': 'block', 'children': ['192', '198', '211']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '197', 'type': 'argument_list', 'children': []}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'paths'}, {'id': '201', 'type': 'conditional_expression', 'children': ['202', '203', '206'], 'value': 'if'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'paths'}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '206', 'type': 'subscript', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '208', 'type': 'slice', 'children': ['209', '210']}, {'id': '209', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '210', 'type': 'colon', 'children': []}, {'id': '211', 'type': 'for_statement', 'children': ['212', '213', '214']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '214', 'type': 'block', 'children': ['215', '225']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'bisect'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'bisect'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'dupes'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'dupes'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '233', 'type': 'for_statement', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'dup'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'dupes'}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'show_output'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'dup'}; {'id': '244', 'type': 'if_statement', 'children': ['245', '251']}, {'id': '245', 'type': 'comparison_operator', 'children': ['246', '250'], 'value': '=='}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'dupes'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'return_statement', 'children': ['253']}, {'id': '253', 'type': 'False', 'children': []}
def do_json_dupes_for_keys(self, params): try: Keys.validate(params.keys) except Keys.Bad as ex: self.show_output(str(ex)) return path_map = PathMap(self._zk, params.path) dupes_by_path = defaultdict(lambda: defaultdict(list)) for path, data in path_map.get(): parent, child = split(path) if not child.startswith(params.prefix): continue try: value = Keys.value(json_deserialize(data), params.keys) dupes_by_path[parent][value].append(path) except BadJSON as ex: if params.report_errors: self.show_output("Path %s has bad JSON.", path) except Keys.Missing as ex: if params.report_errors: self.show_output("Path %s is missing key %s.", path, ex) dupes = [] for _, paths_by_value in dupes_by_path.items(): for _, paths in paths_by_value.items(): if len(paths) > 1: paths.sort() paths = paths if params.first else paths[1:] for path in paths: idx = bisect.bisect(dupes, path) dupes.insert(idx, path) for dup in dupes: self.show_output(dup) if len(dupes) == 0: return False
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_property_orders'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'query_proto'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'orders'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'for_statement', 'children': ['9', '10', '11']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'orders'}, {'id': '11', 'type': 'block', 'children': ['12', '22', '59']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'proto'}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'query_proto'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'if_statement', 'children': ['23', '28', '47']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '=='}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '28', 'type': 'block', 'children': ['29', '37']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '34', 'type': 'slice', 'children': ['35', '36']}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'colon', 'children': []}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'proto'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'query_pb2'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'PropertyOrder'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'}, {'id': '47', 'type': 'else_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'proto'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '54', 'type': 'attribute', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'query_pb2'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'PropertyOrder'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'proto'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'property'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'name'}
def add_property_orders(query_proto, *orders): for order in orders: proto = query_proto.order.add() if order[0] == '-': order = order[1:] proto.direction = query_pb2.PropertyOrder.DESCENDING else: proto.direction = query_pb2.PropertyOrder.ASCENDING proto.property.name = order
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_levels'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'imls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'imt'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'min_iml'}; {'id': '8', 'type': 'float', 'children': [], 'value': '1E-10'}, {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17', '27', '44', '67', '92']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '16'], 'value': '<'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'imls'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '%'}, {'id': '23', 'type': 'string', 'children': [], 'value': "'No imls for %s: %s'"}; {'id': '24', 'type': 'tuple', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'imt'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'imls'}, {'id': '27', 'type': 'elif_clause', 'children': ['28', '34']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '!='}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'imls'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'imls'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '%'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'The imls for %s are not sorted: %s'"}, {'id': '41', 'type': 'tuple', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'imt'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'imls'}; {'id': '44', 'type': 'elif_clause', 'children': ['45', '57']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '53'], 'value': '<'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'distinct'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'imls'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'imls'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'raise_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '%'}, {'id': '63', 'type': 'string', 'children': [], 'value': '"Found duplicated levels for %s: %s"'}; {'id': '64', 'type': 'tuple', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'imt'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'imls'}, {'id': '67', 'type': 'elif_clause', 'children': ['68', '79']}; {'id': '68', 'type': 'boolean_operator', 'children': ['69', '74'], 'value': 'and'}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '=='}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'imls'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '<='}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'imls'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'min_iml'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'raise_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '88'], 'value': '%'}, {'id': '85', 'type': 'concatenated_string', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': '"The min_iml %s=%s is larger than the second level "'}, {'id': '87', 'type': 'string', 'children': [], 'value': '"for %s"'}; {'id': '88', 'type': 'tuple', 'children': ['89', '90', '91']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'imt'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'min_iml'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'imls'}; {'id': '92', 'type': 'elif_clause', 'children': ['93', '104']}, {'id': '93', 'type': 'boolean_operator', 'children': ['94', '99'], 'value': 'and'}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': '=='}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'imls'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '>'}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'imls'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'min_iml'}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '110']}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'imls'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '0'}
def check_levels(imls, imt, min_iml=1E-10): if len(imls) < 1: raise ValueError('No imls for %s: %s' % (imt, imls)) elif imls != sorted(imls): raise ValueError('The imls for %s are not sorted: %s' % (imt, imls)) elif len(distinct(imls)) < len(imls): raise ValueError("Found duplicated levels for %s: %s" % (imt, imls)) elif imls[0] == 0 and imls[1] <= min_iml: raise ValueError("The min_iml %s=%s is larger than the second level " "for %s" % (imt, min_iml, imls)) elif imls[0] == 0 and imls[1] > min_iml: imls[0] = min_iml