Exemple #1
0
import ThrustRTC as trtc



identity = trtc.Identity()

darr = trtc.device_vector_from_list([True, True, False], 'bool')

print(trtc.All_Of(darr.range(0,2), identity))
print(trtc.All_Of(darr.range(0,3), identity))
print(trtc.All_Of(darr.range(0,0), identity))

print(trtc.Any_Of(darr.range(0,2), identity))
print(trtc.Any_Of(darr.range(0,3), identity))
print(trtc.Any_Of(darr.range(2,3), identity))
print(trtc.Any_Of(darr.range(0,0), identity))

print(trtc.None_Of(darr.range(0,2), identity))
print(trtc.None_Of(darr.range(0,3), identity))
print(trtc.None_Of(darr.range(2,3), identity))
print(trtc.None_Of(darr.range(0,0), identity))
Exemple #2
0
d_value = trtc.device_vector_from_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                                       'int32_t')
d_evens = trtc.device_vector('int32_t', 10)
d_odds = trtc.device_vector('int32_t', 10)
count = trtc.Partition_Copy(d_value, d_evens, d_odds, is_even)
print(d_evens.to_host(0, count))
print(d_odds.to_host(0, 10 - count))

d_value = trtc.device_vector_from_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                                       'int32_t')
d_stencil = trtc.device_vector_from_list([0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
                                         'int32_t')
d_evens = trtc.device_vector('int32_t', 10)
d_odds = trtc.device_vector('int32_t', 10)
count = trtc.Partition_Copy_Stencil(d_value, d_stencil, d_evens, d_odds,
                                    trtc.Identity())
print(d_evens.to_host(0, count))
print(d_odds.to_host(0, 10 - count))

d_value = trtc.device_vector_from_list([2, 4, 6, 8, 10, 1, 3, 5, 7, 9],
                                       'int32_t')
print(trtc.Partition_Point(d_value, is_even))

d_value = trtc.device_vector_from_list([2, 4, 6, 8, 10, 1, 3, 5, 7, 9],
                                       'int32_t')
print(trtc.Is_Partitioned(d_value, is_even))

d_value = trtc.device_vector_from_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                                       'int32_t')
print(trtc.Is_Partitioned(d_value, is_even))
                                    'int32_t')
trtc.Transform(darr, darr, trtc.Negate())
print(darr.to_host())

darr_in1 = trtc.device_vector_from_list([-5, 0, 2, 3, 2, 4], 'int32_t')
darr_in2 = trtc.device_vector_from_list([3, 6, -2, 1, 2, 3], 'int32_t')
darr_out = trtc.device_vector('int32_t', 6)
trtc.Transform_Binary(darr_in1, darr_in2, darr_out, trtc.Plus())
print(darr_out.to_host())

darr = trtc.device_vector_from_list([-5, 0, 2, -3, 2, 4, 0, -1, 2, 8],
                                    'int32_t')
trtc.Transform_If(darr, darr, trtc.Negate(), is_odd)
print(darr.to_host())

darr_data = trtc.device_vector_from_list([-5, 0, 2, -3, 2, 4, 0, -1, 2, 8],
                                         'int32_t')
darr_stencil = trtc.device_vector_from_list([1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
                                            'int32_t')
trtc.Transform_If_Stencil(darr_data, darr_stencil, darr_data, trtc.Negate(),
                          trtc.Identity())
print(darr_data.to_host())

darr_in1 = trtc.device_vector_from_list([-5, 0, 2, 3, 2, 4], 'int32_t')
darr_in2 = trtc.device_vector_from_list([3, 6, -2, 1, 2, 3], 'int32_t')
darr_stencil = trtc.device_vector_from_list([1, 0, 1, 0, 1, 0], 'int32_t')
darr_out = trtc.device_vector_from_list([-1, -1, -1, -1, -1, -1], 'int32_t')
trtc.Transform_Binary_If_Stencil(darr_in1, darr_in2, darr_stencil, darr_out,
                                 trtc.Plus(), trtc.Identity())
print(darr_out.to_host())
Exemple #4
0
print(d_value.to_host(0, count))

d_in = trtc.device_vector_from_list([-2, 0, -1, 0, 1, 2], 'int32_t')
d_out = trtc.device_vector('int32_t', 6)
count = trtc.Remove_Copy(d_in, d_out, trtc.DVInt32(0))
print(d_out.to_host(0, count))

is_even = trtc.Functor({}, ['x'], '''
         return x % 2 == 0;
''')

d_value = trtc.device_vector_from_list([1, 4, 2, 8, 5, 7], 'int32_t')
count = trtc.Remove_If(d_value, is_even)
print(d_value.to_host(0, count))

d_in = trtc.device_vector_from_list([-2, 0, -1, 0, 1, 2], 'int32_t')
d_out = trtc.device_vector('int32_t', 6)
count = trtc.Remove_Copy_If(d_in, d_out, is_even)
print(d_out.to_host(0, count))

d_value = trtc.device_vector_from_list([1, 4, 2, 8, 5, 7], 'int32_t')
d_stencil = trtc.device_vector_from_list([0, 1, 1, 1, 0, 0], 'int32_t')
count = trtc.Remove_If_Stencil(d_value, d_stencil, trtc.Identity())
print(d_value.to_host(0, count))

d_in = trtc.device_vector_from_list([-2, 0, -1, 0, 1, 2], 'int32_t')
d_stencil = trtc.device_vector_from_list([1, 1, 0, 1, 0, 1], 'int32_t')
d_out = trtc.device_vector('int32_t', 6)
count = trtc.Remove_Copy_If_Stencil(d_in, d_stencil, d_out, trtc.Identity())
print(d_out.to_host(0, count))