How to use forward_list method in ATX

Best Python code snippet using ATX

mec_power.py

Source:mec_power.py Github

copy

Full Screen

...221 def caculate_capacity(self, available_mec_id, capacity):222 usage = self.caculate_usage(available_mec_id)223 usage += capacity224 return usage225 def caculate_forward_list(self, mec_list, mec_type):226 total_capacity = 0227 total_available_usage = 0228 pm_id = 0229 print "available mec is not enough, add mec from cold mec"230 if mec_type == "cold":231 self.find_available_mec_list(0.1)232 else:233 self.find_available_mec_list(1.0)234 print "new available mec list=", self.available_mec_list235 forward_list = {}236 for mec_id in mec_list:237 forward_list[mec_id] = {}238 capacity = self.caculate_usage(mec_id)239 if mec_type != "cold":240 capacity = self.caculate_usage(mec_id)241 available_mec_id = self.find_neast_mec(mec_id, 0)242 print mec_id, capacity, available_mec_id243 if available_mec_id == -1:244 continue245 usage = self.pm_usage_list[available_mec_id][pm_id]246 remaind_usage = UP_BOUND1 - usage247 print "mec_id=", mec_id, "find available_mec=", available_mec_id, usage248 if remaind_usage > 0 and usage < 1:249 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id, mec_type="hot")250 if capacity >= UP_BOUND1:251 available_mec_id = self.find_neast_mec(mec_id, 1)252 if available_mec_id == -1:253 continue254 usage = self.pm_usage_list[available_mec_id][pm_id]255 remaind_usage = UP_BOUND1 - usage256 if remaind_usage > 0 and usage < 1:257 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id, mec_type="hot")258 if capacity >= UP_BOUND1:259 available_mec_id = self.find_neast_mec(mec_id, 2)260 if available_mec_id == -1:261 continue262 usage = self.pm_usage_list[available_mec_id][pm_id]263 remaind_usage = UP_BOUND1 - usage264 if remaind_usage > 0 and usage < 1:265 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id, mec_type="hot")266 if capacity >= UP_BOUND1:267 available_mec_id = self.find_neast_mec(mec_id, 3)268 if available_mec_id == -1:269 continue270 usage = self.pm_usage_list[available_mec_id][pm_id]271 remaind_usage = UP_BOUND1 - usage272 if remaind_usage > 0 and usage < 1:273 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id, mec_type="hot")274 else:275 available_mec_id = self.find_neast_mec(mec_id, 2)276 if available_mec_id == -1:277 continue278 usage = self.pm_usage_list[available_mec_id][pm_id]279 remaind_usage = UP_BOUND1 - usage280 if remaind_usage > 0 and usage < 1:281 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id, mec_type="hot")282 #print mec_id, "forwading 02 ", available_mec_id, usage, remaind_usage, capacity, "==>", self.pm_usage_list[available_mec_id][pm_id], self.pm_usage_list[mec_id][pm_id]283 if capacity >= UP_BOUND1:284 available_mec_id = self.find_neast_mec(mec_id, 3)285 if available_mec_id == -1:286 continue287 usage = self.pm_usage_list[available_mec_id][pm_id]288 remaind_usage = UP_BOUND1 - usage289 if remaind_usage > 0 and usage < 1:290 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id, mec_type="hot")291 #print mec_id, "forwading 04 ", available_mec_id, usage, remaind_usage, capacity, "==>", self.pm_usage_list[available_mec_id][pm_id], self.pm_usage_list[mec_id][pm_id]292 else:293 available_mec_id = self.find_neast_mec(mec_id, 4)294 if available_mec_id == -1:295 continue296 usage = self.pm_usage_list[available_mec_id][pm_id]297 remaind_usage = UP_BOUND1 - usage298 if remaind_usage > 0 and usage < 1:299 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id, mec_type="hot")300 #print mec_id, "forwading 06 ", available_mec_id, usage, remaind_usage, capacity, "==>", self.pm_usage_list[available_mec_id][pm_id], self.pm_usage_list[mec_id][pm_id] 301 else:302 available_mec_id = self.find_neast_mec(mec_id, 1)303 if available_mec_id == -1:304 continue305 usage = self.pm_usage_list[available_mec_id][pm_id]306 remaind_usage = UP_BOUND1 - usage307 if remaind_usage > 0 and usage < 1:308 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id)309 #print mec_id, "forwading 11 ", available_mec_id, usage, remaind_usage, capacity310 if capacity > UP_BOUND1:311 available_mec_id = self.find_neast_mec(mec_id, 2)312 usage = self.pm_usage_list[available_mec_id][pm_id]313 remaind_usage = UP_BOUND1 - usage314 if remaind_usage > 0 and usage < 1:315 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id)316 #print mec_id, "forwading 12 ",available_mec_id, usage, remaind_usage, capacity317 else:318 available_mec_id = self.find_neast_mec(mec_id, 3)319 usage = self.pm_usage_list[available_mec_id][pm_id]320 remaind_usage = UP_BOUND1 - usage321 if remaind_usage > 0 and usage < 1:322 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id)323 #print mec_id, "forwading 13 ",available_mec_id, usage, remaind_usage, capacity324 else:325 available_mec_id = self.find_neast_mec(mec_id, 0)326 if available_mec_id == -1:327 continue328 usage = self.pm_usage_list[available_mec_id][pm_id]329 remaind_usage = UP_BOUND1 - usage330 if remaind_usage > 0 and usage < 1:331 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id)332 #print mec_id, "forwading 21 ", available_mec_id, usage, remaind_usage, capacity, "==>", self.pm_usage_list[available_mec_id][pm_id], self.pm_usage_list[mec_id][pm_id]333 else:334 available_mec_id = self.find_neast_mec(mec_id, 1)335 usage = self.pm_usage_list[available_mec_id][pm_id]336 remaind_usage = UP_BOUND1 - usage337 if remaind_usage > 0 and usage < 1:338 capacity, forward_list = self.caculate_forwarding(available_mec_id, capacity, forward_list, mec_id)339 #print mec_id, "forwading 22 ", available_mec_id, usage, remaind_usage, capacity, "==>", self.pm_usage_list[available_mec_id][pm_id], self.pm_usage_list[mec_id][pm_id]340 for mec_id in mec_list:341 capacity = self.caculate_usage(mec_id)342 if mec_type == "cold":343 if capacity <= LOW_BOUND and capacity > 0:344 print "still cold after forwarding= ",mec_id, capacity345 else:346 if capacity >= UP_BOUND:347 print "still hot after forwarding=", mec_id, capacity348 return forward_list349 def caculate_forwarding(self, available_mec_id, capacity, forward_list, mec_id, mec_type="cold"):350 pm_id = 0351 usage = self.pm_usage_list[available_mec_id][pm_id]352 remaind_usage = UP_BOUND1 - usage353 #print "before===", mec_id, capacity, available_mec_id, usage, remaind_usage354 if capacity > usage:355 if mec_type == "cold":356 move_usage = remaind_usage357 else:358 move_capacity = capacity - UP_BOUND1359 if move_capacity - remaind_usage > 0:360 move_usage = remaind_usage361 362 else:363 move_usage = move_capacity364 else:365 move_usage = capacity366 capacity = 0367 #print "after===", mec_id, capacity, available_mec_id, usage, remaind_usage368 self.pm_usage_list[available_mec_id][pm_id] += move_usage369 self.pm_usage_list[mec_id][pm_id] -= move_usage370 capacity = self.pm_usage_list[mec_id][pm_id]371 usage = self.pm_usage_list[available_mec_id][pm_id]372 if usage > UP_BOUND1:373 self.available_mec_list.remove(available_mec_id)374 forward_list[mec_id][available_mec_id] = move_usage 375 return capacity, forward_list376 377 def caculate_available_mec_capacity(self):378 available_mec_usage_list = {}379 for mec_id in self.available_mec_list:380 usage = self.caculate_usage(mec_id)381 self.available_mec_capacity_list[mec_id] = usage382 #print self.available_mec_capacity_list383 def cold_mec_algorithm(self):384 print ("cold MEC algorithm")385 forward_list = {}386 if not self.cold_mec_list:387 print ("no cold MEC")388 return forward_list389 BOUND = 0.2390 print "available_list=", self.available_mec_list391 if not self.available_mec_list and self.cold_mec_list:392 self.find_available_mec_list(BOUND)393 print "before="394 self.caculate_available_mec_capacity() # renew395 forward_list = self.caculate_forward_list(self.cold_mec_list, mec_type="cold")396 print "after="397 self.caculate_available_mec_capacity()398 return forward_list399 def hot_mec_algorithm(self):400 print("HOT MECAlgorithm")401 forward_list = {}402 if not self.hot_mec_list:403 print("No HOT MEC")404 return forward_list405 print "available_list=", self.available_mec_list406 BOUND = 1.0 407 if (not self.available_mec_list and self.cold_mec_list) or len(self.available_mec_list) <= UP_BOUND*NUM_CELL:408 self.find_available_mec_list(BOUND)409 print "before="410 self.caculate_available_mec_capacity()411 forward_list = self.caculate_forward_list(self.hot_mec_list, mec_type="hot")412 print "after="413 self.caculate_available_mec_capacity()414 return forward_list415 def write_request_delay(self, forward_list):416 self.write_qos_counter = 0417 self.mw_counter = 0418 self.w_counter = 0419 total_delay = 0420 cloud_delay = 0421 pm_id = 0422 for write_request in self.write_request_list:423 if count_interval(write_request.time, self.time) == self.time:424 rate = write_request.rate425 if write_request.rate == 0:...

Full Screen

Full Screen

TestDataFormatterLibcxxForwardList.py

Source:TestDataFormatterLibcxxForwardList.py Github

copy

Full Screen

1"""2Test lldb data formatter subsystem.3"""4from __future__ import print_function5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9class TestDataFormatterLibcxxForwardList(TestBase):10 mydir = TestBase.compute_mydir(__file__)11 def setUp(self):12 TestBase.setUp(self)13 self.line = line_number('main.cpp', '// break here')14 ns = 'ndk' if lldbplatformutil.target_is_android() else ''15 self.namespace = 'std::__' + ns + '1'16 @add_test_categories(["libc++"])17 def test(self):18 """Test that std::forward_list is displayed correctly"""19 self.build()20 lldbutil.run_to_source_breakpoint(self, '// break here',21 lldb.SBFileSpec("main.cpp", False))22 forward_list = self.namespace + '::forward_list'23 self.expect("frame variable empty",24 substrs=[forward_list,25 'size=0',26 '{}'])27 self.expect("frame variable one_elt",28 substrs=[forward_list,29 'size=1',30 '{',31 '[0] = 47',32 '}'])33 self.expect("frame variable five_elts",34 substrs=[forward_list,35 'size=5',36 '{',37 '[0] = 1',38 '[1] = 22',39 '[2] = 333',40 '[3] = 4444',41 '[4] = 55555',...

Full Screen

Full Screen

NNets_utils.py

Source:NNets_utils.py Github

copy

Full Screen

1import torch2if torch.__version__ != '0.4.0':3 raise RuntimeError('PyTorch version must be 0.4.0')4import torch.nn as nn5def apply_linear(inp,out,act,shape=None,std=0.0,drop=0.0,bn=True):6 bias = False if bn else True7 w=nn.Linear(inp,out,bias=bias)8 if bn:9 wBN=nn.BatchNorm1d(out)10 activation=return_activation(act)11 if drop!=0:12 dropl=nn.Dropout(drop)13 if std!=0.0:14 assert shape!=None15 nlayer=add_gaussian(shape,std)16 #define the sequential17 forward_list=[w]18 if bn:19 forward_list.append(wBN)20 if std!=0.0:21 forward_list.append(nlayer)22 forward_list.append(activation)23 if drop!=0:24 forward_list.append(dropl)25 return nn.Sequential(*forward_list)26#class for linear activation27class Linear_act(nn.Module):28 def __init__(self):29 super(Linear_act, self).__init__()30 def forward(self,x):31 return x32def linear(x):33 return x34def return_activation(act,dim=1):35 if act=='relu':36 return nn.ReLU()37 elif act=='linear':38 return Linear_act()39 elif act=='softmax':40 return nn.Softmax(dim)41 elif act=='sigmoid':42 return nn.Sigmoid()43 elif act=='tanh':44 return nn.Tanh()45 else:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful