Exemplo n.º 1
0
    def arcsin(x):
        try:
            x._reverse_scalars
            child = ReverseVector(np.arcsin(x._val))
            for var in x._children.keys():
                child._children[var] = [(x, 1 / np.sqrt(1 - x._val**2))]
            return child
        except AttributeError:
            try:  # If scalar variable
                child = ReverseScalar(np.arcsin(x._val))
                child._children[x] = 1 / np.sqrt(1 - x._val**2)
                return child

            except AttributeError:  # If contant
                return np.arcsin(x)
Exemplo n.º 2
0
    def log(x):
        try:
            x._reverse_scalars
            child = ReverseVector(np.log(x._val))
            for var in x._children.keys():
                child._children[var] = [(x, 1 / x._val)]
            return child
        except AttributeError:
            try:  # If scalar variable
                child = ReverseScalar(np.log(x._val))
                child._children[x] = 1 / x._val
                return child

            except AttributeError:  # If contant
                return np.log(x)
Exemplo n.º 3
0
 def reverse_vector(vals):
     '''
     Creates a ReverseVector object with the values given
     
     INPUTS
     =======
     vals: The list of numeric values at which to evaluate
     
     RETURNS
     =======
     ReverseVector objects
     '''
     reverse_vecs = [None] * len(vals)
     for i in range(len(vals)):
         reverse_vecs[i] = ReverseVector(vals[i])
         reverse_vecs[i]._init_children()
     return reverse_vecs
Exemplo n.º 4
0
def test_getitem():
    x = ReverseVector([1, 2])
    assert x[0].get()[0] == 1
    assert x[1].get()[0] == 2
Exemplo n.º 5
0
def new_create():
    vars = ReverseVector([10, 10, 3]), ReverseVector([20, 20, 25]), ReverseVector([30, 30, 1])
    for var in vars:
        var._init_children()
    return tuple(vars)
Exemplo n.º 6
0
def create():
    var1, var2 = ReverseVector([10, 3]), ReverseVector([20, 25])
    var1._init_children()
    var2._init_children()
    return var1, var2