intersection

Why intersection of Thrust Library is returning unexpected result?

て烟熏妆下的殇ゞ 提交于 2019-12-01 10:22:29
问题 I'm using the library Thrust to get intersection set of a two larger sets of integers. In test with 2 small inputs i got correct results, but when i use two sets with 10^8 and 65535*1024 elements i got a empty set. Who's can explain this problem? Changing the two first variables to smaller values the thrust returns a expected intersection set. My code is following. #include <thrust/set_operations.h> #include <thrust/device_vector.h> #include <thrust/device_ptr.h> #include <iostream> #include

Python merge multiple list with intersection [duplicate]

孤街浪徒 提交于 2019-12-01 08:53:29
Possible Duplicate: Python: simple list merging based on intersections I have a multiple list: list=[[1,2,3],[3,5,6],[8,9,10],[11,12,13]] Is there a smart and fast way to get all the sublists with at least one intersection. In my example I want that the code return result=[[1,2,3,5,6],[8,9,10],[11,12,13]] This works, but maybe isn't very elegant: def merge_lists(l): s=map(set, l) i, n=0, len(s) while i < n-1: for j in xrange(i+1, n): if s[i].intersection(s[j]): s[i].update(s[j]) del s[j] n-=1 break else: i+=1 return [sorted(i) for i in s] Katriel Nice question! It's much simpler if you think

How to find the intersection of two NFA

删除回忆录丶 提交于 2019-12-01 07:46:13
In DFA we can do the intersection of two automata by doing the cross product of the states of the two automata and accepting those states that are accepting in both the initial automata. Union is performed similarly. How ever although i can do union in NFA easily using epsilon transition how do i do their intersection? You can use the cross-product construction on NFAs just as you would DFAs. The only changes are how you'd handle ε-transitions. Specifically, for each state (q i , r j ) in the cross-product automaton, you add an ε-transition from that state to each pair of states (q k , r j )

Python merge multiple list with intersection [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-01 06:26:52
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Python: simple list merging based on intersections I have a multiple list: list=[[1,2,3],[3,5,6],[8,9,10],[11,12,13]] Is there a smart and fast way to get all the sublists with at least one intersection. In my example I want that the code return result=[[1,2,3,5,6],[8,9,10],[11,12,13]] 回答1: This works, but maybe isn't very elegant: def merge_lists(l): s=map(set, l) i, n=0, len(s) while i < n-1: for j in xrange(i

Python list intersection efficiency: generator or filter()?

独自空忆成欢 提交于 2019-12-01 05:18:18
I would like to intersect two lists in Python (2.7). I need the result to be iterable: list1 = [1,2,3,4] list2 = [3,4,5,6] result = (3,4) # any kind of iterable Providing a full iteration will be performed first thing after the intersection, which of the following is more efficient? Using a generator: result = (x for x in list1 if x in list2) Using filter(): result = filter(lambda x: x in list2, list1) Other suggestions? Thanks in advance, Amnon Neither of these. The best way is to use sets. list1 = [1,2,3,4] list2 = [3,4,5,6] result = set(list1).intersection(list2) Sets are iterable, so no

How to find the intersection of two NFA

和自甴很熟 提交于 2019-12-01 04:26:24
问题 In DFA we can do the intersection of two automata by doing the cross product of the states of the two automata and accepting those states that are accepting in both the initial automata. Union is performed similarly. How ever although i can do union in NFA easily using epsilon transition how do i do their intersection? 回答1: You can use the cross-product construction on NFAs just as you would DFAs. The only changes are how you'd handle ε-transitions. Specifically, for each state (q i , r j )

Match all values in a nested array using elasticsearch

梦想与她 提交于 2019-12-01 02:55:57
问题 I am trying to use elasticsearch to match all values in a nested array. For eg. my search array is ["1","2","3","4","5","6","7","8","9"] and my document contains an array of arrays like "arr":[ ["1","2","10"], ["4","5"], ["8","9","11"] ] I need to match all the values inside a nested array but only one of the nested arrays needs to be a match for the document to be a match. So, in this example only the second nested array is a match because "4" and "5" are both present in the search array

Python list intersection efficiency: generator or filter()?

佐手、 提交于 2019-12-01 01:57:43
问题 I would like to intersect two lists in Python (2.7). I need the result to be iterable: list1 = [1,2,3,4] list2 = [3,4,5,6] result = (3,4) # any kind of iterable Providing a full iteration will be performed first thing after the intersection, which of the following is more efficient? Using a generator: result = (x for x in list1 if x in list2) Using filter(): result = filter(lambda x: x in list2, list1) Other suggestions? Thanks in advance, Amnon 回答1: Neither of these. The best way is to use

Ruby - array intersection (with duplicates)

倾然丶 夕夏残阳落幕 提交于 2019-12-01 01:17:30
问题 I have array(1 and 2) . How can I get array3 from them? array1 = [2,2,2,2,3,3,4,5,6,7,8,9] array2 = [2,2,2,3,4,4,4,4,8,8,0,0,0] array3 = [2,2,2,3,4,8] array1 & array2 returns [2,3,4,8] , but I need to hold onto the duplicates. 回答1: (array1 & array2).flat_map { |n| [n]*[array1.count(n), array2.count(n)].min } #=> [2,2,2,3,4,8] The steps: a = array1 & array2 #=> [2, 3, 4, 8] The first element of a ( 2 ) is passed to the block and assigned to the block variable: n = 2 and the block calculation

javascript polygon intersection

亡梦爱人 提交于 2019-11-30 23:45:52
I have used the code in the following : http://www.amphibian.com/blogstuff/collision.html . in the html test file I have changed the the first triangle to triangle1.addPoint({"x":-20, "y":-20}); triangle1.addPoint({"x":-20, "y":20}); triangle1.addPoint({"x":20, "y":20}); triangle1.addPoint({"x":20, "y":10}); triangle1.addPoint({"x":10, "y":10}); triangle1.addPoint({"x":10, "y":-20}); now when I move the other triangle with inside this shape before crossing it gives me wrongly intersection. Any idea where could be the problem? All right, I set up a fiddle for anyone else wanting to play with