From 37aa4b98ff85f16ce70ee6349d4e4e1acd340906 Mon Sep 17 00:00:00 2001 From: qijun Date: Fri, 11 Aug 2017 05:26:13 +0000 Subject: [PATCH] refine unittest --- paddle/operators/math/math_function.cc | 24 ++---------------------- paddle/operators/math/math_function.cu | 23 ++--------------------- 2 files changed, 4 insertions(+), 43 deletions(-) diff --git a/paddle/operators/math/math_function.cc b/paddle/operators/math/math_function.cc index fa4c298fe..e5eefedde 100644 --- a/paddle/operators/math/math_function.cc +++ b/paddle/operators/math/math_function.cc @@ -60,16 +60,6 @@ void matmul(const framework::Tensor& in1, bool in1_T, in1_dim.size() == 2 && in2_dim.size() == 2 && out_dim.size() == 2, "The input and output of matmul be matrix"); - if (!in1_T && !in2_T) { - PADDLE_ENFORCE(in1_dim[1] == in2_dim[0]); - } else if (in1_T && !in2_T) { - PADDLE_ENFORCE(in1_dim[0] == in2_dim[0]); - } else if (!in1_T && in2_T) { - PADDLE_ENFORCE(in1_dim[1] == in2_dim[0]); - } else { - PADDLE_ENFORCE(in1_dim[0] == in2_dim[1]); - } - PADDLE_ENFORCE(platform::is_cpu_place(in1.place()) && platform::is_cpu_place(in2.place()) && platform::is_cpu_place(out->place()), @@ -77,7 +67,7 @@ void matmul(const framework::Tensor& in1, bool in1_T, int M = out_dim[0]; int N = out_dim[1]; - int K = in1_dim[1]; + int K = (in1_T == false) ? in1_dim[1] : in1_dim[0]; CBLAS_TRANSPOSE in1_Trans = (in1_T == false) ? CblasNoTrans : CblasTrans; CBLAS_TRANSPOSE in2_Trans = (in2_T == false) ? CblasNoTrans : CblasTrans; @@ -100,16 +90,6 @@ void matmul(const framework::Tensor& in1, PADDLE_ENFORCE( in1_dim.size() == 2 && in2_dim.size() == 2 && out_dim.size() == 2, "The input and output of matmul be matrix"); - if (!in1_T && !in2_T) { - PADDLE_ENFORCE(in1_dim[1] == in2_dim[0]); - } else if (in1_T && !in2_T) { - PADDLE_ENFORCE(in1_dim[0] == in2_dim[0]); - } else if (!in1_T && in2_T) { - PADDLE_ENFORCE(in1_dim[1] == in2_dim[0]); - } else { - PADDLE_ENFORCE(in1_dim[0] == in2_dim[1]); - } - PADDLE_ENFORCE(platform::is_cpu_place(in1.place()) && platform::is_cpu_place(in2.place()) && platform::is_cpu_place(out->place()), @@ -117,7 +97,7 @@ void matmul(const framework::Tensor& in1, int M = out_dim[0]; int N = out_dim[1]; - int K = in1_dim[1]; + int K = (in1_T == false) ? in1_dim[1] : in1_dim[0]; CBLAS_TRANSPOSE in1_Trans = (in1_T == false) ? CblasNoTrans : CblasTrans; CBLAS_TRANSPOSE in2_Trans = (in2_T == false) ? CblasNoTrans : CblasTrans; diff --git a/paddle/operators/math/math_function.cu b/paddle/operators/math/math_function.cu index d2c8aec54..ff02c6ad7 100644 --- a/paddle/operators/math/math_function.cu +++ b/paddle/operators/math/math_function.cu @@ -71,15 +71,6 @@ void matmul(const framework::Tensor& in1, bool in1_T, PADDLE_ENFORCE( in1_dim.size() == 2 && in2_dim.size() == 2 && out_dim.size() == 2, "The input and output of matmul be matrix"); - if (!in1_T && !in2_T) { - PADDLE_ENFORCE(in1_dim[1] == in2_dim[0]); - } else if (in1_T && !in2_T) { - PADDLE_ENFORCE(in1_dim[0] == in2_dim[0]); - } else if (!in1_T && in2_T) { - PADDLE_ENFORCE(in1_dim[1] == in2_dim[0]); - } else { - PADDLE_ENFORCE(in1_dim[0] == in2_dim[1]); - } PADDLE_ENFORCE(platform::is_gpu_place(in1.place()) && platform::is_gpu_place(in2.place()) && @@ -88,7 +79,7 @@ void matmul(const framework::Tensor& in1, bool in1_T, int M = out_dim[0]; int N = out_dim[1]; - int K = in1_dim[1]; + int K = (in1_T == false) ? in1_dim[1] : in1_dim[0]; CBLAS_TRANSPOSE in1_Trans = (in1_T == false) ? CblasNoTrans : CblasTrans; CBLAS_TRANSPOSE in2_Trans = (in2_T == false) ? CblasNoTrans : CblasTrans; @@ -111,16 +102,6 @@ void matmul(const framework::Tensor& in1, PADDLE_ENFORCE( in1_dim.size() == 2 && in2_dim.size() == 2 && out_dim.size() == 2, "The input and output of matmul be matrix"); - if (!in1_T && !in2_T) { - PADDLE_ENFORCE(in1_dim[1] == in2_dim[0]); - } else if (in1_T && !in2_T) { - PADDLE_ENFORCE(in1_dim[0] == in2_dim[0]); - } else if (!in1_T && in2_T) { - PADDLE_ENFORCE(in1_dim[1] == in2_dim[0]); - } else { - PADDLE_ENFORCE(in1_dim[0] == in2_dim[1]); - } - PADDLE_ENFORCE(platform::is_gpu_place(in1.place()) && platform::is_gpu_place(in2.place()) && platform::is_gpu_place(out->place()), @@ -128,7 +109,7 @@ void matmul(const framework::Tensor& in1, int M = out_dim[0]; int N = out_dim[1]; - int K = in1_dim[1]; + int K = (in1_T == false) ? in1_dim[1] : in1_dim[0]; CBLAS_TRANSPOSE in1_Trans = (in1_T == false) ? CblasNoTrans : CblasTrans; CBLAS_TRANSPOSE in2_Trans = (in2_T == false) ? CblasNoTrans : CblasTrans; -- GitLab