2021年1月29日星期五

Vectorize itertools combination_with_replacement

My goal is to speed up the creation of a list of combinations by using my GPU. How can I accomplish this?

By way of example, the following code creates a list of 260 text strings ranging from "aa" through "jz". We then use itertools combinations_with_replacement() to create all possible combinations of R elements of this list. The use of timeit shows that, beyond 3 elements, extracting a list of these combinations slows exponentially. I suspect this can be done with numba cuda, but I don't know how.

import timeit  timeit.timeit('''    from itertools import combinations_with_replacement    combo_count = 2    alphabet = 'a'  alpha_list = []  item_list = []    for i in range(0,26):      alpha_list.append(alphabet)      alphabet = chr(ord(alphabet) + 1)    for first_letter in alpha_list[0:10]:      for second_letter in alpha_list:          item_list.append(first_letter+second_letter)    print("Length of item list:",len(item_list))        combos = combinations_with_replacement(item_list,combo_count)  cmb_lst = [bla for bla in combos]  print("Length of list of all {} combinations: {}".format(combo_count,len(cmb_lst)))                ''', number=1)  
https://stackoverflow.com/questions/65909331/vectorize-itertools-combination-with-replacement January 27, 2021 at 05:10AM

没有评论:

发表评论