How to use _is_complex_type method in gabbi

Best Python code snippet using gabbi_python

emitter.py

Source:emitter.py Github

copy

Full Screen

...354 raise NotImplementedError("Unsupported 'floor' operand: {x}")355 def _unary_negf(self, x: Value) -> Value:356 if _is_floating_point_type(x.type):357 return arith.NegFOp(x).result358 if _is_complex_type(x.type):359 return complex.NegOp(x).result360 raise NotImplementedError("Unsupported 'negf' operand: {x}")361 def _binary_add(self, lhs: Value, rhs: Value) -> Value:362 if _is_floating_point_type(lhs.type):363 return arith.AddFOp(lhs, rhs).result364 if _is_integer_type(lhs.type) or _is_index_type(lhs.type):365 return arith.AddIOp(lhs, rhs).result366 if _is_complex_type(lhs.type):367 return complex.AddOp(lhs, rhs).result368 raise NotImplementedError("Unsupported 'add' operands: {lhs}, {rhs}")369 def _binary_sub(self, lhs: Value, rhs: Value) -> Value:370 if _is_floating_point_type(lhs.type):371 return arith.SubFOp(lhs, rhs).result372 if _is_integer_type(lhs.type) or _is_index_type(lhs.type):373 return arith.SubIOp(lhs, rhs).result374 if _is_complex_type(lhs.type):375 return complex.SubOp(lhs, rhs).result376 raise NotImplementedError("Unsupported 'sub' operands: {lhs}, {rhs}")377 def _binary_mul(self, lhs: Value, rhs: Value) -> Value:378 if _is_floating_point_type(lhs.type):379 return arith.MulFOp(lhs, rhs).result380 if _is_integer_type(lhs.type) or _is_index_type(lhs.type):381 return arith.MulIOp(lhs, rhs).result382 if _is_complex_type(lhs.type):383 return complex.MulOp(lhs, rhs).result384 raise NotImplementedError("Unsupported 'mul' operands: {lhs}, {rhs}")385 def _binary_max_signed(self, lhs: Value, rhs: Value) -> Value:386 if _is_floating_point_type(lhs.type):387 return arith.MaxFOp(lhs, rhs).result388 if _is_integer_type(lhs.type) or _is_index_type(lhs.type):389 return arith.MaxSIOp(lhs, rhs).result390 raise NotImplementedError("Unsupported 'max' operands: {lhs}, {rhs}")391 def _binary_max_unsigned(self, lhs: Value, rhs: Value) -> Value:392 if _is_floating_point_type(lhs.type):393 return arith.MaxFOp(lhs, rhs).result394 if _is_integer_type(lhs.type) or _is_index_type(lhs.type):395 return arith.MaxUIOp(lhs, rhs).result396 raise NotImplementedError(397 "Unsupported 'max_unsigned' operands: {lhs}, {rhs}")398 def _binary_min_signed(self, lhs: Value, rhs: Value) -> Value:399 if _is_floating_point_type(lhs.type):400 return arith.MinFOp(lhs, rhs).result401 if _is_integer_type(lhs.type) or _is_index_type(lhs.type):402 return arith.MinSIOp(lhs, rhs).result403 raise NotImplementedError("Unsupported 'min' operands: {lhs}, {rhs}")404 def _binary_min_unsigned(self, lhs: Value, rhs: Value) -> Value:405 if _is_floating_point_type(lhs.type):406 return arith.MinFOp(lhs, rhs).result407 if _is_integer_type(lhs.type) or _is_index_type(lhs.type):408 return arith.MinUIOp(lhs, rhs).result409 raise NotImplementedError(410 "Unsupported 'min_unsigned' operands: {lhs}, {rhs}")411def _infer_structured_outs(412 op_config: LinalgStructuredOpConfig,413 in_arg_defs: Sequence[OperandDefConfig], ins: Sequence[Value],414 out_arg_defs: Sequence[OperandDefConfig],415 outs: Union[Sequence[Value], OpResultList]) -> Tuple[ValueList, List[Type]]:416 """Infers implicit outs and output types.417 Respects existing contents of outs if not empty.418 Returns:419 normalized outs, output types420 """421 # If outs were explicitly provided, we accept them verbatim.422 if outs:423 return outs, [out.type for out in outs]424 raise NotImplementedError(f"Output tensor inference not yet supported for "425 "structured ops")426def _get_types_from_values(*values: Value) -> Sequence[Type]:427 types = []428 for v in values:429 types.append(v.type)430 return types431def _get_operand_def_names(*operand_configs: OperandDefConfig) -> Sequence[str]:432 return [odc.operand_def.name for odc in operand_configs]433def _add_type_mapping(operand_config: OperandDefConfig, operand_type: Type,434 type_mapping: Dict[str, Type],435 block_arg_types: Sequence[Type]):436 element_or_self_type = operand_type437 # Get the element type for tensor operands and the type itself for scalars.438 if operand_config.shape_map:439 try:440 element_or_self_type = ShapedType(operand_type).element_type441 except Exception as e:442 raise ValueError(f"Expected ShapedType but got {operand_type}") from e443 name = operand_config.type_var.name444 if name in type_mapping:445 if type_mapping[name] != element_or_self_type:446 raise ValueError(f"Cannot overwrite type mapping {name} = "447 f"{type_mapping[name]} by type {element_or_self_type}")448 type_mapping[name] = element_or_self_type449 block_arg_types.append(element_or_self_type)450def _is_complex_type(t: Type) -> bool:451 return ComplexType.isinstance(t)452def _is_floating_point_type(t: Type) -> bool:453 # TODO: Create a FloatType in the Python API and implement the switch454 # there.455 return (F64Type.isinstance(t) or F32Type.isinstance(t) or456 F16Type.isinstance(t) or BF16Type.isinstance(t))457def _is_integer_type(t: Type) -> bool:458 return IntegerType.isinstance(t)459def _is_index_type(t: Type) -> bool:460 return IndexType.isinstance(t)461def _get_floating_point_width(t: Type) -> int:462 # TODO: Create a FloatType in the Python API and implement the switch463 # there.464 if F64Type.isinstance(t):...

Full Screen

Full Screen

serializer_utils.py

Source:serializer_utils.py Github

copy

Full Screen

...7 self.payload = payload8 self.opts = opts9 def key_for_attribute(self, attribute):10 def transform_callback(acc, value, key):11 if self._is_complex_type(value):12 acc[self.key_for_attribute(key)] = self.key_for_attribute(value)13 else:14 acc[self.key_for_attribute(key)] = value15 return acc, value, key16 def map_function(item):17 if self._is_complex_type(item):18 return self.key_for_attribute(item)19 else:20 return item21 if _.is_dict(attribute):22 return _.transform(attribute, transform_callback)23 elif _.is_list(attribute):24 map(map_function, attribute)25 else:26 if _.is_function(self.opts.get('key_for_attribute')):27 return self.opts['key_for_attribute'](attribute)28 else:29 caserized = inflector.caserize(attribute, self.opts)30 return caserized31 def get_id(self):32 return self.opts.get('id', 'id')33 def _is_complex_type(self, obj):34 return _.is_list(obj) or _.is_dict(obj)35 def get_ref(self, current, item, opts):36 if _.is_function(opts.get('ref')):37 return opts['ref'](current, item)38 elif opts.get('ref') is True:39 if _.is_list(item):40 return map(lambda val: str(val), item)41 elif item:42 return str(item)43 elif isinstance(item, dict) and item.get(opts.get('ref')):44 return str(item[opts['ref']])45 def get_type(self, string, attr_val):46 type_ = None47 attr_val = attr_val or {}48 if _.is_function(self.opts.get('type_for_attribute')):49 type_ = self.opts['type_for_attribute'](string, attr_val)50 if (self.opts.get('pluralize_type') is None or self.opts.get('pluralize_type')) and type_ is None:51 type_ = inflector.pluralize(string)52 if type_ is None:53 type_ = string54 return type_55 def get_links(self, current, links, dest):56 def map_function(item):57 if _.is_function(item):58 return item(self.record, current, dest)59 else:60 return item61 return _.map_values(links, map_function)62 def get_meta(self, current, meta):63 def map_function(item):64 if _.is_function(item):65 return item(self.record, current)66 else:67 return item68 return _.map_values(meta, map_function)69 def pick(self, obj, attributes):70 def map_function(value, key):71 return self.key_for_attribute(key)72 return _.map_keys(_.pick(obj, attributes), map_function)73 def is_compound_document_included(self, included, item):74 return _.find(self.payload.get('included', {}), {75 'id': item.get('id'),76 'type': item.get('type')77 })78 def push_to_included(self, dest, include):79 if not self.is_compound_document_included(dest, include):80 if not dest.get('included'):81 dest['included'] = []82 dest['included'].append(include)83 def serialize(self, dest, current, attribute, opts):84 data = None85 if opts and opts.get('ref'):86 if not dest.get('relationships'):87 dest['relationships'] = {}88 def map_current(item):89 return self.serialize_ref(item, current, attribute, opts)90 if _.is_list(current.get(attribute)):91 data = map(map_current, current[attribute])92 else:93 data = self.serialize_ref(current[attribute], current,94 attribute, opts)95 dest['relationships'][self.key_for_attribute(attribute)] = {}96 if not opts.get('ignore_relationship_data'):97 dest['relationships'][self.key_for_attribute(attribute)]['data'] = data98 if opts.get('relationship_links'):99 dest['relationships'][self.key_for_attribute(attribute)]['links'] = \100 self.get_links(current[attribute], opts['relationship_links'], dest)101 if opts.get('relationship_meta'):102 dest['relationships'][self.key_for_attribute(attribute)]['meta'] = \103 self.get_meta(current['attribute'], opts['relationship_meta'])104 else:105 if _.is_list(current[attribute]):106 if len(current[attribute]) and _.is_dict(current[attribute][0]):107 def map_current(item):108 return self.serialize_nested(item, current, attribute,109 opts)110 data = map(map_current, current[attribute])111 else:112 data = current[attribute]113 dest['attributes'][self.key_for_attribute(attribute)] = data114 elif _.is_dict(current[attribute]):115 data = self.serialize_nested(current[attribute], current,116 attribute, opts)117 dest['attributes'][self.key_for_attribute(attribute)] = data118 else:119 dest['attributes'][self.key_for_attribute(attribute)] = current[attribute]120 def serialize_ref(self, dest, current, attribute, opts):121 id_ = self.get_ref(current, dest, opts)122 type_ = self.get_type(attribute, dest)123 relationships = []124 included_attrs = []125 if opts.get('attributes'):126 relationships = filter(lambda x: opts.get(x), opts['attributes'])127 included_attrs = filter(lambda x: opts.get(x) is None, opts['attributes'])128 included = { 'type': type_, 'id': id_ }129 if included_attrs:130 included['attributes'] = self.pick(dest, included_attrs)131 for rel in relationships:132 if self._is_complex_type(dest[rel]):133 self.serialize(included, dest, rel, opts[rel])134 if included_attrs and (opts.get('included') is None or135 opts.get('included') is True):136 if opts.get('included_links'):137 included['links'] = self.get_links(dest, opts['included_links'])138 if id_ is not None:139 self.push_to_included(self.payload, included)140 if id_ is not None:141 return { 'type': type_, 'id': id_ }142 else:143 return None144 def serialize_nested(self, dest, current, attribute, opts):145 embeds = []146 attributes = []147 if opts and opts.get('attributes'):148 embeds = filter(lambda x: opts.get(x), opts['attributes'])149 attributes = filter(lambda x: opts.get(x) is None, opts['attributes'])150 else:151 attributes = _.keys(dest)152 ret = {}153 if attributes:154 ret['attributes'] = self.pick(dest, attributes)155 for embed in embeds:156 if self._is_complex_type(dest[embed]):157 self.serialize(ret, dest, embed, opts[embed])158 return ret['attributes']159 def perform(self):160 if self.record is None:161 return None162 data = {163 'type': self.get_type(self.collection_name, self.record),164 'id': str(self.record[self.get_id()])165 }166 if self.opts.get('data_links'):167 data['links'] = self.get_links(self.record, self.opts['data_links'], None)168 for attr in self.opts.get('attributes', []):169 splitted_attributes = attr.split(':')170 if len(splitted_attributes) and splitted_attributes[0] in self.record:...

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