nwo
stringlengths
5
106
sha
stringlengths
40
40
path
stringlengths
4
174
language
stringclasses
1 value
identifier
stringlengths
1
140
parameters
stringlengths
0
87.7k
argument_list
stringclasses
1 value
return_statement
stringlengths
0
426k
docstring
stringlengths
0
64.3k
docstring_summary
stringlengths
0
26.3k
docstring_tokens
list
function
stringlengths
18
4.83M
function_tokens
list
url
stringlengths
83
304
iclavera/learning_to_adapt
bd7d99ba402521c96631e7d09714128f549db0f1
learning_to_adapt/spaces/box.py
python
Box.__init__
(self, low, high, shape=None)
Two kinds of valid input: Box(-1.0, 1.0, (3,4)) # low and high are scalars, and shape is provided Box(np.array([-1.0,-2.0]), np.array([2.0,4.0])) # low and high are arrays of the same shape
Two kinds of valid input: Box(-1.0, 1.0, (3,4)) # low and high are scalars, and shape is provided Box(np.array([-1.0,-2.0]), np.array([2.0,4.0])) # low and high are arrays of the same shape
[ "Two", "kinds", "of", "valid", "input", ":", "Box", "(", "-", "1", ".", "0", "1", ".", "0", "(", "3", "4", "))", "#", "low", "and", "high", "are", "scalars", "and", "shape", "is", "provided", "Box", "(", "np", ".", "array", "(", "[", "-", "1"...
def __init__(self, low, high, shape=None): """ Two kinds of valid input: Box(-1.0, 1.0, (3,4)) # low and high are scalars, and shape is provided Box(np.array([-1.0,-2.0]), np.array([2.0,4.0])) # low and high are arrays of the same shape """ if shape is None: assert low.shape == high.shape self.low = low self.high = high else: assert np.isscalar(low) and np.isscalar(high) self.low = low + np.zeros(shape) self.high = high + np.zeros(shape)
[ "def", "__init__", "(", "self", ",", "low", ",", "high", ",", "shape", "=", "None", ")", ":", "if", "shape", "is", "None", ":", "assert", "low", ".", "shape", "==", "high", ".", "shape", "self", ".", "low", "=", "low", "self", ".", "high", "=", ...
https://github.com/iclavera/learning_to_adapt/blob/bd7d99ba402521c96631e7d09714128f549db0f1/learning_to_adapt/spaces/box.py#L11-L24
DeepLabCut/DeepLabCut
1dd14c54729ae0d8e66ca495aa5baeb83502e1c7
deeplabcut/gui/multiple_individuals_labeling_toolbox.py
python
MainFrame.onClick
(self, event)
This function adds labels and auto advances to the next label.
This function adds labels and auto advances to the next label.
[ "This", "function", "adds", "labels", "and", "auto", "advances", "to", "the", "next", "label", "." ]
def onClick(self, event): """ This function adds labels and auto advances to the next label. """ x1 = event.xdata y1 = event.ydata if event.button == 3: num_indiv = self.individualrdb.GetSelection() indiv = self.individual_names[num_indiv] idcolor = self.idmap(num_indiv) if self.individualrdb.GetStringSelection() == "single": self.norm, self.colorIndex = self.image_panel.getColorIndices( self.img, self.uniquebodyparts ) if ( self.uniquebodyparts[self.rdb.GetSelection()] in self.buttonCounter[indiv] ): wx.MessageBox( "%s is already annotated for %s. \n Select another body part to annotate." % ( str(self.uniquebodyparts[self.rdb.GetSelection()]), str( self.individual_names[self.individualrdb.GetSelection()] ), ), "Error!", wx.OK | wx.ICON_ERROR, ) else: color = self.colormap( self.norm(self.colorIndex[self.rdb.GetSelection()]) ) circle = [ patches.Circle( (x1, y1), radius=self.markerSize, fc=color, ec=idcolor, lw=self.edgewidth, alpha=self.alpha, ) ] self.num.append(circle) self.axes.add_patch(circle[0]) self.dr = auxfun_drag.DraggablePoint( circle[0], self.uniquebodyparts[self.rdb.GetSelection()], individual_names=indiv, ) self.dr.connect() self.buttonCounter[indiv].append( self.uniquebodyparts[self.rdb.GetSelection()] ) self.dr.coords = [ [x1, y1, indiv, self.uniquebodyparts[self.rdb.GetSelection()]] ] self.drs.append(self.dr) self.updatedCoords.append(self.dr.coords) if self.rdb.GetSelection() < len(self.uniquebodyparts) - 1: self.rdb.SetSelection(self.rdb.GetSelection() + 1) else: self.rdb.SetSelection(0) if ( self.individualrdb.GetSelection() < len(self.individual_names) - 1 ): self.individualrdb.SetSelection( self.individualrdb.GetSelection() + 1 ) MainFrame.select_individual(self, event) else: self.norm, self.colorIndex = self.image_panel.getColorIndices( self.img, self.multibodyparts ) if ( self.multibodyparts[self.rdb.GetSelection()] in self.buttonCounter[indiv] ): wx.MessageBox( "%s is already annotated for %s. \n Select another body part to annotate." % ( str(self.multibodyparts[self.rdb.GetSelection()]), str( self.individual_names[self.individualrdb.GetSelection()] ), ), "Error!", wx.OK | wx.ICON_ERROR, ) else: color = self.colormap( self.norm(self.colorIndex[self.rdb.GetSelection()]) ) circle = [ patches.Circle( (x1, y1), radius=self.markerSize, fc=color, ec=idcolor, lw=self.edgewidth, alpha=self.alpha, ) ] self.num.append(circle) self.axes.add_patch(circle[0]) self.dr = auxfun_drag.DraggablePoint( circle[0], self.multibodyparts[self.rdb.GetSelection()], individual_names=indiv, ) self.dr.connect() self.buttonCounter[indiv].append( self.multibodyparts[self.rdb.GetSelection()] ) self.dr.coords = [ [x1, y1, indiv, self.multibodyparts[self.rdb.GetSelection()]] ] self.drs.append(self.dr) self.updatedCoords.append(self.dr.coords) if self.rdb.GetSelection() < len(self.multibodyparts) - 1: self.rdb.SetSelection(self.rdb.GetSelection() + 1) else: self.rdb.SetSelection(0) if ( self.individualrdb.GetSelection() < len(self.individual_names) - 1 ): self.individualrdb.SetSelection( self.individualrdb.GetSelection() + 1 ) MainFrame.select_individual(self, event) self.canvas.mpl_disconnect(self.onClick)
[ "def", "onClick", "(", "self", ",", "event", ")", ":", "x1", "=", "event", ".", "xdata", "y1", "=", "event", ".", "ydata", "if", "event", ".", "button", "==", "3", ":", "num_indiv", "=", "self", ".", "individualrdb", ".", "GetSelection", "(", ")", ...
https://github.com/DeepLabCut/DeepLabCut/blob/1dd14c54729ae0d8e66ca495aa5baeb83502e1c7/deeplabcut/gui/multiple_individuals_labeling_toolbox.py#L562-L697
Tautulli/Tautulli
2410eb33805aaac4bd1c5dad0f71e4f15afaf742
plexpy/webserve.py
python
WebInterface.get_server_update_params
(self, **kwargs)
return {'plexpass': plexpass, 'pms_platform': common.PMS_PLATFORM_NAME_OVERRIDES.get( plexpy.CONFIG.PMS_PLATFORM, plexpy.CONFIG.PMS_PLATFORM), 'pms_update_channel': plexpy.CONFIG.PMS_UPDATE_CHANNEL, 'pms_update_distro': plexpy.CONFIG.PMS_UPDATE_DISTRO, 'pms_update_distro_build': plexpy.CONFIG.PMS_UPDATE_DISTRO_BUILD, 'plex_update_channel': 'plexpass' if update_channel == 'beta' else 'public'}
[]
def get_server_update_params(self, **kwargs): plex_tv = plextv.PlexTV() plexpass = plex_tv.get_plexpass_status() update_channel = pmsconnect.PmsConnect().get_server_update_channel() return {'plexpass': plexpass, 'pms_platform': common.PMS_PLATFORM_NAME_OVERRIDES.get( plexpy.CONFIG.PMS_PLATFORM, plexpy.CONFIG.PMS_PLATFORM), 'pms_update_channel': plexpy.CONFIG.PMS_UPDATE_CHANNEL, 'pms_update_distro': plexpy.CONFIG.PMS_UPDATE_DISTRO, 'pms_update_distro_build': plexpy.CONFIG.PMS_UPDATE_DISTRO_BUILD, 'plex_update_channel': 'plexpass' if update_channel == 'beta' else 'public'}
[ "def", "get_server_update_params", "(", "self", ",", "*", "*", "kwargs", ")", ":", "plex_tv", "=", "plextv", ".", "PlexTV", "(", ")", "plexpass", "=", "plex_tv", ".", "get_plexpass_status", "(", ")", "update_channel", "=", "pmsconnect", ".", "PmsConnect", "(...
https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/plexpy/webserve.py#L3454-L3466
VirtueSecurity/aws-extender
d123b7e1a845847709ba3a481f11996bddc68a1c
BappModules/boto/sqs/connection.py
python
SQSConnection.set_queue_attribute
(self, queue, attribute, value)
return self.get_status('SetQueueAttributes', params, queue.id)
Set a new value for an attribute of a Queue. :type queue: A Queue object :param queue: The SQS queue to get attributes for :type attribute: String :param attribute: The name of the attribute you want to set. :param value: The new value for the attribute must be: * For `DelaySeconds` the value must be an integer number of seconds from 0 to 900 (15 minutes). >>> connection.set_queue_attribute(queue, 'DelaySeconds', 900) * For `MaximumMessageSize` the value must be an integer number of bytes from 1024 (1 KiB) to 262144 (256 KiB). >>> connection.set_queue_attribute(queue, 'MaximumMessageSize', 262144) * For `MessageRetentionPeriod` the value must be an integer number of seconds from 60 (1 minute) to 1209600 (14 days). >>> connection.set_queue_attribute(queue, 'MessageRetentionPeriod', 1209600) * For `Policy` the value must be an string that contains JSON formatted parameters and values. >>> connection.set_queue_attribute(queue, 'Policy', json.dumps({ ... 'Version': '2008-10-17', ... 'Id': '/123456789012/testQueue/SQSDefaultPolicy', ... 'Statement': [ ... { ... 'Sid': 'Queue1ReceiveMessage', ... 'Effect': 'Allow', ... 'Principal': { ... 'AWS': '*' ... }, ... 'Action': 'SQS:ReceiveMessage', ... 'Resource': 'arn:aws:aws:sqs:us-east-1:123456789012:testQueue' ... } ... ] ... })) * For `ReceiveMessageWaitTimeSeconds` the value must be an integer number of seconds from 0 to 20. >>> connection.set_queue_attribute(queue, 'ReceiveMessageWaitTimeSeconds', 20) * For `VisibilityTimeout` the value must be an integer number of seconds from 0 to 43200 (12 hours). >>> connection.set_queue_attribute(queue, 'VisibilityTimeout', 43200) * For `RedrivePolicy` the value must be an string that contains JSON formatted parameters and values. You can set maxReceiveCount to a value between 1 and 1000. The deadLetterTargetArn value is the Amazon Resource Name (ARN) of the queue that will receive the dead letter messages. >>> connection.set_queue_attribute(queue, 'RedrivePolicy', json.dumps({ ... 'maxReceiveCount': 5, ... 'deadLetterTargetArn': "arn:aws:aws:sqs:us-east-1:123456789012:testDeadLetterQueue" ... }))
Set a new value for an attribute of a Queue.
[ "Set", "a", "new", "value", "for", "an", "attribute", "of", "a", "Queue", "." ]
def set_queue_attribute(self, queue, attribute, value): """ Set a new value for an attribute of a Queue. :type queue: A Queue object :param queue: The SQS queue to get attributes for :type attribute: String :param attribute: The name of the attribute you want to set. :param value: The new value for the attribute must be: * For `DelaySeconds` the value must be an integer number of seconds from 0 to 900 (15 minutes). >>> connection.set_queue_attribute(queue, 'DelaySeconds', 900) * For `MaximumMessageSize` the value must be an integer number of bytes from 1024 (1 KiB) to 262144 (256 KiB). >>> connection.set_queue_attribute(queue, 'MaximumMessageSize', 262144) * For `MessageRetentionPeriod` the value must be an integer number of seconds from 60 (1 minute) to 1209600 (14 days). >>> connection.set_queue_attribute(queue, 'MessageRetentionPeriod', 1209600) * For `Policy` the value must be an string that contains JSON formatted parameters and values. >>> connection.set_queue_attribute(queue, 'Policy', json.dumps({ ... 'Version': '2008-10-17', ... 'Id': '/123456789012/testQueue/SQSDefaultPolicy', ... 'Statement': [ ... { ... 'Sid': 'Queue1ReceiveMessage', ... 'Effect': 'Allow', ... 'Principal': { ... 'AWS': '*' ... }, ... 'Action': 'SQS:ReceiveMessage', ... 'Resource': 'arn:aws:aws:sqs:us-east-1:123456789012:testQueue' ... } ... ] ... })) * For `ReceiveMessageWaitTimeSeconds` the value must be an integer number of seconds from 0 to 20. >>> connection.set_queue_attribute(queue, 'ReceiveMessageWaitTimeSeconds', 20) * For `VisibilityTimeout` the value must be an integer number of seconds from 0 to 43200 (12 hours). >>> connection.set_queue_attribute(queue, 'VisibilityTimeout', 43200) * For `RedrivePolicy` the value must be an string that contains JSON formatted parameters and values. You can set maxReceiveCount to a value between 1 and 1000. The deadLetterTargetArn value is the Amazon Resource Name (ARN) of the queue that will receive the dead letter messages. >>> connection.set_queue_attribute(queue, 'RedrivePolicy', json.dumps({ ... 'maxReceiveCount': 5, ... 'deadLetterTargetArn': "arn:aws:aws:sqs:us-east-1:123456789012:testDeadLetterQueue" ... })) """ params = {'Attribute.Name' : attribute, 'Attribute.Value' : value} return self.get_status('SetQueueAttributes', params, queue.id)
[ "def", "set_queue_attribute", "(", "self", ",", "queue", ",", "attribute", ",", "value", ")", ":", "params", "=", "{", "'Attribute.Name'", ":", "attribute", ",", "'Attribute.Value'", ":", "value", "}", "return", "self", ".", "get_status", "(", "'SetQueueAttrib...
https://github.com/VirtueSecurity/aws-extender/blob/d123b7e1a845847709ba3a481f11996bddc68a1c/BappModules/boto/sqs/connection.py#L160-L221
pikpikcu/Pentest-Tools-Framework
cd6e6107764a809943dc4e073cde8149c1a2cd03
modules/xsser/build/lib/core/threadpool.py
python
_handle_thread_exception
(request, exc_info)
Default exception handler callback function. This just prints the exception info via ``traceback.print_exception``.
Default exception handler callback function.
[ "Default", "exception", "handler", "callback", "function", "." ]
def _handle_thread_exception(request, exc_info): """Default exception handler callback function. This just prints the exception info via ``traceback.print_exception``. """ traceback.print_exception(*exc_info)
[ "def", "_handle_thread_exception", "(", "request", ",", "exc_info", ")", ":", "traceback", ".", "print_exception", "(", "*", "exc_info", ")" ]
https://github.com/pikpikcu/Pentest-Tools-Framework/blob/cd6e6107764a809943dc4e073cde8149c1a2cd03/modules/xsser/build/lib/core/threadpool.py#L95-L101
opencobra/cobrapy
0b9ea70cb0ffe78568d445ce3361ad10ec6b02a2
src/cobra/manipulation/delete.py
python
prune_unused_metabolites
(model: "Model")
return output_model, inactive_metabolites
Remove metabolites not involved in any reactions. Parameters ---------- model: cobra.Model The model to remove unused metabolites from. Returns ------- cobra.Model Input model with unused metabolites removed. list of cobra.Metabolite List of metabolites that were removed.
Remove metabolites not involved in any reactions.
[ "Remove", "metabolites", "not", "involved", "in", "any", "reactions", "." ]
def prune_unused_metabolites(model: "Model") -> Tuple["Model", List["Metabolite"]]: """Remove metabolites not involved in any reactions. Parameters ---------- model: cobra.Model The model to remove unused metabolites from. Returns ------- cobra.Model Input model with unused metabolites removed. list of cobra.Metabolite List of metabolites that were removed. """ output_model = model.copy() inactive_metabolites = [ m for m in output_model.metabolites if len(m.reactions) == 0 ] output_model.remove_metabolites(inactive_metabolites) return output_model, inactive_metabolites
[ "def", "prune_unused_metabolites", "(", "model", ":", "\"Model\"", ")", "->", "Tuple", "[", "\"Model\"", ",", "List", "[", "\"Metabolite\"", "]", "]", ":", "output_model", "=", "model", ".", "copy", "(", ")", "inactive_metabolites", "=", "[", "m", "for", "...
https://github.com/opencobra/cobrapy/blob/0b9ea70cb0ffe78568d445ce3361ad10ec6b02a2/src/cobra/manipulation/delete.py#L14-L35
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/point/__init__.py
python
MinutPointEntity.device_info
(self)
return DeviceInfo( connections={ (device_registry.CONNECTION_NETWORK_MAC, device["device_mac"]) }, identifiers={(DOMAIN, device["device_id"])}, manufacturer="Minut", model=f"Point v{device['hardware_version']}", name=device["description"], sw_version=device["firmware"]["installed"], via_device=(DOMAIN, device["home"]), )
Return a device description for device registry.
Return a device description for device registry.
[ "Return", "a", "device", "description", "for", "device", "registry", "." ]
def device_info(self) -> DeviceInfo: """Return a device description for device registry.""" device = self.device.device return DeviceInfo( connections={ (device_registry.CONNECTION_NETWORK_MAC, device["device_mac"]) }, identifiers={(DOMAIN, device["device_id"])}, manufacturer="Minut", model=f"Point v{device['hardware_version']}", name=device["description"], sw_version=device["firmware"]["installed"], via_device=(DOMAIN, device["home"]), )
[ "def", "device_info", "(", "self", ")", "->", "DeviceInfo", ":", "device", "=", "self", ".", "device", ".", "device", "return", "DeviceInfo", "(", "connections", "=", "{", "(", "device_registry", ".", "CONNECTION_NETWORK_MAC", ",", "device", "[", "\"device_mac...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/point/__init__.py#L315-L328
atomistic-machine-learning/schnetpack
dacf6076d43509dfd8b6694a846ac8453ae39b5e
src/schnetpack/md/simulation_hooks/sampling.py
python
AcceleratedMD.on_step_middle
(self, simulator)
Compute the bias potential and derivatives and use them to update the current state of :obj:`schnetpack.md.System` in the simulator. While the forces are updated, the bias potential itself is stored in the properties dictionary of the system. Args: simulator (schnetpack.md.Simulator): Main simulator used for driving the dynamics
Compute the bias potential and derivatives and use them to update the current state of :obj:`schnetpack.md.System` in the simulator. While the forces are updated, the bias potential itself is stored in the properties dictionary of the system.
[ "Compute", "the", "bias", "potential", "and", "derivatives", "and", "use", "them", "to", "update", "the", "current", "state", "of", ":", "obj", ":", "schnetpack", ".", "md", ".", "System", "in", "the", "simulator", ".", "While", "the", "forces", "are", "...
def on_step_middle(self, simulator): """ Compute the bias potential and derivatives and use them to update the current state of :obj:`schnetpack.md.System` in the simulator. While the forces are updated, the bias potential itself is stored in the properties dictionary of the system. Args: simulator (schnetpack.md.Simulator): Main simulator used for driving the dynamics """ energies, forces = self._get_energies_forces(simulator) # Compute bias potential and derivatives bias_potential = self._function(energies) bias_forces = self._derivative(energies) * forces # Store bias potential and update forces simulator.system.properties["bias_potential"] = bias_potential simulator.system.forces = forces + bias_forces.detach()
[ "def", "on_step_middle", "(", "self", ",", "simulator", ")", ":", "energies", ",", "forces", "=", "self", ".", "_get_energies_forces", "(", "simulator", ")", "# Compute bias potential and derivatives", "bias_potential", "=", "self", ".", "_function", "(", "energies"...
https://github.com/atomistic-machine-learning/schnetpack/blob/dacf6076d43509dfd8b6694a846ac8453ae39b5e/src/schnetpack/md/simulation_hooks/sampling.py#L82-L100
aiqm/torchani
258e6c36cf2b35a3a672137ebe30cb923db75952
torchani/neurochem/__init__.py
python
load_model_ensemble
(species, prefix, count)
return Ensemble(models)
Returns an instance of :class:`torchani.Ensemble` loaded from NeuroChem's network directories beginning with the given prefix. Arguments: species (:class:`collections.abc.Sequence`): Sequence of strings for chemical symbols of each supported atom type in correct order. prefix (str): Prefix of paths of directory that networks configurations are stored. count (int): Number of models in the ensemble.
Returns an instance of :class:`torchani.Ensemble` loaded from NeuroChem's network directories beginning with the given prefix.
[ "Returns", "an", "instance", "of", ":", "class", ":", "torchani", ".", "Ensemble", "loaded", "from", "NeuroChem", "s", "network", "directories", "beginning", "with", "the", "given", "prefix", "." ]
def load_model_ensemble(species, prefix, count): """Returns an instance of :class:`torchani.Ensemble` loaded from NeuroChem's network directories beginning with the given prefix. Arguments: species (:class:`collections.abc.Sequence`): Sequence of strings for chemical symbols of each supported atom type in correct order. prefix (str): Prefix of paths of directory that networks configurations are stored. count (int): Number of models in the ensemble. """ models = [] for i in range(count): network_dir = os.path.join('{}{}'.format(prefix, i), 'networks') models.append(load_model(species, network_dir)) return Ensemble(models)
[ "def", "load_model_ensemble", "(", "species", ",", "prefix", ",", "count", ")", ":", "models", "=", "[", "]", "for", "i", "in", "range", "(", "count", ")", ":", "network_dir", "=", "os", ".", "path", ".", "join", "(", "'{}{}'", ".", "format", "(", ...
https://github.com/aiqm/torchani/blob/258e6c36cf2b35a3a672137ebe30cb923db75952/torchani/neurochem/__init__.py#L258-L273
yeephycho/nasnet-tensorflow
189e22f2de9d6ee1b4abd0a65275d5e6a6c04c45
nets/nasnet/nasnet.py
python
build_nasnet_mobile
(images, num_classes, is_training=True, final_endpoint=None)
Build NASNet Mobile model for the ImageNet Dataset.
Build NASNet Mobile model for the ImageNet Dataset.
[ "Build", "NASNet", "Mobile", "model", "for", "the", "ImageNet", "Dataset", "." ]
def build_nasnet_mobile(images, num_classes, is_training=True, final_endpoint=None): """Build NASNet Mobile model for the ImageNet Dataset.""" hparams = _mobile_imagenet_config() if tf.test.is_gpu_available() and hparams.data_format == 'NHWC': tf.logging.info('A GPU is available on the machine, consider using NCHW ' 'data format for increased speed on GPU.') if hparams.data_format == 'NCHW': images = tf.transpose(images, [0, 3, 1, 2]) # Calculate the total number of cells in the network # Add 2 for the reduction cells total_num_cells = hparams.num_cells + 2 # If ImageNet, then add an additional two for the stem cells total_num_cells += 2 normal_cell = nasnet_utils.NasNetANormalCell( hparams.num_conv_filters, hparams.drop_path_keep_prob, total_num_cells, hparams.total_training_steps) reduction_cell = nasnet_utils.NasNetAReductionCell( hparams.num_conv_filters, hparams.drop_path_keep_prob, total_num_cells, hparams.total_training_steps) with arg_scope([slim.dropout, nasnet_utils.drop_path, slim.batch_norm], is_training=is_training): with arg_scope([slim.avg_pool2d, slim.max_pool2d, slim.conv2d, slim.batch_norm, slim.separable_conv2d, nasnet_utils.factorized_reduction, nasnet_utils.global_avg_pool, nasnet_utils.get_channel_index, nasnet_utils.get_channel_dim], data_format=hparams.data_format): return _build_nasnet_base(images, normal_cell=normal_cell, reduction_cell=reduction_cell, num_classes=num_classes, hparams=hparams, is_training=is_training, stem_type='imagenet', final_endpoint=final_endpoint)
[ "def", "build_nasnet_mobile", "(", "images", ",", "num_classes", ",", "is_training", "=", "True", ",", "final_endpoint", "=", "None", ")", ":", "hparams", "=", "_mobile_imagenet_config", "(", ")", "if", "tf", ".", "test", ".", "is_gpu_available", "(", ")", "...
https://github.com/yeephycho/nasnet-tensorflow/blob/189e22f2de9d6ee1b4abd0a65275d5e6a6c04c45/nets/nasnet/nasnet.py#L326-L370
Juniper/py-junos-eznc
fd81d476e37ac1a234b503ab77f76ec658d04590
lib/jnpr/junos/facts/swver.py
python
provides_facts
()
return {}
Doesn't really provide any facts.
Doesn't really provide any facts.
[ "Doesn", "t", "really", "provide", "any", "facts", "." ]
def provides_facts(): """ Doesn't really provide any facts. """ return {}
[ "def", "provides_facts", "(", ")", ":", "return", "{", "}" ]
https://github.com/Juniper/py-junos-eznc/blob/fd81d476e37ac1a234b503ab77f76ec658d04590/lib/jnpr/junos/facts/swver.py#L101-L105
andresriancho/w3af
cd22e5252243a87aaa6d0ddea47cf58dacfe00a9
w3af/plugins/attack/db/sqlmap/thirdparty/odict/odict.py
python
Values.__contains__
(self, item)
return item in self._main.values()
[]
def __contains__(self, item): return item in self._main.values()
[ "def", "__contains__", "(", "self", ",", "item", ")", ":", "return", "item", "in", "self", ".", "_main", ".", "values", "(", ")" ]
https://github.com/andresriancho/w3af/blob/cd22e5252243a87aaa6d0ddea47cf58dacfe00a9/w3af/plugins/attack/db/sqlmap/thirdparty/odict/odict.py#L1135-L1135
pySTEPS/pysteps
bd9478538249e1d64036a721ceb934085d6e1da9
pysteps/verification/lifetime.py
python
lifetime_init
(rule="1/e")
return lifetime
Initialize a lifetime object. Parameters ---------- rule: str {'1/e', 'trapz', 'simpson'}, optional Name of the method to integrate the correlation curve. \n '1/e' uses the 1/e rule and assumes an exponential decay. It linearly interpolates the time when the correlation goes below the value 1/e. When all values are > 1/e it returns the max lead time. When all values are < 1/e it returns the min lead time.\n 'trapz' uses the trapezoidal rule for integration.\n 'simpson' uses the Simpson's rule for integration. Returns ------- out: dict The lifetime object.
Initialize a lifetime object.
[ "Initialize", "a", "lifetime", "object", "." ]
def lifetime_init(rule="1/e"): """Initialize a lifetime object. Parameters ---------- rule: str {'1/e', 'trapz', 'simpson'}, optional Name of the method to integrate the correlation curve. \n '1/e' uses the 1/e rule and assumes an exponential decay. It linearly interpolates the time when the correlation goes below the value 1/e. When all values are > 1/e it returns the max lead time. When all values are < 1/e it returns the min lead time.\n 'trapz' uses the trapezoidal rule for integration.\n 'simpson' uses the Simpson's rule for integration. Returns ------- out: dict The lifetime object. """ list_rules = ["trapz", "simpson", "1/e"] if rule not in list_rules: raise ValueError( "Unknown rule %s for integration.\n" % rule + "The available methods are: " + str(list_rules) ) lifetime = {} lifetime["lifetime_sum"] = 0.0 lifetime["n"] = 0.0 lifetime["rule"] = rule return lifetime
[ "def", "lifetime_init", "(", "rule", "=", "\"1/e\"", ")", ":", "list_rules", "=", "[", "\"trapz\"", ",", "\"simpson\"", ",", "\"1/e\"", "]", "if", "rule", "not", "in", "list_rules", ":", "raise", "ValueError", "(", "\"Unknown rule %s for integration.\\n\"", "%",...
https://github.com/pySTEPS/pysteps/blob/bd9478538249e1d64036a721ceb934085d6e1da9/pysteps/verification/lifetime.py#L63-L94
tkuanlun350/3DUnet-Tensorflow-Brats18
8f9e49747ea316d0c6777ab090bdaf7d2f8baf93
eval.py
python
eval_brats
(df, detect_func, with_gt=True)
return ret
evalutation
evalutation
[ "evalutation" ]
def eval_brats(df, detect_func, with_gt=True): """ evalutation """ df.reset_state() gts = [] results = [] with tqdm.tqdm(total=df.size(), **get_tqdm_kwargs()) as pbar: for filename, image_id, data in df.get_data(): final_label, probs = detect_func(data) if config.TEST_FLIP: pred_flip, probs_flip = detect_func(flip_lr(data)) final_prob = (probs + probs_flip) / 2.0 pred = np.argmax(final_prob, axis=-1) pred[pred == 3] = 4 if config.ADVANCE_POSTPROCESSING: pred = crop_ND_volume_with_bounding_box(pred, data['bbox'][0], data['bbox'][1]) pred = post_processing(pred, data['weights'][:,:,:,0]) pred = np.asarray(pred, np.int16) final_label = np.zeros(data['original_shape'], np.int16) final_label = set_ND_volume_roi_with_bounding_box_range(final_label, data['bbox'][0], data['bbox'][1], pred) else: final_label = pred gt = load_nifty_volume_as_array("{}/{}_seg.nii.gz".format(filename, image_id)) gts.append(gt) results.append(final_label) pbar.update() test_types = ['whole', 'core', 'enhancing'] ret = {} for type_idx in range(3): dice = dice_of_brats_data_set(gts, results, type_idx) dice = np.asarray(dice) dice_mean = dice.mean(axis = 0) dice_std = dice.std(axis = 0) test_type = test_types[type_idx] ret[test_type] = dice_mean[0] print('tissue type', test_type) print('dice mean', dice_mean) return ret
[ "def", "eval_brats", "(", "df", ",", "detect_func", ",", "with_gt", "=", "True", ")", ":", "df", ".", "reset_state", "(", ")", "gts", "=", "[", "]", "results", "=", "[", "]", "with", "tqdm", ".", "tqdm", "(", "total", "=", "df", ".", "size", "(",...
https://github.com/tkuanlun350/3DUnet-Tensorflow-Brats18/blob/8f9e49747ea316d0c6777ab090bdaf7d2f8baf93/eval.py#L271-L309
jython/jython3
def4f8ec47cb7a9c799ea4c745f12badf92c5769
lib-python/3.5.1/threading.py
python
current_thread
()
Return the current Thread object, corresponding to the caller's thread of control. If the caller's thread of control was not created through the threading module, a dummy thread object with limited functionality is returned.
Return the current Thread object, corresponding to the caller's thread of control.
[ "Return", "the", "current", "Thread", "object", "corresponding", "to", "the", "caller", "s", "thread", "of", "control", "." ]
def current_thread(): """Return the current Thread object, corresponding to the caller's thread of control. If the caller's thread of control was not created through the threading module, a dummy thread object with limited functionality is returned. """ try: return _active[get_ident()] except KeyError: return _DummyThread()
[ "def", "current_thread", "(", ")", ":", "try", ":", "return", "_active", "[", "get_ident", "(", ")", "]", "except", "KeyError", ":", "return", "_DummyThread", "(", ")" ]
https://github.com/jython/jython3/blob/def4f8ec47cb7a9c799ea4c745f12badf92c5769/lib-python/3.5.1/threading.py#L1224-L1234
beeware/ouroboros
a29123c6fab6a807caffbb7587cf548e0c370296
ouroboros/tarfile.py
python
_Stream.tell
(self)
return self.pos
Return the stream's file pointer position.
Return the stream's file pointer position.
[ "Return", "the", "stream", "s", "file", "pointer", "position", "." ]
def tell(self): """Return the stream's file pointer position. """ return self.pos
[ "def", "tell", "(", "self", ")", ":", "return", "self", ".", "pos" ]
https://github.com/beeware/ouroboros/blob/a29123c6fab6a807caffbb7587cf548e0c370296/ouroboros/tarfile.py#L505-L508
Netflix/security_monkey
c28592ffd518fa399527d26262683fc860c30eef
security_monkey/watchers/rds/rds_snapshot.py
python
RDSSnapshot.slurp
(self)
return item_list, exception_map
:returns: item_list - list of RDS snapshots in use by account :returns: exception_map - A dict where the keys are a tuple containing the location of the exception and the value is the actual exception
:returns: item_list - list of RDS snapshots in use by account :returns: exception_map - A dict where the keys are a tuple containing the location of the exception and the value is the actual exception
[ ":", "returns", ":", "item_list", "-", "list", "of", "RDS", "snapshots", "in", "use", "by", "account", ":", "returns", ":", "exception_map", "-", "A", "dict", "where", "the", "keys", "are", "a", "tuple", "containing", "the", "location", "of", "the", "exc...
def slurp(self): """ :returns: item_list - list of RDS snapshots in use by account :returns: exception_map - A dict where the keys are a tuple containing the location of the exception and the value is the actual exception """ self.prep_for_slurp() from security_monkey.common.sts_connect import connect item_list = [] exception_map = {} for account in self.accounts: for region in regions(): app.logger.debug( "Checking {}/{}/{}".format(self.index, account, region.name)) snapshots = [] try: rds = connect(account, 'boto3.rds.client', region=region) marker = '' while True: response = self.wrap_aws_rate_limited_call( rds.describe_db_snapshots, Marker=marker) snapshots.extend(response.get('DBSnapshots')) if response.get('Marker'): marker = response.get('Marker') else: break except Exception as e: if region.name not in TROUBLE_REGIONS: exc = BotoConnectionIssue( str(e), self.index, account, region.name) self.slurp_exception( (self.index, account, region.name), exc, exception_map) continue app.logger.debug("Found {} {}".format( len(snapshots), self.i_am_plural)) for snapshot in snapshots: name = snapshot.get('DBSnapshotIdentifier') if self.check_ignore_list(name): continue config = dict(snapshot) config['InstanceCreateTime'] = str(config.get('InstanceCreateTime')) config['SnapshotCreateTime'] = str(config.get('SnapshotCreateTime')) config['Arn'] = str(config.get('DBSnapshotArn')) config['Attributes'] = dict() try: attributes = self.wrap_aws_rate_limited_call( rds.describe_db_snapshot_attributes, DBSnapshotIdentifier=snapshot.get('DBSnapshotIdentifier')) for attribute in attributes['DBSnapshotAttributesResult']['DBSnapshotAttributes']: config['Attributes'][attribute['AttributeName']] = attribute['AttributeValues'] except Exception as e: if region.name not in TROUBLE_REGIONS: exc = BotoConnectionIssue(str(e), self.index, account, region.name) self.slurp_exception((self.index, account, region.name, name), exc, exception_map) item = RDSSnapshotItem( region=region.name, account=account, name=name, arn=snapshot.get('DBSnapshotArn'), config=dict(config), source_watcher=self) item_list.append(item) return item_list, exception_map
[ "def", "slurp", "(", "self", ")", ":", "self", ".", "prep_for_slurp", "(", ")", "from", "security_monkey", ".", "common", ".", "sts_connect", "import", "connect", "item_list", "=", "[", "]", "exception_map", "=", "{", "}", "for", "account", "in", "self", ...
https://github.com/Netflix/security_monkey/blob/c28592ffd518fa399527d26262683fc860c30eef/security_monkey/watchers/rds/rds_snapshot.py#L40-L115
stanfordnlp/stanza-old
920c55d8eaa1e7105971059c66eb448a74c100d6
stanza/monitoring/experiment.py
python
AttrDict.__init__
(self, *args, **kwargs)
[]
def __init__(self, *args, **kwargs): super(AttrDict, self).__init__(*args, **kwargs) self.__dict__ = self
[ "def", "__init__", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "super", "(", "AttrDict", ",", "self", ")", ".", "__init__", "(", "*", "args", ",", "*", "*", "kwargs", ")", "self", ".", "__dict__", "=", "self" ]
https://github.com/stanfordnlp/stanza-old/blob/920c55d8eaa1e7105971059c66eb448a74c100d6/stanza/monitoring/experiment.py#L23-L25
tendenci/tendenci
0f2c348cc0e7d41bc56f50b00ce05544b083bf1d
tendenci/apps/jobs/migrations/0003_auto_20170910_1702.py
python
migrate_customized_jobs_templates
()
Update those jobs templates that are pulled to sites jobs/add.html, jobs/edit.html: ============================= Remove: <fieldset class="boxy-grey" > <legend id="category-title" style="cursor: pointer"><span>+</span> {% trans 'Category' %}</legend> <div id="category-form"> {{ categoryform|styled_form }} </div> </fieldset> Replace: <script type="text/javascript" src="{% static 'js/email-verification.js' %}"> </script> With: <script type="text/javascript" src="{% static 'js/email-verification.js' %}"> </script> <script type="text/javascript">{% include 'jobs/include/get_subcategories.js' %} </script> jobs/meta.html: =============== Replace: {% with job.category_set as job_cat %} With: {% with job.cat as job_cat %} Replace: {% if job_cat.category %} With: {% if job_cat %} Replace: categories={{ job_cat.category.pk }}">{{ job_cat.category }} With: cat={{ job_cat.pk }}">{{ job_cat.name }} Replace: {% if job_cat.sub_category %} With: {% if job.sub_cat %} Replace: subcategories={{ job_cat.sub_category.pk }}">{{ job_cat.sub_category }} With: cat={{ job_cat.pk }}&sub_cat={{ job.sub_cat.pk }}">{{ job.sub_cat.name }} Remove: <li> <a href="{% url 'category.update' job.opt_app_label job.opt_module_name job.pk %}">{% trans "Edit Categories" %}</a> </li> jobs/search-form.html: ====================== Replace: form.categories With: form.cat Replace: form.subcategories With: form.sub_cat jobs/search.html: ================= Replace: var $catAndSubcatSelect = $('#id_categories, #id_subcategories') With: var $catAndSubcatSelect = $('#id_cat, #id_sub_cat') jobs/top_nav_items.html: ======================== Replace: <li class="content-item"> <span class="app-name"> <a href="{% url 'category.update' app_object.opt_app_label job.opt_module_name app_object.pk %}">{% trans "Edit Categories" %}</a> </span> </li> With: {% if request.user.is_superuser %} <li class="content-item"> <span class="app-name"> <a href="{% url 'admin:jobs_category_changelist' %}">{% trans "Manage Categories" %}</a> </span> </li> {% endif %}
Update those jobs templates that are pulled to sites
[ "Update", "those", "jobs", "templates", "that", "are", "pulled", "to", "sites" ]
def migrate_customized_jobs_templates(): """ Update those jobs templates that are pulled to sites jobs/add.html, jobs/edit.html: ============================= Remove: <fieldset class="boxy-grey" > <legend id="category-title" style="cursor: pointer"><span>+</span> {% trans 'Category' %}</legend> <div id="category-form"> {{ categoryform|styled_form }} </div> </fieldset> Replace: <script type="text/javascript" src="{% static 'js/email-verification.js' %}"> </script> With: <script type="text/javascript" src="{% static 'js/email-verification.js' %}"> </script> <script type="text/javascript">{% include 'jobs/include/get_subcategories.js' %} </script> jobs/meta.html: =============== Replace: {% with job.category_set as job_cat %} With: {% with job.cat as job_cat %} Replace: {% if job_cat.category %} With: {% if job_cat %} Replace: categories={{ job_cat.category.pk }}">{{ job_cat.category }} With: cat={{ job_cat.pk }}">{{ job_cat.name }} Replace: {% if job_cat.sub_category %} With: {% if job.sub_cat %} Replace: subcategories={{ job_cat.sub_category.pk }}">{{ job_cat.sub_category }} With: cat={{ job_cat.pk }}&sub_cat={{ job.sub_cat.pk }}">{{ job.sub_cat.name }} Remove: <li> <a href="{% url 'category.update' job.opt_app_label job.opt_module_name job.pk %}">{% trans "Edit Categories" %}</a> </li> jobs/search-form.html: ====================== Replace: form.categories With: form.cat Replace: form.subcategories With: form.sub_cat jobs/search.html: ================= Replace: var $catAndSubcatSelect = $('#id_categories, #id_subcategories') With: var $catAndSubcatSelect = $('#id_cat, #id_sub_cat') jobs/top_nav_items.html: ======================== Replace: <li class="content-item"> <span class="app-name"> <a href="{% url 'category.update' app_object.opt_app_label job.opt_module_name app_object.pk %}">{% trans "Edit Categories" %}</a> </span> </li> With: {% if request.user.is_superuser %} <li class="content-item"> <span class="app-name"> <a href="{% url 'admin:jobs_category_changelist' %}">{% trans "Manage Categories" %}</a> </span> </li> {% endif %} """ import re from tendenci.apps.theme.utils import get_theme_root dir_path = get_theme_root() # jobs/add.html and edit.html files_list = ['{}/templates/jobs/add.html'.format(dir_path), '{}/templates/jobs/edit.html'.format(dir_path)] for file_path in files_list: if os.path.isfile(file_path): with open(file_path, 'r') as f: content = f.read() # remove categoryform p = r'{0}([\d\D\s\S\w\W]*?){1}([\d\D\s\S\w\W]*?){2}'.format(re.escape('<fieldset class="boxy-grey" >'), re.escape('{{ categoryform|styled_form }}'), re.escape('</fieldset>')) content = re.sub(p, '', content) # add js link p = r'{0}\s*{1}'.format(re.escape('<script type="text/javascript" src="{% static \'js/email-verification.js\' %}">'), re.escape('</script>')) content = re.sub(p, '{0}\n{1}'.format('<script type="text/javascript" src="{% static \'js/email-verification.js\' %}"> </script>', '<script type="text/javascript">{% include \'jobs/include/get_subcategories.js\' %} </script>)'), content) with open(file_path, 'w') as f: # save the updated content back to file f.write(content) # jobs/meta.html file_path = '{}/templates/jobs/meta.html'.format(dir_path) if os.path.isfile(file_path): find_replace_list = [('{% with job.category_set as job_cat %}', '{% with job.cat as job_cat %}'), ('{% if job_cat.category %}', '{% if job_cat %}'), ('categories={{ job_cat.category.pk }}">{{ job_cat.category }}', 'cat={{ job_cat.pk }}">{{ job_cat.name }}'), ('{% if job_cat.sub_category %}', '{% if job.sub_cat %}'), ('subcategories={{ job_cat.sub_category.pk }}">{{ job_cat.sub_category }}', 'cat={{ job_cat.pk }}&sub_cat={{ job.sub_cat.pk }}">{{ job.sub_cat.name }}'), ] with open(file_path, 'r') as f: content = f.read() for (string_to_find, string_to_replace) in find_replace_list: content = content.replace(string_to_find, string_to_replace) p = r'{0}\s+{1}\s+{2}'.format(re.escape('<li>'), re.escape("""<a href="{% url 'category.update' job.opt_app_label job.opt_module_name job.pk %}">{% trans "Edit Categories" %}</a>"""), re.escape('</li>')) content = re.sub(p, '', content) with open(file_path, 'w') as f: f.write(content) # jobs/search-form.html file_path = '{}/templates/jobs/search-form.html'.format(dir_path) if os.path.isfile(file_path): find_replace_list = [('form.categories', 'form.cat'), ('form.subcategories', 'form.sub_cat') ] with open(file_path, 'r') as f: content = f.read() for (string_to_find, string_to_replace) in find_replace_list: content = content.replace(string_to_find, string_to_replace) with open(file_path, 'w') as f: f.write(content) # jobs/search.html file_path = '{}/templates/jobs/search.html'.format(dir_path) if os.path.isfile(file_path): with open(file_path, 'r') as f: content = f.read() content = content.replace("var $catAndSubcatSelect = $('#id_categories, #id_subcategories')", "var $catAndSubcatSelect = $('#id_cat, #id_sub_cat')") with open(file_path, 'w') as f: f.write(content) #jobs/top_nav_items.html file_path = '{}/templates/jobs/top_nav_items.html'.format(dir_path) if os.path.isfile(file_path): with open(file_path, 'r') as f: content = f.read() p = r'{0}\s+{1}\s+{2}\s+{3}\s+{4}'.format( re.escape('<li class="content-item">'), re.escape('<span class="app-name">'), re.escape("""<a href="{% url 'category.update' app_object.opt_app_label job.opt_module_name app_object.pk %}">{% trans "Edit Categories" %}</a>"""), re.escape('</span>'), re.escape('</li>')) manage_cat = """ {% if request.user.is_superuser %} <li class="content-item"> <span class="app-name"> <a href="{% url 'admin:jobs_category_changelist' %}">{% trans "Manage Categories" %}</a> </span> </li> {% endif %} """ content = re.sub(p, manage_cat, content) with open(file_path, 'w') as f: f.write(content)
[ "def", "migrate_customized_jobs_templates", "(", ")", ":", "import", "re", "from", "tendenci", ".", "apps", ".", "theme", ".", "utils", "import", "get_theme_root", "dir_path", "=", "get_theme_root", "(", ")", "# jobs/add.html and edit.html", "files_list", "=", "[", ...
https://github.com/tendenci/tendenci/blob/0f2c348cc0e7d41bc56f50b00ce05544b083bf1d/tendenci/apps/jobs/migrations/0003_auto_20170910_1702.py#L9-L216
gem/oq-engine
1bdb88f3914e390abcbd285600bfd39477aae47c
openquake/hazardlib/gsim/tusa_langer_2016.py
python
_compute_magnitude1
(kind, ctx, C)
return C['a'] + (C['b1'] * (ctx.mag)) + (C['b2'] * (ctx.mag) ** 2)
Compute the magnitude function, equation (9):
Compute the magnitude function, equation (9):
[ "Compute", "the", "magnitude", "function", "equation", "(", "9", ")", ":" ]
def _compute_magnitude1(kind, ctx, C): """ Compute the magnitude function, equation (9): """ return C['a'] + (C['b1'] * (ctx.mag)) + (C['b2'] * (ctx.mag) ** 2)
[ "def", "_compute_magnitude1", "(", "kind", ",", "ctx", ",", "C", ")", ":", "return", "C", "[", "'a'", "]", "+", "(", "C", "[", "'b1'", "]", "*", "(", "ctx", ".", "mag", ")", ")", "+", "(", "C", "[", "'b2'", "]", "*", "(", "ctx", ".", "mag",...
https://github.com/gem/oq-engine/blob/1bdb88f3914e390abcbd285600bfd39477aae47c/openquake/hazardlib/gsim/tusa_langer_2016.py#L74-L78
radlab/sparrow
afb8efadeb88524f1394d1abe4ea66c6fd2ac744
deploy/third_party/boto-2.1.1/boto/sdb/item.py
python
Item.delete
(self)
Deletes this item in SDB. .. note:: This local Python object remains in its current state after deletion, this only deletes the remote item in SDB.
Deletes this item in SDB. .. note:: This local Python object remains in its current state after deletion, this only deletes the remote item in SDB.
[ "Deletes", "this", "item", "in", "SDB", ".", "..", "note", "::", "This", "local", "Python", "object", "remains", "in", "its", "current", "state", "after", "deletion", "this", "only", "deletes", "the", "remote", "item", "in", "SDB", "." ]
def delete(self): """ Deletes this item in SDB. .. note:: This local Python object remains in its current state after deletion, this only deletes the remote item in SDB. """ self.domain.delete_item(self)
[ "def", "delete", "(", "self", ")", ":", "self", ".", "domain", ".", "delete_item", "(", "self", ")" ]
https://github.com/radlab/sparrow/blob/afb8efadeb88524f1394d1abe4ea66c6fd2ac744/deploy/third_party/boto-2.1.1/boto/sdb/item.py#L170-L177
metamorphose/metamorphose2
d2bdd6a86340b9668e93b35a6a568894c9909d68
src/mutagen/_util.py
python
dict_match
(d, key, default=None)
return default
Like __getitem__ but works as if the keys() are all filename patterns. Returns the value of any dict key that matches the passed key.
Like __getitem__ but works as if the keys() are all filename patterns. Returns the value of any dict key that matches the passed key.
[ "Like", "__getitem__", "but", "works", "as", "if", "the", "keys", "()", "are", "all", "filename", "patterns", ".", "Returns", "the", "value", "of", "any", "dict", "key", "that", "matches", "the", "passed", "key", "." ]
def dict_match(d, key, default=None): """Like __getitem__ but works as if the keys() are all filename patterns. Returns the value of any dict key that matches the passed key. """ if key in d and "[" not in key: return d[key] else: for pattern, value in iteritems(d): if fnmatchcase(key, pattern): return value return default
[ "def", "dict_match", "(", "d", ",", "key", ",", "default", "=", "None", ")", ":", "if", "key", "in", "d", "and", "\"[\"", "not", "in", "key", ":", "return", "d", "[", "key", "]", "else", ":", "for", "pattern", ",", "value", "in", "iteritems", "("...
https://github.com/metamorphose/metamorphose2/blob/d2bdd6a86340b9668e93b35a6a568894c9909d68/src/mutagen/_util.py#L421-L432
kensho-technologies/graphql-compiler
4318443b7b2512a059f3616112bfc40bbf8eec06
graphql_compiler/schema_generation/orientdb/schema_graph_builder.py
python
_get_inherited_property_definitions
(superclass_set, class_name_to_definition)
return list( chain.from_iterable( class_name_to_definition[inherited_class_name]["properties"] for inherited_class_name in superclass_set ) )
Return a class's inherited OrientDB property definitions.
Return a class's inherited OrientDB property definitions.
[ "Return", "a", "class", "s", "inherited", "OrientDB", "property", "definitions", "." ]
def _get_inherited_property_definitions(superclass_set, class_name_to_definition): """Return a class's inherited OrientDB property definitions.""" return list( chain.from_iterable( class_name_to_definition[inherited_class_name]["properties"] for inherited_class_name in superclass_set ) )
[ "def", "_get_inherited_property_definitions", "(", "superclass_set", ",", "class_name_to_definition", ")", ":", "return", "list", "(", "chain", ".", "from_iterable", "(", "class_name_to_definition", "[", "inherited_class_name", "]", "[", "\"properties\"", "]", "for", "i...
https://github.com/kensho-technologies/graphql-compiler/blob/4318443b7b2512a059f3616112bfc40bbf8eec06/graphql_compiler/schema_generation/orientdb/schema_graph_builder.py#L318-L325
danilobellini/audiolazy
dba0a278937909980ed40b976d866b8e97c35dee
audiolazy/lazy_midi.py
python
octaves
(freq, fmin=20., fmax=2e4)
return list(it.takewhile(lambda x: x > fmin, (freq * 2 ** harm for harm in it.count(0, -1)) ))[::-1] \ + list(it.takewhile(lambda x: x < fmax, (freq * 2 ** harm for harm in it.count(1)) ))
Given a frequency and a frequency range, returns all frequencies in that range that is an integer number of octaves related to the given frequency. Parameters ---------- freq : Frequency, in any (linear) unit. fmin, fmax : Frequency range, in the same unit of ``freq``. Defaults to 20.0 and 20,000.0, respectively. Returns ------- A list of frequencies, in the same unit of ``freq`` and in ascending order. Examples -------- >>> from audiolazy import octaves, sHz >>> octaves(440.) [27.5, 55.0, 110.0, 220.0, 440.0, 880.0, 1760.0, 3520.0, 7040.0, 14080.0] >>> octaves(440., fmin=3000) [3520.0, 7040.0, 14080.0] >>> Hz = sHz(44100)[1] # Conversion unit from sample rate >>> freqs = octaves(440 * Hz, fmin=300 * Hz, fmax = 1000 * Hz) # rad/sample >>> len(freqs) # Number of octaves 2 >>> [round(f, 6) for f in freqs] # Values in rad/sample [0.062689, 0.125379] >>> [round(f / Hz, 6) for f in freqs] # Values in Hz [440.0, 880.0]
Given a frequency and a frequency range, returns all frequencies in that range that is an integer number of octaves related to the given frequency.
[ "Given", "a", "frequency", "and", "a", "frequency", "range", "returns", "all", "frequencies", "in", "that", "range", "that", "is", "an", "integer", "number", "of", "octaves", "related", "to", "the", "given", "frequency", "." ]
def octaves(freq, fmin=20., fmax=2e4): """ Given a frequency and a frequency range, returns all frequencies in that range that is an integer number of octaves related to the given frequency. Parameters ---------- freq : Frequency, in any (linear) unit. fmin, fmax : Frequency range, in the same unit of ``freq``. Defaults to 20.0 and 20,000.0, respectively. Returns ------- A list of frequencies, in the same unit of ``freq`` and in ascending order. Examples -------- >>> from audiolazy import octaves, sHz >>> octaves(440.) [27.5, 55.0, 110.0, 220.0, 440.0, 880.0, 1760.0, 3520.0, 7040.0, 14080.0] >>> octaves(440., fmin=3000) [3520.0, 7040.0, 14080.0] >>> Hz = sHz(44100)[1] # Conversion unit from sample rate >>> freqs = octaves(440 * Hz, fmin=300 * Hz, fmax = 1000 * Hz) # rad/sample >>> len(freqs) # Number of octaves 2 >>> [round(f, 6) for f in freqs] # Values in rad/sample [0.062689, 0.125379] >>> [round(f / Hz, 6) for f in freqs] # Values in Hz [440.0, 880.0] """ # Input validation if any(f <= 0 for f in (freq, fmin, fmax)): raise ValueError("Frequencies have to be positive") # If freq is out of range, avoid range extension while freq < fmin: freq *= 2 while freq > fmax: freq /= 2 if freq < fmin: # Gone back and forth return [] # Finds the range for a valid input return list(it.takewhile(lambda x: x > fmin, (freq * 2 ** harm for harm in it.count(0, -1)) ))[::-1] \ + list(it.takewhile(lambda x: x < fmax, (freq * 2 ** harm for harm in it.count(1)) ))
[ "def", "octaves", "(", "freq", ",", "fmin", "=", "20.", ",", "fmax", "=", "2e4", ")", ":", "# Input validation", "if", "any", "(", "f", "<=", "0", "for", "f", "in", "(", "freq", ",", "fmin", ",", "fmax", ")", ")", ":", "raise", "ValueError", "(",...
https://github.com/danilobellini/audiolazy/blob/dba0a278937909980ed40b976d866b8e97c35dee/audiolazy/lazy_midi.py#L111-L163
barneygale/quarry
eac47471fc55598de6b4723a728a37d035002237
quarry/types/buffer/v1_13.py
python
Buffer1_13.unpack_entity_metadata
(self)
Unpacks entity metadata.
Unpacks entity metadata.
[ "Unpacks", "entity", "metadata", "." ]
def unpack_entity_metadata(self): """ Unpacks entity metadata. """ metadata = {} while True: key = self.unpack('B') if key == 255: return metadata ty = self.unpack('B') if ty == 0: val = self.unpack('b') elif ty == 1: val = self.unpack_varint() elif ty == 2: val = self.unpack('f') elif ty == 3: val = self.unpack_string() elif ty == 4: val = self.unpack_chat() elif ty == 5: val = self.unpack_optional(self.unpack_chat) elif ty == 6: val = self.unpack_slot() elif ty == 7: val = self.unpack('?') elif ty == 8: val = self.unpack_rotation() elif ty == 9: val = self.unpack_position() elif ty == 10: val = self.unpack_optional(self.unpack_position) elif ty == 11: val = self.unpack_direction() elif ty == 12: val = self.unpack_optional(self.unpack_uuid) elif ty == 13: val = self.unpack_block() elif ty == 14: val = self.unpack_nbt() elif ty == 15: val = self.unpack_particle() else: raise ValueError("Unknown entity metadata type: %d" % ty) metadata[ty, key] = val
[ "def", "unpack_entity_metadata", "(", "self", ")", ":", "metadata", "=", "{", "}", "while", "True", ":", "key", "=", "self", ".", "unpack", "(", "'B'", ")", "if", "key", "==", "255", ":", "return", "metadata", "ty", "=", "self", ".", "unpack", "(", ...
https://github.com/barneygale/quarry/blob/eac47471fc55598de6b4723a728a37d035002237/quarry/types/buffer/v1_13.py#L93-L121
morganstanley/treadmill
f18267c665baf6def4374d21170198f63ff1cde4
lib/python/treadmill/bootstrap/install.py
python
install
(package, dst_dir, params, run=None, profile=None)
Installs the services.
Installs the services.
[ "Installs", "the", "services", "." ]
def install(package, dst_dir, params, run=None, profile=None): """Installs the services. """ _LOGGER.info('install: %s - %s, profile: %s', package, dst_dir, profile) packages = [package] module = plugin_manager.load('treadmill.bootstrap', package) extension_module = None if profile: _LOGGER.info('Installing profile: %s', profile) extension_name = '{}.{}'.format(package, profile) packages.append(extension_name) try: extension_module = plugin_manager.load('treadmill.bootstrap', extension_name) except KeyError: _LOGGER.info('Extension not defined: %s, profile: %s', package, profile) subproc.load_packages(packages, lazy=False) # Store resolved aliases aliases_path = os.path.join(dst_dir, '.aliases.json') aliases = subproc.get_aliases() with io.open(aliases_path, 'w') as f_aliases: f_aliases.write(json.dumps(aliases)) defaults = {} defaults.update(getattr(module, 'DEFAULTS', {})) if extension_module: defaults.update(getattr(extension_module, 'DEFAULTS', {})) # TODO: this is ugly, error prone and should go away. # aliases should be in default scope, everything else in _args. defaults['_alias'] = aliases defaults.update(aliases) defaults.update(params) defaults['aliases_path'] = aliases_path os.environ['TREADMILL_ALIASES_PATH'] = defaults['aliases_path'] interpolated = bootstrap.interpolate(defaults, defaults) fs.mkdir_safe(dst_dir) with io.open(os.path.join(dst_dir, '.install'), 'w') as rec: _install(module, PLATFORM, dst_dir, interpolated, rec=rec) if extension_module: _install( extension_module, '.'.join([profile, PLATFORM]), dst_dir, interpolated, rec=rec ) # Extract logging configuration. logconf_dir = os.path.join(dst_dir, 'logging') fs.mkdir_safe(logconf_dir) tm_logging.write_configs(logconf_dir) # Write entry-point cache distributions = pkg_resources.AvailableDistributions() plugin_manager.dump_cache( os.path.join(dst_dir, 'plugins.json'), distributions ) if run: _run(run)
[ "def", "install", "(", "package", ",", "dst_dir", ",", "params", ",", "run", "=", "None", ",", "profile", "=", "None", ")", ":", "_LOGGER", ".", "info", "(", "'install: %s - %s, profile: %s'", ",", "package", ",", "dst_dir", ",", "profile", ")", "packages"...
https://github.com/morganstanley/treadmill/blob/f18267c665baf6def4374d21170198f63ff1cde4/lib/python/treadmill/bootstrap/install.py#L340-L411
llSourcell/AI_Artist
3038c06c2e389b9c919c881c9a169efe2fd7810e
lib/python2.7/site.py
python
setencoding
()
Set the string encoding used by the Unicode implementation. The default is 'ascii', but if you're willing to experiment, you can change this.
Set the string encoding used by the Unicode implementation. The default is 'ascii', but if you're willing to experiment, you can change this.
[ "Set", "the", "string", "encoding", "used", "by", "the", "Unicode", "implementation", ".", "The", "default", "is", "ascii", "but", "if", "you", "re", "willing", "to", "experiment", "you", "can", "change", "this", "." ]
def setencoding(): """Set the string encoding used by the Unicode implementation. The default is 'ascii', but if you're willing to experiment, you can change this.""" encoding = "ascii" # Default value set by _PyUnicode_Init() if 0: # Enable to support locale aware default string encodings. import locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1] if 0: # Enable to switch off string to Unicode coercion and implicit # Unicode to string conversion. encoding = "undefined" if encoding != "ascii": # On Non-Unicode builds this will raise an AttributeError... sys.setdefaultencoding(encoding)
[ "def", "setencoding", "(", ")", ":", "encoding", "=", "\"ascii\"", "# Default value set by _PyUnicode_Init()", "if", "0", ":", "# Enable to support locale aware default string encodings.", "import", "locale", "loc", "=", "locale", ".", "getdefaultlocale", "(", ")", "if", ...
https://github.com/llSourcell/AI_Artist/blob/3038c06c2e389b9c919c881c9a169efe2fd7810e/lib/python2.7/site.py#L525-L542
PaddlePaddle/PaddleX
2bab73f81ab54e328204e7871e6ae4a82e719f5d
paddlex/cv/transforms/batch_operators.py
python
BatchCompose.__init__
(self, batch_transforms=None, collate_batch=True)
[]
def __init__(self, batch_transforms=None, collate_batch=True): super(BatchCompose, self).__init__() self.batch_transforms = batch_transforms self.collate_batch = collate_batch
[ "def", "__init__", "(", "self", ",", "batch_transforms", "=", "None", ",", "collate_batch", "=", "True", ")", ":", "super", "(", "BatchCompose", ",", "self", ")", ".", "__init__", "(", ")", "self", ".", "batch_transforms", "=", "batch_transforms", "self", ...
https://github.com/PaddlePaddle/PaddleX/blob/2bab73f81ab54e328204e7871e6ae4a82e719f5d/paddlex/cv/transforms/batch_operators.py#L29-L32
openedx/edx-platform
68dd185a0ab45862a2a61e0f803d7e03d2be71b5
common/lib/xmodule/xmodule/modulestore/__init__.py
python
BulkOperationsMixin._end_outermost_bulk_operation
(self, bulk_ops_record, structure_key)
The outermost nested bulk_operation call: do the actual end of the bulk operation. Implementing classes must override this method; otherwise, the bulk operations are a noop
The outermost nested bulk_operation call: do the actual end of the bulk operation.
[ "The", "outermost", "nested", "bulk_operation", "call", ":", "do", "the", "actual", "end", "of", "the", "bulk", "operation", "." ]
def _end_outermost_bulk_operation(self, bulk_ops_record, structure_key): """ The outermost nested bulk_operation call: do the actual end of the bulk operation. Implementing classes must override this method; otherwise, the bulk operations are a noop """ pass
[ "def", "_end_outermost_bulk_operation", "(", "self", ",", "bulk_ops_record", ",", "structure_key", ")", ":", "pass" ]
https://github.com/openedx/edx-platform/blob/68dd185a0ab45862a2a61e0f803d7e03d2be71b5/common/lib/xmodule/xmodule/modulestore/__init__.py#L253-L259
Rhizome-Conifer/conifer
308fbb98c1b9e668ef4facb66b43f0c362c202de
webrecorder/webrecorder/models/base.py
python
RedisUnorderedList.get_objects
(self, cls, load=True)
return obj_list
Return set elements. :param class cls: Redis building block class :param bool load: whether to load Redis entries :returns: set elements :rtype: list
Return set elements.
[ "Return", "set", "elements", "." ]
def get_objects(self, cls, load=True): """Return set elements. :param class cls: Redis building block class :param bool load: whether to load Redis entries :returns: set elements :rtype: list """ all_objs = self.get_keys() obj_list = [] for val in all_objs: obj = cls(my_id=val, redis=self.redis, access=self.comp.access) obj.owner = self.comp if load: obj.load() obj_list.append(obj) return obj_list
[ "def", "get_objects", "(", "self", ",", "cls", ",", "load", "=", "True", ")", ":", "all_objs", "=", "self", ".", "get_keys", "(", ")", "obj_list", "=", "[", "]", "for", "val", "in", "all_objs", ":", "obj", "=", "cls", "(", "my_id", "=", "val", ",...
https://github.com/Rhizome-Conifer/conifer/blob/308fbb98c1b9e668ef4facb66b43f0c362c202de/webrecorder/webrecorder/models/base.py#L821-L845
cortex-lab/phy
9a330b9437a3d0b40a37a201d147224e6e7fb462
phy/apps/base.py
python
BaseController._get_firing_rate
(self, cluster_id)
return Bunch(data=st, x_min=0, x_max=dur)
Return the firing rate data of a cluster.
Return the firing rate data of a cluster.
[ "Return", "the", "firing", "rate", "data", "of", "a", "cluster", "." ]
def _get_firing_rate(self, cluster_id): """Return the firing rate data of a cluster.""" st = self.get_spike_times(cluster_id) dur = self.model.duration return Bunch(data=st, x_min=0, x_max=dur)
[ "def", "_get_firing_rate", "(", "self", ",", "cluster_id", ")", ":", "st", "=", "self", ".", "get_spike_times", "(", "cluster_id", ")", "dur", "=", "self", ".", "model", ".", "duration", "return", "Bunch", "(", "data", "=", "st", ",", "x_min", "=", "0"...
https://github.com/cortex-lab/phy/blob/9a330b9437a3d0b40a37a201d147224e6e7fb462/phy/apps/base.py#L1526-L1530
fastai/imagenet-fast
faa0f9dfc9e8e058ffd07a248724bf384f526fae
imagenet_nv/jh_tmp.py
python
top5
(output, target)
return correct_k.mul_(1.0 / batch_size)
Computes the precision@k for the specified values of k
Computes the precision
[ "Computes", "the", "precision" ]
def top5(output, target): """Computes the precision@k for the specified values of k""" top5 = 5 batch_size = target.size(0) _, pred = output.topk(top5, 1, True, True) pred = pred.t() correct = pred.eq(target.view(1, -1).expand_as(pred)) correct_k = correct[:top5].view(-1).float().sum(0, keepdim=True) return correct_k.mul_(1.0 / batch_size)
[ "def", "top5", "(", "output", ",", "target", ")", ":", "top5", "=", "5", "batch_size", "=", "target", ".", "size", "(", "0", ")", "_", ",", "pred", "=", "output", ".", "topk", "(", "top5", ",", "1", ",", "True", ",", "True", ")", "pred", "=", ...
https://github.com/fastai/imagenet-fast/blob/faa0f9dfc9e8e058ffd07a248724bf384f526fae/imagenet_nv/jh_tmp.py#L177-L185
wrr/wwwhisper
38a55dd9c828fbb1b5a8234ea3ddf2242e684983
wwwhisper_auth/assets.py
python
HtmlFileView.do_get
(self, body)
return http.HttpResponseOKHtml(body)
[]
def do_get(self, body): return http.HttpResponseOKHtml(body)
[ "def", "do_get", "(", "self", ",", "body", ")", ":", "return", "http", ".", "HttpResponseOKHtml", "(", "body", ")" ]
https://github.com/wrr/wwwhisper/blob/38a55dd9c828fbb1b5a8234ea3ddf2242e684983/wwwhisper_auth/assets.py#L32-L33
tornadomeet/mxnet-face
25d212791908c9dc0ea0c1de8e05af6d56f15e81
detection/symbol/processing.py
python
bbox_transform
(ex_rois, gt_rois)
return targets
compute bounding box regression targets from ex_rois to gt_rois :param ex_rois: [N, 4] :param gt_rois: [N, 4] :return: [N, 4]
compute bounding box regression targets from ex_rois to gt_rois :param ex_rois: [N, 4] :param gt_rois: [N, 4] :return: [N, 4]
[ "compute", "bounding", "box", "regression", "targets", "from", "ex_rois", "to", "gt_rois", ":", "param", "ex_rois", ":", "[", "N", "4", "]", ":", "param", "gt_rois", ":", "[", "N", "4", "]", ":", "return", ":", "[", "N", "4", "]" ]
def bbox_transform(ex_rois, gt_rois): """ compute bounding box regression targets from ex_rois to gt_rois :param ex_rois: [N, 4] :param gt_rois: [N, 4] :return: [N, 4] """ ex_widths = ex_rois[:, 2] - ex_rois[:, 0] + 1.0 ex_heights = ex_rois[:, 3] - ex_rois[:, 1] + 1.0 ex_ctr_x = ex_rois[:, 0] + 0.5 * (ex_widths - 1.0) ex_ctr_y = ex_rois[:, 1] + 0.5 * (ex_heights - 1.0) gt_widths = gt_rois[:, 2] - gt_rois[:, 0] + 1.0 gt_heights = gt_rois[:, 3] - gt_rois[:, 1] + 1.0 gt_ctr_x = gt_rois[:, 0] + 0.5 * (gt_widths - 1.0) gt_ctr_y = gt_rois[:, 1] + 0.5 * (gt_heights - 1.0) targets_dx = (gt_ctr_x - ex_ctr_x) / (ex_widths + 1e-14) targets_dy = (gt_ctr_y - ex_ctr_y) / (ex_heights + 1e-14) targets_dw = np.log(gt_widths / ex_widths) targets_dh = np.log(gt_heights / ex_heights) targets = np.vstack( (targets_dx, targets_dy, targets_dw, targets_dh)).transpose() return targets
[ "def", "bbox_transform", "(", "ex_rois", ",", "gt_rois", ")", ":", "ex_widths", "=", "ex_rois", "[", ":", ",", "2", "]", "-", "ex_rois", "[", ":", ",", "0", "]", "+", "1.0", "ex_heights", "=", "ex_rois", "[", ":", ",", "3", "]", "-", "ex_rois", "...
https://github.com/tornadomeet/mxnet-face/blob/25d212791908c9dc0ea0c1de8e05af6d56f15e81/detection/symbol/processing.py#L8-L32
apigee/henchman
13c53c66669800aaa89f1799ac974b45ec473c3d
modules/curl/curl/requests/requests/models.py
python
Response.__iter__
(self)
return self.iter_content(128)
Allows you to use a response as an iterator.
Allows you to use a response as an iterator.
[ "Allows", "you", "to", "use", "a", "response", "as", "an", "iterator", "." ]
def __iter__(self): """Allows you to use a response as an iterator.""" return self.iter_content(128)
[ "def", "__iter__", "(", "self", ")", ":", "return", "self", ".", "iter_content", "(", "128", ")" ]
https://github.com/apigee/henchman/blob/13c53c66669800aaa89f1799ac974b45ec473c3d/modules/curl/curl/requests/requests/models.py#L613-L615
clovaai/voxceleb_trainer
a0466aa285106c631a58c0ddb8ea27805e13ef7b
loss/proto.py
python
LossFunction.forward
(self, x, label=None)
return nloss, prec1
[]
def forward(self, x, label=None): assert x.size()[1] >= 2 out_anchor = torch.mean(x[:,1:,:],1) out_positive = x[:,0,:] stepsize = out_anchor.size()[0] output = -1 * (F.pairwise_distance(out_positive.unsqueeze(-1),out_anchor.unsqueeze(-1).transpose(0,2))**2) label = torch.from_numpy(numpy.asarray(range(0,stepsize))).cuda() nloss = self.criterion(output, label) prec1 = accuracy(output.detach(), label.detach(), topk=(1,))[0] return nloss, prec1
[ "def", "forward", "(", "self", ",", "x", ",", "label", "=", "None", ")", ":", "assert", "x", ".", "size", "(", ")", "[", "1", "]", ">=", "2", "out_anchor", "=", "torch", ".", "mean", "(", "x", "[", ":", ",", "1", ":", ",", ":", "]", ",", ...
https://github.com/clovaai/voxceleb_trainer/blob/a0466aa285106c631a58c0ddb8ea27805e13ef7b/loss/proto.py#L23-L36
nopernik/mpDNS
b17dc39e7068406df82cb3431b3042e74e520cf9
circuits/web/parsers/multipart.py
python
MultiDict.keys
(self)
return self.dict.keys()
[]
def keys(self): return self.dict.keys()
[ "def", "keys", "(", "self", ")", ":", "return", "self", ".", "dict", ".", "keys", "(", ")" ]
https://github.com/nopernik/mpDNS/blob/b17dc39e7068406df82cb3431b3042e74e520cf9/circuits/web/parsers/multipart.py#L86-L87
yuxiaokui/Intranet-Penetration
f57678a204840c83cbf3308e3470ae56c5ff514b
proxy/XX-Net/code/default/gae_proxy/server/lib/google/appengine/tools/handler.py
python
_HandleWildcardCases
(first_handler, second_handler)
return merged_handlers
Handle cases with trailing and leading wildcards. This function finds the set of intersections of two handlers where one has a leading wildcard (eg. *foo) in its pattern and at least one has a trailing wildcard (eg. baz*) in its pattern. The arguments are not symmetric. Args: first_handler: A SimpleHandler instance second_handler: A SimpleHandler instance Returns: A set of intersection patterns of the two Handlers. Example: If the pattern of first_handler is abc* and that of the second is *xyz, we return the intersection of the patterns, abc*xyz. Find more examples in the inline comments.
Handle cases with trailing and leading wildcards.
[ "Handle", "cases", "with", "trailing", "and", "leading", "wildcards", "." ]
def _HandleWildcardCases(first_handler, second_handler): """Handle cases with trailing and leading wildcards. This function finds the set of intersections of two handlers where one has a leading wildcard (eg. *foo) in its pattern and at least one has a trailing wildcard (eg. baz*) in its pattern. The arguments are not symmetric. Args: first_handler: A SimpleHandler instance second_handler: A SimpleHandler instance Returns: A set of intersection patterns of the two Handlers. Example: If the pattern of first_handler is abc* and that of the second is *xyz, we return the intersection of the patterns, abc*xyz. Find more examples in the inline comments. """ merged_handlers = set() if len(first_handler.pattern) <= 1 or len(second_handler.pattern) <= 1: return merged_handlers if (first_handler.pattern[-1], second_handler.pattern[0]) != ('*', '*'): return merged_handlers first_no_star = first_handler.pattern[:-1] merged_handlers.add(SimpleHandler(first_no_star + second_handler.pattern)) if second_handler.MatchesString(first_no_star): merged_handlers.add(SimpleHandler(first_no_star)) return merged_handlers
[ "def", "_HandleWildcardCases", "(", "first_handler", ",", "second_handler", ")", ":", "merged_handlers", "=", "set", "(", ")", "if", "len", "(", "first_handler", ".", "pattern", ")", "<=", "1", "or", "len", "(", "second_handler", ".", "pattern", ")", "<=", ...
https://github.com/yuxiaokui/Intranet-Penetration/blob/f57678a204840c83cbf3308e3470ae56c5ff514b/proxy/XX-Net/code/default/gae_proxy/server/lib/google/appengine/tools/handler.py#L423-L455
jython/frozen-mirror
b8d7aa4cee50c0c0fe2f4b235dd62922dd0f3f99
Lib/decimal.py
python
_format_sign
(is_negative, spec)
Determine sign character.
Determine sign character.
[ "Determine", "sign", "character", "." ]
def _format_sign(is_negative, spec): """Determine sign character.""" if is_negative: return '-' elif spec['sign'] in ' +': return spec['sign'] else: return ''
[ "def", "_format_sign", "(", "is_negative", ",", "spec", ")", ":", "if", "is_negative", ":", "return", "'-'", "elif", "spec", "[", "'sign'", "]", "in", "' +'", ":", "return", "spec", "[", "'sign'", "]", "else", ":", "return", "''" ]
https://github.com/jython/frozen-mirror/blob/b8d7aa4cee50c0c0fe2f4b235dd62922dd0f3f99/Lib/decimal.py#L6102-L6110
namisan/mt-dnn
8564c8cfa971391187bd699116fbe4388438d62d
experiments/xnli/extract_cat.py
python
load_xnli
(file, header=True)
return lang_dict, label_dict
[]
def load_xnli(file, header=True): lang_dict = collections.defaultdict(list) label_dict = {} cnt = 0 label_map = {"contradiction": 0, "neutral": 1, "entailment": 2} with open(file, encoding="utf8") as f: for line in f: if header: header = False continue blocks = line.strip().split('\t') #if blocks[1] == '-': continue lab = label_map[blocks[1]] if lab is None: import pdb; pdb.set_trace() uid = str(cnt) label_dict[uid] = lab lang_dict[blocks[0]].append(uid) cnt += 1 print(cnt) return lang_dict, label_dict
[ "def", "load_xnli", "(", "file", ",", "header", "=", "True", ")", ":", "lang_dict", "=", "collections", ".", "defaultdict", "(", "list", ")", "label_dict", "=", "{", "}", "cnt", "=", "0", "label_map", "=", "{", "\"contradiction\"", ":", "0", ",", "\"ne...
https://github.com/namisan/mt-dnn/blob/8564c8cfa971391187bd699116fbe4388438d62d/experiments/xnli/extract_cat.py#L4-L24
ryu577/pyray
860b71463e2729a85b1319b5c3571c0b8f3ba50c
pyray/shapes/solid/polyhedron.py
python
dodecahedron
(draw, r, shift = [1000,1000,0], scale = 300)
Draws the vertices, faces and edges of a dodecahedron.
Draws the vertices, faces and edges of a dodecahedron.
[ "Draws", "the", "vertices", "faces", "and", "edges", "of", "a", "dodecahedron", "." ]
def dodecahedron(draw, r, shift = [1000,1000,0], scale = 300): """ Draws the vertices, faces and edges of a dodecahedron. """ phi = (1+np.sqrt(5)) / 2 tet_orig = [] for i in [-1,1]: for j in [-1,1]: for k in [-1,1]: tet_orig.append(np.array([i,j,k])) phi = (1+np.sqrt(5))/2 for i in [-1,1]: for j in [-1,1]: tet_orig.append(np.array([0,i*phi,j/phi])) tet_orig.append(np.array([i/phi,0,j*phi])) tet_orig.append(np.array([i*phi,j/phi,0])) tet_orig = np.array(tet_orig) draw_dodecahedron_planes(draw, r, tet_orig, scale, shift)
[ "def", "dodecahedron", "(", "draw", ",", "r", ",", "shift", "=", "[", "1000", ",", "1000", ",", "0", "]", ",", "scale", "=", "300", ")", ":", "phi", "=", "(", "1", "+", "np", ".", "sqrt", "(", "5", ")", ")", "/", "2", "tet_orig", "=", "[", ...
https://github.com/ryu577/pyray/blob/860b71463e2729a85b1319b5c3571c0b8f3ba50c/pyray/shapes/solid/polyhedron.py#L668-L685
Antergos/Cnchi
13ac2209da9432d453e0097cf48a107640b563a9
src/installation/mkinitcpio.py
python
run
(dest_dir, settings, mount_devices, blvm)
Runs mkinitcpio
Runs mkinitcpio
[ "Runs", "mkinitcpio" ]
def run(dest_dir, settings, mount_devices, blvm): """ Runs mkinitcpio """ swap = 'swap' in mount_devices usr = '/usr' in mount_devices hooks = get_hooks(dest_dir, settings, swap, blvm, usr) modules = get_modules(settings) files = get_files(settings) set_hooks_modules_and_files(dest_dir, hooks, modules, files) # Run mkinitcpio on the target system # Fix for bsdcpio error. See: http://forum.antergos.com/viewtopic.php?f=5&t=1378&start=20#p5450 locale = settings.get('locale') cmd = ['sh', '-c', 'LANG={0} /usr/bin/mkinitcpio -p linux'.format(locale)] chroot_call(cmd, dest_dir) if settings.get('feature_lts'): cmd = ['sh', '-c', 'LANG={0} /usr/bin/mkinitcpio -p linux-lts'.format(locale)] chroot_call(cmd, dest_dir)
[ "def", "run", "(", "dest_dir", ",", "settings", ",", "mount_devices", ",", "blvm", ")", ":", "swap", "=", "'swap'", "in", "mount_devices", "usr", "=", "'/usr'", "in", "mount_devices", "hooks", "=", "get_hooks", "(", "dest_dir", ",", "settings", ",", "swap"...
https://github.com/Antergos/Cnchi/blob/13ac2209da9432d453e0097cf48a107640b563a9/src/installation/mkinitcpio.py#L38-L57
inasafe/inasafe
355eb2ce63f516b9c26af0c86a24f99e53f63f87
safe/gui/tools/print_report_dialog.py
python
PrintReportDialog.__init__
(self, impact_function, iface, dock=None, parent=None)
Constructor for the dialog. :param iface: A Quantum GIS QgisAppInterface instance. :type iface: QgisAppInterface :param parent: Parent widget of this dialog :type parent: QWidget :param dock: Optional dock widget instance that we can notify of changes to the keywords. :type dock: Dock .. versionadded: 4.3.0
Constructor for the dialog.
[ "Constructor", "for", "the", "dialog", "." ]
def __init__(self, impact_function, iface, dock=None, parent=None): """Constructor for the dialog. :param iface: A Quantum GIS QgisAppInterface instance. :type iface: QgisAppInterface :param parent: Parent widget of this dialog :type parent: QWidget :param dock: Optional dock widget instance that we can notify of changes to the keywords. :type dock: Dock .. versionadded: 4.3.0 """ QtWidgets.QDialog.__init__(self, parent) self.setupUi(self) # Save reference to the QGIS interface and parent self.iface = iface self.parent = parent self.dock = dock self.impact_function = impact_function self.create_pdf = False self.all_checkboxes = { impact_report_pdf_component['key']: self.impact_summary_checkbox, action_checklist_pdf_component['key']: self.action_checklist_checkbox, analysis_provenance_details_pdf_component['key']: self.provenance_checkbox, infographic_report['key']: self.infographic_checkbox } # setup checkboxes, all checkboxes are checked by default for checkbox in list(self.all_checkboxes.values()): checkbox.setChecked(True) # override template is selected by default self.default_template_radio.setChecked(True) self.is_population = False self.is_multi_exposure = isinstance( self.impact_function, MultiExposureImpactFunction) override_template_found = None population_found = False if self.is_multi_exposure: self.override_template_radio.setEnabled(False) self.override_template_label.setEnabled(False) self.override_template_found_label.setEnabled(False) # below features are currently not applicable for multi-exposure IF self.action_checklist_checkbox.setEnabled(False) self.action_checklist_checkbox.setChecked(False) self.provenance_checkbox.setEnabled(False) self.provenance_checkbox.setChecked(False) provenances = [ analysis.provenance for analysis in ( self.impact_function.impact_functions)] for provenance in provenances: exposure_keywords = provenance['exposure_keywords'] exposure_type = definition(exposure_keywords['exposure']) if exposure_type == exposure_population: population_found = True break self.infographic_checkbox.setEnabled(population_found) self.infographic_checkbox.setChecked(population_found) else: # search for available override template hazard_type = definition( self.impact_function.provenance['hazard_keywords'][ 'hazard']) exposure_type = definition( self.impact_function.provenance['exposure_keywords'][ 'exposure']) # noinspection PyArgumentList custom_template_dir = join( QgsApplication.qgisSettingsDirPath(), 'inasafe') if exists(custom_template_dir) and hazard_type and exposure_type: for filename in listdir(custom_template_dir): file_name, file_format = splitext(filename) if file_format[1:] != ( QgisComposerComponentsMetadata.OutputFormat.QPT): continue if hazard_type['key'] in file_name and ( exposure_type['key'] in file_name): override_template_found = filename # check for population exposure self.is_population = exposure_type == exposure_population self.infographic_checkbox.setEnabled( self.is_population or population_found) if override_template_found: string_format = tr('*Template override found: {template_path}') self.override_template_found_label.setText( string_format.format(template_path=override_template_found)) else: self.override_template_radio.setEnabled(False) # additional buttons self.button_print_pdf = QtWidgets.QPushButton(tr('Open as PDF')) self.button_print_pdf.setObjectName('button_print_pdf') self.button_print_pdf.setToolTip(tr( 'Write report to PDF and open it in default viewer')) self.button_box.addButton( self.button_print_pdf, QtWidgets.QDialogButtonBox.ActionRole) self.template_chooser.clicked.connect(self.template_chooser_clicked) self.button_print_pdf.clicked.connect(self.accept) self.button_open_composer.clicked.connect(self.accept) # self.no_map_radio.toggled.connect(self.toggle_template_selector) # self.no_map_radio.toggled.connect( # self.button_open_composer.setDisabled) self.default_template_radio.toggled.connect( self.toggle_template_selector) self.override_template_radio.toggled.connect( self.toggle_template_selector) self.search_directory_radio.toggled.connect( self.toggle_template_selector) self.search_on_disk_radio.toggled.connect( self.toggle_template_selector) # Set up things for context help self.help_button = self.button_box.button( QtWidgets.QDialogButtonBox.Help) # Allow toggling the help button self.help_button.setCheckable(True) self.help_button.toggled.connect(self.help_toggled) self.main_stacked_widget.setCurrentIndex(1) self.unwanted_templates = ['merged_report.qpt', 'infographic.qpt'] # Load templates from resources... template_dir_path = resources_path('qgis-composer-templates') self.populate_template_combobox( template_dir_path, self.unwanted_templates) # ...and user directory default_path = join(QgsApplication.qgisSettingsDirPath(), 'inasafe') path = setting( 'inasafe/reportTemplatePath', default_path, expected_type=str) if exists(path): self.populate_template_combobox(path) self.restore_state()
[ "def", "__init__", "(", "self", ",", "impact_function", ",", "iface", ",", "dock", "=", "None", ",", "parent", "=", "None", ")", ":", "QtWidgets", ".", "QDialog", ".", "__init__", "(", "self", ",", "parent", ")", "self", ".", "setupUi", "(", "self", ...
https://github.com/inasafe/inasafe/blob/355eb2ce63f516b9c26af0c86a24f99e53f63f87/safe/gui/tools/print_report_dialog.py#L60-L215
dropbox/dropbox-sdk-python
015437429be224732990041164a21a0501235db1
dropbox/team_log.py
python
EventTypeArg.is_extended_version_history_change_policy
(self)
return self._tag == 'extended_version_history_change_policy'
Check if the union tag is ``extended_version_history_change_policy``. :rtype: bool
Check if the union tag is ``extended_version_history_change_policy``.
[ "Check", "if", "the", "union", "tag", "is", "extended_version_history_change_policy", "." ]
def is_extended_version_history_change_policy(self): """ Check if the union tag is ``extended_version_history_change_policy``. :rtype: bool """ return self._tag == 'extended_version_history_change_policy'
[ "def", "is_extended_version_history_change_policy", "(", "self", ")", ":", "return", "self", ".", "_tag", "==", "'extended_version_history_change_policy'" ]
https://github.com/dropbox/dropbox-sdk-python/blob/015437429be224732990041164a21a0501235db1/dropbox/team_log.py#L42951-L42957
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/apps/users/bulk_download.py
python
make_mobile_user_dict
(user, group_names, location_cache, domain, fields_definition)
return user_dict
[]
def make_mobile_user_dict(user, group_names, location_cache, domain, fields_definition): model_data = {} uncategorized_data = {} model_data, uncategorized_data = ( fields_definition.get_model_and_uncategorized(user.metadata) ) role = user.get_role(domain) profile = None if PROFILE_SLUG in user.metadata and domain_has_privilege(domain, privileges.APP_USER_PROFILES): try: profile = CustomDataFieldsProfile.objects.get(id=user.metadata[PROFILE_SLUG]) except CustomDataFieldsProfile.DoesNotExist: profile = None activity = user.reporting_metadata location_codes = get_location_codes(location_cache, user.location_id, user.assigned_location_ids) def _format_date(date): return date.strftime('%Y-%m-%d %H:%M:%S') if date else '' user_dict = { 'data': model_data, 'uncategorized_data': uncategorized_data, 'group': group_names, 'name': user.full_name, 'password': "********", # dummy display string for passwords 'email': user.email, 'username': user.raw_username, 'language': user.language, 'user_id': user._id, 'is_active': str(user.is_active), 'User IMEIs (read only)': get_devices(user), 'location_code': location_codes, 'role': role.name if role else '', 'domain': domain, 'user_profile': profile.name if profile else '', 'registered_on (read only)': _format_date(user.created_on), 'last_submission (read only)': _format_date(activity.last_submission_for_user.submission_date), 'last_sync (read only)': activity.last_sync_for_user.sync_date, } user_dict.update(get_phone_numbers(user)) return user_dict
[ "def", "make_mobile_user_dict", "(", "user", ",", "group_names", ",", "location_cache", ",", "domain", ",", "fields_definition", ")", ":", "model_data", "=", "{", "}", "uncategorized_data", "=", "{", "}", "model_data", ",", "uncategorized_data", "=", "(", "field...
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/apps/users/bulk_download.py#L94-L136
cea-hpc/clustershell
c421133ed4baa69e35ff76c476d4097201485344
lib/ClusterShell/Task.py
python
Task.running
(self)
return self._engine and self._engine.running
Return True if the task is running.
Return True if the task is running.
[ "Return", "True", "if", "the", "task", "is", "running", "." ]
def running(self): """ Return True if the task is running. """ return self._engine and self._engine.running
[ "def", "running", "(", "self", ")", ":", "return", "self", ".", "_engine", "and", "self", ".", "_engine", ".", "running" ]
https://github.com/cea-hpc/clustershell/blob/c421133ed4baa69e35ff76c476d4097201485344/lib/ClusterShell/Task.py#L985-L989
hendrycks/outlier-exposure
e6ede98a5474a0620d9befa50b38eaf584df4401
NLP_language_modeling/data.py
python
OODCorpus.tokenize
(self, path, char=False)
return corpus, torch.LongTensor(ids)
Tokenizes a text file.
Tokenizes a text file.
[ "Tokenizes", "a", "text", "file", "." ]
def tokenize(self, path, char=False): """Tokenizes a text file.""" assert os.path.exists(path) # Add words to the dictionary corpus = [] ids = [] with open(path, 'r') as f: for line in f: if len(line) == 1: # end of example if char: corpus.append('<eos>') ids.append(self.dictionary.word2idx['<eos>']) else: corpus.append('<eos>') ids.append(self.dictionary.word2idx['<eos>']) continue word = line.split('\t')[1] if char: if word not in self.dictionary.word2idx.keys(): word = '<unk>' corpus.extend(list(word)) corpus.append('_') ids.extend([self.dictionary.word2idx[char] for char in word]) ids.append(self.dictionary.word2idx['_']) else: corpus.append(word) ids.append(self.dictionary.word2idx.get(word, self.dictionary.word2idx['<unk>'])) return corpus, torch.LongTensor(ids)
[ "def", "tokenize", "(", "self", ",", "path", ",", "char", "=", "False", ")", ":", "assert", "os", ".", "path", ".", "exists", "(", "path", ")", "# Add words to the dictionary", "corpus", "=", "[", "]", "ids", "=", "[", "]", "with", "open", "(", "path...
https://github.com/hendrycks/outlier-exposure/blob/e6ede98a5474a0620d9befa50b38eaf584df4401/NLP_language_modeling/data.py#L118-L146
exoplanet-dev/exoplanet
57935f373cf1ead935868e15bb4823b6de93027b
src/exoplanet/light_curves/limb_dark.py
python
LimbDarkLightCurve._compute_light_curve
(self, b, r, los=None)
return tt.switch(tt.gt(los, 0), lc, tt.zeros_like(lc))
Compute the light curve for a set of impact parameters and radii .. note:: The stellar radius is *not* included in this method so the coordinates should be in units of the star's radius. Args: b (tensor): A tensor of impact parameter values. r (tensor): A tensor of radius ratios with the same shape as ``b``. los (Optional[tensor]): The coordinates of the body along the line-of-sight. If ``los > 0`` the body is between the observer and the source.
Compute the light curve for a set of impact parameters and radii
[ "Compute", "the", "light", "curve", "for", "a", "set", "of", "impact", "parameters", "and", "radii" ]
def _compute_light_curve(self, b, r, los=None): """Compute the light curve for a set of impact parameters and radii .. note:: The stellar radius is *not* included in this method so the coordinates should be in units of the star's radius. Args: b (tensor): A tensor of impact parameter values. r (tensor): A tensor of radius ratios with the same shape as ``b``. los (Optional[tensor]): The coordinates of the body along the line-of-sight. If ``los > 0`` the body is between the observer and the source. """ b = as_tensor_variable(b) if los is None: los = tt.ones_like(b) lc = quad_limbdark_light_curve(self.c, b, r) return tt.switch(tt.gt(los, 0), lc, tt.zeros_like(lc))
[ "def", "_compute_light_curve", "(", "self", ",", "b", ",", "r", ",", "los", "=", "None", ")", ":", "b", "=", "as_tensor_variable", "(", "b", ")", "if", "los", "is", "None", ":", "los", "=", "tt", ".", "ones_like", "(", "b", ")", "lc", "=", "quad_...
https://github.com/exoplanet-dev/exoplanet/blob/57935f373cf1ead935868e15bb4823b6de93027b/src/exoplanet/light_curves/limb_dark.py#L237-L255
3DLIRIOUS/MeshLabXML
e19fdc911644474f74463aabba1e6860cfad818e
meshlabxml/transform.py
python
scale2
(script, value=1.0, uniform=True, center_pt='origin', custom_center_pt=None, unit=False, freeze=True, all_layers=False)
return None
Args: script: the FilterScript object or script filename to write the filter to. value (float): Scaling along the X axis. uniform (bool): If selected an uniform scaling (the same for all the', ' three axis) is applied (the X axis value is used). center_pt (str): Choose a method. custom_center_pt (point): This scaling center is used only if the', ' _custom point_ option is chosen. unit (bool): If selected, the object is scaled to a box whose', ' sides are at most 1 unit length. freeze (bool): The transformation is explicitly applied and the', ' vertex coords are actually changed. all_layers (bool): The transformation is explicitly applied to all the', ' mesh and raster layers in the project.
[]
def scale2(script, value=1.0, uniform=True, center_pt='origin', custom_center_pt=None, unit=False, freeze=True, all_layers=False): """ Args: script: the FilterScript object or script filename to write the filter to. value (float): Scaling along the X axis. uniform (bool): If selected an uniform scaling (the same for all the', ' three axis) is applied (the X axis value is used). center_pt (str): Choose a method. custom_center_pt (point): This scaling center is used only if the', ' _custom point_ option is chosen. unit (bool): If selected, the object is scaled to a box whose', ' sides are at most 1 unit length. freeze (bool): The transformation is explicitly applied and the', ' vertex coords are actually changed. all_layers (bool): The transformation is explicitly applied to all the', ' mesh and raster layers in the project. """ """# Convert value to list if it isn't already if not isinstance(value, list): value = list(value) # If a single value was supplied use it for all 3 axes if len(value) == 1: value = [value[0], value[0], value[0]]""" value = util.make_list(value, 3) # Convert center point name into number if center_pt.lower() == 'origin': center_pt_num = 0 elif center_pt.lower() == 'barycenter': center_pt_num = 1 else: # custom axis center_pt_num = 2 if custom_center_pt is None: print('WARNING: a custom center point was selected, however', '"custom_center_pt" was not provided. Using default', '(origin).') custom_center_pt = [0.0, 0.0, 0.0] filter_xml = ''.join([ ' <filter name="Transform: Scale">\n', ' <Param name="axisX" ', 'value="%s" ' % value[0], 'description="X Axis" ', 'type="RichFloat" ', '/>\n', ' <Param name="axisY" ', 'value="%s" ' % value[1], 'description="Y Axis" ', 'type="RichFloat" ', '/>\n', ' <Param name="axisZ" ', 'value="%s" ' % value[2], 'description="Z Axis" ', 'type="RichFloat" ', '/>\n', ' <Param name="uniformFlag" ', 'value="%s" ' % str(uniform).lower(), 'description="Uniform Scaling" ', 'type="RichBool" ', '/>\n', ' <Param name="scaleCenter" ', 'value="%d" ' % center_pt_num, 'description="Center of scaling:" ', 'enum_val0="origin" ', 'enum_val1="barycenter" ', 'enum_val2="custom point" ', 'enum_cardinality="3" ', 'type="RichEnum" ', '/>\n', ' <Param name="customCenter" ', 'x="%s" ' % custom_center_pt[0], 'y="%s" ' % custom_center_pt[1], 'z="%s" ' % custom_center_pt[2], 'description="Custom center" ', 'type="RichPoint3f" ', '/>\n', ' <Param name="unitFlag" ', 'value="%s" ' % str(unit).lower(), 'description="Scale to Unit bbox" ', 'type="RichBool" ', '/>\n', ' <Param name="Freeze" ', 'value="%s" ' % str(freeze).lower(), 'description="Freeze Matrix." ', 'type="RichBool" ', '/>\n', ' <Param name="ToAll" ', 'value="%s" ' % str(all_layers).lower(), 'description="Apply to all layers." ', 'type="RichBool" ', '/>\n', ' </filter>\n']) util.write_filter(script, filter_xml) return None
[ "def", "scale2", "(", "script", ",", "value", "=", "1.0", ",", "uniform", "=", "True", ",", "center_pt", "=", "'origin'", ",", "custom_center_pt", "=", "None", ",", "unit", "=", "False", ",", "freeze", "=", "True", ",", "all_layers", "=", "False", ")",...
https://github.com/3DLIRIOUS/MeshLabXML/blob/e19fdc911644474f74463aabba1e6860cfad818e/meshlabxml/transform.py#L223-L317
DataDog/integrations-core
934674b29d94b70ccc008f76ea172d0cdae05e1e
cilium/datadog_checks/cilium/config_models/defaults.py
python
instance_non_cumulative_histogram_buckets
(field, value)
return False
[]
def instance_non_cumulative_histogram_buckets(field, value): return False
[ "def", "instance_non_cumulative_histogram_buckets", "(", "field", ",", "value", ")", ":", "return", "False" ]
https://github.com/DataDog/integrations-core/blob/934674b29d94b70ccc008f76ea172d0cdae05e1e/cilium/datadog_checks/cilium/config_models/defaults.py#L209-L210
jina-ai/jina
c77a492fcd5adba0fc3de5347bea83dd4e7d8087
docarray/math/distance/numpy.py
python
sparse_sqeuclidean
(x_mat: 'ArrayType', y_mat: 'ArrayType')
return np.asarray( y_mat.power(2).sum(axis=1).flatten() + x_mat.power(2).sum(axis=1) - 2 * x_mat.dot(y_mat.T) )
Cosine distance between each row in x_mat and each row in y_mat. :param x_mat: scipy.sparse like array with ndim=2 :param y_mat: scipy.sparse like array with ndim=2 :return: np.ndarray with ndim=2
Cosine distance between each row in x_mat and each row in y_mat.
[ "Cosine", "distance", "between", "each", "row", "in", "x_mat", "and", "each", "row", "in", "y_mat", "." ]
def sparse_sqeuclidean(x_mat: 'ArrayType', y_mat: 'ArrayType') -> 'np.ndarray': """Cosine distance between each row in x_mat and each row in y_mat. :param x_mat: scipy.sparse like array with ndim=2 :param y_mat: scipy.sparse like array with ndim=2 :return: np.ndarray with ndim=2 """ # we need the np.asarray otherwise we get a np.matrix object that iterates differently return np.asarray( y_mat.power(2).sum(axis=1).flatten() + x_mat.power(2).sum(axis=1) - 2 * x_mat.dot(y_mat.T) )
[ "def", "sparse_sqeuclidean", "(", "x_mat", ":", "'ArrayType'", ",", "y_mat", ":", "'ArrayType'", ")", "->", "'np.ndarray'", ":", "# we need the np.asarray otherwise we get a np.matrix object that iterates differently", "return", "np", ".", "asarray", "(", "y_mat", ".", "p...
https://github.com/jina-ai/jina/blob/c77a492fcd5adba0fc3de5347bea83dd4e7d8087/docarray/math/distance/numpy.py#L58-L70
XX-net/XX-Net
a9898cfcf0084195fb7e69b6bc834e59aecdf14f
python3.8.2/Lib/shlex.py
python
split
(s, comments=False, posix=True)
return list(lex)
Split the string *s* using shell-like syntax.
Split the string *s* using shell-like syntax.
[ "Split", "the", "string", "*", "s", "*", "using", "shell", "-", "like", "syntax", "." ]
def split(s, comments=False, posix=True): """Split the string *s* using shell-like syntax.""" lex = shlex(s, posix=posix) lex.whitespace_split = True if not comments: lex.commenters = '' return list(lex)
[ "def", "split", "(", "s", ",", "comments", "=", "False", ",", "posix", "=", "True", ")", ":", "lex", "=", "shlex", "(", "s", ",", "posix", "=", "posix", ")", "lex", ".", "whitespace_split", "=", "True", "if", "not", "comments", ":", "lex", ".", "...
https://github.com/XX-net/XX-Net/blob/a9898cfcf0084195fb7e69b6bc834e59aecdf14f/python3.8.2/Lib/shlex.py#L305-L311
facebookresearch/pysparnn
c299c825fd99f263f3957e9b31197daf23a1e7a3
pysparnn/cluster_index.py
python
MultiClusterIndex.insert
(self, feature, record)
Insert a single record into the index. Args: feature: feature vector record: record to return as the result of a search
Insert a single record into the index.
[ "Insert", "a", "single", "record", "into", "the", "index", "." ]
def insert(self, feature, record): """Insert a single record into the index. Args: feature: feature vector record: record to return as the result of a search """ for ind in self.indexes: ind.insert(feature, record)
[ "def", "insert", "(", "self", ",", "feature", ",", "record", ")", ":", "for", "ind", "in", "self", ".", "indexes", ":", "ind", ".", "insert", "(", "feature", ",", "record", ")" ]
https://github.com/facebookresearch/pysparnn/blob/c299c825fd99f263f3957e9b31197daf23a1e7a3/pysparnn/cluster_index.py#L429-L437
aajanki/yle-dl
b0aa1bb5d943fdbd9a18da2604f21bb2094eadd7
yledl/downloader.py
python
YleDlDownloader.pipe
(self, clips, io, filters)
return self.process(clips, pipe_clip, needs_retry, filters)
[]
def pipe(self, clips, io, filters): def pipe_clip(clip, downloader): if not downloader: logger.error('Downloading the stream at %s is not yet ' 'supported.' % clip.webpage) return RD_FAILED downloader.warn_on_unsupported_feature(io) res = downloader.pipe(io) return (res, None) def needs_retry(res): return res == RD_SUBPROCESS_EXECUTE_FAILED return self.process(clips, pipe_clip, needs_retry, filters)
[ "def", "pipe", "(", "self", ",", "clips", ",", "io", ",", "filters", ")", ":", "def", "pipe_clip", "(", "clip", ",", "downloader", ")", ":", "if", "not", "downloader", ":", "logger", ".", "error", "(", "'Downloading the stream at %s is not yet '", "'supporte...
https://github.com/aajanki/yle-dl/blob/b0aa1bb5d943fdbd9a18da2604f21bb2094eadd7/yledl/downloader.py#L61-L74
hydroshare/hydroshare
7ba563b55412f283047fb3ef6da367d41dec58c6
hs_tracking/management/commands/tracking_popular.py
python
Command.handle
(self, *args, **options)
[]
def handle(self, *args, **options): days = options['days'] n_resources = options['n_resources'] popular = Variable.popular_resources(days=days, n_resources=n_resources) for v in popular: print("users={} short_id={}" .format(v.users, v.short_id)) print(" title={}".format(v.title)) print(" created={} updated={}" .format(v.created.strftime("%Y-%m-%d %H:%M:%S"), v.last_updated.strftime("%Y-%m-%d %H:%M:%S"))) print(" published={} public={} discoverable={} first author={}" .format(v.published, v.public, v.discoverable, v.first_creator))
[ "def", "handle", "(", "self", ",", "*", "args", ",", "*", "*", "options", ")", ":", "days", "=", "options", "[", "'days'", "]", "n_resources", "=", "options", "[", "'n_resources'", "]", "popular", "=", "Variable", ".", "popular_resources", "(", "days", ...
https://github.com/hydroshare/hydroshare/blob/7ba563b55412f283047fb3ef6da367d41dec58c6/hs_tracking/management/commands/tracking_popular.py#L17-L33
jensl/critic
c2d962b909ff7ef2f09bccbeb636333920b3659e
src/api/file.py
python
File.path
(self)
return self._impl.path
The path
The path
[ "The", "path" ]
def path(self): """The path""" return self._impl.path
[ "def", "path", "(", "self", ")", ":", "return", "self", ".", "_impl", ".", "path" ]
https://github.com/jensl/critic/blob/c2d962b909ff7ef2f09bccbeb636333920b3659e/src/api/file.py#L48-L50
Tautulli/Tautulli
2410eb33805aaac4bd1c5dad0f71e4f15afaf742
lib/plexapi/base.py
python
PlexPartialObject.isFullObject
(self)
return not self.key or (self._details_key or self.key) == self._initpath
Returns True if this is already a full object. A full object means all attributes were populated from the api path representing only this item. For example, the search result for a movie often only contain a portion of the attributes a full object (main url) for that movie would contain.
Returns True if this is already a full object. A full object means all attributes were populated from the api path representing only this item. For example, the search result for a movie often only contain a portion of the attributes a full object (main url) for that movie would contain.
[ "Returns", "True", "if", "this", "is", "already", "a", "full", "object", ".", "A", "full", "object", "means", "all", "attributes", "were", "populated", "from", "the", "api", "path", "representing", "only", "this", "item", ".", "For", "example", "the", "sea...
def isFullObject(self): """ Returns True if this is already a full object. A full object means all attributes were populated from the api path representing only this item. For example, the search result for a movie often only contain a portion of the attributes a full object (main url) for that movie would contain. """ return not self.key or (self._details_key or self.key) == self._initpath
[ "def", "isFullObject", "(", "self", ")", ":", "return", "not", "self", ".", "key", "or", "(", "self", ".", "_details_key", "or", "self", ".", "key", ")", "==", "self", ".", "_initpath" ]
https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/plexapi/base.py#L496-L502
florath/rmtoo
6ffe08703451358dca24b232ee4380b1da23bcad
rmtoo/inputs/ReqClass.py
python
ReqClass.rewrite
(self, rid, req)
return self.get_tag(), val
This tag (Class) is mandatory optional (which means: if it's not there, there is a default - but every requirement do own one class)
This tag (Class) is mandatory optional (which means: if it's not there, there is a default - but every requirement do own one class)
[ "This", "tag", "(", "Class", ")", "is", "mandatory", "optional", "(", "which", "means", ":", "if", "it", "s", "not", "there", "there", "is", "a", "default", "-", "but", "every", "requirement", "do", "own", "one", "class", ")" ]
def rewrite(self, rid, req): """This tag (Class) is mandatory optional (which means: if it's not there, there is a default - but every requirement do own one class) """ if self.get_tag() not in req: val = ClassTypeDetailable() else: tcontent = req[self.get_tag()].get_content() val = create_class_type(rid, tcontent) del req[self.get_tag()] return self.get_tag(), val
[ "def", "rewrite", "(", "self", ",", "rid", ",", "req", ")", ":", "if", "self", ".", "get_tag", "(", ")", "not", "in", "req", ":", "val", "=", "ClassTypeDetailable", "(", ")", "else", ":", "tcontent", "=", "req", "[", "self", ".", "get_tag", "(", ...
https://github.com/florath/rmtoo/blob/6ffe08703451358dca24b232ee4380b1da23bcad/rmtoo/inputs/ReqClass.py#L24-L35
Chaffelson/nipyapi
d3b186fd701ce308c2812746d98af9120955e810
nipyapi/nifi/models/bulletin_board_dto.py
python
BulletinBoardDTO.generated
(self, generated)
Sets the generated of this BulletinBoardDTO. The timestamp when this report was generated. :param generated: The generated of this BulletinBoardDTO. :type: str
Sets the generated of this BulletinBoardDTO. The timestamp when this report was generated.
[ "Sets", "the", "generated", "of", "this", "BulletinBoardDTO", ".", "The", "timestamp", "when", "this", "report", "was", "generated", "." ]
def generated(self, generated): """ Sets the generated of this BulletinBoardDTO. The timestamp when this report was generated. :param generated: The generated of this BulletinBoardDTO. :type: str """ self._generated = generated
[ "def", "generated", "(", "self", ",", "generated", ")", ":", "self", ".", "_generated", "=", "generated" ]
https://github.com/Chaffelson/nipyapi/blob/d3b186fd701ce308c2812746d98af9120955e810/nipyapi/nifi/models/bulletin_board_dto.py#L91-L100
lbryio/lbry-sdk
f78e3825ca0f130834d3876a824f9d380501ced8
lbry/wallet/server/session.py
python
LBRYElectrumX.scripthash_listunspent
(self, scripthash)
return await self.hashX_listunspent(hashX)
Return the list of UTXOs of a scripthash.
Return the list of UTXOs of a scripthash.
[ "Return", "the", "list", "of", "UTXOs", "of", "a", "scripthash", "." ]
async def scripthash_listunspent(self, scripthash): """Return the list of UTXOs of a scripthash.""" hashX = scripthash_to_hashX(scripthash) return await self.hashX_listunspent(hashX)
[ "async", "def", "scripthash_listunspent", "(", "self", ",", "scripthash", ")", ":", "hashX", "=", "scripthash_to_hashX", "(", "scripthash", ")", "return", "await", "self", ".", "hashX_listunspent", "(", "hashX", ")" ]
https://github.com/lbryio/lbry-sdk/blob/f78e3825ca0f130834d3876a824f9d380501ced8/lbry/wallet/server/session.py#L1255-L1258
docker/docker-py
a48a5a9647761406d66e8271f19fab7fa0c5f582
docker/utils/config.py
python
home_dir
()
Get the user's home directory, using the same logic as the Docker Engine client - use %USERPROFILE% on Windows, $HOME/getuid on POSIX.
Get the user's home directory, using the same logic as the Docker Engine client - use %USERPROFILE% on Windows, $HOME/getuid on POSIX.
[ "Get", "the", "user", "s", "home", "directory", "using", "the", "same", "logic", "as", "the", "Docker", "Engine", "client", "-", "use", "%USERPROFILE%", "on", "Windows", "$HOME", "/", "getuid", "on", "POSIX", "." ]
def home_dir(): """ Get the user's home directory, using the same logic as the Docker Engine client - use %USERPROFILE% on Windows, $HOME/getuid on POSIX. """ if IS_WINDOWS_PLATFORM: return os.environ.get('USERPROFILE', '') else: return os.path.expanduser('~')
[ "def", "home_dir", "(", ")", ":", "if", "IS_WINDOWS_PLATFORM", ":", "return", "os", ".", "environ", ".", "get", "(", "'USERPROFILE'", ",", "''", ")", "else", ":", "return", "os", ".", "path", ".", "expanduser", "(", "'~'", ")" ]
https://github.com/docker/docker-py/blob/a48a5a9647761406d66e8271f19fab7fa0c5f582/docker/utils/config.py#L40-L48
isnowfy/pydown
71ecc891868cd2a34b7e5fe662c99474f2d0fd7f
pygments/formatters/latex.py
python
LatexFormatter.format_unencoded
(self, tokensource, outfile)
[]
def format_unencoded(self, tokensource, outfile): # TODO: add support for background colors t2n = self.ttype2name cp = self.commandprefix if self.full: realoutfile = outfile outfile = StringIO() outfile.write(ur'\begin{Verbatim}[commandchars=\\\{\}') if self.linenos: start, step = self.linenostart, self.linenostep outfile.write(u',numbers=left' + (start and u',firstnumber=%d' % start or u'') + (step and u',stepnumber=%d' % step or u'')) if self.mathescape or self.texcomments: outfile.write(ur',codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}') if self.verboptions: outfile.write(u',' + self.verboptions) outfile.write(u']\n') for ttype, value in tokensource: if ttype in Token.Comment: if self.texcomments: # Try to guess comment starting lexeme and escape it ... start = value[0:1] for i in xrange(1, len(value)): if start[0] != value[i]: break start += value[i] value = value[len(start):] start = escape_tex(start, self.commandprefix) # ... but do not escape inside comment. value = start + value elif self.mathescape: # Only escape parts not inside a math environment. parts = value.split('$') in_math = False for i, part in enumerate(parts): if not in_math: parts[i] = escape_tex(part, self.commandprefix) in_math = not in_math value = '$'.join(parts) else: value = escape_tex(value, self.commandprefix) else: value = escape_tex(value, self.commandprefix) styles = [] while ttype is not Token: try: styles.append(t2n[ttype]) except KeyError: # not in current style styles.append(_get_ttype_name(ttype)) ttype = ttype.parent styleval = '+'.join(reversed(styles)) if styleval: spl = value.split('\n') for line in spl[:-1]: if line: outfile.write("\\%s{%s}{%s}" % (cp, styleval, line)) outfile.write('\n') if spl[-1]: outfile.write("\\%s{%s}{%s}" % (cp, styleval, spl[-1])) else: outfile.write(value) outfile.write(u'\\end{Verbatim}\n') if self.full: realoutfile.write(DOC_TEMPLATE % dict(docclass = self.docclass, preamble = self.preamble, title = self.title, encoding = self.encoding or 'latin1', styledefs = self.get_style_defs(), code = outfile.getvalue()))
[ "def", "format_unencoded", "(", "self", ",", "tokensource", ",", "outfile", ")", ":", "# TODO: add support for background colors", "t2n", "=", "self", ".", "ttype2name", "cp", "=", "self", ".", "commandprefix", "if", "self", ".", "full", ":", "realoutfile", "=",...
https://github.com/isnowfy/pydown/blob/71ecc891868cd2a34b7e5fe662c99474f2d0fd7f/pygments/formatters/latex.py#L300-L378
oracle/oci-cli
2c0932ebd36a155521231ecb2965c14268f018ac
src/oci_cli/util/pymd5.py
python
md5
(arg=None)
return new(arg)
Same as new(). For backward compatibility reasons, this is an alternative name for the new() function.
Same as new(). For backward compatibility reasons, this is an alternative name for the new() function.
[ "Same", "as", "new", "()", ".", "For", "backward", "compatibility", "reasons", "this", "is", "an", "alternative", "name", "for", "the", "new", "()", "function", "." ]
def md5(arg=None): """Same as new(). For backward compatibility reasons, this is an alternative name for the new() function. """ return new(arg)
[ "def", "md5", "(", "arg", "=", "None", ")", ":", "return", "new", "(", "arg", ")" ]
https://github.com/oracle/oci-cli/blob/2c0932ebd36a155521231ecb2965c14268f018ac/src/oci_cli/util/pymd5.py#L437-L442
airbus-cert/regrippy
cdee0d626ec5d7dfe55a82a4fd9d161027e32c7e
regrippy/__init__.py
python
BasePlugin.display_machine
(self, result)
Displays a result for further processing by a machine (piping into mactime for example). :param result: the result to display :type result: regrip.PluginResult
Displays a result for further processing by a machine (piping into mactime for example).
[ "Displays", "a", "result", "for", "further", "processing", "by", "a", "machine", "(", "piping", "into", "mactime", "for", "example", ")", "." ]
def display_machine(self, result): """Displays a result for further processing by a machine (piping into mactime for example). :param result: the result to display :type result: regrip.PluginResult """ print(mactime(name=result.path, mtime=result.mtime))
[ "def", "display_machine", "(", "self", ",", "result", ")", ":", "print", "(", "mactime", "(", "name", "=", "result", ".", "path", ",", "mtime", "=", "result", ".", "mtime", ")", ")" ]
https://github.com/airbus-cert/regrippy/blob/cdee0d626ec5d7dfe55a82a4fd9d161027e32c7e/regrippy/__init__.py#L123-L130
mozillazg/pypy
2ff5cd960c075c991389f842c6d59e71cf0cb7d0
pypy/interpreter/eval.py
python
Code.getvarnames
(self)
return self.signature().getallvarnames()
List of names including the arguments, vararg and kwarg, and possibly more locals.
List of names including the arguments, vararg and kwarg, and possibly more locals.
[ "List", "of", "names", "including", "the", "arguments", "vararg", "and", "kwarg", "and", "possibly", "more", "locals", "." ]
def getvarnames(self): """List of names including the arguments, vararg and kwarg, and possibly more locals.""" return self.signature().getallvarnames()
[ "def", "getvarnames", "(", "self", ")", ":", "return", "self", ".", "signature", "(", ")", ".", "getallvarnames", "(", ")" ]
https://github.com/mozillazg/pypy/blob/2ff5cd960c075c991389f842c6d59e71cf0cb7d0/pypy/interpreter/eval.py#L38-L41
MagicStack/asyncpg
a2f093df6aceec7842709eaf92c5ff9df093efae
asyncpg/connection.py
python
Connection.reload_schema_state
(self)
Indicate that the database schema information must be reloaded. For performance reasons, asyncpg caches certain aspects of the database schema, such as the layout of composite types. Consequently, when the database schema changes, and asyncpg is not able to gracefully recover from an error caused by outdated schema assumptions, an :exc:`~asyncpg.exceptions.OutdatedSchemaCacheError` is raised. To prevent the exception, this method may be used to inform asyncpg that the database schema has changed. Example: .. code-block:: pycon >>> import asyncpg >>> import asyncio >>> async def change_type(con): ... result = await con.fetch('SELECT id, info FROM tbl') ... # Change composite's attribute type "int"=>"text" ... await con.execute('ALTER TYPE custom DROP ATTRIBUTE y') ... await con.execute('ALTER TYPE custom ADD ATTRIBUTE y text') ... await con.reload_schema_state() ... for id_, info in result: ... new = (info['x'], str(info['y'])) ... await con.execute( ... 'UPDATE tbl SET info=$2 WHERE id=$1', id_, new) ... >>> async def run(): ... # Initial schema: ... # CREATE TYPE custom AS (x int, y int); ... # CREATE TABLE tbl(id int, info custom); ... con = await asyncpg.connect(user='postgres') ... async with con.transaction(): ... # Prevent concurrent changes in the table ... await con.execute('LOCK TABLE tbl') ... await change_type(con) ... >>> asyncio.get_event_loop().run_until_complete(run()) .. versionadded:: 0.14.0
Indicate that the database schema information must be reloaded.
[ "Indicate", "that", "the", "database", "schema", "information", "must", "be", "reloaded", "." ]
async def reload_schema_state(self): """Indicate that the database schema information must be reloaded. For performance reasons, asyncpg caches certain aspects of the database schema, such as the layout of composite types. Consequently, when the database schema changes, and asyncpg is not able to gracefully recover from an error caused by outdated schema assumptions, an :exc:`~asyncpg.exceptions.OutdatedSchemaCacheError` is raised. To prevent the exception, this method may be used to inform asyncpg that the database schema has changed. Example: .. code-block:: pycon >>> import asyncpg >>> import asyncio >>> async def change_type(con): ... result = await con.fetch('SELECT id, info FROM tbl') ... # Change composite's attribute type "int"=>"text" ... await con.execute('ALTER TYPE custom DROP ATTRIBUTE y') ... await con.execute('ALTER TYPE custom ADD ATTRIBUTE y text') ... await con.reload_schema_state() ... for id_, info in result: ... new = (info['x'], str(info['y'])) ... await con.execute( ... 'UPDATE tbl SET info=$2 WHERE id=$1', id_, new) ... >>> async def run(): ... # Initial schema: ... # CREATE TYPE custom AS (x int, y int); ... # CREATE TABLE tbl(id int, info custom); ... con = await asyncpg.connect(user='postgres') ... async with con.transaction(): ... # Prevent concurrent changes in the table ... await con.execute('LOCK TABLE tbl') ... await change_type(con) ... >>> asyncio.get_event_loop().run_until_complete(run()) .. versionadded:: 0.14.0 """ self._drop_global_type_cache() self._drop_global_statement_cache()
[ "async", "def", "reload_schema_state", "(", "self", ")", ":", "self", ".", "_drop_global_type_cache", "(", ")", "self", ".", "_drop_global_statement_cache", "(", ")" ]
https://github.com/MagicStack/asyncpg/blob/a2f093df6aceec7842709eaf92c5ff9df093efae/asyncpg/connection.py#L1602-L1645
Roger/escrotum
a41d0f11bb6af4f08e724b8ccddf8513d905c0d1
escrotum/main.py
python
Escrotum.event_handler
(self, event)
Handle mouse and keyboard events
Handle mouse and keyboard events
[ "Handle", "mouse", "and", "keyboard", "events" ]
def event_handler(self, event): """ Handle mouse and keyboard events """ if event.type == gdk.EventType.BUTTON_PRESS: if event.button.button != 1: print("Canceled by the user") exit(EXIT_CANCEL) self.started = True self.start_x = int(event.x) self.start_y = int(event.y) self.move(self.x, self.y) self.queue_draw() elif event.type == gdk.EventType.KEY_RELEASE: if gdk.keyval_name(event.keyval) == "Escape": print("Canceled by the user") exit(EXIT_CANCEL) elif event.type == gdk.EventType.MOTION_NOTIFY: if not self.started: return self.set_rect_size(event) self.draw() if self.width > 3 and self.height > 3: self.resize(self.width, self.height) self.move(self.x, self.y) self.show_all() self.queue_draw() elif event.type == gdk.EventType.BUTTON_RELEASE: if not self.started: return self.set_rect_size(event) self.queue_draw() self.ungrab() self.wait() else: gtk.main_do_event(event)
[ "def", "event_handler", "(", "self", ",", "event", ")", ":", "if", "event", ".", "type", "==", "gdk", ".", "EventType", ".", "BUTTON_PRESS", ":", "if", "event", ".", "button", ".", "button", "!=", "1", ":", "print", "(", "\"Canceled by the user\"", ")", ...
https://github.com/Roger/escrotum/blob/a41d0f11bb6af4f08e724b8ccddf8513d905c0d1/escrotum/main.py#L184-L228
xcmyz/FastSpeech
d8bd89790100542fda836b8f3f9342b64ad67e39
audio/stft.py
python
STFT.forward
(self, input_data)
return reconstruction
[]
def forward(self, input_data): self.magnitude, self.phase = self.transform(input_data) reconstruction = self.inverse(self.magnitude, self.phase) return reconstruction
[ "def", "forward", "(", "self", ",", "input_data", ")", ":", "self", ".", "magnitude", ",", "self", ".", "phase", "=", "self", ".", "transform", "(", "input_data", ")", "reconstruction", "=", "self", ".", "inverse", "(", "self", ".", "magnitude", ",", "...
https://github.com/xcmyz/FastSpeech/blob/d8bd89790100542fda836b8f3f9342b64ad67e39/audio/stft.py#L116-L119
fluentpython/notebooks
0f6e1e8d1686743dacd9281df7c5b5921812010a
16-coroutine/taxi_sim0.py
python
Simulator.run
(self, end_time)
Schedule and display events until time is up
Schedule and display events until time is up
[ "Schedule", "and", "display", "events", "until", "time", "is", "up" ]
def run(self, end_time): # <1> """Schedule and display events until time is up""" # schedule the first event for each cab for _, proc in sorted(self.procs.items()): # <2> first_event = next(proc) # <3> self.events.put(first_event) # <4> # main loop of the simulation time = 0 while time < end_time: # <5> if self.events.empty(): # <6> print('*** end of events ***') break # get and display current event current_event = self.events.get() # <7> print('taxi:', current_event.proc, # <8> current_event.proc * ' ', current_event) # schedule next action for current proc time = current_event.time # <9> proc = self.procs[current_event.proc] # <10> try: next_event = proc.send(time) # <11> except StopIteration: del self.procs[current_event.proc] # <12> else: self.events.put(next_event) # <13> else: # <14> msg = '*** end of simulation time: {} events pending ***' print(msg.format(self.events.qsize()))
[ "def", "run", "(", "self", ",", "end_time", ")", ":", "# <1>", "# schedule the first event for each cab", "for", "_", ",", "proc", "in", "sorted", "(", "self", ".", "procs", ".", "items", "(", ")", ")", ":", "# <2>", "first_event", "=", "next", "(", "pro...
https://github.com/fluentpython/notebooks/blob/0f6e1e8d1686743dacd9281df7c5b5921812010a/16-coroutine/taxi_sim0.py#L72-L102
yt-project/yt
dc7b24f9b266703db4c843e329c6c8644d47b824
yt/visualization/fixed_resolution_filters.py
python
apply_filter
(f)
return newfunc
[]
def apply_filter(f): @wraps(f) def newfunc(*args, **kwargs): args[0]._filters.append((f.__name__, (args, kwargs))) return args[0] return newfunc
[ "def", "apply_filter", "(", "f", ")", ":", "@", "wraps", "(", "f", ")", "def", "newfunc", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "args", "[", "0", "]", ".", "_filters", ".", "append", "(", "(", "f", ".", "__name__", ",", "(", "a...
https://github.com/yt-project/yt/blob/dc7b24f9b266703db4c843e329c6c8644d47b824/yt/visualization/fixed_resolution_filters.py#L8-L14
kenfar/DataGristle
248f255d69b41e0c306d0a893c917923f2cb39a3
datagristle/field_misc.py
python
get_field_names
(filename: str, dialect)
return final_names
Determines names of fields Inputs: Outputs: Misc: - if the file is empty it will return None
Determines names of fields Inputs: Outputs: Misc: - if the file is empty it will return None
[ "Determines", "names", "of", "fields", "Inputs", ":", "Outputs", ":", "Misc", ":", "-", "if", "the", "file", "is", "empty", "it", "will", "return", "None" ]
def get_field_names(filename: str, dialect) -> List[str]: """ Determines names of fields Inputs: Outputs: Misc: - if the file is empty it will return None """ reader = csv.reader(open(filename, newline=''), dialect=dialect) for field_names in reader: break else: raise EOFError final_names = [] for col_sub in range(len(field_names)): if dialect.has_header: final_names.append(field_names[col_sub].strip()) else: final_names.append('field_%d' % col_sub) return final_names
[ "def", "get_field_names", "(", "filename", ":", "str", ",", "dialect", ")", "->", "List", "[", "str", "]", ":", "reader", "=", "csv", ".", "reader", "(", "open", "(", "filename", ",", "newline", "=", "''", ")", ",", "dialect", "=", "dialect", ")", ...
https://github.com/kenfar/DataGristle/blob/248f255d69b41e0c306d0a893c917923f2cb39a3/datagristle/field_misc.py#L56-L76
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/flaskbb/core/auth/registration.py
python
UserValidator.__call__
(self, user_info)
return self.validate(user_info)
[]
def __call__(self, user_info): return self.validate(user_info)
[ "def", "__call__", "(", "self", ",", "user_info", ")", ":", "return", "self", ".", "validate", "(", "user_info", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/flaskbb/core/auth/registration.py#L48-L49
WenRichard/Customer-Chatbot
48508c40574ffac8ced414a5bea799e2c85341ca
xiaotian-chatbot1.0/Rerank/model.py
python
SiameseQACNN._cnn_layer
(self, input)
return cnn_outs
卷积层
卷积层
[ "卷积层" ]
def _cnn_layer(self, input): """ 卷积层 """ all = [] max_len = input.get_shape()[1] for i, filter_size in enumerate(self.window_sizes): with tf.variable_scope('filter{}'.format(filter_size)): # 卷积 cnn_out = tf.layers.conv1d(input, self.n_filters, filter_size, padding='valid', activation=tf.nn.relu, name='q_conv_' + str(i)) # 池化 pool_out = tf.reduce_max(cnn_out, axis=1, keepdims=True) tanh_out = tf.nn.tanh(pool_out) all.append(tanh_out) cnn_outs = tf.concat(all, axis=-1) dim = cnn_outs.get_shape()[-1] cnn_outs = tf.reshape(cnn_outs, [-1, dim]) return cnn_outs
[ "def", "_cnn_layer", "(", "self", ",", "input", ")", ":", "all", "=", "[", "]", "max_len", "=", "input", ".", "get_shape", "(", ")", "[", "1", "]", "for", "i", ",", "filter_size", "in", "enumerate", "(", "self", ".", "window_sizes", ")", ":", "with...
https://github.com/WenRichard/Customer-Chatbot/blob/48508c40574ffac8ced414a5bea799e2c85341ca/xiaotian-chatbot1.0/Rerank/model.py#L86-L104
python/cpython
e13cdca0f5224ec4e23bdd04bb3120506964bc8b
Lib/telnetlib.py
python
test
()
Test program for telnetlib. Usage: python telnetlib.py [-d] ... [host [port]] Default host is localhost; default port is 23.
Test program for telnetlib.
[ "Test", "program", "for", "telnetlib", "." ]
def test(): """Test program for telnetlib. Usage: python telnetlib.py [-d] ... [host [port]] Default host is localhost; default port is 23. """ debuglevel = 0 while sys.argv[1:] and sys.argv[1] == '-d': debuglevel = debuglevel+1 del sys.argv[1] host = 'localhost' if sys.argv[1:]: host = sys.argv[1] port = 0 if sys.argv[2:]: portstr = sys.argv[2] try: port = int(portstr) except ValueError: port = socket.getservbyname(portstr, 'tcp') with Telnet() as tn: tn.set_debuglevel(debuglevel) tn.open(host, port, timeout=0.5) tn.interact()
[ "def", "test", "(", ")", ":", "debuglevel", "=", "0", "while", "sys", ".", "argv", "[", "1", ":", "]", "and", "sys", ".", "argv", "[", "1", "]", "==", "'-d'", ":", "debuglevel", "=", "debuglevel", "+", "1", "del", "sys", ".", "argv", "[", "1", ...
https://github.com/python/cpython/blob/e13cdca0f5224ec4e23bdd04bb3120506964bc8b/Lib/telnetlib.py#L648-L673
demisto/content
5c664a65b992ac8ca90ac3f11b1b2cdf11ee9b07
Packs/PAN-OS/Integrations/Panorama/Panorama.py
python
panorama_delete_custom_url_category_command
(custom_url_category_name: str)
Delete a custom url category
Delete a custom url category
[ "Delete", "a", "custom", "url", "category" ]
def panorama_delete_custom_url_category_command(custom_url_category_name: str): """ Delete a custom url category """ result = panorama_delete_custom_url_category(custom_url_category_name) custom_url_category_output = {'Name': custom_url_category_name} if DEVICE_GROUP: custom_url_category_output['DeviceGroup'] = DEVICE_GROUP return_results({ 'Type': entryTypes['note'], 'ContentsFormat': formats['json'], 'Contents': result, 'ReadableContentsFormat': formats['text'], 'HumanReadable': 'Custom URL category was deleted successfully.', 'EntryContext': { "Panorama.CustomURLCategory(val.Name == obj.Name)": custom_url_category_output } })
[ "def", "panorama_delete_custom_url_category_command", "(", "custom_url_category_name", ":", "str", ")", ":", "result", "=", "panorama_delete_custom_url_category", "(", "custom_url_category_name", ")", "custom_url_category_output", "=", "{", "'Name'", ":", "custom_url_category_n...
https://github.com/demisto/content/blob/5c664a65b992ac8ca90ac3f11b1b2cdf11ee9b07/Packs/PAN-OS/Integrations/Panorama/Panorama.py#L2107-L2126
mchristopher/PokemonGo-DesktopMap
ec37575f2776ee7d64456e2a1f6b6b78830b4fe0
app/pywin/Lib/telnetlib.py
python
Telnet.process_rawq
(self)
Transfer from raw queue to cooked queue. Set self.eof when connection is closed. Don't block unless in the midst of an IAC sequence.
Transfer from raw queue to cooked queue.
[ "Transfer", "from", "raw", "queue", "to", "cooked", "queue", "." ]
def process_rawq(self): """Transfer from raw queue to cooked queue. Set self.eof when connection is closed. Don't block unless in the midst of an IAC sequence. """ buf = ['', ''] try: while self.rawq: c = self.rawq_getchar() if not self.iacseq: if c == theNULL: continue if c == "\021": continue if c != IAC: buf[self.sb] = buf[self.sb] + c continue else: self.iacseq += c elif len(self.iacseq) == 1: # 'IAC: IAC CMD [OPTION only for WILL/WONT/DO/DONT]' if c in (DO, DONT, WILL, WONT): self.iacseq += c continue self.iacseq = '' if c == IAC: buf[self.sb] = buf[self.sb] + c else: if c == SB: # SB ... SE start. self.sb = 1 self.sbdataq = '' elif c == SE: self.sb = 0 self.sbdataq = self.sbdataq + buf[1] buf[1] = '' if self.option_callback: # Callback is supposed to look into # the sbdataq self.option_callback(self.sock, c, NOOPT) else: # We can't offer automatic processing of # suboptions. Alas, we should not get any # unless we did a WILL/DO before. self.msg('IAC %d not recognized' % ord(c)) elif len(self.iacseq) == 2: cmd = self.iacseq[1] self.iacseq = '' opt = c if cmd in (DO, DONT): self.msg('IAC %s %d', cmd == DO and 'DO' or 'DONT', ord(opt)) if self.option_callback: self.option_callback(self.sock, cmd, opt) else: self.sock.sendall(IAC + WONT + opt) elif cmd in (WILL, WONT): self.msg('IAC %s %d', cmd == WILL and 'WILL' or 'WONT', ord(opt)) if self.option_callback: self.option_callback(self.sock, cmd, opt) else: self.sock.sendall(IAC + DONT + opt) except EOFError: # raised by self.rawq_getchar() self.iacseq = '' # Reset on EOF self.sb = 0 pass self.cookedq = self.cookedq + buf[0] self.sbdataq = self.sbdataq + buf[1]
[ "def", "process_rawq", "(", "self", ")", ":", "buf", "=", "[", "''", ",", "''", "]", "try", ":", "while", "self", ".", "rawq", ":", "c", "=", "self", ".", "rawq_getchar", "(", ")", "if", "not", "self", ".", "iacseq", ":", "if", "c", "==", "theN...
https://github.com/mchristopher/PokemonGo-DesktopMap/blob/ec37575f2776ee7d64456e2a1f6b6b78830b4fe0/app/pywin/Lib/telnetlib.py#L474-L544
cloudera/hue
23f02102d4547c17c32bd5ea0eb24e9eadd657a4
desktop/core/ext-py/vine-1.2.0/vine/funtools.py
python
transform
(filter_, callback, *filter_args, **filter_kwargs)
return P
Filter final argument to a promise. E.g. to coerce callback argument to :class:`int`:: transform(int, callback) or a more complex example extracting something from a dict and coercing the value to :class:`float`: .. code-block:: python def filter_key_value(key, filter_, mapping): return filter_(mapping[key]) def get_page_expires(self, url, callback=None): return self.request( 'GET', url, callback=transform(get_key, callback, 'PageExpireValue', int), )
Filter final argument to a promise.
[ "Filter", "final", "argument", "to", "a", "promise", "." ]
def transform(filter_, callback, *filter_args, **filter_kwargs): """Filter final argument to a promise. E.g. to coerce callback argument to :class:`int`:: transform(int, callback) or a more complex example extracting something from a dict and coercing the value to :class:`float`: .. code-block:: python def filter_key_value(key, filter_, mapping): return filter_(mapping[key]) def get_page_expires(self, url, callback=None): return self.request( 'GET', url, callback=transform(get_key, callback, 'PageExpireValue', int), ) """ callback = ensure_promise(callback) P = promise(_transback, (filter_, callback, filter_args, filter_kwargs)) P.then(promise(), callback.throw) return P
[ "def", "transform", "(", "filter_", ",", "callback", ",", "*", "filter_args", ",", "*", "*", "filter_kwargs", ")", ":", "callback", "=", "ensure_promise", "(", "callback", ")", "P", "=", "promise", "(", "_transback", ",", "(", "filter_", ",", "callback", ...
https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/vine-1.2.0/vine/funtools.py#L66-L91
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Demo/pdist/rcsclient.py
python
RCSProxyClient.__init__
(self, address, verbose = client.VERBOSE)
[]
def __init__(self, address, verbose = client.VERBOSE): client.SecureClient.__init__(self, address, verbose)
[ "def", "__init__", "(", "self", ",", "address", ",", "verbose", "=", "client", ".", "VERBOSE", ")", ":", "client", ".", "SecureClient", ".", "__init__", "(", "self", ",", "address", ",", "verbose", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Demo/pdist/rcsclient.py#L25-L26
mesalock-linux/mesapy
ed546d59a21b36feb93e2309d5c6b75aa0ad95c9
rpython/rlib/rsiphash.py
python
siphash24
(s)
s' is a normal string. Returns its siphash-2-4 as a r_uint64. Don't forget to cast the result to a regular integer if needed, e.g. with rarithmetic.intmask().
s' is a normal string. Returns its siphash-2-4 as a r_uint64. Don't forget to cast the result to a regular integer if needed, e.g. with rarithmetic.intmask().
[ "s", "is", "a", "normal", "string", ".", "Returns", "its", "siphash", "-", "2", "-", "4", "as", "a", "r_uint64", ".", "Don", "t", "forget", "to", "cast", "the", "result", "to", "a", "regular", "integer", "if", "needed", "e", ".", "g", ".", "with", ...
def siphash24(s): """'s' is a normal string. Returns its siphash-2-4 as a r_uint64. Don't forget to cast the result to a regular integer if needed, e.g. with rarithmetic.intmask(). """ with rffi.scoped_nonmovingbuffer(s) as p: return _siphash24(llmemory.cast_ptr_to_adr(p), len(s))
[ "def", "siphash24", "(", "s", ")", ":", "with", "rffi", ".", "scoped_nonmovingbuffer", "(", "s", ")", "as", "p", ":", "return", "_siphash24", "(", "llmemory", ".", "cast_ptr_to_adr", "(", "p", ")", ",", "len", "(", "s", ")", ")" ]
https://github.com/mesalock-linux/mesapy/blob/ed546d59a21b36feb93e2309d5c6b75aa0ad95c9/rpython/rlib/rsiphash.py#L321-L327
mtrazzi/rl-book-challenge
83a9b7608c805189a39b4ef81893f6ebe982f9e1
chapter5/mc.py
python
OffPolicyMCPrediction.weighted_is
(self, n_episodes, start_state=None, step_list=None)
Weighted Importance Sampling when start_state happens once per episode.
Weighted Importance Sampling when start_state happens once per episode.
[ "Weighted", "Importance", "Sampling", "when", "start_state", "happens", "once", "per", "episode", "." ]
def weighted_is(self, n_episodes, start_state=None, step_list=None): """Weighted Importance Sampling when start_state happens once per episode.""" step_list = [] if step_list is None else step_list q_steps = [] for episode in range(n_episodes + 1): trajs = self.generate_trajectory(start_state=start_state, det=False) G = 0 W = 1 for (i, (s, a, r)) in enumerate(trajs[::-1]): G = self.gamma * G + r self.C[(s, a)] += W self.Q[(s, a)] += (W / self.C[(s, a)]) * (G - self.Q[(s, a)]) W *= self.target[(a, s)] / self.b[(a, s)] if W == 0: break if episode in step_list: self.estimates.append(self.target_estimate(start_state))
[ "def", "weighted_is", "(", "self", ",", "n_episodes", ",", "start_state", "=", "None", ",", "step_list", "=", "None", ")", ":", "step_list", "=", "[", "]", "if", "step_list", "is", "None", "else", "step_list", "q_steps", "=", "[", "]", "for", "episode", ...
https://github.com/mtrazzi/rl-book-challenge/blob/83a9b7608c805189a39b4ef81893f6ebe982f9e1/chapter5/mc.py#L198-L214
gurnec/btcrecover
129c09d653bd21e0eb0989a53c0e15949e37cfff
progressbar/widgets.py
python
Bar.__init__
(self, marker='#', left='|', right='|', fill=' ', fill_left=True)
Creates a customizable progress bar. marker - string or updatable object to use as a marker left - string or updatable object to use as a left border right - string or updatable object to use as a right border fill - character to use for the empty part of the progress bar fill_left - whether to fill from the left or the right
Creates a customizable progress bar.
[ "Creates", "a", "customizable", "progress", "bar", "." ]
def __init__(self, marker='#', left='|', right='|', fill=' ', fill_left=True): '''Creates a customizable progress bar. marker - string or updatable object to use as a marker left - string or updatable object to use as a left border right - string or updatable object to use as a right border fill - character to use for the empty part of the progress bar fill_left - whether to fill from the left or the right ''' self.marker = marker self.left = left self.right = right self.fill = fill self.fill_left = fill_left
[ "def", "__init__", "(", "self", ",", "marker", "=", "'#'", ",", "left", "=", "'|'", ",", "right", "=", "'|'", ",", "fill", "=", "' '", ",", "fill_left", "=", "True", ")", ":", "self", ".", "marker", "=", "marker", "self", ".", "left", "=", "left"...
https://github.com/gurnec/btcrecover/blob/129c09d653bd21e0eb0989a53c0e15949e37cfff/progressbar/widgets.py#L236-L250
n1nj4sec/pupy
a5d766ea81fdfe3bc2c38c9bdaf10e9b75af3b39
pupy/network/lib/tinyhttp.py
python
NullHandler.http_open
(self, req)
return self.do_open(build, req)
[]
def http_open(self, req): def build(host, port=None, strict=None, timeout=0): with self.lock: return NullConnection(self.table[host], timeout, host) return self.do_open(build, req)
[ "def", "http_open", "(", "self", ",", "req", ")", ":", "def", "build", "(", "host", ",", "port", "=", "None", ",", "strict", "=", "None", ",", "timeout", "=", "0", ")", ":", "with", "self", ".", "lock", ":", "return", "NullConnection", "(", "self",...
https://github.com/n1nj4sec/pupy/blob/a5d766ea81fdfe3bc2c38c9bdaf10e9b75af3b39/pupy/network/lib/tinyhttp.py#L213-L218
haiwen/seahub
e92fcd44e3e46260597d8faa9347cb8222b8b10d
seahub/notifications/management/commands/send_dingtalk_notifications.py
python
CommandLogMixin.log_info
(self, msg)
[]
def log_info(self, msg): logger.info(msg) self.println(msg)
[ "def", "log_info", "(", "self", ",", "msg", ")", ":", "logger", ".", "info", "(", "msg", ")", "self", ".", "println", "(", "msg", ")" ]
https://github.com/haiwen/seahub/blob/e92fcd44e3e46260597d8faa9347cb8222b8b10d/seahub/notifications/management/commands/send_dingtalk_notifications.py#L51-L53
iskandr/fancyimpute
36374f84b14a0e870049815bd0b2bc4792d697a1
fancyimpute/scaler.py
python
BiScaler.transform
(self, X)
return X
[]
def transform(self, X): X = np.asarray(X).copy() X = self.center(X, self.row_means, self.column_means, inplace=True) X = self.rescale(X, self.row_scales, self.column_scales, inplace=True) return X
[ "def", "transform", "(", "self", ",", "X", ")", ":", "X", "=", "np", ".", "asarray", "(", "X", ")", ".", "copy", "(", ")", "X", "=", "self", ".", "center", "(", "X", ",", "self", ".", "row_means", ",", "self", ".", "column_means", ",", "inplace...
https://github.com/iskandr/fancyimpute/blob/36374f84b14a0e870049815bd0b2bc4792d697a1/fancyimpute/scaler.py#L379-L383
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/scipy/weave/bytecodecompiler.py
python
ByteCodeMeaning.INPLACE_POWER
(self,pc)
Implements in-place TOS = TOS1 ** TOS.
Implements in-place TOS = TOS1 ** TOS.
[ "Implements", "in", "-", "place", "TOS", "=", "TOS1", "**", "TOS", "." ]
def INPLACE_POWER(self,pc): "Implements in-place TOS = TOS1 ** TOS." raise NotImplementedError
[ "def", "INPLACE_POWER", "(", "self", ",", "pc", ")", ":", "raise", "NotImplementedError" ]
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/scipy/weave/bytecodecompiler.py#L361-L363
aneisch/home-assistant-config
86e381fde9609cb8871c439c433c12989e4e225d
custom_components/alexa_media/media_player.py
python
AlexaClient.async_media_next_track
(self)
Send next track command.
Send next track command.
[ "Send", "next", "track", "command", "." ]
async def async_media_next_track(self): """Send next track command.""" if not (self.state in [STATE_PLAYING, STATE_PAUSED] and self.available): return if self._playing_parent: await self._playing_parent.async_media_next_track() else: if self.hass: self.hass.async_create_task(self.alexa_api.next()) else: await self.alexa_api.next() if not ( self.hass.data[DATA_ALEXAMEDIA]["accounts"][self._login.email]["websocket"] ): await self.async_update()
[ "async", "def", "async_media_next_track", "(", "self", ")", ":", "if", "not", "(", "self", ".", "state", "in", "[", "STATE_PLAYING", ",", "STATE_PAUSED", "]", "and", "self", ".", "available", ")", ":", "return", "if", "self", ".", "_playing_parent", ":", ...
https://github.com/aneisch/home-assistant-config/blob/86e381fde9609cb8871c439c433c12989e4e225d/custom_components/alexa_media/media_player.py#L1218-L1232
awslabs/sockeye
ec2d13f7beb42d8c4f389dba0172250dc9154d5a
sockeye/inference_pt.py
python
_reduce_nbest_translations
(nbest_translations_list: List[Translation])
return Translation(best_translation.target_ids, best_translation.scores, nbest_translations, best_translation.estimated_reference_length)
Combines Translation objects that are nbest translations of the same sentence. :param nbest_translations_list: A list of Translation objects, all of them translations of the same source sentence. :return: A single Translation object where nbest lists are collapsed.
Combines Translation objects that are nbest translations of the same sentence.
[ "Combines", "Translation", "objects", "that", "are", "nbest", "translations", "of", "the", "same", "sentence", "." ]
def _reduce_nbest_translations(nbest_translations_list: List[Translation]) -> Translation: """ Combines Translation objects that are nbest translations of the same sentence. :param nbest_translations_list: A list of Translation objects, all of them translations of the same source sentence. :return: A single Translation object where nbest lists are collapsed. """ best_translation = nbest_translations_list[0] sequences = [translation.target_ids for translation in nbest_translations_list] scores = [translation.scores for translation in nbest_translations_list] nbest_translations = NBestTranslations(sequences, scores) return Translation(best_translation.target_ids, best_translation.scores, nbest_translations, best_translation.estimated_reference_length)
[ "def", "_reduce_nbest_translations", "(", "nbest_translations_list", ":", "List", "[", "Translation", "]", ")", "->", "Translation", ":", "best_translation", "=", "nbest_translations_list", "[", "0", "]", "sequences", "=", "[", "translation", ".", "target_ids", "for...
https://github.com/awslabs/sockeye/blob/ec2d13f7beb42d8c4f389dba0172250dc9154d5a/sockeye/inference_pt.py#L515-L533
bruderstein/PythonScript
df9f7071ddf3a079e3a301b9b53a6dc78cf1208f
PythonLib/full/urllib/request.py
python
FancyURLopener.retry_https_basic_auth
(self, url, realm, data=None)
[]
def retry_https_basic_auth(self, url, realm, data=None): host, selector = _splithost(url) i = host.find('@') + 1 host = host[i:] user, passwd = self.get_user_passwd(host, realm, i) if not (user or passwd): return None host = "%s:%s@%s" % (quote(user, safe=''), quote(passwd, safe=''), host) newurl = 'https://' + host + selector if data is None: return self.open(newurl) else: return self.open(newurl, data)
[ "def", "retry_https_basic_auth", "(", "self", ",", "url", ",", "realm", ",", "data", "=", "None", ")", ":", "host", ",", "selector", "=", "_splithost", "(", "url", ")", "i", "=", "host", ".", "find", "(", "'@'", ")", "+", "1", "host", "=", "host", ...
https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/full/urllib/request.py#L2314-L2326
intrig-unicamp/mininet-wifi
3c8a8f63bd4aa043aa9c1ad16f304dec2916f5ba
examples/cluster.py
python
RemoteMixin.popen
( self, *args, **kwargs )
return super( RemoteMixin, self).popen( *args, tt=False, **kwargs )
Override: disable -tt
Override: disable -tt
[ "Override", ":", "disable", "-", "tt" ]
def popen( self, *args, **kwargs ): "Override: disable -tt" return super( RemoteMixin, self).popen( *args, tt=False, **kwargs )
[ "def", "popen", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "super", "(", "RemoteMixin", ",", "self", ")", ".", "popen", "(", "*", "args", ",", "tt", "=", "False", ",", "*", "*", "kwargs", ")" ]
https://github.com/intrig-unicamp/mininet-wifi/blob/3c8a8f63bd4aa043aa9c1ad16f304dec2916f5ba/examples/cluster.py#L284-L286
caiiiac/Machine-Learning-with-Python
1a26c4467da41ca4ebc3d5bd789ea942ef79422f
MachineLearning/venv/lib/python3.5/site-packages/pandas/core/indexes/interval.py
python
IntervalIndex._maybe_cast_indexed
(self, key)
return key
we need to cast the key, which could be a scalar or an array-like to the type of our subtype
we need to cast the key, which could be a scalar or an array-like to the type of our subtype
[ "we", "need", "to", "cast", "the", "key", "which", "could", "be", "a", "scalar", "or", "an", "array", "-", "like", "to", "the", "type", "of", "our", "subtype" ]
def _maybe_cast_indexed(self, key): """ we need to cast the key, which could be a scalar or an array-like to the type of our subtype """ if isinstance(key, IntervalIndex): return key subtype = self.dtype.subtype if is_float_dtype(subtype): if is_integer(key): key = float(key) elif isinstance(key, (np.ndarray, Index)): key = key.astype('float64') elif is_integer_dtype(subtype): if is_integer(key): key = int(key) return key
[ "def", "_maybe_cast_indexed", "(", "self", ",", "key", ")", ":", "if", "isinstance", "(", "key", ",", "IntervalIndex", ")", ":", "return", "key", "subtype", "=", "self", ".", "dtype", ".", "subtype", "if", "is_float_dtype", "(", "subtype", ")", ":", "if"...
https://github.com/caiiiac/Machine-Learning-with-Python/blob/1a26c4467da41ca4ebc3d5bd789ea942ef79422f/MachineLearning/venv/lib/python3.5/site-packages/pandas/core/indexes/interval.py#L586-L604
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_hxb2/lib/python3.5/site-packages/django/utils/autoreload.py
python
gen_filenames
(only_new=False)
Returns a list of filenames referenced in sys.modules and translation files.
Returns a list of filenames referenced in sys.modules and translation files.
[ "Returns", "a", "list", "of", "filenames", "referenced", "in", "sys", ".", "modules", "and", "translation", "files", "." ]
def gen_filenames(only_new=False): """ Returns a list of filenames referenced in sys.modules and translation files. """ # N.B. ``list(...)`` is needed, because this runs in parallel with # application code which might be mutating ``sys.modules``, and this will # fail with RuntimeError: cannot mutate dictionary while iterating global _cached_modules, _cached_filenames module_values = set(sys.modules.values()) _cached_filenames = clean_files(_cached_filenames) if _cached_modules == module_values: # No changes in module list, short-circuit the function if only_new: return [] else: return _cached_filenames + clean_files(_error_files) new_modules = module_values - _cached_modules new_filenames = clean_files( [filename.__file__ for filename in new_modules if hasattr(filename, '__file__')]) if not _cached_filenames and settings.USE_I18N: # Add the names of the .mo files that can be generated # by compilemessages management command to the list of files watched. basedirs = [os.path.join(os.path.dirname(os.path.dirname(__file__)), 'conf', 'locale'), 'locale'] for app_config in reversed(list(apps.get_app_configs())): basedirs.append(os.path.join(npath(app_config.path), 'locale')) basedirs.extend(settings.LOCALE_PATHS) basedirs = [os.path.abspath(basedir) for basedir in basedirs if os.path.isdir(basedir)] for basedir in basedirs: for dirpath, dirnames, locale_filenames in os.walk(basedir): for filename in locale_filenames: if filename.endswith('.mo'): new_filenames.append(os.path.join(dirpath, filename)) _cached_modules = _cached_modules.union(new_modules) _cached_filenames += new_filenames if only_new: return new_filenames + clean_files(_error_files) else: return _cached_filenames + clean_files(_error_files)
[ "def", "gen_filenames", "(", "only_new", "=", "False", ")", ":", "# N.B. ``list(...)`` is needed, because this runs in parallel with", "# application code which might be mutating ``sys.modules``, and this will", "# fail with RuntimeError: cannot mutate dictionary while iterating", "global", ...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/django/utils/autoreload.py#L82-L127
tomplus/kubernetes_asyncio
f028cc793e3a2c519be6a52a49fb77ff0b014c9b
kubernetes_asyncio/client/models/v1_container_status.py
python
V1ContainerStatus.image_id
(self, image_id)
Sets the image_id of this V1ContainerStatus. ImageID of the container's image. # noqa: E501 :param image_id: The image_id of this V1ContainerStatus. # noqa: E501 :type: str
Sets the image_id of this V1ContainerStatus.
[ "Sets", "the", "image_id", "of", "this", "V1ContainerStatus", "." ]
def image_id(self, image_id): """Sets the image_id of this V1ContainerStatus. ImageID of the container's image. # noqa: E501 :param image_id: The image_id of this V1ContainerStatus. # noqa: E501 :type: str """ if self.local_vars_configuration.client_side_validation and image_id is None: # noqa: E501 raise ValueError("Invalid value for `image_id`, must not be `None`") # noqa: E501 self._image_id = image_id
[ "def", "image_id", "(", "self", ",", "image_id", ")", ":", "if", "self", ".", "local_vars_configuration", ".", "client_side_validation", "and", "image_id", "is", "None", ":", "# noqa: E501", "raise", "ValueError", "(", "\"Invalid value for `image_id`, must not be `None`...
https://github.com/tomplus/kubernetes_asyncio/blob/f028cc793e3a2c519be6a52a49fb77ff0b014c9b/kubernetes_asyncio/client/models/v1_container_status.py#L150-L161
bjmayor/hacker
e3ce2ad74839c2733b27dac6c0f495e0743e1866
venv/lib/python3.5/site-packages/pip/_vendor/requests/sessions.py
python
Session.get_adapter
(self, url)
Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter
Returns the appropriate connection adapter for the given URL.
[ "Returns", "the", "appropriate", "connection", "adapter", "for", "the", "given", "URL", "." ]
def get_adapter(self, url): """ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter """ for (prefix, adapter) in self.adapters.items(): if url.lower().startswith(prefix): return adapter # Nothing matches :-/ raise InvalidSchema("No connection adapters were found for '%s'" % url)
[ "def", "get_adapter", "(", "self", ",", "url", ")", ":", "for", "(", "prefix", ",", "adapter", ")", "in", "self", ".", "adapters", ".", "items", "(", ")", ":", "if", "url", ".", "lower", "(", ")", ".", "startswith", "(", "prefix", ")", ":", "retu...
https://github.com/bjmayor/hacker/blob/e3ce2ad74839c2733b27dac6c0f495e0743e1866/venv/lib/python3.5/site-packages/pip/_vendor/requests/sessions.py#L660-L672
CPJKU/madmom
3bc8334099feb310acfce884ebdb76a28e01670d
madmom/ml/nn/layers.py
python
ReshapeLayer.activate
(self, data, **kwargs)
return np.reshape(data, self.newshape, self.order)
Activate ReshapeLayer. Parameters ---------- data : numpy array Activate with this data. Returns ------- numpy array Reshaped data.
Activate ReshapeLayer.
[ "Activate", "ReshapeLayer", "." ]
def activate(self, data, **kwargs): """ Activate ReshapeLayer. Parameters ---------- data : numpy array Activate with this data. Returns ------- numpy array Reshaped data. """ return np.reshape(data, self.newshape, self.order)
[ "def", "activate", "(", "self", ",", "data", ",", "*", "*", "kwargs", ")", ":", "return", "np", ".", "reshape", "(", "data", ",", "self", ".", "newshape", ",", "self", ".", "order", ")" ]
https://github.com/CPJKU/madmom/blob/3bc8334099feb310acfce884ebdb76a28e01670d/madmom/ml/nn/layers.py#L1209-L1224
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/nest/config_flow.py
python
NestFlowHandler.async_oauth_create_entry
(self, data: dict[str, Any])
return await self.async_step_pubsub()
Complete OAuth setup and finish pubsub or finish.
Complete OAuth setup and finish pubsub or finish.
[ "Complete", "OAuth", "setup", "and", "finish", "pubsub", "or", "finish", "." ]
async def async_oauth_create_entry(self, data: dict[str, Any]) -> FlowResult: """Complete OAuth setup and finish pubsub or finish.""" assert self.config_mode != ConfigMode.LEGACY, "Step only supported for SDM API" self._data.update(data) if not self._configure_pubsub(): _LOGGER.debug("Skipping Pub/Sub configuration") return await self.async_step_finish() return await self.async_step_pubsub()
[ "async", "def", "async_oauth_create_entry", "(", "self", ",", "data", ":", "dict", "[", "str", ",", "Any", "]", ")", "->", "FlowResult", ":", "assert", "self", ".", "config_mode", "!=", "ConfigMode", ".", "LEGACY", ",", "\"Step only supported for SDM API\"", "...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/nest/config_flow.py#L181-L188
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/tkinter/tix.py
python
TList.insert
(self, index, cnf={}, **kw)
[]
def insert(self, index, cnf={}, **kw): self.tk.call(self._w, 'insert', index, *self._options(cnf, kw))
[ "def", "insert", "(", "self", ",", "index", ",", "cnf", "=", "{", "}", ",", "*", "*", "kw", ")", ":", "self", ".", "tk", ".", "call", "(", "self", ".", "_w", ",", "'insert'", ",", "index", ",", "*", "self", ".", "_options", "(", "cnf", ",", ...
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/tkinter/tix.py#L1459-L1460
veekun/pokedex
cc483e1877f22b8c19ac27ec0ff5fafd09c5cd5b
pokedex/struct/_pokemon_struct.py
python
LittleEndianBitStruct
(*args)
return Buffered( BitStruct(*args), encoder=lambda s: s[::-1], decoder=lambda s: s[::-1], resizer=lambda _: _, )
Construct's bit structs read a byte at a time in the order they appear, reading each bit from most to least significant. Alas, this doesn't work at all for a 32-bit bit field, because the bytes are 'backwards' in little-endian files. So this acts as a bit struct, but reverses the order of bytes before reading/writing, so ALL the bits are read from most to least significant.
Construct's bit structs read a byte at a time in the order they appear, reading each bit from most to least significant. Alas, this doesn't work at all for a 32-bit bit field, because the bytes are 'backwards' in little-endian files.
[ "Construct", "s", "bit", "structs", "read", "a", "byte", "at", "a", "time", "in", "the", "order", "they", "appear", "reading", "each", "bit", "from", "most", "to", "least", "significant", ".", "Alas", "this", "doesn", "t", "work", "at", "all", "for", "...
def LittleEndianBitStruct(*args): """Construct's bit structs read a byte at a time in the order they appear, reading each bit from most to least significant. Alas, this doesn't work at all for a 32-bit bit field, because the bytes are 'backwards' in little-endian files. So this acts as a bit struct, but reverses the order of bytes before reading/writing, so ALL the bits are read from most to least significant. """ return Buffered( BitStruct(*args), encoder=lambda s: s[::-1], decoder=lambda s: s[::-1], resizer=lambda _: _, )
[ "def", "LittleEndianBitStruct", "(", "*", "args", ")", ":", "return", "Buffered", "(", "BitStruct", "(", "*", "args", ")", ",", "encoder", "=", "lambda", "s", ":", "s", "[", ":", ":", "-", "1", "]", ",", "decoder", "=", "lambda", "s", ":", "s", "...
https://github.com/veekun/pokedex/blob/cc483e1877f22b8c19ac27ec0ff5fafd09c5cd5b/pokedex/struct/_pokemon_struct.py#L476-L490
bruderstein/PythonScript
df9f7071ddf3a079e3a301b9b53a6dc78cf1208f
PythonLib/full/pickle.py
python
_Unpickler.load_long1
(self)
[]
def load_long1(self): n = self.read(1)[0] data = self.read(n) self.append(decode_long(data))
[ "def", "load_long1", "(", "self", ")", ":", "n", "=", "self", ".", "read", "(", "1", ")", "[", "0", "]", "data", "=", "self", ".", "read", "(", "n", ")", "self", ".", "append", "(", "decode_long", "(", "data", ")", ")" ]
https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/full/pickle.py#L1299-L1302
ctpbee/ctpbee
c504e141c0a6fb2c5509bb6a77494c592997c0d4
ctpbee/jsond/tag.py
python
PollenTag.check
(self, data)
检查类型
检查类型
[ "检查类型" ]
def check(self, data): """检查类型""" pass
[ "def", "check", "(", "self", ",", "data", ")", ":", "pass" ]
https://github.com/ctpbee/ctpbee/blob/c504e141c0a6fb2c5509bb6a77494c592997c0d4/ctpbee/jsond/tag.py#L22-L24
vim-scripts/UltiSnips
5f88199e373a7eea4644b8dc1ff433688e8f2ebd
pythonx/UltiSnips/text_objects/_python_code.py
python
SnippetUtil.opt
(self, option, default=None)
return default
Gets a Vim variable.
Gets a Vim variable.
[ "Gets", "a", "Vim", "variable", "." ]
def opt(self, option, default=None): # pylint:disable=no-self-use """Gets a Vim variable.""" if _vim.eval("exists('%s')" % option) == '1': try: return _vim.eval(option) except _vim.error: pass return default
[ "def", "opt", "(", "self", ",", "option", ",", "default", "=", "None", ")", ":", "# pylint:disable=no-self-use", "if", "_vim", ".", "eval", "(", "\"exists('%s')\"", "%", "option", ")", "==", "'1'", ":", "try", ":", "return", "_vim", ".", "eval", "(", "...
https://github.com/vim-scripts/UltiSnips/blob/5f88199e373a7eea4644b8dc1ff433688e8f2ebd/pythonx/UltiSnips/text_objects/_python_code.py#L206-L213