summaryrefslogtreecommitdiff
path: root/tests/rotate_test.py
diff options
context:
space:
mode:
authorAnthony LaTorre <telatorre@gmail.com>2011-05-06 12:06:58 -0400
committerAnthony LaTorre <telatorre@gmail.com>2011-05-06 12:06:58 -0400
commit4e2720ff56afff978acaf589218cee0122d2ae29 (patch)
tree98be56318474b5d87c3514bd97bb4ae5b33f0d1b /tests/rotate_test.py
parent98dc8b3d4eb46fdb73b01e78c5e53ff3a779ab85 (diff)
downloadchroma-4e2720ff56afff978acaf589218cee0122d2ae29.tar.gz
chroma-4e2720ff56afff978acaf589218cee0122d2ae29.tar.bz2
chroma-4e2720ff56afff978acaf589218cee0122d2ae29.zip
added rotations
Diffstat (limited to 'tests/rotate_test.py')
-rw-r--r--tests/rotate_test.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/rotate_test.py b/tests/rotate_test.py
new file mode 100644
index 0000000..8c2cfcb
--- /dev/null
+++ b/tests/rotate_test.py
@@ -0,0 +1,63 @@
+import numpy as np
+from pycuda import autoinit
+from pycuda.compiler import SourceModule
+import pycuda.driver as cuda
+from pycuda import gpuarray
+float3 = gpuarray.vec.float3
+
+def rotate(x, phi, n):
+ x = np.asarray(x)
+ n = np.asarray(n)
+
+ r = np.cos(phi)*np.identity(3) + (1-np.cos(phi))*np.outer(n,n) + \
+ np.sin(phi)*np.array([[0,n[2],-n[1]],[-n[2],0,n[0]],[n[1],-n[0],0]])
+
+ return np.inner(x,r)
+
+print 'device %s' % autoinit.device.name()
+
+source = open('../linalg.h').read() + open('../matrix.h').read() + \
+ open('../rotate.h').read() + open('rotate_test.cu').read()
+mod = SourceModule(source, no_extern_c=True, arch='sm_13')
+
+rotate_gpu = mod.get_function('rotate')
+
+size = {'block': (100,1,1), 'grid': (1,1)}
+
+a = np.empty(size['block'][0], dtype=float3)
+n = np.empty(size['block'][0], dtype=float3)
+phi = np.random.random_sample(size=a.size).astype(np.float32)
+
+a['x'] = np.random.random_sample(size=a.size)
+a['y'] = np.random.random_sample(size=a.size)
+a['z'] = np.random.random_sample(size=a.size)
+
+n['x'] = np.random.random_sample(size=n.size)
+n['y'] = np.random.random_sample(size=n.size)
+n['z'] = np.random.random_sample(size=n.size)
+
+a['x'] = np.ones(a.size)
+a['y'] = np.zeros(a.size)
+a['z'] = np.zeros(a.size)
+
+n['x'] = np.zeros(n.size)
+n['y'] = np.zeros(n.size)
+n['z'] = np.ones(n.size)
+
+phi = np.array([np.pi/2]*a.size).astype(np.float32)
+
+def testrotate():
+ dest = np.empty(a.size, dtype=float3)
+ rotate_gpu(cuda.In(a), cuda.In(phi), cuda.In(n), cuda.Out(dest), **size)
+ for v, theta, w, rdest in zip(a,phi,n,dest):
+ r = rotate((v['x'], v['y'], v['z']), theta, (w['x'], w['y'], w['z']))
+ if not np.allclose(rdest['x'], r[0]) or \
+ not np.allclose(rdest['y'], r[1]) or \
+ not np.allclose(rdest['z'], r[2]):
+ print v
+ print theta
+ print w
+ print r
+ print rdest
+ assert False
+