Best Python code snippet using locust
math_ops_linspace_test.py
Source:math_ops_linspace_test.py
1# Copyright 2020 The TensorFlow Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Tests for tensorflow.ops.math_ops.linspace."""16from __future__ import absolute_import17from __future__ import division18from __future__ import print_function19# Using distutils.version.LooseVersion was resulting in an error, so importing20# directly.21from distutils.version import LooseVersion # pylint: disable=g-importing-member22from absl.testing import parameterized23import numpy as np24from tensorflow.python.framework import test_util25from tensorflow.python.ops import math_ops26from tensorflow.python.platform import googletest27@test_util.run_all_in_graph_and_eager_modes28class LinspaceTest(test_util.TensorFlowTestCase, parameterized.TestCase):29 # pylint: disable=g-complex-comprehension30 @parameterized.parameters([31 {32 "start_shape": start_shape,33 "stop_shape": stop_shape,34 "dtype": dtype,35 "num": num36 }37 for start_shape in [(), (2,), (2, 2)]38 for stop_shape in [(), (2,), (2, 2)]39 for dtype in [np.float64, np.int64]40 for num in [0, 1, 2, 20]41 ])42 # pylint: enable=g-complex-comprehension43 def testLinspaceBroadcasts(self, start_shape, stop_shape, dtype, num):44 if LooseVersion(np.version.version) < LooseVersion("1.16.0"):45 self.skipTest("numpy doesn't support axes before version 1.16.0")46 ndims = max(len(start_shape), len(stop_shape))47 for axis in range(-ndims, ndims):48 start = np.ones(start_shape, dtype)49 stop = 10 * np.ones(stop_shape, dtype)50 np_ans = np.linspace(start, stop, num, axis=axis)51 tf_ans = self.evaluate(52 math_ops.linspace_nd(start, stop, num, axis=axis))53 self.assertAllClose(np_ans, tf_ans)54if __name__ == "__main__":...
math_ops_linspace_test.py.transformed.py
Source:math_ops_linspace_test.py.transformed.py
1from absl.testing import parameterized2import numpy as np3from tensorflow.python.framework import test_util4from tensorflow.python.ops import math_ops5from tensorflow.python.platform import googletest6@test_util.run_all_in_graph_and_eager_modes7class LinspaceTest(test_util.TensorFlowTestCase, parameterized.TestCase):8 @parameterized.parameters([9 {10 "start_shape": start_shape,11 "stop_shape": stop_shape,12 "dtype": dtype,13 "num": num14 }15 for start_shape in [(), (2,), (2, 2)]16 for stop_shape in [(), (2,), (2, 2)]17 for dtype in [np.float64, np.int64]18 for num in [0, 1, 2, 20]19 ])20 def testLinspaceBroadcasts(self, start_shape, stop_shape, dtype, num):21 if LooseVersion(np.version.version) < LooseVersion("1.16.0"):22 self.skipTest("numpy doesn't support axes before version 1.16.0")23 ndims = max(len(start_shape), len(stop_shape))24 for axis in range(-ndims, ndims):25 start = np.ones(start_shape, dtype)26 stop = 10 * np.ones(stop_shape, dtype)27 np_ans = np.linspace(start, stop, num, axis=axis)28 tf_ans = self.evaluate(29 math_ops.linspace_nd(start, stop, num, axis=axis))30 self.assertAllClose(np_ans, tf_ans)31if __name__ == "__main__":...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!