def test_assign(v): u = Vector.new_from_values([0, 2], [9, 8]) result = Vector.new_from_values([0, 1, 3, 4, 6], [9, 1, 1, 8, 0]) w = Vector.new_from_existing(v) w.assign[[0, 2, 4]] = u assert w == result w = Vector.new_from_existing(v) w.assign[:5:2] = u assert w == result
def test_assign_scalar(v): result = Vector.new_from_values([1, 3, 4, 5, 6], [9, 9, 2, 9, 0]) w = Vector.new_from_existing(v) w.assign[[1, 3, 5]] = 9 assert w == result w = Vector.new_from_existing(v) w.assign[1::2] = 9 assert w == result w = Vector.new_from_values([0, 1, 2], [1, 1, 1]) s = Scalar.new_from_value(9) w.assign[:] = s assert w == Vector.new_from_values([0, 1, 2], [9, 9, 9])
def test_binary_op(v): v2 = Vector.new_from_existing(v) v2.element[1] = 0 w = v.ewise_mult(v2, BinaryOp.GT).new() result = Vector.new_from_values([1, 3, 4, 6], [True, False, False, False]) assert w.dtype == 'BOOL' assert w == result
def test_vxm_mask(v, A): mask = Vector.new_from_values([0, 3, 4], [True, True, True], size=7) u = Vector.new_from_existing(v) u[mask] = v.vxm(A, Semiring.PLUS_TIMES) result = Vector.new_from_values([0, 1, 3, 4, 6], [3, 1, 0, 8, 0], size=7) assert u == result u = Vector.new_from_existing(v) u[~mask] = v.vxm(A, Semiring.PLUS_TIMES) result2 = Vector.new_from_values([2, 3, 4, 5, 6], [3, 1, 2, 14, 4], size=7) assert u == result2 u = Vector.new_from_existing(v) u[mask, REPLACE] = v.vxm(A, Semiring.PLUS_TIMES) result3 = Vector.new_from_values([0, 3, 4], [3, 0, 8], size=7) assert u == result3 w = v.vxm(A, Semiring.PLUS_TIMES).new(mask=mask) assert w == result3
def test_new_from_existing(v): u = Vector.new_from_existing(v) assert u is not v assert u.dtype == v.dtype assert u.nvals == v.nvals assert u.size == v.size # Ensure they are not the same backend object v.element[0] = 1000 assert u.element[0] != 1000