Example #1
0
def _compile_slice(ndim, pos, view):
    slices = [_fill_the_slice(p) for p in pos]
    slices_str = f"[{', '.join(_range_or_slice_to_str(s) for s in slices)}]"
    new_index_set = [
        _range_or_slice_to_str(zn.range(s.stop - s.start)) for s in slices
    ]
    new_index_set_str = ", ".join(new_index_set)
    return f"slice_{ndim}d({view.array.name}, {slices_str}, {new_index_set_str})", new_index_set
Example #2
0
class TestCreate:
    def test_int_tuple(self):
        a = zn.Set((1, 2, 3))
        assert isinstance(a, SetPar)
        assert a.value == (1, 2, 3)

    @pytest.mark.parametrize("collection", [zn.range(1, 4), range(1, 4)])
    def test_int_range(self, collection):
        a = zn.Set(collection)
        assert isinstance(a, SetPar)
        assert a.value == collection

    def test_int_generator(self):
        a = zn.Set((a + 1 for a in range(4)))
        assert isinstance(a, SetPar)
        assert a.value == (1, 2, 3, 4)

    @pytest.mark.parametrize(
        "arg", ["aaa", zn.var(float), (a for a in "aaa"), (1.2, 2.5)])
    def test_wrong_type(self, arg):
        with pytest.raises(ValueError,
                           match="Unsupported type for set: <class"):
            zn.Set(arg)
Example #3
0
 def test_range_with_expr(self):
     v = create_var("a")
     p = create_par("b")
     assert "(a - 1)..((b + 1) - 1)" == to_str(zn.range(v - 1, p + 1))
Example #4
0
def test_simple():
    v = var(range(10, 100))
    assert v.type.start == 10
    assert v.type.stop == 100
Example #5
0
def test_with_op(par_val):
    x = par(4)
    v = var(range(x, 10))
    assert v.type.start == x
    assert v.type.stop == 10
Example #6
0
def test_float_start_and_stop():
    v = var(range(3.14, 10.5))
    assert v.type.start == pytest.approx(3.14)
    assert v.type.stop == pytest.approx(10.5)
Example #7
0
def test_float_stop():
    v = var(range(1, 10.5))
    assert v.type.start == 1
    assert v.type.stop == pytest.approx(10.5)
Example #8
0
def test_float_start():
    v = var(range(1.3, 10))
    assert v.type.start == pytest.approx(1.3)
    assert v.type.stop == 10
Example #9
0
def test_step_arg():
    with pytest.raises(ValueError,
                       match="Step values other than 1 are not supported"):
        v = var(range(10, 100, 2))
Example #10
0
def test_one_arg():
    v = var(range(100))
    assert v.type.start == 0
    assert v.type.stop == 100
Example #11
0
 def __init__(self, ):
     self.a = zn.Set(zn.var(zn.range(5)))
     self.b = zn.Set(zn.range(10))