How to use partial_sort method in hypothesis

Best Python code snippet using hypothesis

sim_synth.py

Source:sim_synth.py Github

copy

Full Screen

1#!/usr/bin/python2import sys3import os4# 4x4, uniform random5workload_dir = "../../bin/workload_list/"6workload = "workloads_null"7traffic = 'uniform_random' # [bit_complement, transpose, uniform_random]8synth_rate_set = [0.01, 0.02, 0.05, 0.1, 0.15, 0.20, 0.25, 0.30, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9]9synthPattern = "UR"10router_maxPacketSize = "4"11network_nrX = "4"12network_nrY = "4"13subnet_sel_rand = "false" #False: inject to subnet with lower load; True: randomly select a subnet14uniform_size = "1" # in packet; # of flits will be determined by the number of subnets15sub_net = "1"16uniform_size_enable = "false" # assume 50% of control + 50% of data17num_bypass = "1"18meshEjectTrial = "1"19partial_sort = "true"20def run():21 HEADER="\n\22#########################################################################\n\23########################### New Simulation #########################\n\24#########################################################################\n"25 if not os.path.exists(out_dir):26 os.makedirs(out_dir)27 for sim_index in range(0, len(synth_rate_set)):28# print HEADER29 synth_rate = str(synth_rate_set[sim_index])30 out_file = out_dir + synth_rate + ".out"31 command_line = "mono ../../bin/sim.exe -output " + out_file + " -workload " + workload_dir + workload + ' 1' + " -router.algorithm " + router_algorithm + " -router.addrPacketSize " + router_addrPacketSize + " -router.dataPacketSize " + router_dataPacketSize + " -router.maxPacketSize " + router_maxPacketSize + " -network_nrX " + network_nrX + " -network_nrY " + network_nrY + " -topology " + topology + " -synth_rate " + synth_rate + ' -sub_net ' + sub_net + ' -subnet_sel_rand ' + subnet_sel_rand + " -uniform_size_enable " + uniform_size_enable + " -uniform_size " + uniform_size + " -synthPattern " + synthPattern + " -meshEjectTrial " + meshEjectTrial + " -num_bypass " + num_bypass + " -partial_sort " + partial_sort32# print command_line33 os.system (command_line)34"""35Test 136Motivate the benefit of using a wider channel37 - control flit = 128b38 - data flit = 512b39 - synth_rate: sweep40 - channel size = 128b, 256b, 512b41 emulate by changing data size to 512b, 256b, and 128b (4, 2, and 1 control flit)42 - Assume 50% of control + 50% of data43 Conclusion: wider channels provide more bandwidth which dramatically speed up the packet delivery.44 Problem: channel will be underutilized when transferring control flit.45"""46router_algorithm = "BLESS_BYPASS"47topology = "Mesh_Multi"48router_addrPacketSize = "1"49channel_size_dict = {'128b':'4', '256b':'2', '512b':'1',}50for channel_width, router_dataPacketSize in channel_size_dict.items():51 out_dir = "./results/DeC/channel_width/"+channel_width+"/"52 run()53"""54Test 255Prove using a multiple network can better utilize the channel56 - control flit = 128b57 - data flit = 512b58 - synth_rate: sweep59 Curve 1: channel size = 256b60 - sub_net = 1, data flit size = 261 - sub_net = 2, data flit size = 262 - sub_net = 4, data flit size = 263 - BLESS, data flit size = 264 - minbd, data flit size = 265 Curve 2: channel size = 512b66 - sub_net = 1, data flit size = 167 - sub_net = 2, data flit size = 168 - sub_net = 4, data flit size = 169 - BLESS, data flit size = 170 - minbd, data flit size = 171 72"""73router_algorithm = "BLESS_BYPASS"74topology = "Mesh_Multi"75router_addrPacketSize = "1"76router_dataPacketSize = "2"77channel_size = "256b"78sub_net_array = ["1", "2", "4"]79for sub_net in sub_net_array:80 out_dir = "./results/DeC/multi_subnet/chnlwidth256b/"+sub_net+"/"81 run()82router_algorithm = "DR_FLIT_SWITCHED_OLDEST_FIRST"83topology = "Mesh"84partial_sort = "false"85sub_net = "1" # Aggregated link width = 512b86out_dir = "./results/DeC/multi_subnet/chnlwidth256b/bless/"87run()88router_algorithm = "Router_MinBD"89topology = "Mesh"90sub_net = "1" # Aggregated link width = 512b91num_bypass = "0"92meshEjectTrial = "1"93partial_sort = "true"94out_dir = "./results/DeC/multi_subnet/chnlwidth256b/minbd/"95run()96router_algorithm = "BLESS_BYPASS"97topology = "Mesh_Multi"98router_addrPacketSize = "1"99router_dataPacketSize = "1"100channel_size = "512b"101synth_rate_set = [0.01, 0.02, 0.05, 0.1, 0.15, 0.20, 0.25, 0.30, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 1.0, 1.1, 1.2, 1.3]102sub_net_array = ["1", "2", "4"]103for sub_net in sub_net_array:104 out_dir = "./results/DeC/multi_subnet/chnlwidth512b/"+sub_net+"/"105 run()106router_algorithm = "DR_FLIT_SWITCHED_OLDEST_FIRST"107topology = "Mesh"108partial_sort = "false"109sub_net = "1" # Aggregated link width = 512b110out_dir = "./results/DeC/multi_subnet/chnlwidth512b/bless/"111run()112router_algorithm = "Router_MinBD"113topology = "Mesh"114sub_net = "1" # Aggregated link width = 512b115num_bypass = "0"116meshEjectTrial = "1"117partial_sort = "true"118out_dir = "./results/DeC/multi_subnet/chnlwidth512b/minbd/"119run()120"""121Test 3122Using DeC with 1 subnet to compare with minBD and BLESS123assume the same channel width and same flit size124"""125uniform_size_enable = "true" 126# Test 3.1: DeC with 1 subnet127router_algorithm = "BLESS_BYPASS"128topology = "Mesh_Multi"129sub_net = "1" 130out_dir = "./results/router_cmp/DeC/"131run()132# Test 3.2: BLESS synth_rate_set = [0.01, 0.02, 0.05, 0.1, 0.15, 0.20, 0.25, 0.30, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7]133router_algorithm = "DR_FLIT_SWITCHED_OLDEST_FIRST"134topology = "Mesh"135partial_sort = "false"136sub_net = "1" # Aggregated link width = 512b137out_dir = "./results/router_cmp/bless/"138run()139# Test 3.3: minbd140synth_rate_set = [0.01, 0.02, 0.05, 0.1, 0.15, 0.20, 0.25, 0.30, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7]141router_algorithm = "Router_MinBD"142topology = "Mesh"143sub_net = "1" # Aggregated link width = 512b144num_bypass = "0"145meshEjectTrial = "1"146partial_sort = "true"147out_dir = "./results/router_cmp/minbd/"...

Full Screen

Full Screen

ps_logic.py

Source:ps_logic.py Github

copy

Full Screen

...19 i = len(arr) // 2 - 120 while i >= 0:21 min_heapify(arr, i, len(arr))22 i -= 123def partial_sort(arr, k):24 if k == 0:25 return []26 build_heap(arr)27 k_rest = k28 result = []29 i = len(arr) - 130 while i >= 0 and k_rest > 0:31 result.append(arr[0])32 arr[0] = arr[i]33 min_heapify(arr, 0, i)34 i -= 135 k_rest -= 136 return result37if __name__ == "__main__":38 import unittest39 class PartialSortTestCase(unittest.TestCase):40 def test_one_element_take_zero(self):41 arr = [6]42 model = []43 result = partial_sort(arr, 0)44 self.assertSequenceEqual(result, model)45 def test_one_element_take_one(self):46 arr = [6]47 model = [6]48 result = partial_sort(arr, 1)49 self.assertSequenceEqual(result, model)50 def test_sorted_array(self):51 arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]52 model = [1, 2, 3, 4]53 result = partial_sort(arr, 4)54 self.assertSequenceEqual(result, model)55 def test_reverse_sorted_array(self):56 arr = [8, 7, 6, 5, 4, 3, 2, 1]57 model = [1, 2, 3, 4]58 result = partial_sort(arr, 4)59 self.assertSequenceEqual(result, model)60 def test_mixed(self):61 arr = [-12, 2, 1, 3, 4, 5, 6, 7, 8, 100, 0]62 model = [-12, 0, 1, 2]63 result = partial_sort(arr, 4)64 self.assertSequenceEqual(result, model)...

Full Screen

Full Screen

next_permutation.py

Source:next_permutation.py Github

copy

Full Screen

...14 if nums[i] > nums[most_left] and nums[i] < min_num:15 min_num = nums[i]16 min_index = i17 nums[min_index], nums[most_left] = nums[most_left], nums[min_index]18 self.partial_sort(nums, most_left + 1, len(nums) - 1)19 20 def partial_sort(self, nums, min_index, max_index):21 if min_index >= max_index:22 return23 24 r = nums[max_index]25 bound = min_index26 for i in range(min_index, max_index):27 if nums[i] < r:28 nums[i], nums[bound] = nums[bound], nums[i]29 bound += 130 nums[bound], nums[max_index] = nums[max_index], nums[bound]31 self.partial_sort(nums, min_index, bound - 1)32 self.partial_sort(nums, bound + 1, max_index)33class Solution2:34 def nextPermutation(self, nums):35 most_left = len(nums) - 136 while most_left > 0 and nums[most_left] <= nums[most_left - 1]:37 most_left -= 138 most_left -= 139 if most_left < 0:40 nums.sort()41 return42 min_num = float('inf')43 min_index = -144 for i in range(most_left + 1, len(nums)):45 if nums[i] > nums[most_left] and nums[i] <= min_num:46 min_num = nums[i]...

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 hypothesis 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