Best Python code snippet using slash
mpgen_catalog.py
Source:mpgen_catalog.py
...75 Sets is_checkable_kernel in the MP template header76 """77 self.is_checkable_kernel = 078def kprobes(config):79 if ( config.is_parameter('CONFIG_FTRACE', 'y')80 or config.is_parameter('CONFIG_KPROBES', 'y')) :81 return True82 else :83 return False84def errata(config):85 if ( config.is_parameter('CONFIG_ARM64_ERRATUM_826319', 'y')86 or config.is_parameter('CONFIG_ARM64_ERRATUM_827319', 'y')87 or config.is_parameter('CONFIG_ARM64_ERRATUM_824069', 'y')88 or config.is_parameter('CONFIG_ARM64_ERRATUM_819472', 'y')89 or config.is_parameter('CONFIG_ARM64_ERRATUM_832075', 'y')90 or config.is_parameter('CONFIG_ARM64_ERRATUM_845719', 'y')91 or config.is_parameter('CONFIG_ARM64_ERRATUM_843419', 'y')92 or config.is_parameter('CONFIG_CAVIUM_ERRATUM_22375', 'y')93 or config.is_parameter('CONFIG_CAVIUM_ERRATUM_23154', 'y')94 or config.is_parameter('CONFIG_CAVIUM_ERRATUM_27456', 'y')95 or config.is_parameter('CONFIG_QCOM_QDF2400_ERRATUM_0065', 'y')) :96 return True97 else : return False98def get_catalog(config):99 cat = Catalog()100 # TEST CATALOG101 # For production catalog contact Qualcomm Technologies, Inc.102 if 1 == 0 :103 cat.ro_section('populate_all_ro_sections')104 else :105 if (kprobes(config)):106 cat.mark_kernel_non_checkable()107 cat.mp_warning('report is not trusted due to kprobes or tracing')108 cat.ro_section('.head.text', attrs = 'MP_SECTION_ATTRIBUTE_NQHEE | MP_SECTION_ATTRIBUTE_NONSTRICT')109 ...
parameter_api.py
Source:parameter_api.py
1import logging2import nginx3from datetime import datetime, timedelta4from api.base import BaseAPI5from uuid import uuid46from core.settings_utils import settings7from models import Parameter, ApiErrorCode, ApiParameter, Category, Function, SiteParameter, EventParameter, HttpParameter, LocationParameter, ParameterOptionsField, ParameterVariable, ParameterType, ServerParameter, UpstreamParameter8from mongoengine.queryset.visitor import Q9logger = logging.getLogger(__name__)10model_map = {11 'category': {12 "model": Category13 },14 'function': {15 "model": Function16 },17 'parameter_type': {18 "model": ParameterType19 },20 'parameter': {21 "model": Parameter22 },23 'api_parameter': {24 "model": ApiParameter,25 "is_parameter": True # æ¯å¦å±äºå¼ç¨å±æ§26 },27 'site_parameter': {28 "model": SiteParameter,29 "is_parameter": True30 },31 'event_parameter': {32 "model": EventParameter,33 "is_parameter": True34 },35 'http_parameter': {36 "model": HttpParameter,37 "is_parameter": True38 },39 'location_parameter': {40 "model": LocationParameter,41 "is_parameter": True42 },43 'parameter_variable': {44 "model": ParameterVariable,45 },46 'server_parameter': {47 "model": ServerParameter,48 "is_parameter": True49 },50 'upstream_parameter': {51 "model": UpstreamParameter,52 "is_parameter": True53 }54}55class ListAPI(BaseAPI):56 def parse_url_args(self, args, kwargs):57 self.modelCls = model_map[args[0]]['model']58 self.is_parameter = model_map[args[0]].get('is_parameter', False)59 def api(self, params):60 print(params)61 page = params.get("page", 1)62 pagesize = params.get("pagesize", 10)63 query_args = Q(is_enable=True) 64 keyword = params.get("keyword", "")65 if keyword:66 query_args = query_args & Q(key__contains=params.keyword)67 count, total_page, records = self.modelCls.paginate(page, pagesize, query_args)68 data = []69 records = records.order_by('id')70 for item in records:71 item_dct = item.to_dict()72 data.append(item_dct)73 if self.is_parameter is True:74 for item in data:75 parameter = Parameter.get_first(key=item['key'], is_enable=True)76 if parameter:77 item['_parameter'] = parameter.to_dict()78 pageData = {79 'data': data,80 'total': count,81 'total_page': total_page,82 'pagesize': pagesize,83 'page': page84 }85 pageData['keyword'] = keyword86 return pageData87class GetAPI(BaseAPI):88 def parse_url_args(self, args, kwargs):89 self.modelCls = model_map[args[0]]['model']90 self.is_parameter = model_map[args[0]].get('is_parameter', False)91 def api(self, params):92 entity = None93 parameter = None94 if params.get('id'):95 entity = self.modelCls.get_first(id=params.id, is_enable=True)96 elif params.get('key'):97 entity = self.modelCls.get_first(key=params.key, is_enable=True)98 else:99 self.fail(code=-1, message='id_or_key_required')100 return101 if not entity:102 self.fail(code=-1, message='entity_not_found')103 return104 if self.is_parameter is True:105 parameter = Parameter.get_first(key=entity.key, is_enable=True)106 data = {107 "entity": entity.to_dict(),108 }109 if parameter is not None:110 data.update(_parameter=parameter)111 return data112fields_exclude = ['id', '_cls', 'is_import', 'is_enable', 'create_at', 'update_at', 'status']113class CreateAPI(BaseAPI):114 def parse_url_args(self, args, kwargs):115 self.modelCls = model_map[args[0]]['model']116 self.is_parameter = model_map[args[0]].get('is_parameter', False)117 def api(self, params):118 now = datetime.now()119 fields = {120 "update_at": now,121 "create_at": now122 }123 for field in self.modelCls._fields.keys():124 if field not in fields_exclude:125 fields[field] = params.entity.get(field, '')126 entity = self.modelCls(**fields)127 entity.save()128 return {129 "entity": entity.to_dict()130 }131class UpdateAPI(BaseAPI):132 def parse_url_args(self, args, kwargs):133 self.modelCls = model_map[args[0]]['model']134 self.is_parameter = model_map[args[0]].get('is_parameter', False)135 def api(self, params):136 print(params)137 now = datetime.now()138 entity = None139 if params.get('id'):140 entity = self.modelCls.get_first(id=params.id, is_enable=True)141 elif params.get('key'):142 entity = self.modelCls.get_first(key=params.key, is_enable=True)143 else:144 self.fail(code=-1, message='id_or_key_required')145 return146 if not entity:147 self.fail(code=-1, message='entity_not_found')148 return149 150 for field in dict(params.entity).keys():151 if field not in fields_exclude:152 if field != 'options':153 value = params.entity.get(field, '')154 else:155 print('****')156 print(value)157 value = params.entity.get(field, [])158 value = [ParameterOptionsField(**v.to_dict()) for v in value]159 setattr(entity, field, value)160 entity.update_at = now161 entity.save()162 return {163 "entity": entity.to_dict()164 }165class DeleteAPI(BaseAPI):166 def parse_url_args(self, args, kwargs):167 self.modelCls = model_map[args[0]]['model']168 self.is_parameter = model_map[args[0]].get('is_parameter', False)169 def api(self, params):170 now = datetime.now()171 entity = None172 if params.get('id'):173 entity = self.modelCls.get_first(id=params.id, is_enable=True)174 elif params.get('key'):175 entity = self.modelCls.get_first(key=params.key, is_enable=True)176 else:177 self.fail(code=-1, message='id_or_key_required')178 return179 entity.update_at = now180 entity.is_enable = False181 entity.save()182 return {183 "id": str(entity.id)...
gru.py
Source:gru.py
1import numpy as np2from mytorch import tensor3from mytorch.tensor import Tensor4from mytorch.nn.module import Module5from mytorch.nn.activations import Tanh, ReLU, Sigmoid6from mytorch.nn.util import PackedSequence, pack_sequence, unpack_sequence7from mytorch.nn.rnn import TimeIterator8class GRUUnit(Module):9 """10 This class defines a single GRU Unit block.11 12 NOTE: *args is placed just to ignore the nonlinearity parameter that it recevies from GRU module as GRUs have fixed set of activation functions that are called unlike RNNs. Given we will be using the same rnn.TimeIterator class to construct GRU we need to ignore the nonlinearity parameter. 13 Args:14 input_size (int): # features in each timestep15 hidden_size (int): # features generated by the GRUUnit at each timestep16 """17 def __init__(self, input_size, hidden_size, *args, **kwargs):18 super(GRUUnit, self).__init__()19 # Initializing parameters20 self.weight_ir = Tensor(21 np.random.randn(hidden_size, input_size),22 requires_grad=True,23 is_parameter=True,24 )25 self.bias_ir = Tensor(26 np.zeros(hidden_size), requires_grad=True, is_parameter=True27 )28 self.weight_iz = Tensor(29 np.random.randn(hidden_size, input_size),30 requires_grad=True,31 is_parameter=True,32 )33 self.bias_iz = Tensor(34 np.zeros(hidden_size), requires_grad=True, is_parameter=True35 )36 self.weight_in = Tensor(37 np.random.randn(hidden_size, input_size),38 requires_grad=True,39 is_parameter=True,40 )41 self.bias_in = Tensor(42 np.zeros(hidden_size), requires_grad=True, is_parameter=True43 )44 self.weight_hr = Tensor(45 np.random.randn(hidden_size, hidden_size),46 requires_grad=True,47 is_parameter=True,48 )49 self.bias_hr = Tensor(50 np.zeros(hidden_size), requires_grad=True, is_parameter=True51 )52 self.weight_hz = Tensor(53 np.random.randn(hidden_size, hidden_size),54 requires_grad=True,55 is_parameter=True,56 )57 self.bias_hz = Tensor(58 np.zeros(hidden_size), requires_grad=True, is_parameter=True59 )60 self.weight_hn = Tensor(61 np.random.randn(hidden_size, hidden_size),62 requires_grad=True,63 is_parameter=True,64 )65 self.bias_hn = Tensor(66 np.zeros(hidden_size), requires_grad=True, is_parameter=True67 )68 self.hidden_size = hidden_size69 def __call__(self, input, hidden=None):70 return self.forward(input, hidden)71 def forward(self, input: Tensor, hidden=None):72 """73 Args:74 input (Tensor): (effective_batch_size,input_size)75 hidden (Tensor,None): (effective_batch_size,hidden_size)76 Return:77 Tensor: (effective_batch_size,hidden_size)78 """79 # TODO: INSTRUCTIONS80 # Perform matrix operations to construct the intermediary value from input and hidden tensors81 # Remeber to handle the case when hidden = None. Construct a tensor of appropriate size, filled with 0s to use as the hidden.82 if not hidden:83 hidden_shape = (input.shape[0], self.hidden_size)84 hidden = Tensor(85 np.zeros(hidden_shape), requires_grad=True, is_parameter=True,86 )87 self.sigmoid = Sigmoid()88 self.tanh = Tanh()89 r_t = self.sigmoid(90 (input @ self.weight_ir.T())91 + self.bias_ir92 + (hidden @ self.weight_hr.T())93 + self.bias_hr94 )95 z_t = self.sigmoid(96 (input @ self.weight_iz.T())97 + self.bias_iz98 + (hidden @ self.weight_hz.T())99 + self.bias_hz100 )101 n_t = self.tanh(102 (input @ self.weight_in.T())103 + self.bias_in104 + (r_t * ((hidden @ self.weight_hn.T()) + self.bias_hn))105 )106 one = Tensor(1, requires_grad=True, is_parameter=True,)107 h_t = (one - z_t) * n_t + (z_t * hidden)108 return h_t109class GRU(TimeIterator):110 """111 Child class for TimeIterator which appropriately initializes the parent class to construct an GRU.112 Args:113 input_size (int): # features in each timestep114 hidden_size (int): # features generated by the GRUUnit at each timestep115 """116 def __init__(self, input_size, hidden_size):117 super(GRU, self).__init__(118 basic_unit=GRUUnit, input_size=input_size, hidden_size=hidden_size,...
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!!