Ejemplo n.º 1
0
    def create_rvector(self, vals):
        '''
        Return rScalar object(s) with user defined value(s).

        INPUTS
        ======
        vals: list of lists of floats, compulsory
            Value of the list of Vector variables

        RETURNS
        ========
        A list of Vector variables

        NOTES
        =====

        POST:
            returns a list of vector variables with value defined in vals
        '''
        try:
            rvectors = [None] * len(vals)
            for i in range(len(vals)):
                rvectors[i] = rVector(vals[i])
                rvectors[i]._init_roots()
            return rvectors
        except TypeError:
            rvector = rVector(vals)
            rvector._init_roots()
            return rvector
Ejemplo n.º 2
0
def test_arccosh():
    # Test rScalar
    x = generate(1)
    f = op.arccosh(x)
    assert f.eval() == np.arccosh(x._val)

    f._grad_val = 1
    f.gradient(x)
    assert x._grad_val == -np.arccosh(x._val) * np.tanh(x._val)

    # Test constant
    assert op.arccosh(c2) == np.arccosh(c2)

    # Test vector
    y = rVector([2, 4])
    y._init_roots()
    g = op.arccosh(y)
    g._grad_val = 1
    g.gradient(y)
    assert (y._grad_val == np.array(-np.arccosh(y._val) *
                                    np.tanh(y._val))).all()
Ejemplo n.º 3
0
def generate():
    vars = rVector([10, 10, 15]), rVector([20, 20, 25]), rVector([30, 30, 1])
    for var in vars:
        var._init_roots()
    return tuple(vars)
Ejemplo n.º 4
0
def test_get_item():
    x = rVector([10, 20])
    assert x[0].eval() == 10
    assert x[1].eval() == 20
Ejemplo n.º 5
0
def generate_vec():
    var = rVector([0.2, 0.3])
    var._init_roots()
    return var