Python types.LambdaType() Examples
The following are 30
code examples of types.LambdaType().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
types
, or try the search function
.
Example #1
Source File: structure.py From smbprotocol with MIT License | 6 votes |
def _get_calculated_size(self, size, data): """ Get's the final size of the field and runs the lambda functions recursively until a final size is derived. If size is None then it will just return the length of the data as it is assumed it is the final field (None should only be set on size for the final field). :param size: The size to calculate/expand :param data: The data that the size is being calculated for :return: The final size """ # if the size is derived from a lambda function, run it now; otherwise # return the value we passed in or the length of the data if the size # is None (last field value) if size is None: return len(data) elif isinstance(size, types.LambdaType): expanded_size = size(self.structure) return self._get_calculated_size(expanded_size, data) else: return size
Example #2
Source File: processor.py From rasa_wechat with Apache License 2.0 | 6 votes |
def __init__(self, interpreter, # type: NaturalLanguageInterpreter policy_ensemble, # type: PolicyEnsemble domain, # type: Domain tracker_store, # type: TrackerStore max_number_of_predictions=10, # type: int message_preprocessor=None, # type: Optional[LambdaType] on_circuit_break=None # type: Optional[LambdaType] ): self.interpreter = interpreter self.policy_ensemble = policy_ensemble self.domain = domain self.tracker_store = tracker_store self.max_number_of_predictions = max_number_of_predictions self.message_preprocessor = message_preprocessor self.on_circuit_break = on_circuit_break
Example #3
Source File: structure.py From smbprotocol with MIT License | 6 votes |
def _parse_value(self, value): if value is None: uuid_value = uuid.UUID(bytes=b"\x00" * 16) elif isinstance(value, bytes) and self.little_endian: uuid_value = uuid.UUID(bytes=value) elif isinstance(value, bytes) and not self.little_endian: uuid_value = uuid.UUID(bytes_le=value) elif isinstance(value, integer_types): uuid_value = uuid.UUID(int=value) elif isinstance(value, uuid.UUID): uuid_value = value elif isinstance(value, types.LambdaType): uuid_value = value else: raise TypeError("Cannot parse value for field %s of type %s to a " "uuid" % (self.name, type(value).__name__)) return uuid_value
Example #4
Source File: structure.py From smbprotocol with MIT License | 6 votes |
def _parse_value(self, value): if value is None: datetime_value = datetime.today() elif isinstance(value, types.LambdaType): datetime_value = value elif isinstance(value, bytes): format = self._get_struct_format(8) struct_string = "%s%s"\ % ("<" if self.little_endian else ">", format) int_value = struct.unpack(struct_string, value)[0] return self._parse_value(int_value) # just parse the value again elif isinstance(value, integer_types): time_microseconds = (value - self.EPOCH_FILETIME) // 10 datetime_value = datetime(1970, 1, 1) + \ timedelta(microseconds=time_microseconds) elif isinstance(value, datetime): datetime_value = value else: raise TypeError("Cannot parse value for field %s of type %s to a " "datetime" % (self.name, type(value).__name__)) return datetime_value
Example #5
Source File: structure.py From smbprotocol with MIT License | 6 votes |
def _parse_value(self, value): if value is None: structure_value = b"" elif isinstance(value, types.LambdaType): structure_value = value elif isinstance(value, bytes): structure_value = value elif isinstance(value, Structure): structure_value = value else: raise TypeError("Cannot parse value for field %s of type %s to a " "structure" % (self.name, type(value).__name__)) if isinstance(structure_value, bytes) and self.structure_type and \ structure_value != b"": if isinstance(self.structure_type, types.LambdaType): structure_type = self.structure_type(self.structure) else: structure_type = self.structure_type structure = structure_type() structure.unpack(structure_value) structure_value = structure return structure_value
Example #6
Source File: structure.py From smbprotocol with MIT License | 6 votes |
def _parse_value(self, value): if value is None: list_value = [] elif isinstance(value, types.LambdaType): return value elif isinstance(value, bytes) and isinstance(self.unpack_func, types.LambdaType): # use the lambda function to parse the bytes to a list list_value = self.unpack_func(self.structure, value) elif isinstance(value, bytes): # we have a fixed length array with a specified count list_value = self._create_list_from_bytes(self.list_count, self.list_type, value) elif isinstance(value, list): # manually parse each list entry to the field type specified list_value = value else: raise TypeError("Cannot parse value for field %s of type %s to a " "list" % (self.name, type(value).__name__)) list_value = [self._parse_sub_value(v) for v in list_value] return list_value
Example #7
Source File: structure.py From smbprotocol with MIT License | 6 votes |
def _parse_value(self, value): if value is None: bytes_value = b"" elif isinstance(value, types.LambdaType): bytes_value = value elif isinstance(value, integer_types): format = self._get_struct_format(self.size) struct_string = "%s%s"\ % ("<" if self.little_endian else ">", format) bytes_value = struct.pack(struct_string, value) elif isinstance(value, Structure): bytes_value = value.pack() elif isinstance(value, bytes): bytes_value = value else: raise TypeError("Cannot parse value for field %s of type %s to a " "byte string" % (self.name, type(value).__name__)) return bytes_value
Example #8
Source File: structure.py From smbprotocol with MIT License | 6 votes |
def _parse_value(self, value): if value is None: int_value = 0 elif isinstance(value, types.LambdaType): int_value = value elif isinstance(value, bytes): format = self._get_struct_format(self.size, self.unsigned) struct_string = "%s%s"\ % ("<" if self.little_endian else ">", format) int_value = struct.unpack(struct_string, value)[0] elif isinstance(value, integer_types): int_value = value else: raise TypeError("Cannot parse value for field %s of type %s to " "an int" % (self.name, type(value).__name__)) return int_value
Example #9
Source File: recipe-473818.py From code with MIT License | 6 votes |
def new_looper(a, arg=None): """Helper function for nest() determines what sort of looper to make given a's type""" if isinstance(a,types.TupleType): if len(a) == 2: return RangeLooper(a[0],a[1]) elif len(a) == 3: return RangeLooper(a[0],a[1],a[2]) elif isinstance(a, types.BooleanType): return BooleanLooper(a) elif isinstance(a,types.IntType) or isinstance(a, types.LongType): return RangeLooper(a) elif isinstance(a, types.StringType) or isinstance(a, types.ListType): return ListLooper(a) elif isinstance(a, Looper): return a elif isinstance(a, types.LambdaType): return CalcField(a, arg)
Example #10
Source File: run_context.py From ai-platform with MIT License | 6 votes |
def __init__(self, submit_config: submit.SubmitConfig, config_module: types.ModuleType = None, max_epoch: Any = None): self.submit_config = submit_config self.should_stop_flag = False self.has_closed = False self.start_time = time.time() self.last_update_time = time.time() self.last_update_interval = 0.0 self.max_epoch = max_epoch # pretty print the all the relevant content of the config module to a text file if config_module is not None: with open(os.path.join(submit_config.run_dir, "config.txt"), "w") as f: filtered_dict = {k: v for k, v in config_module.__dict__.items() if not k.startswith("_") and not isinstance(v, (types.ModuleType, types.FunctionType, types.LambdaType, submit.SubmitConfig, type))} pprint.pprint(filtered_dict, stream=f, indent=4, width=200, compact=False) # write out details about the run to a text file self.run_txt_data = {"task_name": submit_config.task_name, "host_name": submit_config.host_name, "start_time": datetime.datetime.now().isoformat(sep=" ")} with open(os.path.join(submit_config.run_dir, "run.txt"), "w") as f: pprint.pprint(self.run_txt_data, stream=f, indent=4, width=200, compact=False)
Example #11
Source File: core.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def get_config(self): if isinstance(self.function, python_types.LambdaType): function = func_dump(self.function) function_type = 'lambda' else: function = self.function.__name__ function_type = 'function' if isinstance(self._output_shape, python_types.LambdaType): output_shape = func_dump(self._output_shape) output_shape_type = 'lambda' elif callable(self._output_shape): output_shape = self._output_shape.__name__ output_shape_type = 'function' else: output_shape = self._output_shape output_shape_type = 'raw' config = {'function': function, 'function_type': function_type, 'output_shape': output_shape, 'output_shape_type': output_shape_type, 'arguments': self.arguments} base_config = super(Lambda, self).get_config() return dict(list(base_config.items()) + list(config.items()))
Example #12
Source File: backend.py From blitzdb with MIT License | 6 votes |
def get_field_type(self,field,name = None): m = { IntegerField : Integer, FloatField : Float, CharField : lambda field: String(length = field.length), EnumField : lambda field: Enum(*field.enums,name = name,native_enum = field.native_enum), TextField : Text, BooleanField: Boolean, BinaryField: LargeBinary, DateField: Date, DateTimeField: DateTime } for cls,t in m.items(): if isinstance(field,cls): if isinstance(t,LambdaType): return t(field) return t raise AttributeError("Invalid field type: %s" % field)
Example #13
Source File: processor.py From rasa_core with Apache License 2.0 | 6 votes |
def __init__(self, interpreter: NaturalLanguageInterpreter, policy_ensemble: PolicyEnsemble, domain: Domain, tracker_store: TrackerStore, generator: NaturalLanguageGenerator, action_endpoint: Optional[EndpointConfig] = None, max_number_of_predictions: int = 10, message_preprocessor: Optional[LambdaType] = None, on_circuit_break: Optional[LambdaType] = None, ): self.interpreter = interpreter self.nlg = generator self.policy_ensemble = policy_ensemble self.domain = domain self.tracker_store = tracker_store self.max_number_of_predictions = max_number_of_predictions self.message_preprocessor = message_preprocessor self.on_circuit_break = on_circuit_break self.action_endpoint = action_endpoint
Example #14
Source File: generic_utils.py From recurrentshop with MIT License | 5 votes |
def serialize_function(func): if isinstance(func, types.LambdaType): function = func_dump(func) function_type = 'lambda' else: function = func.__name__ function_type = 'function' return (function_type, function)
Example #15
Source File: hierarchy.py From Xpedite with Apache License 2.0 | 5 votes |
def buildEventRetriever(counterMap): """Returns delegate to locate value for pmu events in a counter map""" def delegate(event, level): """ Returns value of a PMC event from counter map :param event: PMC event being looked up :param level: Level of node in the topdown hierarchy tree """ if isinstance(event, types.LambdaType): return event(delegate, level) return counterMap[event] return delegate
Example #16
Source File: hierarchy.py From Xpedite with Apache License 2.0 | 5 votes |
def buildEventsCollector(events): """Returns delegate used to gather pmu events for nodes in a topdown hierarchy""" def delegate(event, level): """ Appends the given event to an events collection :param event: Event to be added :param level: Level of the node in the topdown tree """ if isinstance(event, types.LambdaType): return event(delegate, level) events[event] = None return 99 return delegate
Example #17
Source File: cvtransforms.py From opencv_transforms_torchvision with MIT License | 5 votes |
def __init__(self, lambd): # assert isinstance(lambd, types.LambdaType) self.lambd = lambd # if 'Windows' in platform.system(): # raise RuntimeError("Can't pickle lambda funciton in windows system")
Example #18
Source File: transforms.py From pytorch-ssd with MIT License | 5 votes |
def __init__(self, lambd): assert isinstance(lambd, types.LambdaType) self.lambd = lambd
Example #19
Source File: transforms.py From pnn.pytorch with MIT License | 5 votes |
def __init__(self, lambd): assert type(lambd) is types.LambdaType self.lambd = lambd
Example #20
Source File: transforms.py From transforms with MIT License | 5 votes |
def HalfBlood(img, anchor_index, f1, f2): # assert isinstance(f1, types.LambdaType) and isinstance(f2, types.LambdaType) if isinstance(anchor_index, numbers.Number): anchor_index = int(np.ceil(anchor_index)) if isinstance(anchor_index, int) and img.ndim == 3 and 0 < anchor_index < img.shape[2]: img1, img2 = img[:,:,:anchor_index], img[:,:,anchor_index:] if img1.shape[2] == 1: img1 = img1[:, :, 0] if img2.shape[2] == 1: img2 = img2[:, :, 0] img1 = f1(img1) img2 = f2(img2) if img1.ndim == 2: img1 = img1[..., np.newaxis] if img2.ndim == 2: img2 = img2[..., np.newaxis] return np.concatenate((img1, img2), axis=2) elif anchor_index == 0: img = f2(img) if img.ndim == 2: img = img[..., np.newaxis] return img else: img = f1(img) if img.ndim == 2: img = img[..., np.newaxis] return img # Photometric Transform
Example #21
Source File: augmentations.py From nn_tools with MIT License | 5 votes |
def __init__(self, lambd): assert isinstance(lambd, types.LambdaType) self.lambd = lambd
Example #22
Source File: __init__.py From wait_for with Apache License 2.0 | 5 votes |
def is_lambda_function(obj): return isinstance(obj, LambdaType) and obj.__name__ == "<lambda>"
Example #23
Source File: schema.py From mimesis with MIT License | 5 votes |
def __init__(self, schema: LambdaType) -> None: """Initialize schema. :param schema: A schema. """ if isinstance(schema, LambdaType): self.schema = schema else: raise UndefinedSchema()
Example #24
Source File: augmentations.py From RefinedetLite.pytorch with MIT License | 5 votes |
def __init__(self, lambd): assert isinstance(lambd, types.LambdaType) self.lambd = lambd
Example #25
Source File: testing.py From modern-paste with MIT License | 5 votes |
def random_or_specified_value(cls, value): """ Helper utility for choosing between a user-specified value for a field or a randomly generated value. :param value: Either a lambda type or a non-lambda type. :return: The value itself if not a lambda type, otherwise the value of the evaluated lambda (random value) """ return value() if isinstance(value, types.LambdaType) else value
Example #26
Source File: encapsulation.py From scoop with GNU Lesser General Public License v3.0 | 5 votes |
def unpickleLambda(pickled_callable): # TODO: Set globals to user module return types.LambdaType(marshal.loads(pickled_callable), globals())
Example #27
Source File: co_transforms.py From binseg_pytoch with Apache License 2.0 | 5 votes |
def __init__(self, lambd): assert type(lambd) is types.LambdaType self.lambd = lambd
Example #28
Source File: transforms.py From binseg_pytoch with Apache License 2.0 | 5 votes |
def __init__(self, lambd): assert isinstance(lambd, types.LambdaType) self.lambd = lambd
Example #29
Source File: augmentations.py From DRFNet with MIT License | 5 votes |
def __init__(self, lambd): assert isinstance(lambd, types.LambdaType) self.lambd = lambd
Example #30
Source File: augmentations.py From Grid-Anchor-based-Image-Cropping-Pytorch with MIT License | 5 votes |
def __init__(self, lambd): assert isinstance(lambd, types.LambdaType) self.lambd = lambd