Skip to content

Instantly share code, notes, and snippets.

@shackenberg
Last active December 20, 2015 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shackenberg/6090599 to your computer and use it in GitHub Desktop.
Save shackenberg/6090599 to your computer and use it in GitHub Desktop.
Script to test my GpuJoin.c_code for Theano. See https://github.com/shackenberg/Theano/compare/adding_GpuJoin.c_code
#!/usr/bin/env python
"""
call this to run the code:
export CUDA_LAUNCH_BLOCKING=1
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32,exception_verbosity=high python jointest.py
"""
import theano
import theano.tensor as T
from numpy import *
axis = 0
np_array1 = array(random.random([2]), dtype='float32')
np_array2 = array(random.random([5]), dtype='float32')
T_vector1 = T.vector('T_vector1')
T_vector2 = T.vector('T_vector2')
T_result = T.concatenate([T_vector1, T_vector2], axis)
f1 = theano.function([T_vector1, T_vector2], T_result , profile=True)
numpy_result = concatenate([np_array1, np_array2], axis)
theano_result = f1(np_array1, np_array2)
if not allclose(theano_result,numpy_result):
print numpy_result
print theano_result
axis = 1
np_array1 = array(random.random([2, 3]), dtype='float32')
np_array2 = array(random.random([2, 11]), dtype='float32')
np_array3 = array(random.random([2, 3]), dtype='float32')
T_matrix1 = T.matrix('T_matrix1')
T_matrix2 = T.matrix('T_matrix2')
T_matrix3 = T.matrix('T_matrix3')
T_result = T.concatenate([T_matrix1, T_matrix2, T_matrix3], axis)
f1 = theano.function([T_matrix1, T_matrix2, T_matrix3], T_result , profile=True)
numpy_result = concatenate([np_array1, np_array2, np_array3], axis)
theano_result = f1(np_array1, np_array2, np_array3)
if not allclose(theano_result,numpy_result):
print numpy_result
print theano_result
axis = 2
np_array1 = array(random.random([2, 3, 2, 4]), dtype='float32')
np_array2 = array(random.random([2, 3, 11, 4]), dtype='float32')
np_array3 = array(random.random([2, 3, 44, 4]), dtype='float32')
np_array4 = array(random.random([2, 3, 1, 4]), dtype='float32')
T_tensor_1 = T.tensor4('T_tensor3_1')
T_tensor_2 = T.tensor4('T_tensor3_2')
T_tensor_3 = T.tensor4('T_tensor3_3')
T_tensor_4 = T.tensor4('T_tensor3_4')
T_result = T.concatenate([T_tensor_1, T_tensor_2, T_tensor_3, T_tensor_4], axis)
f1 = theano.function([T_tensor_1, T_tensor_2, T_tensor_3, T_tensor_4], T_result , profile=True)
numpy_result = concatenate([np_array1, np_array2, np_array3, np_array4], axis)
theano_result = f1(np_array1, np_array2, np_array3, np_array4)
if not allclose(theano_result,numpy_result):
print numpy_result
print theano_result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment