Exemple #1
0
 def test_AggByAppending(self):
     x = Coordinate(0)
     y = Coordinate(1)
     z = Coordinate(2)
     L = AggExpr(x)
     L.append(y)
     L.append(z)
     assert (L[0] == x and L[1] == y and L[2] == z)
Exemple #2
0
    def test_NoMultiplyingAggs1(self):
        with pytest.raises(ValueError) as err_info:
            x = Coordinate(0)
            y = Coordinate(1)
            L1 = AggExpr(x)
            f = y * L1

        print('detected expected exception: {}'.format(err_info))
        assert ('not compatible' in str(err_info.value))
Exemple #3
0
    def test_InvalidAggInputAggWithinAgg(self):
        with pytest.raises(ValueError) as err_info:
            x = Coordinate(0)
            y = Coordinate(1)
            L1 = AggExpr(x)
            L2 = AggExpr(y, L1)

        print('detected expected exception: {}'.format(err_info))
        assert ('Agg within list' in str(err_info.value))
Exemple #4
0
    def test_CurlOf2DVector(self):
        with pytest.raises(TypeError) as err_info:
            x = Coordinate(0)
            y = Coordinate(1)
            v = Vector(x, y)
            bad = Curl(v)

        print('detected expected exception: {}'.format(err_info))
        assert ('cannot accept' in str(err_info.value))
Exemple #5
0
    def test_NoAddingAggs2(self):
        with pytest.raises(ValueError) as err_info:
            x = Coordinate(0)
            y = Coordinate(1)
            L1 = AggExpr(x)
            L2 = AggExpr(y)
            f = L1 + L2

        print('detected expected exception: {}'.format(err_info))
        assert ('not compatible' in str(err_info.value))
Exemple #6
0
    def test_Div(self):

        x = Coordinate(0)
        y = Coordinate(1)

        div = _Div()
        F = Vector(x, y)
        divF = Div(F)

        print('Div(F)=', divF)
        assert (divF.sameas(DiffOp(div, F)) and divF.shape() == ScalarShape())
Exemple #7
0
    def test_Partial2(self):

        d_dx = _Partial(0)
        x = Coordinate(0)
        y = Coordinate(1)

        f = Vector(x * y, x + y)
        df_dx = Partial(f, x)

        print('df_dx=', df_dx)
        assert (df_dx.sameas(DiffOp(d_dx, f)) and df_dx.shape() == f.shape())
Exemple #8
0
    def test_Rot(self):

        x = Coordinate(0)
        y = Coordinate(1)

        rot = _Rot()
        F = Vector(x, y)
        rotF = rot(F)

        print('Rot(F)=', rotF)
        assert (rotF.sameas(DiffOp(rot, F)) and rotF.shape() == ScalarShape())
Exemple #9
0
    def test_DiffOpOfAgg(self):
        with pytest.raises(TypeError) as err_info:
            x = Coordinate(0)
            y = Coordinate(1)
            z = Coordinate(2)
            L = AggExpr(x, y, z)

            bad = Rot(L)

        print('detected expected exception: {}'.format(err_info))
        assert ('cannot accept' in str(err_info.value))
Exemple #10
0
    def test_NonsensePartial1(self):
        with pytest.raises(ValueError) as err_info:
            d_dx = _Partial(0)
            x = Coordinate(0)
            y = Coordinate(1)

            f = x * y
            df_dx = Partial(x, f)

        print('detected expected exception: {}'.format(err_info))
        assert ('unable to interpret' in str(err_info.value))
Exemple #11
0
    def test_Curl(self):

        x = Coordinate(0)
        y = Coordinate(1)
        z = Coordinate(2)

        curl = _Curl()
        F = Vector(x, y, z)
        curlF = Curl(F)

        print('Curl(F)=', curlF)
        assert (curlF.sameas(DiffOp(curl, F)) and curlF.shape().dim() == 3)
Exemple #12
0
 def test_AggFromNumpy(self):
     x = Coordinate(0)
     a = np.array([1, 2, 3])
     L = AggExpr(1, x, a)
     print(L)
     assert (L[0].sameas(ConstantScalarExpr(1)) and L[1] == x
             and L[2].sameas(ConstantVectorExpr(a)))
Exemple #13
0
def evalExpr(varNames, varVals, exprString, constNames=[], constVals=[]):

    varToExprMap = {'Exp' : Exp,
        'Sqrt' : Sqrt,
        'Log' : Log,
        'Cos' : Cos,
        'Sin' : Sin,
        'Tan' : Tan,
        'Cosh' : Cosh,
        'Sinh' : Sinh,
        'Tanh' : Tanh,
        'ArcCos' : ArcCos,
        'ArcSin' : ArcSin,
        'ArcTan' : ArcTan,
        'ArcCosh' : ArcCosh,
        'ArcSinh' : ArcSinh,
        'ArcTanh' : ArcTanh,
        'ArcTan2' : ArcTan2}
    varToValMap = {}

    for i,(name,val) in enumerate(zip(varNames, varVals)):
        e = Coordinate(i, name)
        varToExprMap[name]=e
        varToValMap[e]=val

    for name,val in zip(constNames, constVals):
        varToExprMap[name]=val

    #print('expr to eval: {}'.format(exprString), flush=True)
    #print('var to expr map: {}'.format(varToExprMap), flush=True)
    expr = eval(exprString, varToExprMap)
    evaluator = makeEval(expr)

    return evaluator.eval(varToValMap)
Exemple #14
0
    def test_RotOfScalar(self):
        with pytest.raises(TypeError) as err_info:
            x = Coordinate(0)
            bad = Rot(x)

        print('detected expected exception: {}'.format(err_info))
        assert ('cannot accept' in str(err_info.value))
Exemple #15
0
    def test_InvalidAggInputNotAnExpr2(self):
        with pytest.raises(ValueError) as err_info:
            x = Coordinate(0)
            L = AggExpr((x, 'not an Expr'))

        print('detected expected exception: {}'.format(err_info))
        assert ('not convertible' in str(err_info.value))
Exemple #16
0
    def test_NoNegatingAggs(self):
        with pytest.raises(ValueError) as err_info:
            x = Coordinate(0)
            L1 = AggExpr(x)
            f = -L1

        print('detected expected exception: {}'.format(err_info))
        assert ('cannot negate' in str(err_info.value))
Exemple #17
0
    def test_NoDividingOfAggs(self):
        with pytest.raises(ValueError) as err_info:
            x = Coordinate(0)
            L1 = AggExpr(x)
            f = L1 / 2

        print('detected expected exception: {}'.format(err_info))
        assert ('Dividing a list' in str(err_info.value))
Exemple #18
0
    def test_VectorScalarInput1(self):
        with pytest.raises(ValueError) as err_info:
            x = Coordinate(0)
            bad = Vector(x)


        print('detected expected exception: {}'.format(err_info))
        assert('pointless to convert' in str(err_info.value))
Exemple #19
0
    def test_AggIter(self):
        x = Coordinate(0)
        a = np.array([1, 2, 3])
        a2 = Expr._convertToExpr(a)
        c = 1
        c2 = Expr._convertToExpr(c)
        L = AggExpr(c, x, a)
        tup = (c2, x, a2)
        same = True
        for e1, e2 in zip(L, tup):
            same = same and (e1.sameas(e2))

        assert (same)
Exemple #20
0
 def test_ZeroToAPower2(self):
     y = Coordinate(1)
     ex = y**0.0
     assert(ex == 1)
Exemple #21
0
 def test_ExprDividedByOne1(self):
     y = Coordinate(1)
     ex = y/ConstantScalarExpr(1)
     assert(ex == y)
Exemple #22
0
 def test_ExprPowerZero2(self):
     y = Coordinate(1)
     ex = y**0.0
     assert(ex == 1)
Exemple #23
0
 def test_ZeroToAPower1(self):
     y = Coordinate(1)
     ex = ConstantScalarExpr(0)**y
     assert(ex == 0)
Exemple #24
0
 def test_ExprPowerOne2(self):
     y = Coordinate(1)
     ex = y**1.0
     assert(ex == y)
Exemple #25
0
 def test_ExprPowerZero1(self):
     y = Coordinate(1)
     ex = y**ConstantScalarExpr(0)
     assert(ex == 1)
Exemple #26
0
 def test_ExprPowerOne1(self):
     y = Coordinate(1)
     ex = y**ConstantScalarExpr(1)
     assert(ex == y)
Exemple #27
0
 def test_ExprDividedByOne2(self):
     y = Coordinate(1)
     ex = y/1.0
     assert(ex == y)
Exemple #28
0
 def test_ExprTimesOne2(self):
     y = Coordinate(1)
     ex = y * 1
     assert(ex == y)
Exemple #29
0
 def test_OneTimesExpr2(self):
     y = Coordinate(1)
     ex = ConstantScalarExpr(1) * y
     assert(ex == y)
Exemple #30
0
 def test_OneTimesExpr1(self):
     y = Coordinate(1)
     ex = 1 * y
     assert(ex == y)