Best Python code snippet using unittest-xml-reporting_python
conditional_scale_test.py
Source:conditional_scale_test.py
1"""ConditionalScale Tests."""2# Dependency imports3from absl.testing import parameterized4import numpy as np5import tensorflow.compat.v2 as tf6from softlearning.distributions import bijectors7from softlearning.internal import test_util8@test_util.test_all_tf_execution_regimes9class ScaleBijectorTest(test_util.TestCase, parameterized.TestCase):10 """Tests correctness of the Y = scale @ x transformation."""11 def testName(self):12 bijector = bijectors.ConditionalScale()13 self.assertStartsWith(bijector.name, 'conditional_scale')14 @parameterized.named_parameters(15 dict(testcase_name='static_float32', is_static=True, dtype=np.float32),16 dict(testcase_name='static_float64', is_static=True, dtype=np.float64),17 dict(testcase_name='dynamic_float32', is_static=False, dtype=np.float32),18 dict(testcase_name='dynamic_float64', is_static=False, dtype=np.float64),19 )20 def testNoBatchScale(self, is_static, dtype):21 scale = dtype(2.0)22 bijector = bijectors.ConditionalScale(dtype=dtype)23 x = self.maybe_static(np.array([1., 2, 3], dtype), is_static)24 self.assertAllClose([2., 4, 6], bijector.forward(x, scale=scale))25 self.assertAllClose([.5, 1, 1.5], bijector.inverse(x, scale=scale))26 self.assertAllClose(27 -np.log(2.),28 bijector.inverse_log_det_jacobian(x, scale=scale, event_ndims=0))29 @parameterized.named_parameters(30 dict(testcase_name='static_float32', is_static=True, dtype=np.float32),31 dict(testcase_name='static_float64', is_static=True, dtype=np.float64),32 dict(testcase_name='dynamic_float32', is_static=False, dtype=np.float32),33 dict(testcase_name='dynamic_float64', is_static=False, dtype=np.float64),34 )35 def testBatchScale(self, is_static, dtype):36 # Batched scale37 scale = tf.constant([2., 3.], dtype=dtype)38 bijector = bijectors.ConditionalScale(dtype=dtype)39 x = self.maybe_static(np.array([1.], dtype=dtype), is_static)40 self.assertAllClose([2., 3.], bijector.forward(x, scale=scale))41 self.assertAllClose([0.5, 1./3.], bijector.inverse(x, scale=scale))42 self.assertAllClose(43 [-np.log(2.), -np.log(3.)],44 bijector.inverse_log_det_jacobian(x, scale=scale, event_ndims=0))45if __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!!