Beispiel #1
0
def test_typeclass_ndim_v03():
    objects = [
        C.Histogram(np.arange(6), np.arange(5)),
        C.Points(np.arange(5)),
        C.Histogram2d(np.arange(6), np.arange(7)),
        C.Points(np.arange(12).reshape(3, 4))
    ]
    outputs = [p.single() for p in objects]

    obj = C.DummyType()
    list(map(obj.add_input, outputs))

    dt = R.TypeClasses.CheckNdimT(context.current_precision())(1, (0, 1))
    R.SetOwnership(dt, False)
    dt.dump()
    print()
    obj.add_typeclass(dt)
    res = obj.process_types()
    assert res

    dt1 = R.TypeClasses.CheckNdimT(context.current_precision())(2, (-2, -1))
    R.SetOwnership(dt1, False)
    dt1.dump()
    print()
    obj.add_typeclass(dt1)
    res = obj.process_types()
    assert res
def test_typeclass_passtype():
    """Last input has another edges"""
    objects = [
            C.Histogram2d(np.arange(4), np.arange(5)),
            C.Histogram(np.arange(4)),
            C.Points(np.arange(12).reshape(3,4))
            ]
    outputs = [p.single() for p in objects]

    obj = C.DummyType()
    k = list(map(obj.add_input, outputs))
    for i in range(5):
        obj.add_output()

    dt1 = R.TypeClasses.PassTypeT(context.current_precision())((0,), (0,1))
    dt2 = R.TypeClasses.PassTypeT(context.current_precision())((1,), (2,-1))
    R.SetOwnership(dt1, False)
    R.SetOwnership(dt2, False)
    dt1.dump(); print()
    dt2.dump(); print()
    obj.add_typeclass(dt1)
    obj.add_typeclass(dt2)
    res = obj.process_types();
    assert res

    obj.print()
    dta = outputs[0].datatype()
    dtb = outputs[1].datatype()

    doutputs = obj.transformations.back().outputs
    assert doutputs[0].datatype()==dta
    assert doutputs[1].datatype()==dta
    assert doutputs[2].datatype()==dtb
    assert doutputs[3].datatype()==dtb
    assert doutputs[4].datatype()==dtb
Beispiel #3
0
def test_typeclass_kind_v01():
    objects = [
        C.Histogram(np.arange(6), np.arange(5)),
        C.Histogram2d(np.arange(6), np.arange(7))
    ]
    outputs = [p.single() for p in objects]

    obj = C.DummyType()
    list(map(obj.add_input, outputs))

    dt_points = R.TypeClasses.CheckKindT(context.current_precision())(1)
    R.SetOwnership(dt_points, False)
    dt_points.dump()
    print()

    dt_hist = R.TypeClasses.CheckKindT(context.current_precision())(2)
    R.SetOwnership(dt_hist, False)
    dt_hist.dump()
    print()

    obj.add_typeclass(dt_hist)
    res = obj.process_types()
    assert res

    obj.add_typeclass(dt_points)
    print('Exception expected: ', end='')
    res = obj.process_types()
    assert not res
def test_typeclass_passeach_02():
    """Pass with step 2"""
    objects = [
            C.Histogram2d(np.arange(4), np.arange(5)),
            C.Histogram(np.arange(4)),
            C.Points(np.arange(20).reshape(4,5))
            ]
    outputs = [p.single() for p in objects]

    obj = C.DummyType()
    i = list(map(obj.add_input, outputs))
    i1 = list(map(obj.add_input, outputs))
    for i in range(3):
        obj.add_output()

    dt1 = R.TypeClasses.PassEachTypeT(context.current_precision())((0,-1,2), (0,-1))
    R.SetOwnership(dt1, False)
    dt1.dump(); print()
    obj.add_typeclass(dt1)
    res = obj.process_types();
    assert res

    obj.print()
    dta = outputs[0].datatype()
    dtb = outputs[1].datatype()
    dtc = outputs[2].datatype()

    doutputs = obj.transformations.back().outputs
    assert doutputs[0].datatype()==dta
    assert doutputs[1].datatype()==dtc
    assert doutputs[2].datatype()==dtb
Beispiel #5
0
def test_typeclass_same_v02():
    """Last input has another shape"""
    arrays = [np.arange(12, dtype='d').reshape(3,4) for i in range(5)]
    arrays[-1]=arrays[-1].reshape(4,3)
    points = [C.Points(a) for a in arrays]
    outputs = [p.points.points for p in points]
    print(outputs)

    obj = C.DummyType()
    list(map(obj.add_input, outputs))

    dt = R.TypeClasses.CheckSameTypesT(context.current_precision())((1,-2))
    R.SetOwnership(dt, False)
    dt.dump(); print()
    obj.add_typeclass(dt)
    res = obj.process_types();
    assert res

    dt1 = R.TypeClasses.CheckSameTypesT(context.current_precision())((-2,-1))
    R.SetOwnership(dt1, False)
    dt1.dump(); print()
    obj.add_typeclass(dt1)
    print('Exception expected: ',end='')
    res = obj.process_types();
    assert not res
Beispiel #6
0
def test_typeclass_same_v01():
    """All inputs have same types"""
    arrays = [np.arange(12, dtype='d').reshape(3,4) for i in range(5)]
    points = [C.Points(a) for a in arrays]
    outputs = [p.points.points for p in points]

    obj = C.DummyType()
    list(map(obj.add_input, outputs))

    dt = R.TypeClasses.CheckSameTypesT(context.current_precision())((0,-1))
    R.SetOwnership(dt, False)
    dt.dump(); print()
    obj.add_typeclass(dt)
    res = obj.process_types();
    assert res
def test_typeclass_setpoints_v01():
    sizes = (1, 2, 3)

    for size in sizes:
        obj = C.DummyType()
        obj.add_output('out')

        dt = R.TypeClasses.SetPointsT(context.current_precision())(size)
        R.SetOwnership(dt, False)
        dt.dump(); print()
        obj.add_typeclass(dt)
        res = obj.process_types();
        assert res

        dtype = obj.dummytype.out.datatype()
        assert dtype.kind==1
        assert dtype.shape.size()==1
        assert dtype.shape[0]==size
Beispiel #8
0
def test_typeclass_same_v04():
    """Last input has another edges"""
    objects=[C.Histogram2d(np.arange(4), np.arange(5)) for i in range(5)]
    objects.append(C.Histogram2d(np.arange(1,5), np.arange(5)))
    outputs = [p.single() for p in objects]

    obj = C.DummyType()
    list(map(obj.add_input, outputs))

    dt = R.TypeClasses.CheckSameTypesT(context.current_precision())((1,-1), 'shape')
    R.SetOwnership(dt, False)
    dt.dump(); print()
    obj.add_typeclass(dt)
    res = obj.process_types();
    assert res

    dt1 = R.TypeClasses.CheckSameTypesT(context.current_precision())((1,-1),)
    R.SetOwnership(dt1, False)
    dt1.dump(); print()
    obj.add_typeclass(dt1)
    print('Exception expected: ',end='')
    res = obj.process_types();
    assert not res