From dev-return-4979-archive-asf-public=cust-asf.ponee.io@singa.apache.org Wed Apr 8 01:25:39 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 45D93180663 for ; Wed, 8 Apr 2020 03:25:39 +0200 (CEST) Received: (qmail 55141 invoked by uid 500); 8 Apr 2020 01:25:38 -0000 Mailing-List: contact dev-help@singa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@singa.apache.org Delivered-To: mailing list dev@singa.apache.org Received: (qmail 55130 invoked by uid 99); 8 Apr 2020 01:25:38 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Apr 2020 01:25:38 +0000 From: GitBox To: dev@singa.apache.org Subject: [GitHub] [singa] nudles commented on a change in pull request #660: Update test cases for both cpu and gpu Message-ID: <158630913851.20590.1035824300537798887.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Wed, 08 Apr 2020 01:25:38 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit nudles commented on a change in pull request #660: Update test cases for both cpu and gpu URL: https://github.com/apache/singa/pull/660#discussion_r405203811 ########## File path: test/python/test_api.py ########## @@ -201,43 +201,47 @@ def _run_testing(x_0, s_0, b_0, rm_0, rv_0, m_0=0.1): def test_softmax_api(self): - def _run_test(dev, org_shape, axis, aft_shape): - x_0 = np.random.random(org_shape).astype(np.float32) - x_0 = x_0 + 1000 - x0 = tensor.Tensor(device=dev, data=x_0) - - # test with axis - y0 = tensor._call_singa_func(singa_api.SoftMax, x0.data, axis) - - # test with numpy - x_0 = x_0.reshape(aft_shape) - x_0 = x_0 - np.max(x_0) - y1 = np.divide(np.exp(x_0), - np.sum(np.exp(x_0), axis=1).reshape(x_0.shape[0], - 1)) # 2d softmax - y1 = y1.reshape(org_shape) - - np.testing.assert_array_almost_equal(tensor.to_numpy(y0), y1) - - for dev in [gpu_dev, cpu_dev]: - _run_test(dev, [2, 2], 1, [2, 2]) - _run_test(dev, [2, 2], 0, [1, 4]) - _run_test(dev, [2, 2], -1, [2, 2]) - _run_test(dev, [2, 2], -2, [1, 4]) - _run_test(dev, [2, 2, 2], 2, [4, 2]) - _run_test(dev, [2, 2, 2], 1, [2, 4]) - _run_test(dev, [2, 2, 2], 0, [1, 8]) - _run_test(dev, [2, 2, 2], -1, [4, 2]) - _run_test(dev, [2, 2, 2], -2, [2, 4]) - _run_test(dev, [2, 2, 2], -3, [1, 8]) - _run_test(dev, [2, 2, 2, 2], 3, [8, 2]) - _run_test(dev, [2, 2, 2, 2], 2, [4, 4]) - _run_test(dev, [2, 2, 2, 2], 1, [2, 8]) - _run_test(dev, [2, 2, 2, 2], 0, [1, 16]) - _run_test(dev, [2, 2, 2, 2], -1, [8, 2]) - _run_test(dev, [2, 2, 2, 2], -2, [4, 4]) - _run_test(dev, [2, 2, 2, 2], -3, [2, 8]) - _run_test(dev, [2, 2, 2, 2], -4, [1, 16]) + def _helper(dev): + def _run_test(dev, org_shape, axis, aft_shape): + x_0 = np.random.random(org_shape).astype(np.float32) + x_0 = x_0 + 1000 + x0 = tensor.Tensor(device=dev, data=x_0) + + # test with axis + y0 = tensor._call_singa_func(singa_api.SoftMax, x0.data, axis) + + # test with numpy + x_0 = x_0.reshape(aft_shape) + x_0 = x_0 - np.max(x_0) + y1 = np.divide(np.exp(x_0), + np.sum(np.exp(x_0), axis=1).reshape(x_0.shape[0], + 1)) # 2d softmax + y1 = y1.reshape(org_shape) + + np.testing.assert_array_almost_equal(tensor.to_numpy(y0), y1) + + _run_test(dev, [2, 2], 1, [2, 2]) Review comment: indent error? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services