def test_vec_slice_noncontig(): a_orig = numpy.ones((10, ), dtype=float) a = a_orig[::2] # whole vector multiplied (!) -> noncontiguous slice dbl_1 = te.dbl_numpy_vec(a) assert dbl_1.shape == (10, ) assert (dbl_1 == 2 * a_orig).all() # only slice multiplied dbl_2 = te.dbl_numpy_vec_keep_shape_1(a) assert dbl_2.shape == (5, ) assert (dbl_2 == 2 * a).all() # same here dbl_3 = te.dbl_numpy_vec_keep_shape_2(a) assert dbl_3.shape == (5, ) assert (dbl_3 == 2 * a).all() # when copying, take strides into account dbl_4 = te.dbl_ublas_vec(a) assert dbl_4.shape == (5, ) assert (dbl_4 == 2 * a).all() # strided vector should automatically respect strides dbl_5 = te.dbl_numpy_strided_vec(a) assert dbl_5.shape == (5, ) assert (dbl_5 == 2 * a).all() # returned strided vector should behave the same dbl_6 = te.dbl_numpy_strided_vec_ret(a) assert dbl_6.shape == (5, ) assert (dbl_6 == 2 * a).all()
def test_vec_slice_noncontig(): a_orig = numpy.ones((10,), dtype=float) a = a_orig[::2] # whole vector multiplied (!) -> noncontiguous slice dbl_1 = te.dbl_numpy_vec(a) assert dbl_1.shape == (10,) assert (dbl_1 == 2 * a_orig).all() # only slice multiplied dbl_2 = te.dbl_numpy_vec_keep_shape_1(a) assert dbl_2.shape == (5,) assert (dbl_2 == 2 * a).all() # same here dbl_3 = te.dbl_numpy_vec_keep_shape_2(a) assert dbl_3.shape == (5,) assert (dbl_3 == 2 * a).all() # when copying, take strides into account dbl_4 = te.dbl_ublas_vec(a) assert dbl_4.shape == (5,) assert (dbl_4 == 2 * a).all() # strided vector should automatically respect strides dbl_5 = te.dbl_numpy_strided_vec(a) assert dbl_5.shape == (5,) assert (dbl_5 == 2 * a).all() # returned strided vector should behave the same dbl_6 = te.dbl_numpy_strided_vec_ret(a) assert dbl_6.shape == (5,) assert (dbl_6 == 2 * a).all()
def test_0d_array(): a = numpy.ones((), dtype=float) # 0d converted to 1d, single element dbl_1 = te.dbl_numpy_vec(a) assert dbl_1.shape == (1, ) assert dbl_1[0] == 2 # everything preserved dbl_2 = te.dbl_numpy_vec_keep_shape_1(a) assert dbl_2.shape == () assert dbl_2[()] == 2 # everything preserved dbl_3 = te.dbl_numpy_vec_keep_shape_2(a) assert dbl_3.shape == () assert dbl_3[()] == 2
def test_0d_array(): a = numpy.ones((), dtype=float) # 0d converted to 1d, single element dbl_1 = te.dbl_numpy_vec(a) assert dbl_1.shape == (1,) assert dbl_1[0] == 2 # everything preserved dbl_2 = te.dbl_numpy_vec_keep_shape_1(a) assert dbl_2.shape == () assert dbl_2[()] == 2 # everything preserved dbl_3 = te.dbl_numpy_vec_keep_shape_2(a) assert dbl_3.shape == () assert dbl_3[()] == 2
def test_regular_vector(): a = numpy.ones((5, ), dtype=float) assert (te.dbl_numpy_vec(a) == 2 * a).all()
def test_regular_vector(): a = numpy.ones((5,), dtype=float) assert (te.dbl_numpy_vec(a) == 2 * a).all()