Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic differentiation using tapenade #101

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions compyle/array.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import numpy as np
import math
import mako.template as mkt
import time
from pytools import memoize, memoize_method

from .config import get_config
from .types import (annotate, dtype_to_ctype, ctype_to_dtype, declare,
from .types import (annotate, dtype_to_ctype, declare,
dtype_to_knowntype, knowntype_to_ctype)
from .template import Template
from .sort import radix_sort
Expand Down Expand Up @@ -394,7 +393,6 @@ def linspace(start, stop, num, dtype=np.float64, backend='opencl',
out = out * delta+start
elif backend == 'cuda':
import pycuda.gpuarray as gpuarray
import pycuda.autoinit
if endpoint:
delta = (stop-start)/(num-1)
else:
Expand Down Expand Up @@ -445,7 +443,6 @@ def diff(a, n, backend=None):
backend = a.backend

if backend == 'opencl' or backend == 'cuda':
from compyle.api import Elementwise
binom_coeff = np.zeros(n+1)
sign_fac = 1 if (n % 2 == 0) else -1
for i in range(n+1):
Expand Down Expand Up @@ -526,6 +523,7 @@ def trapz(y, x=None, dx=1.0, backend=None):
out = dot(d, sum_ar) * 0.5
return out


@annotate
def where_elwise(i, condition, x, y, ans):
if condition[i]:
Expand Down Expand Up @@ -872,7 +870,6 @@ def comparison_kernel(func, backend, ary_type, other_type):
def comparison_template(func, other, arr, backend=None):
if backend is None:
backend = arr.backend
from compyle.parallel import Elementwise
other_type = dtype_to_ctype(type(other))
ary_type = dtype_to_ctype(arr.dtype) + 'p'
ans = empty(arr.length, dtype=np.int32, backend=arr.backend)
Expand Down Expand Up @@ -1023,7 +1020,7 @@ def get_buff(self, offset=0, length=0):
return cu_bufint(self._data, nbytes, int(offset))

def get(self):
if self.backend == 'cython':
if self.backend == 'cython' or self.backend == 'c':
return self.dev
elif self.backend == 'opencl' or self.backend == 'cuda':
return self.dev.get()
Expand Down
Loading