April 2017
Intermediate to advanced
320 pages
7h 46m
English
We report, just for better understanding, the complete source code:
import numpy as np import tensorflow as tf import datetime log_device_placement = True n = 10 A = np.random.rand(10000, 10000).astype('float32') B = np.random.rand(10000, 10000).astype('float32') c1 = [] def matpow(M, n): if n < 1: #Abstract cases where n < 1 return M else: return tf.matmul(M, matpow(M, n-1)) with tf.device('/gpu:1'): a = tf.placeholder(tf.float32, [10000, 10000]) b = tf.placeholder(tf.float32, [10000, 10000]) c1.append(matpow(a, n)) c1.append(matpow(b, n)) with tf.device('/cpu:0'): sum = tf.add_n(c1) t1_1 = datetime.datetime.now() with tf.Session(config=tf.ConfigProto\ (allow_soft_placement=True,\ log_device_placement=log_device_placement))\ ...Read now
Unlock full access