Ejemplo n.º 1
0
from __future__ import absolute_import
from __future__ import print_function
import autograd.numpy as np
import itertools as it
from autograd.core import grad, safe_type
from copy import copy
from autograd.numpy.use_gpu_numpy import use_gpu_numpy
import six
from six.moves import map
from six.moves import range
from six.moves import zip

if use_gpu_numpy():
    garray_obj = np.garray
    array_types = (np.ndarray, garray_obj)
    EPS, RTOL, ATOL = 1e-4, 1e-2, 1e-2
else:
    garray_obj = ()
    array_types = (np.ndarray,)
    EPS, RTOL, ATOL = 1e-4, 1e-4, 1e-6

def nd(f, *args):
    unary_f = lambda x : f(*x)
    return unary_nd(unary_f, args)

def unary_nd(f, x, eps=EPS):
    if isinstance(x, array_types):
        if np.iscomplexobj(x):
            nd_grad = np.zeros(x.shape) + 0j
        elif isinstance(x, garray_obj):
            nd_grad = np.array(np.zeros(x.shape), dtype=np.gpu_float32)
Ejemplo n.º 2
0
from __future__ import absolute_import
from __future__ import print_function
import autograd.numpy.random as npr
import autograd.numpy as np
import operator as op
from autograd.numpy.use_gpu_numpy import use_gpu_numpy
from numpy_utils import (combo_check, stat_check, unary_ufunc_check,
                         binary_ufunc_check, binary_ufunc_check_no_same_args)

npr.seed(0)

if not use_gpu_numpy():
    print("Can't test GPU support without flag set")
else:

    def R(*shape):
        arr = npr.randn(*shape)
        return np.array(arr, dtype=np.gpu_float32)

    def test_dot():
        combo_check(np.dot, [0, 1], [R(2, 3)], [R(3, 4)])

    # [1.5, R(3), R(2, 3)],
    # [0.3, R(3), R(3, 4)])
Ejemplo n.º 3
0
from __future__ import absolute_import
from __future__ import print_function
import autograd.numpy as np
import itertools as it
from autograd.core import grad, safe_type
from copy import copy
from autograd.numpy.use_gpu_numpy import use_gpu_numpy
from autograd.container_types import ListNode
import six
from six.moves import map
from six.moves import range
from six.moves import zip

if use_gpu_numpy():
    garray_obj = np.garray
    array_types = (np.ndarray, garray_obj)
    EPS, RTOL, ATOL = 1e-4, 1e-2, 1e-2
else:
    garray_obj = ()
    array_types = (np.ndarray, )
    EPS, RTOL, ATOL = 1e-4, 1e-4, 1e-6


def nd(f, *args):
    unary_f = lambda x: f(*x)
    return unary_nd(unary_f, args)


def unary_nd(f, x, eps=EPS):
    if isinstance(x, array_types):
        if np.iscomplexobj(x):
Ejemplo n.º 4
0
from __future__ import absolute_import
from __future__ import print_function
import autograd.numpy.random as npr
import autograd.numpy as np
import operator as op
from autograd.numpy.use_gpu_numpy import use_gpu_numpy
from numpy_utils import (combo_check, stat_check, unary_ufunc_check,
                         binary_ufunc_check, binary_ufunc_check_no_same_args)

npr.seed(0)

if not use_gpu_numpy():
    print("Can't test GPU support without flag set")
else:

    def R(*shape):
        arr = npr.randn(*shape)
        return np.array(arr, dtype=np.gpu_float32)

    def test_dot(): combo_check(np.dot, [0, 1],
                                [R(2, 3)],
                                [R(3, 4)])
                                # [1.5, R(3), R(2, 3)],
                                # [0.3, R(3), R(3, 4)])