SVD计算速度测试

import time
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
#%%  平均2.7秒。 发现conda 创建tf1.15 速度非常慢,应该环境配置有问题 
A = tf.linalg.svd(tf.random.normal([2000,2000]))
with tf.compat.v1.Session() as sess:
    sess.run(tf.compat.v1.global_variables_initializer())
    print(time.localtime())
    y= sess.run(A)
    print(time.localtime())
    y= sess.run(A)
    print(time.localtime())
    y= sess.run(A)
    print(time.localtime())

#%%
from pylab import  svd, randn
import torch
# mac 16 的运行速度
%time Us, Ds, Vs = svd(randn(2000,2000))
#  2.6秒
%time Us, Ds, Vs = torch.svd(torch.randn(2000, 2000))
# 1.6秒
import jax.numpy as jnp
%time u,d,v = jnp.linalg.svd(randn(2000, 2000))
#  1秒
posted @ 2023-05-16 14:14  bregman  阅读(59)  评论(0编辑  收藏  举报