Esempio n. 1
0
from autograd.extend import def_linear
from .sparse_wrapper import dot

def_linear(dot)
Esempio n. 2
0
defjvp(func(ArrayBox.__getitem__), 'same')
defjvp(untake, 'same')

defjvp_argnum(
    anp.array_from_args,
    lambda argnum, g, ans, args, kwargs: untake(g, argnum - 2, vspace(ans)))
defjvp(
    anp._array_from_scalar_or_array, None, None,
    lambda g, ans, args, kwargs, _: anp._array_from_scalar_or_array(
        args, kwargs, g))

# ----- Functions that are constant w.r.t. continuous inputs -----
defjvp(anp.nan_to_num, lambda g, ans, x: anp.where(anp.isfinite(x), g, 0.))

# ----- Binary ufuncs (linear) -----
def_linear(anp.multiply)

# ----- Binary ufuncs -----
defjvp(anp.add, lambda g, ans, x, y: broadcast(g, ans),
       lambda g, ans, x, y: broadcast(g, ans))
defjvp(anp.subtract, lambda g, ans, x, y: broadcast(g, ans),
       lambda g, ans, x, y: broadcast(-g, ans))
defjvp(anp.divide, 'same', lambda g, ans, x, y: -g * x / y**2)
defjvp(anp.maximum, lambda g, ans, x, y: g * balanced_eq(x, ans, y),
       lambda g, ans, x, y: g * balanced_eq(y, ans, x))
defjvp(anp.minimum, lambda g, ans, x, y: g * balanced_eq(x, ans, y),
       lambda g, ans, x, y: g * balanced_eq(y, ans, x))
defjvp(anp.fmax, lambda g, ans, x, y: g * balanced_eq(x, ans, y),
       lambda g, ans, x, y: g * balanced_eq(y, ans, x))
defjvp(anp.fmin, lambda g, ans, x, y: g * balanced_eq(x, ans, y),
       lambda g, ans, x, y: g * balanced_eq(y, ans, x))
Esempio n. 3
0
from autograd.extend import def_linear
from .sparse_wrapper import dot, spsolve

def_linear(dot)
def_linear(spsolve)
Esempio n. 4
0
for fun in nograd_functions:
    register_notrace(JVPNode, fun)

defjvp(func(ArrayBox.__getitem__), 'same')
defjvp(untake, 'same')

defjvp_argnum(anp.array_from_args, lambda argnum, g, ans, args, kwargs: untake(g, argnum-2, vspace(ans)))
defjvp(anp._array_from_scalar_or_array, None, None,
       lambda g, ans, args, kwargs, _: anp._array_from_scalar_or_array(args, kwargs, g))

# ----- Functions that are constant w.r.t. continuous inputs -----
defjvp(anp.nan_to_num, lambda g, ans, x: anp.where(anp.isfinite(x), g, 0.))

# ----- Binary ufuncs (linear) -----
def_linear(anp.multiply)

# ----- Binary ufuncs -----
defjvp(anp.add,        lambda g, ans, x, y : broadcast(g, ans),
                       lambda g, ans, x, y : broadcast(g, ans))
defjvp(anp.subtract,   lambda g, ans, x, y : broadcast(g, ans),
                       lambda g, ans, x, y : broadcast(-g, ans))
defjvp(anp.divide,     'same',
                       lambda g, ans, x, y : - g * x / y**2)
defjvp(anp.maximum,    lambda g, ans, x, y : g * balanced_eq(x, ans, y),
                       lambda g, ans, x, y : g * balanced_eq(y, ans, x))
defjvp(anp.minimum,    lambda g, ans, x, y : g * balanced_eq(x, ans, y),
                       lambda g, ans, x, y : g * balanced_eq(y, ans, x))
defjvp(anp.fmax,       lambda g, ans, x, y : g * balanced_eq(x, ans, y),
                       lambda g, ans, x, y : g * balanced_eq(y, ans, x))
defjvp(anp.fmin,       lambda g, ans, x, y : g * balanced_eq(x, ans, y),