def test_double_s(self): vec_n = tf.constant([1.0, 1.5, 3.5, 1.0]) vec_d = tf.constant([1e-6, 1.33e-6]) ts0, rs0 = vtmm.tmm_rt('s', self.omega, self.kx, vec_n, vec_d) ts1, rs1 = calc_rt_pytmm('s', self.omega, self.kx, vec_n, vec_d) self.assertLessEqual(np.linalg.norm(ts0.numpy() - ts1.numpy()), TOL) self.assertLessEqual(np.linalg.norm(rs0.numpy() - rs1.numpy()), TOL)
def test_double_p(self): vec_n = tf.constant([1.0, 1.5, 3.5, 1.0]) vec_d = tf.constant([1e-6, 1.33e-6]) tp0, rp0 = vtmm.tmm_rt('p', self.omega, self.kx, vec_n, vec_d) tp1, rp1 = calc_rt_pytmm('p', self.omega, self.kx, vec_n, vec_d) self.assertLessEqual(np.linalg.norm(tp0.numpy() - tp1.numpy()), TOL) self.assertLessEqual(np.linalg.norm(rp0.numpy() - rp1.numpy()), TOL)
def test_benchmark_medium(self): vec_n = tf.constant([1.0, 1.5, 3.5, 1.5, 1.0]) vec_d = tf.constant([1e-6, 1e-6, 1e-6]) print("Medium stack benchmark") t1 = timeit.timeit( lambda: vtmm.tmm_rt('p', self.omega, self.kx, vec_n, vec_d), number=NUM) print("vtmm: %.4f s" % t1) t2 = timeit.timeit( lambda: calc_rt_pytmm('p', self.omega, self.kx, vec_n, vec_d), number=NUM) print("tmm: %.4f s" % t2)
def test_benchmark_single(self): vec_n = tf.constant([1.0, 3.5, 1.0]) vec_d = tf.constant([1e-6]) print("Single omega / kx benchmark") t1 = timeit.timeit(lambda: vtmm.tmm_rt('p', self.omega[0:1], self.kx[ 0:1], vec_n, vec_d), number=NUM) print("vtmm: %.4f s" % t1) t2 = timeit.timeit(lambda: calc_rt_pytmm('p', self.omega[0:1], self.kx[ 0:1], vec_n, vec_d), number=NUM) print("tmm: %.4f s" % t2)
def test_benchmark_large(self): vec_n = tf.constant([1.0, 1.5, 3.5, 1.5, 2.5, 3.0, 1.5, 2, 3, 1.0]) vec_d = tf.constant( [1e-6, 1.33e-6, 1e-6, 1e-6, 2e-6, 1e-5, 1.25e-6, 1e-6]) print("Large stack benchmark") t1 = timeit.timeit( lambda: vtmm.tmm_rt('p', self.omega, self.kx, vec_n, vec_d), number=NUM) print("vtmm: %.4f s" % t1) t2 = timeit.timeit( lambda: calc_rt_pytmm('p', self.omega, self.kx, vec_n, vec_d), number=NUM) print("tmm: %.4f s" % t2)
def test_benchmark(self): vec_n = tf.constant([1.0, 1.5, 3.5, 1.5, 2.5, 3.0, 1.5, 2, 3, 1.0]) vec_d = tf.constant( [1e-6, 1.33e-6, 1e-6, 1e-6, 2e-6, 1e-5, 1.25e-6, 1e-6]) print("Running benchmark") print("----------------------") t1 = timeit.timeit( lambda: vtmm.tmm_rt('p', self.omega, self.kx, vec_n, vec_d), number=50) print("Tensorflow (vectorized implementation): %.3f" % t1) t2 = timeit.timeit( lambda: calc_rt_pytmm('p', self.omega, self.kx, vec_n, vec_d), number=50) print("TMM (unvectorized implementation): %.3f" % t2)