Skip to content
Snippets Groups Projects
Commit f0288e9f authored by Denis Arrivault's avatar Denis Arrivault
Browse files

Upadte cuda tests

parent ecba9ede
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -10,19 +10,33 @@ from timeit import default_timer as timer
import numpy as np
def test_svd():
d = 100
A = np.asarray(np.random.randint(1, 10,(d, d)), dtype=np.float64)
d = 1000
A = np.asarray(np.random.randint(1, 10,(d, d)), dtype=np.float32)
# scipy
print("\n****************** Scipy")
from scipy import linalg as sc_linalg
from scipy.linalg import svd as sc_svd
start = timer()
u_sc, s_sc, v_sc = sc_linalg.svd(A)
u_sc, s_sc, v_sc = sc_svd(A)
duration = timer() - start
print("SVD scipy : " + str(duration))
print(s_sc)
print(type(s_sc))
# cupy
print("\n****************** Cupy")
import cupy as cp
from cupy.linalg import svd as cp_svd
start = timer()
A_cp = cp.asarray(A)
u_cp, s_cp, v_cp = cp_svd(A_cp)
u_cp, s_cp, v_cp = u_cp.get(), s_cp.get(), v_cp.get()
duration = timer() - start
print("SVD cupy : " + str(duration))
print(s_cp)
print(A_cp.device)
print(type(s_cp))
# scikit-cuda
print("\n****************** scikit-cuda")
import pycuda.autoinit
......@@ -40,30 +54,44 @@ def test_svd():
print(s_sk)
print(type(s_sk))
# tensorflow
print("\n****************** tensorflow")
import tensorflow as tf
from tensorflow import linalg as tf_linalg
start = timer()
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
s_tf, u_tf, v_tf = tf_linalg.svd(A)
s_tf, u_tf, v_tf = s_tf.eval(), u_tf.eval(), v_tf.eval()
duration = timer() - start
print("SVD tensorflow : " + str(duration))
print(s_tf)
print(type(s_tf))
# # tensorflow
# print("\n****************** tensorflow")
# import tensorflow as tf
# start = timer()
# with tf.device("/cpu:0"):
# s_tf, u_tf, v_tf = tf.svd(A, compute_uv=True)
# s_tf, u_tf, v_tf = tf.Session().run(s_tf), tf.Session().run(u_tf), tf.Session().run(v_tf)
# duration = timer() - start
# print("SVD tensorflow CPU : " + str(duration))
# print(s_tf)
# print(type(s_tf))
# print()
# start = timer()
# with tf.device("/gpu:0"):
# s_tf, u_tf, v_tf = tf.svd(A, compute_uv=True)
# s_tf, u_tf, v_tf = tf.Session().run(s_tf), tf.Session().run(u_tf), tf.Session().run(v_tf)
# duration = timer() - start
# print("SVD tensorflow GPU : " + str(duration))
# print(s_tf)
# print(type(s_tf))
# Theano
print("\n****************** theano")
import theano.tensor as T
from theano import function
from theano import function, shared, tensor, config
import theano.tensor.nlinalg as th_linalg
x = T.dmatrix('x')
x = tensor.dmatrix('x')
u, s, v = th_linalg.svd(x)
f = function([x], (u, s, v))
start = timer()
u_th, s_th, v_th = f(A)
duration = timer() - start
# x = shared(np.asarray(A, config.floatX))
# f = function([], th_linalg.svd(x))
# start = timer()
# u_th, s_th, v_th = f()
# duration = timer() - start
print("SVD theano : " + str(duration))
print(s_th)
print(type(s_th))
......
......@@ -363,8 +363,17 @@ class Hankel(object):
"the smaller dimension of the Hankel Matrix (" +
str(matrix_shape) + ")")
if not self.sparse:
try:
import theano.tensor as T
from theano import function
import theano.tensor.nlinalg as th_linalg
x = T.dmatrix('x')
u, s, v = th_linalg.svd(x)
svd = function([x], (u, s, v))
except :
from scipy.linalg import svd
hankel = self.lhankel[0]
[u, s, v] = np.linalg.svd(hankel)
[u, s, v] = svd(hankel)
u = u[:, :rank]
v = v[:rank, :]
# ds = np.zeros((rank, rank), dtype=complex)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment