pythran

Regular expression to find function definitions in Python file

坚强是说给别人听的谎言 提交于 2020-01-06 07:07:58
问题 I have a python project with function definitions written in CamelCase style. I'm trying to write a script to convert them to snake_case style. CaseFormatter class import re class CaseFormatter: def __init__(self, file_directory): self.first_cap_re = re.compile('(.)([A-Z][a-z]+)') self.all_cap_re = re.compile('([a-z0-9])([A-Z])') self.functions_dict = {} self.file_directory = file_directory self.file = open(file_directory, "r", encoding="UTF-8") self.file_content = self.file.read() self.names

Most efficient way to sort an array into bins specified by an index array?

那年仲夏 提交于 2019-11-26 23:08:45
The task by example: data = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) idx = np.array([2, 0, 1, 1, 2, 0, 1, 1, 2]) Expected result: binned = np.array([2, 6, 3, 4, 7, 8, 1, 5, 9]) Constraints: Should be fast. Should be O(n+k) where n is the length of data and k is the number of bins. Should be stable, i.e. order within bins is preserved. Obvious solution data[np.argsort(idx, kind='stable')] is O(n log n) . O(n+k) solution def sort_to_bins(idx, data, mx=-1): if mx==-1: mx = idx.max() + 1 cnts = np.zeros(mx + 1, int) for i in range(idx.size): cnts[idx[i] + 1] += 1 for i in range(1, cnts.size): cnts[i]

Most efficient way to sort an array into bins specified by an index array?

走远了吗. 提交于 2019-11-26 06:47:44
问题 The task by example: data = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) idx = np.array([2, 0, 1, 1, 2, 0, 1, 1, 2]) Expected result: binned = np.array([2, 6, 3, 4, 7, 8, 1, 5, 9]) Constraints: Should be fast. Should be O(n+k) where n is the length of data and k is the number of bins. Should be stable, i.e. order within bins is preserved. Obvious solution data[np.argsort(idx, kind=\'stable\')] is O(n log n) . O(n+k) solution def sort_to_bins(idx, data, mx=-1): if mx==-1: mx = idx.max() + 1 cnts = np