Best Python code snippet using slash
piglit_test_tests.py
Source:piglit_test_tests.py
...65 test = PiglitGLTest(['foo'], run_concurrent=True)66 nt.assert_in('-auto', test.command)67 nt.assert_in('-fbo', test.command)68def test_PiglitGLTest_include_and_exclude():69 """test.piglit_test.PiglitGLTest.is_skip(): raises if include and exclude are given."""70 with nt.assert_raises(AssertionError):71 PiglitGLTest(['foo'],72 require_platforms=['glx'],73 exclude_platforms=['gbm'])74@utils.not_raises(TestIsSkip)75def test_PiglitGLTest_platform_in_require():76 """test.piglit_test.PiglitGLTest.is_skip(): does not skip if platform is in require_platforms"""77 PiglitGLTest.OPTS.env['PIGLIT_PLATFORM'] = 'glx'78 test = PiglitGLTest(['foo'], require_platforms=['glx'])79 test.is_skip()80@nt.raises(TestIsSkip)81def test_PiglitGLTest_platform_not_in_require():82 """test.piglit_test.PiglitGLTest.is_skip(): skips if platform is not in require_platforms"""83 PiglitGLTest.OPTS.env['PIGLIT_PLATFORM'] = 'gbm'84 test = PiglitGLTest(['foo'], require_platforms=['glx'])85 test.is_skip()86@nt.raises(TestIsSkip)87def test_PiglitGLTest_platform_in_exclude():88 """test.piglit_test.PiglitGLTest.is_skip(): skips if platform is in exclude_platforms"""89 PiglitGLTest.OPTS.env['PIGLIT_PLATFORM'] = 'glx'90 test = PiglitGLTest(['foo'], exclude_platforms=['glx'])91 test.is_skip()92@utils.not_raises(TestIsSkip)93def test_PiglitGLTest_platform_not_in_exclude():94 """test.piglit_test.PiglitGLTest.is_skip(): does not skip if platform is in exclude_platforms"""95 PiglitGLTest.OPTS.env['PIGLIT_PLATFORM'] = 'gbm'96 test = PiglitGLTest(['foo'], exclude_platforms=['glx'])...
model.py
Source:model.py
1import torch2import torch.nn as nn3def default_conv(input_channels, out_channels, kernel_size, bias):4 return nn.Conv2d(5 input_channels, out_channels, kernel_size, padding=(kernel_size // 2), bias=bias6 )7class UpConv(nn.Module):8 def __init__(self):9 super(UpConv, self).__init__()10 self.body = nn.Sequential(11 default_conv(3, 12, 3, True),12 nn.PixelShuffle(2),13 nn.ReLU(inplace=True)14 )15 def forward(self, x):16 return self.body(x)17class ResidualBlock(nn.Module):18 def __init__(self, num_features):19 super(ResidualBlock, self).__init__()20 modules_body = [21 default_conv(num_features, num_features, 3, bias=True),22 nn.ReLU(inplace=True),23 default_conv(num_features, num_features, 3, bias=True)24 ]25 self.body = nn.Sequential(*modules_body)26 def forward(self, x):27 res = self.body(x)28 res += x29 return res30class SingleScaleNet(nn.Module):31 def __init__(self, num_features, num_resblocks, is_skip, num_channels=3):32 super(SingleScaleNet, self).__init__()33 self.is_skip = is_skip34 modules_head = [35 default_conv(num_channels, num_features, 5, bias=True),36 nn.ReLU(inplace=True)]37 modules_body = [38 ResidualBlock(num_features)39 for _ in range(num_resblocks)40 ]41 modules_tail = [default_conv(num_features, 3, 5, bias=True)]42 self.head = nn.Sequential(*modules_head)43 self.body = nn.Sequential(*modules_body)44 self.tail = nn.Sequential(*modules_tail)45 def forward(self, x):46 x = self.head(x)47 res = self.body(x)48 if self.is_skip:49 res += x50 res = self.tail(res)51 return res52class MultiScaleNet(nn.Module):53 def __init__(self, num_features, num_resblocks, is_skip):54 super(MultiScaleNet, self).__init__()55 self.scale3_net = SingleScaleNet(num_features, num_resblocks, is_skip, num_channels=3)56 self.upconv3 = UpConv()57 self.scale2_net = SingleScaleNet(num_features, num_resblocks, is_skip, num_channels=6)58 self.upconv2 = UpConv()59 self.scale1_net = SingleScaleNet(num_features, num_resblocks, is_skip, num_channels=6)60 def forward(self, multiscale_input):61 input_b1, input_b2, input_b3 = multiscale_input62 output_l3 = self.scale3_net(input_b3)63 output_l3_up = self.upconv3(output_l3)64 output_l2 = self.scale2_net(torch.cat((input_b2, output_l3_up), 1))65 output_l2_up = self.upconv2(output_l2)66 output_l1 = self.scale2_net(torch.cat((input_b1, output_l2_up), 1))...
roman_to_int.py
Source:roman_to_int.py
1def romanToInt(s):2 """3 :type s: str4 :rtype: int5 """6 dict = {7 'I': 1,8 'V': 5,9 'X': 10,10 'L': 50,11 'C': 100,12 'D': 500,13 'M' : 100014 }15 16 count = 017 18 for i in range(0, len(s)):19 print(i, is_skip)20 if is_skip:21 is_skip = False22 continue23 if i < len(s)-1:24 if s[i]+s[i+1] == 'IV':25 count += 426 is_skip = True27 i+=128 elif s[i]+s[i+1] == 'IX':29 count += 930 is_skip = True31 i+=132 elif s[i]+s[i+1] == 'XL':33 count += 4034 i+=135 is_skip = True36 elif s[i]+s[i+1] == 'XC':37 count += 9038 i+=139 is_skip = True40 elif s[i]+s[i+1] == 'CD':41 count += 40042 i+=143 is_skip = True44 elif s[i]+s[i+1] == 'CM':45 count += 90046 i+=147 is_skip = True48 elif s[i] in dict:49 count += dict[s[i]]50 # print(s[i],count) 51 print(i,count) 52 elif s[i] in dict:53 count += dict[s[i]]54 print(i,count) 55 return count 56print(romanToInt('CIV'))...
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!!