Пример #1
0
 def test_select_odd_shaped_non_broadcastable(self, dtype):
     a = cupy.arange(10, dtype=dtype)
     b = cupy.arange(20, dtype=dtype)
     condlist = [a < 3, b > 8]
     choicelist = [a, b]
     with pytest.raises(ValueError):
         cupy.select(condlist, choicelist)
Пример #2
0
 def test_select_default_scalar(self, dtype):
     a = cupy.arange(10)
     b = cupy.arange(20)
     condlist = [a < 3, b > 8]
     choicelist = [a, b]
     with pytest.raises(TypeError):
         cupy.select(condlist, choicelist, [dtype(2)])
Пример #3
0
def select(condlist, choicelist, default=0):
    raw_array = _cp.select(list(condlist), list(choicelist), default=default)
    return array(list(raw_array.ravel())).reshape(raw_array.shape)
Пример #4
0
 def test_select_type_error_choicelist(self, dtype):
     a, b = list(range(10)), list(range(-10, 0))
     condlist = [0] * 10
     choicelist = [a, b]
     with pytest.raises(ValueError):
         cupy.select(condlist, choicelist)
Пример #5
0
 def test_select_empty_lists(self):
     condlist = []
     choicelist = []
     with pytest.raises(ValueError):
         cupy.select(condlist, choicelist)
Пример #6
0
 def test_select_length_error(self, dtype):
     a = cupy.arange(10, dtype=dtype)
     condlist = [a > 3]
     choicelist = [a, a**2]
     with pytest.raises(ValueError):
         cupy.select(condlist, choicelist)
Пример #7
0
 def test_select_type_error_condlist(self, dtype):
     a = cupy.arange(10, dtype=dtype)
     condlist = [[3] * 10, [2] * 10]
     choicelist = [a, a**2]
     with pytest.raises(AttributeError):
         cupy.select(condlist, choicelist)
Пример #8
0
 def test_select_choicelist_condlist_broadcast(self, xp, dtype):
     a = cupy.arange(10, dtype=dtype)
     b = cupy.arange(20, dtype=dtype).reshape(2, 10)
     condlist = [a < 4, b > 8]
     choicelist = [cupy.repeat(a, 2).reshape(2, 10), b]
     return cupy.select(condlist, choicelist)
Пример #9
0
 def test_select_1D_choicelist(self, xp, dtype):
     a = cupy.array(1)
     b = cupy.array(3)
     condlist = [a < 3, b > 8]
     choicelist = [a, b]
     return cupy.select(condlist, choicelist)
Пример #10
0
 def test_select_odd_shaped_broadcastable_complex(self, xp, dtype):
     a = cupy.arange(10, dtype=dtype)
     b = cupy.arange(20, dtype=dtype).reshape(2, 10)
     condlist = [a < 3, b > 8]
     choicelist = [a, b**2]
     return cupy.select(condlist, choicelist)
Пример #11
0
 def time_select_larger(self):
     np.select(self.cond_large, ([self.d, self.e] * 10))
Пример #12
0
 def time_select(self):
     np.select(self.cond, [self.d, self.e])