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
fluentpython/example-code-2e
80f7f84274a47579e59c29a4657691525152c9d5
21-async/mojifinder/bottle.py
python
_hkey
(key)
return key.title().replace('_', '-')
[]
def _hkey(key): if '\n' in key or '\r' in key or '\0' in key: raise ValueError("Header names must not contain control characters: %r" % key) return key.title().replace('_', '-')
[ "def", "_hkey", "(", "key", ")", ":", "if", "'\\n'", "in", "key", "or", "'\\r'", "in", "key", "or", "'\\0'", "in", "key", ":", "raise", "ValueError", "(", "\"Header names must not contain control characters: %r\"", "%", "key", ")", "return", "key", ".", "tit...
https://github.com/fluentpython/example-code-2e/blob/80f7f84274a47579e59c29a4657691525152c9d5/21-async/mojifinder/bottle.py#L1407-L1410
flask-admin/flask-admin
7cff9c742d44d42a8d3495c73a6d71381c796396
flask_admin/model/typefmt.py
python
bool_formatter
(view, value)
return Markup('<span class="fa %s glyphicon glyphicon-%s icon-%s"></span>' % (fa, glyph, glyph))
Return check icon if value is `True` or empty string otherwise. :param value: Value to check
Return check icon if value is `True` or empty string otherwise.
[ "Return", "check", "icon", "if", "value", "is", "True", "or", "empty", "string", "otherwise", "." ]
def bool_formatter(view, value): """ Return check icon if value is `True` or empty string otherwise. :param value: Value to check """ glyph = 'ok-circle' if value else 'minus-sign' fa = 'fa-check-circle' if value else 'fa-minus-circle' return Markup('<span class="fa %s glyphicon glyphicon-%s icon-%s"></span>' % (fa, glyph, glyph))
[ "def", "bool_formatter", "(", "view", ",", "value", ")", ":", "glyph", "=", "'ok-circle'", "if", "value", "else", "'minus-sign'", "fa", "=", "'fa-check-circle'", "if", "value", "else", "'fa-minus-circle'", "return", "Markup", "(", "'<span class=\"fa %s glyphicon gly...
https://github.com/flask-admin/flask-admin/blob/7cff9c742d44d42a8d3495c73a6d71381c796396/flask_admin/model/typefmt.py#L31-L40
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/skybeacon/sensor.py
python
Monitor._update
(self, handle, value)
Notification callback from pygatt.
Notification callback from pygatt.
[ "Notification", "callback", "from", "pygatt", "." ]
def _update(self, handle, value): """Notification callback from pygatt.""" _LOGGER.debug( "%s: %15s temperature = %-2d.%-2d, humidity = %3d", handle, self.name, value[0], value[2], value[1], ) self.data["temp"] = float("%d.%d" % (value[0], value[2])) self.data["humid"] = value[1]
[ "def", "_update", "(", "self", ",", "handle", ",", "value", ")", ":", "_LOGGER", ".", "debug", "(", "\"%s: %15s temperature = %-2d.%-2d, humidity = %3d\"", ",", "handle", ",", "self", ".", "name", ",", "value", "[", "0", "]", ",", "value", "[", "2", "]", ...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/skybeacon/sensor.py#L177-L188
uqfoundation/multiprocess
028cc73f02655e6451d92e5147d19d8c10aebe50
py3.6/multiprocess/pool.py
python
Pool.map
(self, func, iterable, chunksize=None)
return self._map_async(func, iterable, mapstar, chunksize).get()
Apply `func` to each element in `iterable`, collecting the results in a list that is returned.
Apply `func` to each element in `iterable`, collecting the results in a list that is returned.
[ "Apply", "func", "to", "each", "element", "in", "iterable", "collecting", "the", "results", "in", "a", "list", "that", "is", "returned", "." ]
def map(self, func, iterable, chunksize=None): ''' Apply `func` to each element in `iterable`, collecting the results in a list that is returned. ''' return self._map_async(func, iterable, mapstar, chunksize).get()
[ "def", "map", "(", "self", ",", "func", ",", "iterable", ",", "chunksize", "=", "None", ")", ":", "return", "self", ".", "_map_async", "(", "func", ",", "iterable", ",", "mapstar", ",", "chunksize", ")", ".", "get", "(", ")" ]
https://github.com/uqfoundation/multiprocess/blob/028cc73f02655e6451d92e5147d19d8c10aebe50/py3.6/multiprocess/pool.py#L261-L266
PaulSonOfLars/tgbot
0ece72778b7772725ab214fe0929daaa2fc7d2d1
tg_bot/modules/helper_funcs/chat_status.py
python
is_user_ban_protected
(chat: Chat, user_id: int, member: ChatMember = None)
return member.status in ('administrator', 'creator')
[]
def is_user_ban_protected(chat: Chat, user_id: int, member: ChatMember = None) -> bool: if chat.type == 'private' \ or user_id in SUDO_USERS \ or user_id in WHITELIST_USERS \ or chat.all_members_are_administrators: return True if not member: member = chat.get_member(user_id) return member.status in ('administrator', 'creator')
[ "def", "is_user_ban_protected", "(", "chat", ":", "Chat", ",", "user_id", ":", "int", ",", "member", ":", "ChatMember", "=", "None", ")", "->", "bool", ":", "if", "chat", ".", "type", "==", "'private'", "or", "user_id", "in", "SUDO_USERS", "or", "user_id...
https://github.com/PaulSonOfLars/tgbot/blob/0ece72778b7772725ab214fe0929daaa2fc7d2d1/tg_bot/modules/helper_funcs/chat_status.py#L13-L22
projectmesa/mesa
246c69d592a82e89c75d555c79736c3f619d434a
mesa/space.py
python
ContinuousSpace.move_agent
(self, agent: Agent, pos: FloatCoordinate)
Move an agent from its current position to a new position. Args: agent: The agent object to move. pos: Coordinate tuple to move the agent to.
Move an agent from its current position to a new position.
[ "Move", "an", "agent", "from", "its", "current", "position", "to", "a", "new", "position", "." ]
def move_agent(self, agent: Agent, pos: FloatCoordinate) -> None: """Move an agent from its current position to a new position. Args: agent: The agent object to move. pos: Coordinate tuple to move the agent to. """ pos = self.torus_adj(pos) idx = self._agent_to_index[agent] self._agent_points[idx, 0] = pos[0] self._agent_points[idx, 1] = pos[1] agent.pos = pos
[ "def", "move_agent", "(", "self", ",", "agent", ":", "Agent", ",", "pos", ":", "FloatCoordinate", ")", "->", "None", ":", "pos", "=", "self", ".", "torus_adj", "(", "pos", ")", "idx", "=", "self", ".", "_agent_to_index", "[", "agent", "]", "self", "....
https://github.com/projectmesa/mesa/blob/246c69d592a82e89c75d555c79736c3f619d434a/mesa/space.py#L748-L759
metabrainz/picard
535bf8c7d9363ffc7abb3f69418ec11823c38118
picard/tagger.py
python
Tagger.extract_and_submit_acousticbrainz_features
(self, objs)
Extract AcousticBrainz features and submit them.
Extract AcousticBrainz features and submit them.
[ "Extract", "AcousticBrainz", "features", "and", "submit", "them", "." ]
def extract_and_submit_acousticbrainz_features(self, objs): """Extract AcousticBrainz features and submit them.""" if not self.ab_extractor.available(): return for file in iter_files_from_objects(objs): # Skip unmatched files if not file.can_extract(): log.warning("AcousticBrainz requires a MusicBrainz Recording ID, but file does not have it: %s" % file.filename) # And process matched ones else: file.set_pending() # Check if file was either already processed or sent to the AcousticBrainz server if file.acousticbrainz_features_file: results = (file.acousticbrainz_features_file, 0, "Writing results") ab_extractor_callback(self, file, results, False) elif file.acousticbrainz_is_duplicate: results = (None, 0, "Duplicate") ab_extractor_callback(self, file, results, False) else: file.acousticbrainz_error = False # Launch the acousticbrainz on a separate process log.debug("Extracting AcousticBrainz features from %s" % file.filename) ab_feature_extraction( self, file.metadata["musicbrainz_recordingid"], file.filename, partial(ab_extractor_callback, self, file) )
[ "def", "extract_and_submit_acousticbrainz_features", "(", "self", ",", "objs", ")", ":", "if", "not", "self", ".", "ab_extractor", ".", "available", "(", ")", ":", "return", "for", "file", "in", "iter_files_from_objects", "(", "objs", ")", ":", "# Skip unmatched...
https://github.com/metabrainz/picard/blob/535bf8c7d9363ffc7abb3f69418ec11823c38118/picard/tagger.py#L866-L895
microsoft/unilm
65f15af2a307ebb64cfb25adf54375b002e6fe8d
xtune/src/transformers/file_utils.py
python
s3_etag
(url, proxies=None)
return s3_object.e_tag
Check ETag on S3 object.
Check ETag on S3 object.
[ "Check", "ETag", "on", "S3", "object", "." ]
def s3_etag(url, proxies=None): """Check ETag on S3 object.""" s3_resource = boto3.resource("s3", config=Config(proxies=proxies)) bucket_name, s3_path = split_s3_path(url) s3_object = s3_resource.Object(bucket_name, s3_path) return s3_object.e_tag
[ "def", "s3_etag", "(", "url", ",", "proxies", "=", "None", ")", ":", "s3_resource", "=", "boto3", ".", "resource", "(", "\"s3\"", ",", "config", "=", "Config", "(", "proxies", "=", "proxies", ")", ")", "bucket_name", ",", "s3_path", "=", "split_s3_path",...
https://github.com/microsoft/unilm/blob/65f15af2a307ebb64cfb25adf54375b002e6fe8d/xtune/src/transformers/file_utils.py#L333-L338
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/speaklater.py
python
_LazyString.__setstate__
(self, tup)
[]
def __setstate__(self, tup): self._func, self._args, self._kwargs = tup
[ "def", "__setstate__", "(", "self", ",", "tup", ")", ":", "self", ".", "_func", ",", "self", ".", "_args", ",", "self", ".", "_kwargs", "=", "tup" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/speaklater.py#L182-L183
wequant-org/liveStrategyEngine
6e799e33cfa83b4496dd694e1d2bf30ea104e2c1
exchangeConnection/huobi/huobiServiceETH.py
python
withdraw
(address_id, amount)
return api_key_post(params, url)
:param address_id: :param amount: :return:
:param address_id: :param amount: :return:
[ ":", "param", "address_id", ":", ":", "param", "amount", ":", ":", "return", ":" ]
def withdraw(address_id, amount): """ :param address_id: :param amount: :return: """ params = {'address-id': address_id, 'amount': amount} url = '/v1/dw/withdraw-virtual/create' return api_key_post(params, url)
[ "def", "withdraw", "(", "address_id", ",", "amount", ")", ":", "params", "=", "{", "'address-id'", ":", "address_id", ",", "'amount'", ":", "amount", "}", "url", "=", "'/v1/dw/withdraw-virtual/create'", "return", "api_key_post", "(", "params", ",", "url", ")" ...
https://github.com/wequant-org/liveStrategyEngine/blob/6e799e33cfa83b4496dd694e1d2bf30ea104e2c1/exchangeConnection/huobi/huobiServiceETH.py#L257-L267
trailofbits/manticore
b050fdf0939f6c63f503cdf87ec0ab159dd41159
manticore/native/cpu/x86.py
python
X86Cpu.PCMPGTD
(cpu, op0, op1)
PCMPGTD: Packed compare for greater than with double words see PCMPEQB
PCMPGTD: Packed compare for greater than with double words see PCMPEQB
[ "PCMPGTD", ":", "Packed", "compare", "for", "greater", "than", "with", "double", "words", "see", "PCMPEQB" ]
def PCMPGTD(cpu, op0, op1): """ PCMPGTD: Packed compare for greater than with double words see PCMPEQB """ arg0 = op0.read() arg1 = op1.read() res = 0 for i in range(0, op0.size, 32): res = Operators.ITEBV( op0.size, Operators.EXTRACT(arg0, i, 32) > Operators.EXTRACT(arg1, i, 32), res | (0xFFFFFFFF << i), res, ) op0.write(res)
[ "def", "PCMPGTD", "(", "cpu", ",", "op0", ",", "op1", ")", ":", "arg0", "=", "op0", ".", "read", "(", ")", "arg1", "=", "op1", ".", "read", "(", ")", "res", "=", "0", "for", "i", "in", "range", "(", "0", ",", "op0", ".", "size", ",", "32", ...
https://github.com/trailofbits/manticore/blob/b050fdf0939f6c63f503cdf87ec0ab159dd41159/manticore/native/cpu/x86.py#L5139-L5155
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.3/django/template/defaultfilters.py
python
get_digit
(value, arg)
Given a whole number, returns the requested digit of it, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Returns the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is always an integer.
Given a whole number, returns the requested digit of it, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Returns the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is always an integer.
[ "Given", "a", "whole", "number", "returns", "the", "requested", "digit", "of", "it", "where", "1", "is", "the", "right", "-", "most", "digit", "2", "is", "the", "second", "-", "right", "-", "most", "digit", "etc", ".", "Returns", "the", "original", "va...
def get_digit(value, arg): """ Given a whole number, returns the requested digit of it, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Returns the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is always an integer. """ try: arg = int(arg) value = int(value) except ValueError: return value # Fail silently for an invalid argument if arg < 1: return value try: return int(str(value)[-arg]) except IndexError: return 0
[ "def", "get_digit", "(", "value", ",", "arg", ")", ":", "try", ":", "arg", "=", "int", "(", "arg", ")", "value", "=", "int", "(", "value", ")", "except", "ValueError", ":", "return", "value", "# Fail silently for an invalid argument", "if", "arg", "<", "...
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.3/django/template/defaultfilters.py#L660-L677
django/channels
6af1bc3ab45f55e3f47d0d1d059d5db0a18a9581
channels/generic/websocket.py
python
AsyncWebsocketConsumer.close
(self, code=None)
Closes the WebSocket from the server end
Closes the WebSocket from the server end
[ "Closes", "the", "WebSocket", "from", "the", "server", "end" ]
async def close(self, code=None): """ Closes the WebSocket from the server end """ if code is not None and code is not True: await super().send({"type": "websocket.close", "code": code}) else: await super().send({"type": "websocket.close"})
[ "async", "def", "close", "(", "self", ",", "code", "=", "None", ")", ":", "if", "code", "is", "not", "None", "and", "code", "is", "not", "True", ":", "await", "super", "(", ")", ".", "send", "(", "{", "\"type\"", ":", "\"websocket.close\"", ",", "\...
https://github.com/django/channels/blob/6af1bc3ab45f55e3f47d0d1d059d5db0a18a9581/channels/generic/websocket.py#L217-L224
meraki/dashboard-api-python
aef5e6fe5d23a40d435d5c64ff30580a28af07f1
meraki/api/switch.py
python
Switch.getNetworkSwitchStack
(self, networkId: str, switchStackId: str)
return self._session.get(metadata, resource)
**Show a switch stack** https://developer.cisco.com/meraki/api-v1/#!get-network-switch-stack - networkId (string): (required) - switchStackId (string): (required)
**Show a switch stack** https://developer.cisco.com/meraki/api-v1/#!get-network-switch-stack
[ "**", "Show", "a", "switch", "stack", "**", "https", ":", "//", "developer", ".", "cisco", ".", "com", "/", "meraki", "/", "api", "-", "v1", "/", "#!get", "-", "network", "-", "switch", "-", "stack" ]
def getNetworkSwitchStack(self, networkId: str, switchStackId: str): """ **Show a switch stack** https://developer.cisco.com/meraki/api-v1/#!get-network-switch-stack - networkId (string): (required) - switchStackId (string): (required) """ metadata = { 'tags': ['switch', 'configure', 'stacks'], 'operation': 'getNetworkSwitchStack' } resource = f'/networks/{networkId}/switch/stacks/{switchStackId}' return self._session.get(metadata, resource)
[ "def", "getNetworkSwitchStack", "(", "self", ",", "networkId", ":", "str", ",", "switchStackId", ":", "str", ")", ":", "metadata", "=", "{", "'tags'", ":", "[", "'switch'", ",", "'configure'", ",", "'stacks'", "]", ",", "'operation'", ":", "'getNetworkSwitch...
https://github.com/meraki/dashboard-api-python/blob/aef5e6fe5d23a40d435d5c64ff30580a28af07f1/meraki/api/switch.py#L1521-L1536
mlrun/mlrun
4c120719d64327a34b7ee1ab08fb5e01b258b00a
mlrun/frameworks/pytorch/callbacks/logging_callback.py
python
LoggingCallback.on_epoch_end
(self, epoch: int)
Before the given epoch ends, this method will be called to log the dynamic hyperparameters as needed. :param epoch: The epoch that has just ended.
Before the given epoch ends, this method will be called to log the dynamic hyperparameters as needed.
[ "Before", "the", "given", "epoch", "ends", "this", "method", "will", "be", "called", "to", "log", "the", "dynamic", "hyperparameters", "as", "needed", "." ]
def on_epoch_end(self, epoch: int): """ Before the given epoch ends, this method will be called to log the dynamic hyperparameters as needed. :param epoch: The epoch that has just ended. """ # Update the dynamic hyperparameters dictionary: if self._dynamic_hyperparameters_keys: for ( parameter_name, (source, key_chain,), ) in self._dynamic_hyperparameters_keys.items(): self._logger.log_dynamic_hyperparameter( parameter_name=parameter_name, value=self._get_hyperparameter(source=source, key_chain=key_chain), )
[ "def", "on_epoch_end", "(", "self", ",", "epoch", ":", "int", ")", ":", "# Update the dynamic hyperparameters dictionary:", "if", "self", ".", "_dynamic_hyperparameters_keys", ":", "for", "(", "parameter_name", ",", "(", "source", ",", "key_chain", ",", ")", ",", ...
https://github.com/mlrun/mlrun/blob/4c120719d64327a34b7ee1ab08fb5e01b258b00a/mlrun/frameworks/pytorch/callbacks/logging_callback.py#L229-L244
Komodo/KomodoEdit
61edab75dce2bdb03943b387b0608ea36f548e8e
src/codeintel/play/core.py
python
Sizer.ShowItems
(*args, **kwargs)
return _core.Sizer_ShowItems(*args, **kwargs)
ShowItems(bool show)
ShowItems(bool show)
[ "ShowItems", "(", "bool", "show", ")" ]
def ShowItems(*args, **kwargs): """ShowItems(bool show)""" return _core.Sizer_ShowItems(*args, **kwargs)
[ "def", "ShowItems", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "_core", ".", "Sizer_ShowItems", "(", "*", "args", ",", "*", "*", "kwargs", ")" ]
https://github.com/Komodo/KomodoEdit/blob/61edab75dce2bdb03943b387b0608ea36f548e8e/src/codeintel/play/core.py#L8445-L8447
krintoxi/NoobSec-Toolkit
38738541cbc03cedb9a3b3ed13b629f781ad64f6
NoobSecToolkit - MAC OSX/scripts/sshbackdoors/backdoors/escalation/shell.py
python
Shell.do_exploit
(self, args)
[]
def do_exploit(self, args): target = self.core.curtarget print(GOOD + "Initializing backdoor...") target.ssh.exec_command(self.get_command()) print(GOOD + "Shell Backdoor attempted.") for mod in self.modules.keys(): print(INFO + "Attempting to execute " + mod.name + " module...") mod.exploit()
[ "def", "do_exploit", "(", "self", ",", "args", ")", ":", "target", "=", "self", ".", "core", ".", "curtarget", "print", "(", "GOOD", "+", "\"Initializing backdoor...\"", ")", "target", ".", "ssh", ".", "exec_command", "(", "self", ".", "get_command", "(", ...
https://github.com/krintoxi/NoobSec-Toolkit/blob/38738541cbc03cedb9a3b3ed13b629f781ad64f6/NoobSecToolkit - MAC OSX/scripts/sshbackdoors/backdoors/escalation/shell.py#L21-L28
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/minion.py
python
Minion._execute_job_function
( self, function_name, function_args, executors, opts, data )
return None
Executes a function within a job given it's name, the args and the executors. It also checks if the function is allowed to run if 'blackout mode' is enabled.
Executes a function within a job given it's name, the args and the executors. It also checks if the function is allowed to run if 'blackout mode' is enabled.
[ "Executes", "a", "function", "within", "a", "job", "given", "it", "s", "name", "the", "args", "and", "the", "executors", ".", "It", "also", "checks", "if", "the", "function", "is", "allowed", "to", "run", "if", "blackout", "mode", "is", "enabled", "." ]
def _execute_job_function( self, function_name, function_args, executors, opts, data ): """ Executes a function within a job given it's name, the args and the executors. It also checks if the function is allowed to run if 'blackout mode' is enabled. """ minion_blackout_violation = False if self.connected and self.opts["pillar"].get("minion_blackout", False): whitelist = self.opts["pillar"].get("minion_blackout_whitelist", []) # this minion is blacked out. Only allow saltutil.refresh_pillar and the whitelist if ( function_name != "saltutil.refresh_pillar" and function_name not in whitelist ): minion_blackout_violation = True # use minion_blackout_whitelist from grains if it exists if self.opts["grains"].get("minion_blackout", False): whitelist = self.opts["grains"].get("minion_blackout_whitelist", []) if ( function_name != "saltutil.refresh_pillar" and function_name not in whitelist ): minion_blackout_violation = True if minion_blackout_violation: raise SaltInvocationError( "Minion in blackout mode. Set 'minion_blackout' " "to False in pillar or grains to resume operations. Only " "saltutil.refresh_pillar allowed in blackout mode." ) if function_name in self.functions: func = self.functions[function_name] args, kwargs = load_args_and_kwargs(func, function_args, data) else: # only run if function_name is not in minion_instance.functions and allow_missing_funcs is True func = function_name args, kwargs = function_args, data self.functions.pack["__context__"]["retcode"] = 0 if isinstance(executors, str): executors = [executors] elif not isinstance(executors, list) or not executors: raise SaltInvocationError( "Wrong executors specification: {}. String or non-empty list expected".format( executors ) ) if opts.get("sudo_user", "") and executors[-1] != "sudo": executors[-1] = "sudo" # replace the last one with sudo log.trace("Executors list %s", executors) # pylint: disable=no-member for name in executors: fname = "{}.execute".format(name) if fname not in self.executors: raise SaltInvocationError("Executor '{}' is not available".format(name)) return_data = self.executors[fname](opts, data, func, args, kwargs) if return_data is not None: return return_data return None
[ "def", "_execute_job_function", "(", "self", ",", "function_name", ",", "function_args", ",", "executors", ",", "opts", ",", "data", ")", ":", "minion_blackout_violation", "=", "False", "if", "self", ".", "connected", "and", "self", ".", "opts", "[", "\"pillar...
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/minion.py#L1812-L1872
burke-software/schooldriver
a07262ba864aee0182548ecceb661e49c925725f
ecwsp/discipline/forms.py
python
get_start_date_default
()
return default_date
Return default date for report. It should be X work days ago.
Return default date for report. It should be X work days ago.
[ "Return", "default", "date", "for", "report", ".", "It", "should", "be", "X", "work", "days", "ago", "." ]
def get_start_date_default(): """ Return default date for report. It should be X work days ago. """ work_days = (0,1,2,3,4) # python day of weeks mon-fri # Traverse back these many days days_back = int(Configuration.get_or_default('Discipline Merit Default Days', default=14).value) default_date = datetime.date.today() while days_back > 0: while not default_date.weekday() in work_days: default_date = default_date - datetime.timedelta(days=1) default_date = default_date - datetime.timedelta(days=1) days_back -= 1 return default_date
[ "def", "get_start_date_default", "(", ")", ":", "work_days", "=", "(", "0", ",", "1", ",", "2", ",", "3", ",", "4", ")", "# python day of weeks mon-fri", "# Traverse back these many days", "days_back", "=", "int", "(", "Configuration", ".", "get_or_default", "("...
https://github.com/burke-software/schooldriver/blob/a07262ba864aee0182548ecceb661e49c925725f/ecwsp/discipline/forms.py#L32-L43
twilio/twilio-python
6e1e811ea57a1edfadd5161ace87397c563f6915
twilio/rest/api/v2010/account/conference/recording.py
python
RecordingInstance.account_sid
(self)
return self._properties['account_sid']
:returns: The SID of the Account that created the resource :rtype: unicode
:returns: The SID of the Account that created the resource :rtype: unicode
[ ":", "returns", ":", "The", "SID", "of", "the", "Account", "that", "created", "the", "resource", ":", "rtype", ":", "unicode" ]
def account_sid(self): """ :returns: The SID of the Account that created the resource :rtype: unicode """ return self._properties['account_sid']
[ "def", "account_sid", "(", "self", ")", ":", "return", "self", ".", "_properties", "[", "'account_sid'", "]" ]
https://github.com/twilio/twilio-python/blob/6e1e811ea57a1edfadd5161ace87397c563f6915/twilio/rest/api/v2010/account/conference/recording.py#L386-L391
laincloud/lain
0fe5f93d06540300c5dafb94d81b3b69d2c8f1da
playbooks/roles/collectd/files/plugins/lain/cluster_monitor.py
python
ClusterPlugin._get_cali_veth_stat
(self)
Check the status of all network interfaces. Value is 1 if any one of them is DOWN
Check the status of all network interfaces. Value is 1 if any one of them is DOWN
[ "Check", "the", "status", "of", "all", "network", "interfaces", ".", "Value", "is", "1", "if", "any", "one", "of", "them", "is", "DOWN" ]
def _get_cali_veth_stat(self): ''' Check the status of all network interfaces. Value is 1 if any one of them is DOWN ''' cali_veth_up = 0 cali_veth_down = 0 cali_veth_total = 0 tmp_veth_up = 0 tmp_veth_down = 0 tmp_veth_total = 0 for name, stat in psutil.net_if_stats().iteritems(): if name.startswith('cali'): cali_veth_total += 1 if stat.isup: cali_veth_up += 1 else: cali_veth_down += 1 elif name.startswith('tmp'): tmp_veth_total += 1 if stat.isup: tmp_veth_up += 1 else: tmp_veth_down += 1 self._result.append( GraphiteData("lain.cluster.calico.veth.cali.up", self._endpoint, cali_veth_up, self._step, "val")) self._result.append( GraphiteData("lain.cluster.calico.veth.cali.down", self._endpoint, cali_veth_down, self._step, "val")) self._result.append( GraphiteData("lain.cluster.calico.veth.cali.total", self._endpoint, cali_veth_total, self._step, "val")) self._result.append( GraphiteData("lain.cluster.calico.veth.tmp.up", self._endpoint, tmp_veth_up, self._step, "val")) self._result.append( GraphiteData("lain.cluster.calico.veth.tmp.down", self._endpoint, tmp_veth_down, self._step, "val")) self._result.append( GraphiteData("lain.cluster.calico.veth.tmp.total", self._endpoint, tmp_veth_total, self._step, "val"))
[ "def", "_get_cali_veth_stat", "(", "self", ")", ":", "cali_veth_up", "=", "0", "cali_veth_down", "=", "0", "cali_veth_total", "=", "0", "tmp_veth_up", "=", "0", "tmp_veth_down", "=", "0", "tmp_veth_total", "=", "0", "for", "name", ",", "stat", "in", "psutil"...
https://github.com/laincloud/lain/blob/0fe5f93d06540300c5dafb94d81b3b69d2c8f1da/playbooks/roles/collectd/files/plugins/lain/cluster_monitor.py#L39-L80
markovmodel/PyEMMA
e9d08d715dde17ceaa96480a9ab55d5e87d3a4b3
pyemma/coordinates/estimation/koopman.py
python
_KoopmanEstimator.weights
(self)
return _KoopmanWeights(u_input[0:-1], u_input[-1])
weights in the input basis (encapsulated in an object)
weights in the input basis (encapsulated in an object)
[ "weights", "in", "the", "input", "basis", "(", "encapsulated", "in", "an", "object", ")" ]
def weights(self): 'weights in the input basis (encapsulated in an object)' self._check_estimated() u_input = self.u return _KoopmanWeights(u_input[0:-1], u_input[-1])
[ "def", "weights", "(", "self", ")", ":", "self", ".", "_check_estimated", "(", ")", "u_input", "=", "self", ".", "u", "return", "_KoopmanWeights", "(", "u_input", "[", "0", ":", "-", "1", "]", ",", "u_input", "[", "-", "1", "]", ")" ]
https://github.com/markovmodel/PyEMMA/blob/e9d08d715dde17ceaa96480a9ab55d5e87d3a4b3/pyemma/coordinates/estimation/koopman.py#L129-L133
hungpham2511/toppra
766a2c736319639c7b0176959d2baa624ef74415
toppra/interpolator.py
python
UnivariateSplineInterpolator.eval
(self, ss_sam)
return np.array(data).T
Return the path position.
Return the path position.
[ "Return", "the", "path", "position", "." ]
def eval(self, ss_sam): """Return the path position.""" data = [] for spl in self.uspl: data.append(spl(ss_sam)) return np.array(data).T
[ "def", "eval", "(", "self", ",", "ss_sam", ")", ":", "data", "=", "[", "]", "for", "spl", "in", "self", ".", "uspl", ":", "data", ".", "append", "(", "spl", "(", "ss_sam", ")", ")", "return", "np", ".", "array", "(", "data", ")", ".", "T" ]
https://github.com/hungpham2511/toppra/blob/766a2c736319639c7b0176959d2baa624ef74415/toppra/interpolator.py#L554-L559
jgagneastro/coffeegrindsize
22661ebd21831dba4cf32bfc6ba59fe3d49f879c
App/venv/lib/python3.7/site-packages/pip/_vendor/ipaddress.py
python
IPv4Address.is_loopback
(self)
return self in self._constants._loopback_network
Test if the address is a loopback address. Returns: A boolean, True if the address is a loopback per RFC 3330.
Test if the address is a loopback address.
[ "Test", "if", "the", "address", "is", "a", "loopback", "address", "." ]
def is_loopback(self): """Test if the address is a loopback address. Returns: A boolean, True if the address is a loopback per RFC 3330. """ return self in self._constants._loopback_network
[ "def", "is_loopback", "(", "self", ")", ":", "return", "self", "in", "self", ".", "_constants", ".", "_loopback_network" ]
https://github.com/jgagneastro/coffeegrindsize/blob/22661ebd21831dba4cf32bfc6ba59fe3d49f879c/App/venv/lib/python3.7/site-packages/pip/_vendor/ipaddress.py#L1459-L1466
dwadden/dygiepp
8faac5711489d4f5fb1189f8344c8ffb5548d2cb
scripts/data/genia/merge_coref.py
python
Corefs._assign_parent_indices
(corefs, coref_ids)
return corefs
Give each coref the index of it parent in the list of corefs.
Give each coref the index of it parent in the list of corefs.
[ "Give", "each", "coref", "the", "index", "of", "it", "parent", "in", "the", "list", "of", "corefs", "." ]
def _assign_parent_indices(corefs, coref_ids): """Give each coref the index of it parent in the list of corefs.""" for coref in corefs: if coref.ref is None: coref.parent_ix = None else: coref.parent_ix = coref_ids.index(coref.ref) return corefs
[ "def", "_assign_parent_indices", "(", "corefs", ",", "coref_ids", ")", ":", "for", "coref", "in", "corefs", ":", "if", "coref", ".", "ref", "is", "None", ":", "coref", ".", "parent_ix", "=", "None", "else", ":", "coref", ".", "parent_ix", "=", "coref_ids...
https://github.com/dwadden/dygiepp/blob/8faac5711489d4f5fb1189f8344c8ffb5548d2cb/scripts/data/genia/merge_coref.py#L128-L135
yaksok/yaksok
73f14863d04f054eef2926f25a091f72f60352a5
yaksok/yacc.py
python
p_atom_paren
(t)
atom : LPAR expression RPAR | LPAR call RPAR | LPAR import_call RPAR
atom : LPAR expression RPAR | LPAR call RPAR | LPAR import_call RPAR
[ "atom", ":", "LPAR", "expression", "RPAR", "|", "LPAR", "call", "RPAR", "|", "LPAR", "import_call", "RPAR" ]
def p_atom_paren(t): '''atom : LPAR expression RPAR | LPAR call RPAR | LPAR import_call RPAR''' t[0] = t[2]
[ "def", "p_atom_paren", "(", "t", ")", ":", "t", "[", "0", "]", "=", "t", "[", "2", "]" ]
https://github.com/yaksok/yaksok/blob/73f14863d04f054eef2926f25a091f72f60352a5/yaksok/yacc.py#L739-L743
zsdlove/Hades
f3d8c43a40ccd7a1bca2a855d8cccc110c34448a
cfg/graphs.py
python
GraphManager.add_block_edge
(self, b1, b2, label="CONT")
join two pydot nodes / create nodes edge
join two pydot nodes / create nodes edge
[ "join", "two", "pydot", "nodes", "/", "create", "nodes", "edge" ]
def add_block_edge(self, b1, b2, label="CONT"): """ join two pydot nodes / create nodes edge """ # Edge color based on label text if label=='false': ecolor = "red" elif label=='true': ecolor = 'green' elif label == 'exception': ecolor = 'orange' elif label == 'try': ecolor = 'blue' else: ecolor = 'gray' # node shape based on block type (First or Last instruction) nodes = [None, None] blocks = [b1,b2] for i in range(2): if re.search("^if-", blocks[i].instructiones[-1]) != None: ncolor = "cornflowerblue" elif re.search("^\:" , blocks[i].instructiones[0]) != None: ncolor = "tan" elif re.search("^goto", blocks[i].instructiones[-1]) != None: ncolor = "darkgreen" elif re.search("^invoke-", blocks[i].instructiones[-1]) != None: ncolor = "lightyellow4" else: ncolor = "mediumaquamarine" insTxt = "%s\r" % blocks[i].etiqueta lidx = int(blocks[i].etiqueta.split(' ')[-1]) for ii in blocks[i].instructiones: insTxt += str(lidx) + ": " + ii lidx+=1 nodes[i] = pydot.Node(b1.etiqueta, color=ncolor, style="filled", shape="box", fontname="Courier", fontsize=8) nodes[i].set_name(insTxt)#函数引用+指令 self.graph.add_node(nodes[i]) ed = pydot.Edge(nodes[0], nodes[1], color=ecolor, label=label, fontname="Courier", fontsize=8, arrowhead="open") self.graph.add_edge(ed)
[ "def", "add_block_edge", "(", "self", ",", "b1", ",", "b2", ",", "label", "=", "\"CONT\"", ")", ":", "# Edge color based on label text", "if", "label", "==", "'false'", ":", "ecolor", "=", "\"red\"", "elif", "label", "==", "'true'", ":", "ecolor", "=", "'g...
https://github.com/zsdlove/Hades/blob/f3d8c43a40ccd7a1bca2a855d8cccc110c34448a/cfg/graphs.py#L31-L70
NeuralEnsemble/python-neo
34d4db8fb0dc950dbbc6defd7fb75e99ea877286
neo/io/nwbio.py
python
EventProxy.load
(self, time_slice=None, strict_slicing=True)
return Event(times * pq.s, labels=labels, name=self.name, description=self.description, **self.annotations)
Load EventProxy args: :param time_slice: None or tuple of the time slice expressed with quantities. None is the entire signal. :param strict_slicing: True by default. Control if an error is raised or not when one of the time_slice members (t_start or t_stop) is outside the real time range of the segment.
Load EventProxy args: :param time_slice: None or tuple of the time slice expressed with quantities. None is the entire signal. :param strict_slicing: True by default. Control if an error is raised or not when one of the time_slice members (t_start or t_stop) is outside the real time range of the segment.
[ "Load", "EventProxy", "args", ":", ":", "param", "time_slice", ":", "None", "or", "tuple", "of", "the", "time", "slice", "expressed", "with", "quantities", ".", "None", "is", "the", "entire", "signal", ".", ":", "param", "strict_slicing", ":", "True", "by"...
def load(self, time_slice=None, strict_slicing=True): """ Load EventProxy args: :param time_slice: None or tuple of the time slice expressed with quantities. None is the entire signal. :param strict_slicing: True by default. Control if an error is raised or not when one of the time_slice members (t_start or t_stop) is outside the real time range of the segment. """ if time_slice: raise NotImplementedError("todo") else: times = self._timeseries.timestamps[:] labels = self._timeseries.data[:] return Event(times * pq.s, labels=labels, name=self.name, description=self.description, **self.annotations)
[ "def", "load", "(", "self", ",", "time_slice", "=", "None", ",", "strict_slicing", "=", "True", ")", ":", "if", "time_slice", ":", "raise", "NotImplementedError", "(", "\"todo\"", ")", "else", ":", "times", "=", "self", ".", "_timeseries", ".", "timestamps...
https://github.com/NeuralEnsemble/python-neo/blob/34d4db8fb0dc950dbbc6defd7fb75e99ea877286/neo/io/nwbio.py#L746-L764
ckan/ckan
b3b01218ad88ed3fb914b51018abe8b07b07bff3
ckanext/datastore/backend/postgres.py
python
DatastorePostgresqlBackend._is_postgresql_engine
(self)
return drivername.startswith('postgres')
Returns True if the read engine is a Postgresql Database. According to http://docs.sqlalchemy.org/en/latest/core/engines.html#postgresql all Postgres driver names start with `postgres`.
Returns True if the read engine is a Postgresql Database.
[ "Returns", "True", "if", "the", "read", "engine", "is", "a", "Postgresql", "Database", "." ]
def _is_postgresql_engine(self): ''' Returns True if the read engine is a Postgresql Database. According to http://docs.sqlalchemy.org/en/latest/core/engines.html#postgresql all Postgres driver names start with `postgres`. ''' drivername = self._get_read_engine().engine.url.drivername return drivername.startswith('postgres')
[ "def", "_is_postgresql_engine", "(", "self", ")", ":", "drivername", "=", "self", ".", "_get_read_engine", "(", ")", ".", "engine", ".", "url", ".", "drivername", "return", "drivername", ".", "startswith", "(", "'postgres'", ")" ]
https://github.com/ckan/ckan/blob/b3b01218ad88ed3fb914b51018abe8b07b07bff3/ckanext/datastore/backend/postgres.py#L1719-L1727
sahana/eden
1696fa50e90ce967df69f66b571af45356cc18da
modules/s3/s3aaa.py
python
AuthS3.s3_link_to_human_resource
(self, user, person_id, hr_type, )
return hr_id
Link the user to a human resource record and make them owner Args: user: the user record person_id: the person ID linked to that user hr_type: the human resource type (staff/volunteer)
Link the user to a human resource record and make them owner
[ "Link", "the", "user", "to", "a", "human", "resource", "record", "and", "make", "them", "owner" ]
def s3_link_to_human_resource(self, user, person_id, hr_type, ): """ Link the user to a human resource record and make them owner Args: user: the user record person_id: the person ID linked to that user hr_type: the human resource type (staff/volunteer) """ db = current.db s3db = current.s3db settings = current.deployment_settings user_id = user.id organisation_id = user.organisation_id htablename = "hrm_human_resource" htable = s3db.table(htablename) if not htable or (not organisation_id and \ settings.get_hrm_org_required()): # Module disabled or no user organisation set return None def customise(hr_id): """ Customise hrm_human_resource """ customise = settings.customise_resource(htablename) if customise: request = S3Request("hrm", "human_resource", current.request, args = [str(hr_id)] if hr_id else [], ) customise(request, htablename) # Determine the site ID site_id = user.site_id if hr_type == 1 else None # Get existing active HR record for this user ptable = s3db.pr_person ltable = s3db.pr_person_user query = (ltable.user_id == user_id) & \ (ptable.pe_id == ltable.pe_id) & \ (htable.person_id == ptable.id) & \ (htable.type == hr_type) & \ (htable.status == 1) & \ (htable.deleted == False) rows = db(query).select(htable.id, limitby = (0, 2), ) accepted = None if len(rows) == 1: # Single active HR record of this type # => update organisation and site record = rows.first() hr_id = record.id # Update the record customise(hr_id) db(htable.id == hr_id).update(organisation_id = organisation_id, site_id = site_id, ) accepted = "update" # Update or create site link hstable = s3db.hrm_human_resource_site query = (hstable.human_resource_id == hr_id) hstable.update_or_insert(query, site_id = site_id, human_resource_id = hr_id, owned_by_user = user_id, ) else: # Multiple or no HR records of this type if rows: # Multiple records # => check if there is one for this organisation and site if type(person_id) is list: person_id = person_id[0] query = (htable.person_id == person_id) & \ (htable.organisation_id == organisation_id) & \ (htable.type == hr_type) & \ (htable.site_id == site_id) & \ (htable.deleted == False) row = db(query).select(htable.id, limitby = (0, 1), ).first() else: # No HR record exists at all row = None if row: # At least one record for this organisation and site exists # => pass hr_id = row.id else: # Create new HR record customise(hr_id = None) record = Storage(person_id = person_id, organisation_id = organisation_id, site_id = site_id, type = hr_type, owned_by_user = user_id, ) hr_id = htable.insert(**record) record["id"] = hr_id accepted = "create" if hr_id and accepted: # Update any super-records s3db.update_super(htable, record) # Set or update the record owner and realm entity # (enforce update to change realm if organisation changed) self.s3_set_record_owner(htable, hr_id, force_update=True) # Run onaccept s3db.onaccept(htablename, record, method=accepted) return hr_id
[ "def", "s3_link_to_human_resource", "(", "self", ",", "user", ",", "person_id", ",", "hr_type", ",", ")", ":", "db", "=", "current", ".", "db", "s3db", "=", "current", ".", "s3db", "settings", "=", "current", ".", "deployment_settings", "user_id", "=", "us...
https://github.com/sahana/eden/blob/1696fa50e90ce967df69f66b571af45356cc18da/modules/s3/s3aaa.py#L3393-L3520
scrtlabs/catalyst
2e8029780f2381da7a0729f7b52505e5db5f535b
catalyst/utils/numpy_utils.py
python
repeat_first_axis
(array, count)
return as_strided(array, (count,) + array.shape, (0,) + array.strides)
Restride `array` to repeat `count` times along the first axis. Parameters ---------- array : np.array The array to restride. count : int Number of times to repeat `array`. Returns ------- result : array Array of shape (count,) + array.shape, composed of `array` repeated `count` times along the first axis. Example ------- >>> from numpy import arange >>> a = arange(3); a array([0, 1, 2]) >>> repeat_first_axis(a, 2) array([[0, 1, 2], [0, 1, 2]]) >>> repeat_first_axis(a, 4) array([[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]) Notes ---- The resulting array will share memory with `array`. If you need to assign to the input or output, you should probably make a copy first. See Also -------- repeat_last_axis
Restride `array` to repeat `count` times along the first axis.
[ "Restride", "array", "to", "repeat", "count", "times", "along", "the", "first", "axis", "." ]
def repeat_first_axis(array, count): """ Restride `array` to repeat `count` times along the first axis. Parameters ---------- array : np.array The array to restride. count : int Number of times to repeat `array`. Returns ------- result : array Array of shape (count,) + array.shape, composed of `array` repeated `count` times along the first axis. Example ------- >>> from numpy import arange >>> a = arange(3); a array([0, 1, 2]) >>> repeat_first_axis(a, 2) array([[0, 1, 2], [0, 1, 2]]) >>> repeat_first_axis(a, 4) array([[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]) Notes ---- The resulting array will share memory with `array`. If you need to assign to the input or output, you should probably make a copy first. See Also -------- repeat_last_axis """ return as_strided(array, (count,) + array.shape, (0,) + array.strides)
[ "def", "repeat_first_axis", "(", "array", ",", "count", ")", ":", "return", "as_strided", "(", "array", ",", "(", "count", ",", ")", "+", "array", ".", "shape", ",", "(", "0", ",", ")", "+", "array", ".", "strides", ")" ]
https://github.com/scrtlabs/catalyst/blob/2e8029780f2381da7a0729f7b52505e5db5f535b/catalyst/utils/numpy_utils.py#L167-L207
aiven/pghoard
1de0d2e33bf087b7ce3b6af556bbf941acfac3a4
pghoard/webserver.py
python
RequestHandler.get_wal_or_timeline_file
(self, site, filename, filetype)
[]
def get_wal_or_timeline_file(self, site, filename, filetype): target_path = self.headers.get("x-pghoard-target-path") if not target_path: raise HttpResponse("x-pghoard-target-path header missing from download", status=400) self._process_completed_download_operations() # See if we have already prefetched the file site_config = self.server.config["backup_sites"][site] xlog_dir = get_pg_wal_directory(site_config) prefetch_target_path = os.path.join(xlog_dir, "{}.pghoard.prefetch".format(filename)) if os.path.exists(prefetch_target_path): ex = self._try_save_and_verify_restored_file(filetype, filename, prefetch_target_path, target_path) if not ex: self._create_prefetch_operations(site, filetype, filename) self.server.most_recently_served_files[filetype] = { "name": filename, "time": time.time(), } raise HttpResponse(status=201) # After reaching a recovery_target and restart of a PG server, PG wants to replay and refetch # files from the archive starting from the latest checkpoint. We have potentially fetched these files # already earlier. Check if we have the files already and if we do, don't go over the network to refetch # them yet again but just rename them to the path that PG is requesting. xlog_path = os.path.join(xlog_dir, filename) exists_on_disk = os.path.exists(xlog_path) if exists_on_disk and filename not in self.server.served_from_disk: self.server.log.info( "Requested %r, found it in pg_xlog directory as: %r, returning directly", filename, xlog_path ) ex = self._try_save_and_verify_restored_file(filetype, filename, xlog_path, target_path, unlink=False) if ex: self.server.log.warning("Found file: %r but it was invalid: %s", xlog_path, ex) else: self.server.served_from_disk.append(filename) self.server.most_recently_served_files[filetype] = { "name": filename, "time": time.time(), } raise HttpResponse(status=201) elif exists_on_disk: self.server.log.info("Found file %r but it was recently already served from disk, fetching remote", xlog_path) key = self._make_file_key(site, filetype, filename) with suppress(ValueError): self.server.prefetch_404.remove(key) self._create_fetch_operation(key, site, filetype, filename, max_age=5, suppress_error=False) self._create_prefetch_operations(site, filetype, filename) last_schedule_call = time.monotonic() start_time = time.monotonic() retries = 2 while (time.monotonic() - start_time) <= 30: self._process_completed_download_operations(timeout=0.01) with self.server.lock: if os.path.isfile(prefetch_target_path): ex = self._try_save_and_verify_restored_file(filetype, filename, prefetch_target_path, target_path) if not ex: self.server.most_recently_served_files[filetype] = { "name": filename, "time": time.time(), } raise HttpResponse(status=201) elif ex and retries == 0: raise ex # pylint: disable=raising-bad-type retries -= 1 if key in self.server.prefetch_404: raise HttpResponse(status=404) with self.server.lock: if key not in self.server.pending_download_ops: if retries == 0: raise HttpResponse(status=500) retries -= 1 self._create_fetch_operation(key, site, filetype, filename, suppress_error=False) if time.monotonic() - last_schedule_call >= 1: last_schedule_call = time.monotonic() # Replace existing download operation if it has been executing for too long self._create_fetch_operation(key, site, filetype, filename, max_age=10, suppress_error=False) raise HttpResponse("TIMEOUT", status=500)
[ "def", "get_wal_or_timeline_file", "(", "self", ",", "site", ",", "filename", ",", "filetype", ")", ":", "target_path", "=", "self", ".", "headers", ".", "get", "(", "\"x-pghoard-target-path\"", ")", "if", "not", "target_path", ":", "raise", "HttpResponse", "(...
https://github.com/aiven/pghoard/blob/1de0d2e33bf087b7ce3b6af556bbf941acfac3a4/pghoard/webserver.py#L412-L492
PrefectHQ/prefect
67bdc94e2211726d99561f6f52614bec8970e981
src/prefect/client/client.py
python
Client.get_available_tenants
(self)
return result.data.tenant
Returns a list of available tenants. NOTE: this should only be called by users who have provided a USER-scoped API token. Returns: - List[Dict]: a list of dictionaries containing the id, slug, and name of available tenants
Returns a list of available tenants.
[ "Returns", "a", "list", "of", "available", "tenants", "." ]
def get_available_tenants(self) -> List[Dict]: """ Returns a list of available tenants. NOTE: this should only be called by users who have provided a USER-scoped API token. Returns: - List[Dict]: a list of dictionaries containing the id, slug, and name of available tenants """ result = self.graphql( {"query": {"tenant(order_by: {slug: asc})": {"id", "slug", "name"}}}, # API keys can see all available tenants. If not using an API key, we can't # use the access token which is scoped to a single tenant token=self.api_key or self._api_token, ) return result.data.tenant
[ "def", "get_available_tenants", "(", "self", ")", "->", "List", "[", "Dict", "]", ":", "result", "=", "self", ".", "graphql", "(", "{", "\"query\"", ":", "{", "\"tenant(order_by: {slug: asc})\"", ":", "{", "\"id\"", ",", "\"slug\"", ",", "\"name\"", "}", "...
https://github.com/PrefectHQ/prefect/blob/67bdc94e2211726d99561f6f52614bec8970e981/src/prefect/client/client.py#L874-L890
naftaliharris/tauthon
5587ceec329b75f7caf6d65a036db61ac1bae214
Lib/pickletools.py
python
read_unicodestring4
(f)
r""" >>> import StringIO >>> s = u'abcd\uabcd' >>> enc = s.encode('utf-8') >>> enc 'abcd\xea\xaf\x8d' >>> n = chr(len(enc)) + chr(0) * 3 # little-endian 4-byte length >>> t = read_unicodestring4(StringIO.StringIO(n + enc + 'junk')) >>> s == t True >>> read_unicodestring4(StringIO.StringIO(n + enc[:-1])) Traceback (most recent call last): ... ValueError: expected 7 bytes in a unicodestring4, but only 6 remain
r""" >>> import StringIO >>> s = u'abcd\uabcd' >>> enc = s.encode('utf-8') >>> enc 'abcd\xea\xaf\x8d' >>> n = chr(len(enc)) + chr(0) * 3 # little-endian 4-byte length >>> t = read_unicodestring4(StringIO.StringIO(n + enc + 'junk')) >>> s == t True
[ "r", ">>>", "import", "StringIO", ">>>", "s", "=", "u", "abcd", "\\", "uabcd", ">>>", "enc", "=", "s", ".", "encode", "(", "utf", "-", "8", ")", ">>>", "enc", "abcd", "\\", "xea", "\\", "xaf", "\\", "x8d", ">>>", "n", "=", "chr", "(", "len", ...
def read_unicodestring4(f): r""" >>> import StringIO >>> s = u'abcd\uabcd' >>> enc = s.encode('utf-8') >>> enc 'abcd\xea\xaf\x8d' >>> n = chr(len(enc)) + chr(0) * 3 # little-endian 4-byte length >>> t = read_unicodestring4(StringIO.StringIO(n + enc + 'junk')) >>> s == t True >>> read_unicodestring4(StringIO.StringIO(n + enc[:-1])) Traceback (most recent call last): ... ValueError: expected 7 bytes in a unicodestring4, but only 6 remain """ n = read_int4(f) if n < 0: raise ValueError("unicodestring4 byte count < 0: %d" % n) data = f.read(n) if len(data) == n: return unicode(data, 'utf-8') raise ValueError("expected %d bytes in a unicodestring4, but only %d " "remain" % (n, len(data)))
[ "def", "read_unicodestring4", "(", "f", ")", ":", "n", "=", "read_int4", "(", "f", ")", "if", "n", "<", "0", ":", "raise", "ValueError", "(", "\"unicodestring4 byte count < 0: %d\"", "%", "n", ")", "data", "=", "f", ".", "read", "(", "n", ")", "if", ...
https://github.com/naftaliharris/tauthon/blob/5587ceec329b75f7caf6d65a036db61ac1bae214/Lib/pickletools.py#L445-L470
ring04h/wyportmap
c4201e2313504e780a7f25238eba2a2d3223e739
sqlalchemy/sql/elements.py
python
ColumnElement.anon_label
(self)
return _anonymous_label( '%%(%d %s)s' % (id(self), getattr(self, 'name', 'anon')) )
provides a constant 'anonymous label' for this ColumnElement. This is a label() expression which will be named at compile time. The same label() is returned each time anon_label is called so that expressions can reference anon_label multiple times, producing the same label name at compile time. the compiler uses this function automatically at compile time for expressions that are known to be 'unnamed' like binary expressions and function calls.
provides a constant 'anonymous label' for this ColumnElement.
[ "provides", "a", "constant", "anonymous", "label", "for", "this", "ColumnElement", "." ]
def anon_label(self): """provides a constant 'anonymous label' for this ColumnElement. This is a label() expression which will be named at compile time. The same label() is returned each time anon_label is called so that expressions can reference anon_label multiple times, producing the same label name at compile time. the compiler uses this function automatically at compile time for expressions that are known to be 'unnamed' like binary expressions and function calls. """ return _anonymous_label( '%%(%d %s)s' % (id(self), getattr(self, 'name', 'anon')) )
[ "def", "anon_label", "(", "self", ")", ":", "return", "_anonymous_label", "(", "'%%(%d %s)s'", "%", "(", "id", "(", "self", ")", ",", "getattr", "(", "self", ",", "'name'", ",", "'anon'", ")", ")", ")" ]
https://github.com/ring04h/wyportmap/blob/c4201e2313504e780a7f25238eba2a2d3223e739/sqlalchemy/sql/elements.py#L785-L800
spesmilo/electrum
bdbd59300fbd35b01605e66145458e5f396108e8
electrum/wallet_db.py
python
WalletDB._convert_version_37
(self)
[]
def _convert_version_37(self): if not self._is_upgrade_method_needed(36, 36): return payments = self.data.get('lightning_payments', {}) for k, v in list(payments.items()): amount_sat, direction, status = v amount_msat = amount_sat * 1000 if amount_sat is not None else None payments[k] = amount_msat, direction, status self.data['lightning_payments'] = payments self.data['seed_version'] = 37
[ "def", "_convert_version_37", "(", "self", ")", ":", "if", "not", "self", ".", "_is_upgrade_method_needed", "(", "36", ",", "36", ")", ":", "return", "payments", "=", "self", ".", "data", ".", "get", "(", "'lightning_payments'", ",", "{", "}", ")", "for"...
https://github.com/spesmilo/electrum/blob/bdbd59300fbd35b01605e66145458e5f396108e8/electrum/wallet_db.py#L752-L761
ctxis/canape
5f0e03424577296bcc60c2008a60a98ec5307e4b
CANAPE.Scripting/Lib/decimal.py
python
_format_align
(sign, body, spec)
return result
Given an unpadded, non-aligned numeric string 'body' and sign string 'sign', add padding and alignment conforming to the given format specifier dictionary 'spec' (as produced by parse_format_specifier). Also converts result to unicode if necessary.
Given an unpadded, non-aligned numeric string 'body' and sign string 'sign', add padding and alignment conforming to the given format specifier dictionary 'spec' (as produced by parse_format_specifier).
[ "Given", "an", "unpadded", "non", "-", "aligned", "numeric", "string", "body", "and", "sign", "string", "sign", "add", "padding", "and", "alignment", "conforming", "to", "the", "given", "format", "specifier", "dictionary", "spec", "(", "as", "produced", "by", ...
def _format_align(sign, body, spec): """Given an unpadded, non-aligned numeric string 'body' and sign string 'sign', add padding and alignment conforming to the given format specifier dictionary 'spec' (as produced by parse_format_specifier). Also converts result to unicode if necessary. """ # how much extra space do we have to play with? minimumwidth = spec['minimumwidth'] fill = spec['fill'] padding = fill*(minimumwidth - len(sign) - len(body)) align = spec['align'] if align == '<': result = sign + body + padding elif align == '>': result = padding + sign + body elif align == '=': result = sign + padding + body elif align == '^': half = len(padding)//2 result = padding[:half] + sign + body + padding[half:] else: raise ValueError('Unrecognised alignment field') # make sure that result is unicode if necessary if spec['unicode']: result = unicode(result) return result
[ "def", "_format_align", "(", "sign", ",", "body", ",", "spec", ")", ":", "# how much extra space do we have to play with?", "minimumwidth", "=", "spec", "[", "'minimumwidth'", "]", "fill", "=", "spec", "[", "'fill'", "]", "padding", "=", "fill", "*", "(", "min...
https://github.com/ctxis/canape/blob/5f0e03424577296bcc60c2008a60a98ec5307e4b/CANAPE.Scripting/Lib/decimal.py#L6003-L6034
tensorflow/tfx
b4a6b83269815ed12ba9df9e9154c7376fef2ea0
tfx/examples/penguin/penguin_utils_cloud_tuner.py
python
_input_fn
(file_pattern: List[str], data_accessor: tfx.components.DataAccessor, tf_transform_output: tft.TFTransformOutput, batch_size: int = 200)
return data_accessor.tf_dataset_factory( file_pattern, tfxio.TensorFlowDatasetOptions( batch_size=batch_size, label_key=_transformed_name(_LABEL_KEY)), tf_transform_output.transformed_metadata.schema).repeat()
Generates features and label for tuning/training. Args: file_pattern: List of paths or patterns of input tfrecord files. data_accessor: DataAccessor for converting input to RecordBatch. tf_transform_output: A `TFTransformOutput` object, containing statistics and metadata from TFTransform component. batch_size: representing the number of consecutive elements of returned dataset to combine in a single batch Returns: A dataset that contains (features, indices) tuple where features is a dictionary of Tensors, and indices is a single Tensor of label indices.
Generates features and label for tuning/training.
[ "Generates", "features", "and", "label", "for", "tuning", "/", "training", "." ]
def _input_fn(file_pattern: List[str], data_accessor: tfx.components.DataAccessor, tf_transform_output: tft.TFTransformOutput, batch_size: int = 200) -> tf.data.Dataset: """Generates features and label for tuning/training. Args: file_pattern: List of paths or patterns of input tfrecord files. data_accessor: DataAccessor for converting input to RecordBatch. tf_transform_output: A `TFTransformOutput` object, containing statistics and metadata from TFTransform component. batch_size: representing the number of consecutive elements of returned dataset to combine in a single batch Returns: A dataset that contains (features, indices) tuple where features is a dictionary of Tensors, and indices is a single Tensor of label indices. """ return data_accessor.tf_dataset_factory( file_pattern, tfxio.TensorFlowDatasetOptions( batch_size=batch_size, label_key=_transformed_name(_LABEL_KEY)), tf_transform_output.transformed_metadata.schema).repeat()
[ "def", "_input_fn", "(", "file_pattern", ":", "List", "[", "str", "]", ",", "data_accessor", ":", "tfx", ".", "components", ".", "DataAccessor", ",", "tf_transform_output", ":", "tft", ".", "TFTransformOutput", ",", "batch_size", ":", "int", "=", "200", ")",...
https://github.com/tensorflow/tfx/blob/b4a6b83269815ed12ba9df9e9154c7376fef2ea0/tfx/examples/penguin/penguin_utils_cloud_tuner.py#L112-L134
radiac/django-tagulous
90c6ee5ac54ef1127f2edcfac10c5ef3ab09e255
tagulous/models/models.py
python
BaseTagModel.__eq__
(self, obj)
return super(BaseTagModel, self).__eq__(obj)
If comparing to a string, is equal if string value matches Otherwise compares normally
If comparing to a string, is equal if string value matches Otherwise compares normally
[ "If", "comparing", "to", "a", "string", "is", "equal", "if", "string", "value", "matches", "Otherwise", "compares", "normally" ]
def __eq__(self, obj): """ If comparing to a string, is equal if string value matches Otherwise compares normally """ if isinstance(obj, str): return self.name == obj return super(BaseTagModel, self).__eq__(obj)
[ "def", "__eq__", "(", "self", ",", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "str", ")", ":", "return", "self", ".", "name", "==", "obj", "return", "super", "(", "BaseTagModel", ",", "self", ")", ".", "__eq__", "(", "obj", ")" ]
https://github.com/radiac/django-tagulous/blob/90c6ee5ac54ef1127f2edcfac10c5ef3ab09e255/tagulous/models/models.py#L147-L154
karanchahal/distiller
a17ec06cbeafcdd2aea19d7c7663033c951392f5
models/vision/densenet.py
python
densenet161
(pretrained=False, progress=True, **kwargs)
return _densenet('densenet161', 48, (6, 12, 36, 24), 96, pretrained, progress, **kwargs)
r"""Densenet-161 model from `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_ Args: pretrained (bool): If True, returns a model pre-trained on ImageNet progress (bool): If True, displays a progress bar of the download to stderr memory_efficient (bool) - If True, uses checkpointing. Much more memory efficient, but slower. Default: *False*. See `"paper" <https://arxiv.org/pdf/1707.06990.pdf>`_
r"""Densenet-161 model from `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_
[ "r", "Densenet", "-", "161", "model", "from", "Densely", "Connected", "Convolutional", "Networks", "<https", ":", "//", "arxiv", ".", "org", "/", "pdf", "/", "1608", ".", "06993", ".", "pdf", ">", "_" ]
def densenet161(pretrained=False, progress=True, **kwargs): r"""Densenet-161 model from `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_ Args: pretrained (bool): If True, returns a model pre-trained on ImageNet progress (bool): If True, displays a progress bar of the download to stderr memory_efficient (bool) - If True, uses checkpointing. Much more memory efficient, but slower. Default: *False*. See `"paper" <https://arxiv.org/pdf/1707.06990.pdf>`_ """ return _densenet('densenet161', 48, (6, 12, 36, 24), 96, pretrained, progress, **kwargs)
[ "def", "densenet161", "(", "pretrained", "=", "False", ",", "progress", "=", "True", ",", "*", "*", "kwargs", ")", ":", "return", "_densenet", "(", "'densenet161'", ",", "48", ",", "(", "6", ",", "12", ",", "36", ",", "24", ")", ",", "96", ",", "...
https://github.com/karanchahal/distiller/blob/a17ec06cbeafcdd2aea19d7c7663033c951392f5/models/vision/densenet.py#L243-L254
unknown-horizons/unknown-horizons
7397fb333006d26c3d9fe796c7bd9cb8c3b43a49
horizons/util/checkupdates.py
python
is_system_installed
(uh_path: Optional[PurePath] = None)
Returns whether UH is likely to have been installed with the systems package manager. In typical usage, you don't need to pass any parameters.
Returns whether UH is likely to have been installed with the systems package manager.
[ "Returns", "whether", "UH", "is", "likely", "to", "have", "been", "installed", "with", "the", "systems", "package", "manager", "." ]
def is_system_installed(uh_path: Optional[PurePath] = None) -> bool: """ Returns whether UH is likely to have been installed with the systems package manager. In typical usage, you don't need to pass any parameters. """ if uh_path is None: uh_path = PurePath(os.path.abspath(__file__)) home_directory = get_home_directory() try: uh_path.relative_to(home_directory) return False except ValueError: return True
[ "def", "is_system_installed", "(", "uh_path", ":", "Optional", "[", "PurePath", "]", "=", "None", ")", "->", "bool", ":", "if", "uh_path", "is", "None", ":", "uh_path", "=", "PurePath", "(", "os", ".", "path", ".", "abspath", "(", "__file__", ")", ")",...
https://github.com/unknown-horizons/unknown-horizons/blob/7397fb333006d26c3d9fe796c7bd9cb8c3b43a49/horizons/util/checkupdates.py#L45-L59
cuthbertLab/music21
bd30d4663e52955ed922c10fdf541419d8c67671
music21/analysis/windowed.py
python
TestMockProcessor.process
(self, subStream)
return len(subStream.flatten().notesAndRests), None
Simply count the number of notes found
Simply count the number of notes found
[ "Simply", "count", "the", "number", "of", "notes", "found" ]
def process(self, subStream): '''Simply count the number of notes found ''' return len(subStream.flatten().notesAndRests), None
[ "def", "process", "(", "self", ",", "subStream", ")", ":", "return", "len", "(", "subStream", ".", "flatten", "(", ")", ".", "notesAndRests", ")", ",", "None" ]
https://github.com/cuthbertLab/music21/blob/bd30d4663e52955ed922c10fdf541419d8c67671/music21/analysis/windowed.py#L358-L361
mme/vergeml
3dc30ba4e0f3d038743b6d468860cbcf3681acc6
vergeml/results.py
python
Results._sync
(self, force=False)
[]
def _sync(self, force=False): now = datetime.datetime.now() if force or (now - self.last_sync).total_seconds() > _SYNC_INTV: self.last_sync = now with open(self.path, "w") as f: json.dump(self.data, f)
[ "def", "_sync", "(", "self", ",", "force", "=", "False", ")", ":", "now", "=", "datetime", ".", "datetime", ".", "now", "(", ")", "if", "force", "or", "(", "now", "-", "self", ".", "last_sync", ")", ".", "total_seconds", "(", ")", ">", "_SYNC_INTV"...
https://github.com/mme/vergeml/blob/3dc30ba4e0f3d038743b6d468860cbcf3681acc6/vergeml/results.py#L27-L32
linxid/Machine_Learning_Study_Path
558e82d13237114bbb8152483977806fc0c222af
Machine Learning In Action/Chapter5-LogisticRegression/venv/Lib/site-packages/setuptools/command/bdist_egg.py
python
walk_egg
(egg_dir)
Walk an unpacked egg's contents, skipping the metadata directory
Walk an unpacked egg's contents, skipping the metadata directory
[ "Walk", "an", "unpacked", "egg", "s", "contents", "skipping", "the", "metadata", "directory" ]
def walk_egg(egg_dir): """Walk an unpacked egg's contents, skipping the metadata directory""" walker = sorted_walk(egg_dir) base, dirs, files = next(walker) if 'EGG-INFO' in dirs: dirs.remove('EGG-INFO') yield base, dirs, files for bdf in walker: yield bdf
[ "def", "walk_egg", "(", "egg_dir", ")", ":", "walker", "=", "sorted_walk", "(", "egg_dir", ")", "base", ",", "dirs", ",", "files", "=", "next", "(", "walker", ")", "if", "'EGG-INFO'", "in", "dirs", ":", "dirs", ".", "remove", "(", "'EGG-INFO'", ")", ...
https://github.com/linxid/Machine_Learning_Study_Path/blob/558e82d13237114bbb8152483977806fc0c222af/Machine Learning In Action/Chapter5-LogisticRegression/venv/Lib/site-packages/setuptools/command/bdist_egg.py#L358-L366
onaio/onadata
89ad16744e8f247fb748219476f6ac295869a95f
onadata/apps/viewer/xls_writer.py
python
XlsWriter.save_workbook_to_file
(self)
return self._file
[]
def save_workbook_to_file(self): self._workbook.save(self._file) return self._file
[ "def", "save_workbook_to_file", "(", "self", ")", ":", "self", ".", "_workbook", ".", "save", "(", "self", ".", "_file", ")", "return", "self", ".", "_file" ]
https://github.com/onaio/onadata/blob/89ad16744e8f247fb748219476f6ac295869a95f/onadata/apps/viewer/xls_writer.py#L90-L92
huawei-noah/vega
d9f13deede7f2b584e4b1d32ffdb833856129989
vega/datasets/tensorflow/adapter.py
python
TfAdapter.loader
(self)
return self
Dataloader arrtribute which is a unified interface to generate the data. :return: a batch data :rtype: dict, list, optional
Dataloader arrtribute which is a unified interface to generate the data.
[ "Dataloader", "arrtribute", "which", "is", "a", "unified", "interface", "to", "generate", "the", "data", "." ]
def loader(self): """Dataloader arrtribute which is a unified interface to generate the data. :return: a batch data :rtype: dict, list, optional """ return self
[ "def", "loader", "(", "self", ")", ":", "return", "self" ]
https://github.com/huawei-noah/vega/blob/d9f13deede7f2b584e4b1d32ffdb833856129989/vega/datasets/tensorflow/adapter.py#L230-L236
dipy/dipy
be956a529465b28085f8fc435a756947ddee1c89
dipy/reconst/fwdti.py
python
nls_iter
(design_matrix, sig, S0, Diso=3e-3, mdreg=2.7e-3, min_signal=1.0e-6, cholesky=False, f_transform=True, jac=False, weighting=None, sigma=None)
return params
Applies non linear least squares fit of the water free elimination model to single voxel signals. Parameters ---------- design_matrix : array (g, 7) Design matrix holding the covariants used to solve for the regression coefficients. sig : array (g, ) Diffusion-weighted signal for a single voxel data. S0 : float Non diffusion weighted signal (i.e. signal for b-value=0). Diso : float, optional Value of the free water isotropic diffusion. Default is set to 3e-3 $mm^{2}.s^{-1}$. Please adjust this value if you are assuming different units of diffusion. mdreg : float, optimal DTI's mean diffusivity regularization threshold. If standard DTI diffusion tensor's mean diffusivity is almost near the free water diffusion value, the diffusion signal is assumed to be only free water diffusion (i.e. volume fraction will be set to 1 and tissue's diffusion parameters are set to zero). Default md_reg is 2.7e-3 $mm^{2}.s^{-1}$ (corresponding to 90% of the free water diffusion value). min_signal : float The minimum signal value. Needs to be a strictly positive number. cholesky : bool, optional If true it uses Cholesky decomposition to insure that diffusion tensor is positive define. Default: False f_transform : bool, optional If true, the water volume fractions is converted during the convergence procedure to ft = arcsin(2*f - 1) + pi/2, insuring f estimates between 0 and 1. Default: True jac : bool Use the Jacobian? Default: False weighting: str, optional the weighting scheme to use in considering the squared-error. Default behavior is to use uniform weighting. Other options: 'sigma' 'gmm' sigma: float, optional If the 'sigma' weighting scheme is used, a value of sigma needs to be provided here. According to [Chang2005]_, a good value to use is 1.5267 * std(background_noise), where background_noise is estimated from some part of the image known to contain no signal (only noise). Returns ------- All parameters estimated from the free water tensor model. Parameters are ordered as follows: 1) Three diffusion tensor's eigenvalues 2) Three lines of the eigenvector matrix each containing the first, second and third coordinates of the eigenvector 3) The volume fraction of the free water compartment.
Applies non linear least squares fit of the water free elimination model to single voxel signals.
[ "Applies", "non", "linear", "least", "squares", "fit", "of", "the", "water", "free", "elimination", "model", "to", "single", "voxel", "signals", "." ]
def nls_iter(design_matrix, sig, S0, Diso=3e-3, mdreg=2.7e-3, min_signal=1.0e-6, cholesky=False, f_transform=True, jac=False, weighting=None, sigma=None): """ Applies non linear least squares fit of the water free elimination model to single voxel signals. Parameters ---------- design_matrix : array (g, 7) Design matrix holding the covariants used to solve for the regression coefficients. sig : array (g, ) Diffusion-weighted signal for a single voxel data. S0 : float Non diffusion weighted signal (i.e. signal for b-value=0). Diso : float, optional Value of the free water isotropic diffusion. Default is set to 3e-3 $mm^{2}.s^{-1}$. Please adjust this value if you are assuming different units of diffusion. mdreg : float, optimal DTI's mean diffusivity regularization threshold. If standard DTI diffusion tensor's mean diffusivity is almost near the free water diffusion value, the diffusion signal is assumed to be only free water diffusion (i.e. volume fraction will be set to 1 and tissue's diffusion parameters are set to zero). Default md_reg is 2.7e-3 $mm^{2}.s^{-1}$ (corresponding to 90% of the free water diffusion value). min_signal : float The minimum signal value. Needs to be a strictly positive number. cholesky : bool, optional If true it uses Cholesky decomposition to insure that diffusion tensor is positive define. Default: False f_transform : bool, optional If true, the water volume fractions is converted during the convergence procedure to ft = arcsin(2*f - 1) + pi/2, insuring f estimates between 0 and 1. Default: True jac : bool Use the Jacobian? Default: False weighting: str, optional the weighting scheme to use in considering the squared-error. Default behavior is to use uniform weighting. Other options: 'sigma' 'gmm' sigma: float, optional If the 'sigma' weighting scheme is used, a value of sigma needs to be provided here. According to [Chang2005]_, a good value to use is 1.5267 * std(background_noise), where background_noise is estimated from some part of the image known to contain no signal (only noise). Returns ------- All parameters estimated from the free water tensor model. Parameters are ordered as follows: 1) Three diffusion tensor's eigenvalues 2) Three lines of the eigenvector matrix each containing the first, second and third coordinates of the eigenvector 3) The volume fraction of the free water compartment. """ # Initial guess params = wls_iter(design_matrix, sig, S0, min_signal=min_signal, Diso=Diso, mdreg=mdreg) # Process voxel if it has significant signal from tissue if params[12] < 0.99 and np.mean(sig) > min_signal and S0 > min_signal: # converting evals and evecs to diffusion tensor elements evals = params[:3] evecs = params[3:12].reshape((3, 3)) dt = lower_triangular(vec_val_vect(evecs, evals)) # Cholesky decomposition if requested if cholesky: dt = lower_triangular_to_cholesky(dt) # f transformation if requested if f_transform: f = np.arcsin(2*params[12] - 1) + np.pi/2 else: f = params[12] # Use the Levenberg-Marquardt algorithm wrapped in opt.leastsq start_params = np.concatenate((dt, [-np.log(S0), f]), axis=0) if jac: this_tensor, status = opt.leastsq(_nls_err_func, start_params[:8], args=(design_matrix, sig, Diso, weighting, sigma, cholesky, f_transform), Dfun=_nls_jacobian_func) else: this_tensor, status = opt.leastsq(_nls_err_func, start_params[:8], args=(design_matrix, sig, Diso, weighting, sigma, cholesky, f_transform)) # Process tissue diffusion tensor if cholesky: this_tensor[:6] = cholesky_to_lower_triangular(this_tensor[:6]) evals, evecs = _decompose_tensor_nan( from_lower_triangular(this_tensor[:6]), from_lower_triangular(start_params[:6])) # Process water volume fraction f f = this_tensor[7] if f_transform: f = 0.5 * (1 + np.sin(f - np.pi/2)) params = np.concatenate((evals, evecs[0], evecs[1], evecs[2], np.array([f])), axis=0) return params
[ "def", "nls_iter", "(", "design_matrix", ",", "sig", ",", "S0", ",", "Diso", "=", "3e-3", ",", "mdreg", "=", "2.7e-3", ",", "min_signal", "=", "1.0e-6", ",", "cholesky", "=", "False", ",", "f_transform", "=", "True", ",", "jac", "=", "False", ",", "w...
https://github.com/dipy/dipy/blob/be956a529465b28085f8fc435a756947ddee1c89/dipy/reconst/fwdti.py#L540-L649
CastagnaIT/plugin.video.netflix
5cf5fa436eb9956576c0f62aa31a4c7d6c5b8a4a
resources/lib/kodi/library.py
python
Library.import_library
(self, path)
Imports an already existing exported STRM library into the add-on library database, allows you to restore an existing library, by avoiding to recreate it from scratch. This operations also update the missing tv shows seasons and episodes, and automatically converts old STRM format type from add-on version 0.13.x or before 1.7.0 to new format.
Imports an already existing exported STRM library into the add-on library database, allows you to restore an existing library, by avoiding to recreate it from scratch. This operations also update the missing tv shows seasons and episodes, and automatically converts old STRM format type from add-on version 0.13.x or before 1.7.0 to new format.
[ "Imports", "an", "already", "existing", "exported", "STRM", "library", "into", "the", "add", "-", "on", "library", "database", "allows", "you", "to", "restore", "an", "existing", "library", "by", "avoiding", "to", "recreate", "it", "from", "scratch", ".", "T...
def import_library(self, path): """ Imports an already existing exported STRM library into the add-on library database, allows you to restore an existing library, by avoiding to recreate it from scratch. This operations also update the missing tv shows seasons and episodes, and automatically converts old STRM format type from add-on version 0.13.x or before 1.7.0 to new format. """ # If set ask to user if want to export NFO files nfo_settings = nfo.NFOSettings() nfo_settings.show_export_dialog() LOG.info('Start importing Kodi library') remove_folders = [] # List of failed imports paths to be optionally removed remove_titles = [] # List of failed imports titles to be optionally removed # Start importing STRM files folders = get_library_subfolders(FOLDER_NAME_MOVIES, path) + get_library_subfolders(FOLDER_NAME_SHOWS, path) with ui.ProgressDialog(True, max_value=len(folders)) as progress_bar: for folder_path in folders: folder_name = os.path.basename(xbmcvfs.translatePath(folder_path)) progress_bar.set_message(folder_name) try: videoid = self.import_videoid_from_existing_strm(folder_path, folder_name) if videoid is None: # Failed to import, add folder to remove list remove_folders.append(folder_path) remove_titles.append(folder_name) continue # Successfully imported, Execute the task for index, total_tasks, title in self.execute_library_task(videoid, self.export_item, nfo_settings=nfo_settings, notify_errors=True): label_partial_op = f' ({index + 1}/{total_tasks})' if total_tasks > 1 else '' progress_bar.set_message(title + label_partial_op) if progress_bar.is_cancelled(): LOG.warn('Import library interrupted by User') return if self.monitor.abortRequested(): LOG.warn('Import library interrupted by Kodi') return except ImportWarning: # Ignore it, something was wrong in STRM file (see _import_videoid in library_jobs.py) pass progress_bar.perform_step() progress_bar.set_wait_message() delay_anti_ban() ret = self._import_library_remove(remove_titles, remove_folders) request_kodi_library_update(scan=True, clean=ret)
[ "def", "import_library", "(", "self", ",", "path", ")", ":", "# If set ask to user if want to export NFO files", "nfo_settings", "=", "nfo", ".", "NFOSettings", "(", ")", "nfo_settings", ".", "show_export_dialog", "(", ")", "LOG", ".", "info", "(", "'Start importing...
https://github.com/CastagnaIT/plugin.video.netflix/blob/5cf5fa436eb9956576c0f62aa31a4c7d6c5b8a4a/resources/lib/kodi/library.py#L297-L343
krintoxi/NoobSec-Toolkit
38738541cbc03cedb9a3b3ed13b629f781ad64f6
NoobSecToolkit /tools/inject/thirdparty/odict/odict.py
python
_OrderedDict.sort
(self, *args, **kwargs)
Sort the key order in the OrderedDict. This method takes the same arguments as the ``list.sort`` method on your version of Python. >>> d = OrderedDict(((4, 1), (2, 2), (3, 3), (1, 4))) >>> d.sort() >>> d OrderedDict([(1, 4), (2, 2), (3, 3), (4, 1)])
Sort the key order in the OrderedDict.
[ "Sort", "the", "key", "order", "in", "the", "OrderedDict", "." ]
def sort(self, *args, **kwargs): """ Sort the key order in the OrderedDict. This method takes the same arguments as the ``list.sort`` method on your version of Python. >>> d = OrderedDict(((4, 1), (2, 2), (3, 3), (1, 4))) >>> d.sort() >>> d OrderedDict([(1, 4), (2, 2), (3, 3), (4, 1)]) """ self._sequence.sort(*args, **kwargs)
[ "def", "sort", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_sequence", ".", "sort", "(", "*", "args", ",", "*", "*", "kwargs", ")" ]
https://github.com/krintoxi/NoobSec-Toolkit/blob/38738541cbc03cedb9a3b3ed13b629f781ad64f6/NoobSecToolkit /tools/inject/thirdparty/odict/odict.py#L858-L870
snarfed/granary
ab085de2aef0cff8ac31a99b5e21443a249e8419
granary/reddit.py
python
Reddit.user_to_actor
(self, user)
return util.trim_nulls({ 'objectType': 'person', 'displayName': username, 'image': {'url': image}, 'id': self.tag_uri(username), # numeric_id is our own custom field that always has the source's numeric # user id, if available. 'numeric_id': user.get('id'), 'published': util.maybe_timestamp_to_iso8601(user.get('created_utc')), 'url': urls[0], 'urls': [{'value': u} for u in urls] if len(urls) > 1 else None, 'username': username, 'description': description, })
Converts a dict user to an actor. Args: user: JSON user Returns: an ActivityStreams actor dict, ready to be JSON-encoded
Converts a dict user to an actor.
[ "Converts", "a", "dict", "user", "to", "an", "actor", "." ]
def user_to_actor(self, user): """Converts a dict user to an actor. Args: user: JSON user Returns: an ActivityStreams actor dict, ready to be JSON-encoded """ username = user.get('name') if not username: return {} # trying my best to grab all the urls from the profile description urls = [f'{self.BASE_URL}/user/{username}/'] description = None subreddit = user.get('subreddit') if subreddit: url = subreddit.get('url') if url: urls.append(self.BASE_URL + url) description = subreddit.get('description') urls += util.trim_nulls(util.extract_links(description)) image = user.get('icon_img') return util.trim_nulls({ 'objectType': 'person', 'displayName': username, 'image': {'url': image}, 'id': self.tag_uri(username), # numeric_id is our own custom field that always has the source's numeric # user id, if available. 'numeric_id': user.get('id'), 'published': util.maybe_timestamp_to_iso8601(user.get('created_utc')), 'url': urls[0], 'urls': [{'value': u} for u in urls] if len(urls) > 1 else None, 'username': username, 'description': description, })
[ "def", "user_to_actor", "(", "self", ",", "user", ")", ":", "username", "=", "user", ".", "get", "(", "'name'", ")", "if", "not", "username", ":", "return", "{", "}", "# trying my best to grab all the urls from the profile description", "urls", "=", "[", "f'{sel...
https://github.com/snarfed/granary/blob/ab085de2aef0cff8ac31a99b5e21443a249e8419/granary/reddit.py#L94-L134
RiotGames/cloud-inquisitor
29a26c705381fdba3538b4efedb25b9e09b387ed
backend/cloud_inquisitor/plugins/types/resources.py
python
BaseResource.update
(self, data)
Updates the resource object with the information from `data`. The changes will be added to the current db.session but will not be commited. The user will need to perform the commit explicitly to save the changes Returns: True if resource object was updated, else False
Updates the resource object with the information from `data`. The changes will be added to the current db.session but will not be commited. The user will need to perform the commit explicitly to save the changes
[ "Updates", "the", "resource", "object", "with", "the", "information", "from", "data", ".", "The", "changes", "will", "be", "added", "to", "the", "current", "db", ".", "session", "but", "will", "not", "be", "commited", ".", "The", "user", "will", "need", ...
def update(self, data): """Updates the resource object with the information from `data`. The changes will be added to the current db.session but will not be commited. The user will need to perform the commit explicitly to save the changes Returns: True if resource object was updated, else False """
[ "def", "update", "(", "self", ",", "data", ")", ":" ]
https://github.com/RiotGames/cloud-inquisitor/blob/29a26c705381fdba3538b4efedb25b9e09b387ed/backend/cloud_inquisitor/plugins/types/resources.py#L110-L116
alanhamlett/pip-update-requirements
ce875601ef278c8ce00ad586434a978731525561
pur/packages/pip/_vendor/urllib3/contrib/securetransport.py
python
WrappedSocket._set_ciphers
(self)
Sets up the allowed ciphers. By default this matches the set in util.ssl_.DEFAULT_CIPHERS, at least as supported by macOS. This is done custom and doesn't allow changing at this time, mostly because parsing OpenSSL cipher strings is going to be a freaking nightmare.
Sets up the allowed ciphers. By default this matches the set in util.ssl_.DEFAULT_CIPHERS, at least as supported by macOS. This is done custom and doesn't allow changing at this time, mostly because parsing OpenSSL cipher strings is going to be a freaking nightmare.
[ "Sets", "up", "the", "allowed", "ciphers", ".", "By", "default", "this", "matches", "the", "set", "in", "util", ".", "ssl_", ".", "DEFAULT_CIPHERS", "at", "least", "as", "supported", "by", "macOS", ".", "This", "is", "done", "custom", "and", "doesn", "t"...
def _set_ciphers(self): """ Sets up the allowed ciphers. By default this matches the set in util.ssl_.DEFAULT_CIPHERS, at least as supported by macOS. This is done custom and doesn't allow changing at this time, mostly because parsing OpenSSL cipher strings is going to be a freaking nightmare. """ ciphers = (Security.SSLCipherSuite * len(CIPHER_SUITES))(*CIPHER_SUITES) result = Security.SSLSetEnabledCiphers( self.context, ciphers, len(CIPHER_SUITES) ) _assert_no_error(result)
[ "def", "_set_ciphers", "(", "self", ")", ":", "ciphers", "=", "(", "Security", ".", "SSLCipherSuite", "*", "len", "(", "CIPHER_SUITES", ")", ")", "(", "*", "CIPHER_SUITES", ")", "result", "=", "Security", ".", "SSLSetEnabledCiphers", "(", "self", ".", "con...
https://github.com/alanhamlett/pip-update-requirements/blob/ce875601ef278c8ce00ad586434a978731525561/pur/packages/pip/_vendor/urllib3/contrib/securetransport.py#L335-L346
tcgoetz/GarminDB
55796eb621df9f6ecd92f16b3a53393d23c0b4dc
garmindb/garmindb/monitoring_db.py
python
Monitoring.get_stats
(cls, session, func, start_ts, end_ts)
return { 'steps': func(session, cls.steps, start_ts, end_ts), 'calories_active_avg': ( cls.get_active_calories(session, fitfile.field_enums.ActivityType.running, start_ts, end_ts) + cls.get_active_calories(session, fitfile.field_enums.ActivityType.cycling, start_ts, end_ts) + cls.get_active_calories(session, fitfile.field_enums.ActivityType.walking, start_ts, end_ts) ) }
Return a dict of stats for table entries within the time span.
Return a dict of stats for table entries within the time span.
[ "Return", "a", "dict", "of", "stats", "for", "table", "entries", "within", "the", "time", "span", "." ]
def get_stats(cls, session, func, start_ts, end_ts): """Return a dict of stats for table entries within the time span.""" return { 'steps': func(session, cls.steps, start_ts, end_ts), 'calories_active_avg': ( cls.get_active_calories(session, fitfile.field_enums.ActivityType.running, start_ts, end_ts) + cls.get_active_calories(session, fitfile.field_enums.ActivityType.cycling, start_ts, end_ts) + cls.get_active_calories(session, fitfile.field_enums.ActivityType.walking, start_ts, end_ts) ) }
[ "def", "get_stats", "(", "cls", ",", "session", ",", "func", ",", "start_ts", ",", "end_ts", ")", ":", "return", "{", "'steps'", ":", "func", "(", "session", ",", "cls", ".", "steps", ",", "start_ts", ",", "end_ts", ")", ",", "'calories_active_avg'", "...
https://github.com/tcgoetz/GarminDB/blob/55796eb621df9f6ecd92f16b3a53393d23c0b4dc/garmindb/garmindb/monitoring_db.py#L220-L229
IntelLabs/coach
dea46ae0d22b0a0cd30b9fc138a4a2642e1b9d9d
rl_coach/architectures/tensorflow_components/architecture.py
python
TensorFlowArchitecture.get_model
(self)
Constructs the model using `network_parameters` and sets `input_embedders`, `middleware`, `output_heads`, `outputs`, `losses`, `total_loss`, `adaptive_learning_rate_scheme`, `current_learning_rate`, and `optimizer`. :return: A list of the model's weights
Constructs the model using `network_parameters` and sets `input_embedders`, `middleware`, `output_heads`, `outputs`, `losses`, `total_loss`, `adaptive_learning_rate_scheme`, `current_learning_rate`, and `optimizer`.
[ "Constructs", "the", "model", "using", "network_parameters", "and", "sets", "input_embedders", "middleware", "output_heads", "outputs", "losses", "total_loss", "adaptive_learning_rate_scheme", "current_learning_rate", "and", "optimizer", "." ]
def get_model(self) -> List: """ Constructs the model using `network_parameters` and sets `input_embedders`, `middleware`, `output_heads`, `outputs`, `losses`, `total_loss`, `adaptive_learning_rate_scheme`, `current_learning_rate`, and `optimizer`. :return: A list of the model's weights """ raise NotImplementedError
[ "def", "get_model", "(", "self", ")", "->", "List", ":", "raise", "NotImplementedError" ]
https://github.com/IntelLabs/coach/blob/dea46ae0d22b0a0cd30b9fc138a4a2642e1b9d9d/rl_coach/architectures/tensorflow_components/architecture.py#L144-L152
EOA-AILab/NER-Chinese
6df4a63a67936c356c578ac68ad49841ac0c9ebc
bert_ner/bert_ner/bert_base/server/zmq_decor.py
python
_SocketDecorator.process_decorator_args
(self, *args, **kwargs)
return kw_name, args, kwargs
Also grab context_name out of kwargs
Also grab context_name out of kwargs
[ "Also", "grab", "context_name", "out", "of", "kwargs" ]
def process_decorator_args(self, *args, **kwargs): """Also grab context_name out of kwargs""" kw_name, args, kwargs = super(_SocketDecorator, self).process_decorator_args(*args, **kwargs) self.context_name = kwargs.pop('context_name', 'context') return kw_name, args, kwargs
[ "def", "process_decorator_args", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "kw_name", ",", "args", ",", "kwargs", "=", "super", "(", "_SocketDecorator", ",", "self", ")", ".", "process_decorator_args", "(", "*", "args", ",", "*", ...
https://github.com/EOA-AILab/NER-Chinese/blob/6df4a63a67936c356c578ac68ad49841ac0c9ebc/bert_ner/bert_ner/bert_base/server/zmq_decor.py#L35-L39
inkandswitch/livebook
93c8d467734787366ad084fc3566bf5cbe249c51
public/pypyjs/modules/cgitb.py
python
reset
()
return '''<!--: spam Content-Type: text/html <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> --> </font> </font> </font> </script> </object> </blockquote> </pre> </table> </table> </table> </table> </table> </font> </font> </font>'''
Return a string that resets the CGI and browser to a known state.
Return a string that resets the CGI and browser to a known state.
[ "Return", "a", "string", "that", "resets", "the", "CGI", "and", "browser", "to", "a", "known", "state", "." ]
def reset(): """Return a string that resets the CGI and browser to a known state.""" return '''<!--: spam Content-Type: text/html <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> <body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> --> </font> </font> </font> </script> </object> </blockquote> </pre> </table> </table> </table> </table> </table> </font> </font> </font>'''
[ "def", "reset", "(", ")", ":", "return", "'''<!--: spam\nContent-Type: text/html\n\n<body bgcolor=\"#f0f0f8\"><font color=\"#f0f0f8\" size=\"-5\"> -->\n<body bgcolor=\"#f0f0f8\"><font color=\"#f0f0f8\" size=\"-5\"> --> -->\n</font> </font> </font> </script> </object> </blockquote> </pre>\n</table> </tab...
https://github.com/inkandswitch/livebook/blob/93c8d467734787366ad084fc3566bf5cbe249c51/public/pypyjs/modules/cgitb.py#L36-L44
django-oscar/django-oscar
ffcc530844d40283b6b1552778a140536b904f5f
src/oscar/apps/payment/bankcards.py
python
luhn
(card_number)
return (sum % 10) == 0
Test whether a bankcard number passes the Luhn algorithm.
Test whether a bankcard number passes the Luhn algorithm.
[ "Test", "whether", "a", "bankcard", "number", "passes", "the", "Luhn", "algorithm", "." ]
def luhn(card_number): """ Test whether a bankcard number passes the Luhn algorithm. """ card_number = str(card_number) sum = 0 num_digits = len(card_number) odd_even = num_digits & 1 for i in range(0, num_digits): digit = int(card_number[i]) if not ((i & 1) ^ odd_even): digit = digit * 2 if digit > 9: digit = digit - 9 sum = sum + digit return (sum % 10) == 0
[ "def", "luhn", "(", "card_number", ")", ":", "card_number", "=", "str", "(", "card_number", ")", "sum", "=", "0", "num_digits", "=", "len", "(", "card_number", ")", "odd_even", "=", "num_digits", "&", "1", "for", "i", "in", "range", "(", "0", ",", "n...
https://github.com/django-oscar/django-oscar/blob/ffcc530844d40283b6b1552778a140536b904f5f/src/oscar/apps/payment/bankcards.py#L60-L77
EmuKit/emukit
cdcb0d070d7f1c5585260266160722b636786859
emukit/core/optimization/anchor_points_generator.py
python
ObjectiveAnchorPointsGenerator.get_anchor_point_scores
(self, X: np.ndarray)
return scores
:param X: The samples at which to evaluate the criterion :return:
:param X: The samples at which to evaluate the criterion :return:
[ ":", "param", "X", ":", "The", "samples", "at", "which", "to", "evaluate", "the", "criterion", ":", "return", ":" ]
def get_anchor_point_scores(self, X: np.ndarray) -> np.ndarray: """ :param X: The samples at which to evaluate the criterion :return: """ are_constraints_satisfied = np.all([np.ones(X.shape[0])] + [c.evaluate(X) for c in self.space.constraints], axis=0) scores = np.zeros((X.shape[0],)) scores[~are_constraints_satisfied] = -np.inf scores[are_constraints_satisfied] = self.acquisition.evaluate(X[are_constraints_satisfied, :])[:, 0] return scores
[ "def", "get_anchor_point_scores", "(", "self", ",", "X", ":", "np", ".", "ndarray", ")", "->", "np", ".", "ndarray", ":", "are_constraints_satisfied", "=", "np", ".", "all", "(", "[", "np", ".", "ones", "(", "X", ".", "shape", "[", "0", "]", ")", "...
https://github.com/EmuKit/emukit/blob/cdcb0d070d7f1c5585260266160722b636786859/emukit/core/optimization/anchor_points_generator.py#L82-L91
larryhastings/gilectomy
4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a
Lib/contextlib.py
python
ExitStack._push_cm_exit
(self, cm, cm_exit)
Helper to correctly register callbacks to __exit__ methods
Helper to correctly register callbacks to __exit__ methods
[ "Helper", "to", "correctly", "register", "callbacks", "to", "__exit__", "methods" ]
def _push_cm_exit(self, cm, cm_exit): """Helper to correctly register callbacks to __exit__ methods""" def _exit_wrapper(*exc_details): return cm_exit(cm, *exc_details) _exit_wrapper.__self__ = cm self.push(_exit_wrapper)
[ "def", "_push_cm_exit", "(", "self", ",", "cm", ",", "cm_exit", ")", ":", "def", "_exit_wrapper", "(", "*", "exc_details", ")", ":", "return", "cm_exit", "(", "cm", ",", "*", "exc_details", ")", "_exit_wrapper", ".", "__self__", "=", "cm", "self", ".", ...
https://github.com/larryhastings/gilectomy/blob/4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a/Lib/contextlib.py#L278-L283
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.2/django/db/models/sql/query.py
python
Query.get_loaded_field_names
(self)
return collection
If any fields are marked to be deferred, returns a dictionary mapping models to a set of names in those fields that will be loaded. If a model is not in the returned dictionary, none of it's fields are deferred. If no fields are marked for deferral, returns an empty dictionary.
If any fields are marked to be deferred, returns a dictionary mapping models to a set of names in those fields that will be loaded. If a model is not in the returned dictionary, none of it's fields are deferred.
[ "If", "any", "fields", "are", "marked", "to", "be", "deferred", "returns", "a", "dictionary", "mapping", "models", "to", "a", "set", "of", "names", "in", "those", "fields", "that", "will", "be", "loaded", ".", "If", "a", "model", "is", "not", "in", "th...
def get_loaded_field_names(self): """ If any fields are marked to be deferred, returns a dictionary mapping models to a set of names in those fields that will be loaded. If a model is not in the returned dictionary, none of it's fields are deferred. If no fields are marked for deferral, returns an empty dictionary. """ collection = {} self.deferred_to_data(collection, self.get_loaded_field_names_cb) return collection
[ "def", "get_loaded_field_names", "(", "self", ")", ":", "collection", "=", "{", "}", "self", ".", "deferred_to_data", "(", "collection", ",", "self", ".", "get_loaded_field_names_cb", ")", "return", "collection" ]
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.2/django/db/models/sql/query.py#L1748-L1759
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/apps/reports/filters/base.py
python
BaseMultipleOptionFilter.get_value
(cls, request, domain)
return request.GET.getlist(cls.slug)
[]
def get_value(cls, request, domain): return request.GET.getlist(cls.slug)
[ "def", "get_value", "(", "cls", ",", "request", ",", "domain", ")", ":", "return", "request", ".", "GET", ".", "getlist", "(", "cls", ".", "slug", ")" ]
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/apps/reports/filters/base.py#L171-L172
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
Python-2.7.13/Lib/plat-mac/ic.py
python
IC.launchurl
(self, url, hint="")
[]
def launchurl(self, url, hint=""): # Work around a bug in ICLaunchURL: file:/foo does # not work but file:///foo does. if url[:6] == 'file:/' and url[6] != '/': url = 'file:///' + url[6:] self.ic.ICLaunchURL(hint, url, 0, len(url))
[ "def", "launchurl", "(", "self", ",", "url", ",", "hint", "=", "\"\"", ")", ":", "# Work around a bug in ICLaunchURL: file:/foo does", "# not work but file:///foo does.", "if", "url", "[", ":", "6", "]", "==", "'file:/'", "and", "url", "[", "6", "]", "!=", "'/...
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/Python-2.7.13/Lib/plat-mac/ic.py#L200-L205
openhatch/oh-mainline
ce29352a034e1223141dcc2f317030bbc3359a51
vendor/packages/gdata/src/gdata/client.py
python
GDClient.client_login
(self, email, password, source, service=None, account_type='HOSTED_OR_GOOGLE', auth_url=atom.http_core.Uri.parse_uri( 'https://www.google.com/accounts/ClientLogin'), captcha_token=None, captcha_response=None)
return self.auth_token
Performs an auth request using the user's email address and password. In order to modify user specific data and read user private data, your application must be authorized by the user. One way to demonstrage authorization is by including a Client Login token in the Authorization HTTP header of all requests. This method requests the Client Login token by sending the user's email address, password, the name of the application, and the service code for the service which will be accessed by the application. If the username and password are correct, the server will respond with the client login code and a new ClientLoginToken object will be set in the client's auth_token member. With the auth_token set, future requests from this client will include the Client Login token. For a list of service names, see http://code.google.com/apis/gdata/faq.html#clientlogin For more information on Client Login, see: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html Args: email: str The user's email address or username. password: str The password for the user's account. source: str The name of your application. This can be anything you like but should should give some indication of which app is making the request. service: str The service code for the service you would like to access. For example, 'cp' for contacts, 'cl' for calendar. For a full list see http://code.google.com/apis/gdata/faq.html#clientlogin If you are using a subclass of the gdata.client.GDClient, the service will usually be filled in for you so you do not need to specify it. For example see BloggerClient, SpreadsheetsClient, etc. account_type: str (optional) The type of account which is being authenticated. This can be either 'GOOGLE' for a Google Account, 'HOSTED' for a Google Apps Account, or the default 'HOSTED_OR_GOOGLE' which will select the Google Apps Account if the same email address is used for both a Google Account and a Google Apps Account. auth_url: str (optional) The URL to which the login request should be sent. captcha_token: str (optional) If a previous login attempt was reponded to with a CAPTCHA challenge, this is the token which identifies the challenge (from the CAPTCHA's URL). captcha_response: str (optional) If a previous login attempt was reponded to with a CAPTCHA challenge, this is the response text which was contained in the challenge. Returns: Generated token, which is also stored in this object. Raises: A RequestError or one of its suclasses: BadAuthentication, BadAuthenticationServiceURL, ClientLoginFailed, ClientLoginTokenMissing, or CaptchaChallenge
Performs an auth request using the user's email address and password. In order to modify user specific data and read user private data, your application must be authorized by the user. One way to demonstrage authorization is by including a Client Login token in the Authorization HTTP header of all requests. This method requests the Client Login token by sending the user's email address, password, the name of the application, and the service code for the service which will be accessed by the application. If the username and password are correct, the server will respond with the client login code and a new ClientLoginToken object will be set in the client's auth_token member. With the auth_token set, future requests from this client will include the Client Login token. For a list of service names, see http://code.google.com/apis/gdata/faq.html#clientlogin For more information on Client Login, see: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
[ "Performs", "an", "auth", "request", "using", "the", "user", "s", "email", "address", "and", "password", ".", "In", "order", "to", "modify", "user", "specific", "data", "and", "read", "user", "private", "data", "your", "application", "must", "be", "authorize...
def client_login(self, email, password, source, service=None, account_type='HOSTED_OR_GOOGLE', auth_url=atom.http_core.Uri.parse_uri( 'https://www.google.com/accounts/ClientLogin'), captcha_token=None, captcha_response=None): """Performs an auth request using the user's email address and password. In order to modify user specific data and read user private data, your application must be authorized by the user. One way to demonstrage authorization is by including a Client Login token in the Authorization HTTP header of all requests. This method requests the Client Login token by sending the user's email address, password, the name of the application, and the service code for the service which will be accessed by the application. If the username and password are correct, the server will respond with the client login code and a new ClientLoginToken object will be set in the client's auth_token member. With the auth_token set, future requests from this client will include the Client Login token. For a list of service names, see http://code.google.com/apis/gdata/faq.html#clientlogin For more information on Client Login, see: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html Args: email: str The user's email address or username. password: str The password for the user's account. source: str The name of your application. This can be anything you like but should should give some indication of which app is making the request. service: str The service code for the service you would like to access. For example, 'cp' for contacts, 'cl' for calendar. For a full list see http://code.google.com/apis/gdata/faq.html#clientlogin If you are using a subclass of the gdata.client.GDClient, the service will usually be filled in for you so you do not need to specify it. For example see BloggerClient, SpreadsheetsClient, etc. account_type: str (optional) The type of account which is being authenticated. This can be either 'GOOGLE' for a Google Account, 'HOSTED' for a Google Apps Account, or the default 'HOSTED_OR_GOOGLE' which will select the Google Apps Account if the same email address is used for both a Google Account and a Google Apps Account. auth_url: str (optional) The URL to which the login request should be sent. captcha_token: str (optional) If a previous login attempt was reponded to with a CAPTCHA challenge, this is the token which identifies the challenge (from the CAPTCHA's URL). captcha_response: str (optional) If a previous login attempt was reponded to with a CAPTCHA challenge, this is the response text which was contained in the challenge. Returns: Generated token, which is also stored in this object. Raises: A RequestError or one of its suclasses: BadAuthentication, BadAuthenticationServiceURL, ClientLoginFailed, ClientLoginTokenMissing, or CaptchaChallenge """ service = service or self.auth_service self.auth_token = self.request_client_login_token(email, password, source, service=service, account_type=account_type, auth_url=auth_url, captcha_token=captcha_token, captcha_response=captcha_response) if self.alt_auth_service is not None: self.alt_auth_token = self.request_client_login_token( email, password, source, service=self.alt_auth_service, account_type=account_type, auth_url=auth_url, captcha_token=captcha_token, captcha_response=captcha_response) return self.auth_token
[ "def", "client_login", "(", "self", ",", "email", ",", "password", ",", "source", ",", "service", "=", "None", ",", "account_type", "=", "'HOSTED_OR_GOOGLE'", ",", "auth_url", "=", "atom", ".", "http_core", ".", "Uri", ".", "parse_uri", "(", "'https://www.go...
https://github.com/openhatch/oh-mainline/blob/ce29352a034e1223141dcc2f317030bbc3359a51/vendor/packages/gdata/src/gdata/client.py#L377-L447
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/paramiko/agent.py
python
Agent.close
(self)
Close the SSH agent connection.
Close the SSH agent connection.
[ "Close", "the", "SSH", "agent", "connection", "." ]
def close(self): """ Close the SSH agent connection. """ self._close()
[ "def", "close", "(", "self", ")", ":", "self", ".", "_close", "(", ")" ]
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/paramiko/agent.py#L365-L369
DetectionTeamUCAS/RRPN_Faster-RCNN_Tensorflow
cca574844df5fc8bbf380227725a4e3106fbc48c
libs/networks/slim_nets/mobilenet_v1.py
python
_reduced_kernel_size_for_small_input
(input_tensor, kernel_size)
return kernel_size_out
Define kernel size which is automatically reduced for small input. If the shape of the input images is unknown at graph construction time this function assumes that the input images are large enough. Args: input_tensor: input tensor of size [batch_size, height, width, channels]. kernel_size: desired kernel size of length 2: [kernel_height, kernel_width] Returns: a tensor with the kernel size.
Define kernel size which is automatically reduced for small input.
[ "Define", "kernel", "size", "which", "is", "automatically", "reduced", "for", "small", "input", "." ]
def _reduced_kernel_size_for_small_input(input_tensor, kernel_size): """Define kernel size which is automatically reduced for small input. If the shape of the input images is unknown at graph construction time this function assumes that the input images are large enough. Args: input_tensor: input tensor of size [batch_size, height, width, channels]. kernel_size: desired kernel size of length 2: [kernel_height, kernel_width] Returns: a tensor with the kernel size. """ shape = input_tensor.get_shape().as_list() if shape[1] is None or shape[2] is None: kernel_size_out = kernel_size else: kernel_size_out = [min(shape[1], kernel_size[0]), min(shape[2], kernel_size[1])] return kernel_size_out
[ "def", "_reduced_kernel_size_for_small_input", "(", "input_tensor", ",", "kernel_size", ")", ":", "shape", "=", "input_tensor", ".", "get_shape", "(", ")", ".", "as_list", "(", ")", "if", "shape", "[", "1", "]", "is", "None", "or", "shape", "[", "2", "]", ...
https://github.com/DetectionTeamUCAS/RRPN_Faster-RCNN_Tensorflow/blob/cca574844df5fc8bbf380227725a4e3106fbc48c/libs/networks/slim_nets/mobilenet_v1.py#L338-L357
chribsen/simple-machine-learning-examples
dc94e52a4cebdc8bb959ff88b81ff8cfeca25022
venv/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/tarfile.py
python
itn
(n, digits=8, format=DEFAULT_FORMAT)
return s
Convert a python number to a number field.
Convert a python number to a number field.
[ "Convert", "a", "python", "number", "to", "a", "number", "field", "." ]
def itn(n, digits=8, format=DEFAULT_FORMAT): """Convert a python number to a number field. """ # POSIX 1003.1-1988 requires numbers to be encoded as a string of # octal digits followed by a null-byte, this allows values up to # (8**(digits-1))-1. GNU tar allows storing numbers greater than # that if necessary. A leading 0o200 byte indicates this particular # encoding, the following digits-1 bytes are a big-endian # representation. This allows values up to (256**(digits-1))-1. if 0 <= n < 8 ** (digits - 1): s = ("%0*o" % (digits - 1, n)).encode("ascii") + NUL else: if format != GNU_FORMAT or n >= 256 ** (digits - 1): raise ValueError("overflow in number field") if n < 0: # XXX We mimic GNU tar's behaviour with negative numbers, # this could raise OverflowError. n = struct.unpack("L", struct.pack("l", n))[0] s = bytearray() for i in range(digits - 1): s.insert(0, n & 0o377) n >>= 8 s.insert(0, 0o200) return s
[ "def", "itn", "(", "n", ",", "digits", "=", "8", ",", "format", "=", "DEFAULT_FORMAT", ")", ":", "# POSIX 1003.1-1988 requires numbers to be encoded as a string of", "# octal digits followed by a null-byte, this allows values up to", "# (8**(digits-1))-1. GNU tar allows storing numbe...
https://github.com/chribsen/simple-machine-learning-examples/blob/dc94e52a4cebdc8bb959ff88b81ff8cfeca25022/venv/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/tarfile.py#L216-L241
LinuxCNC/simple-gcode-generators
d06c2750fe03c41becd6bd5863ace54b52920155
counterbore/counterbore.py
python
Application.__init__
(self, master=None)
[]
def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createMenu() self.createWidgets()
[ "def", "__init__", "(", "self", ",", "master", "=", "None", ")", ":", "Frame", ".", "__init__", "(", "self", ",", "master", ")", "self", ".", "grid", "(", ")", "self", ".", "createMenu", "(", ")", "self", ".", "createWidgets", "(", ")" ]
https://github.com/LinuxCNC/simple-gcode-generators/blob/d06c2750fe03c41becd6bd5863ace54b52920155/counterbore/counterbore.py#L47-L51
cloudera/impyla
0c736af4cad2bade9b8e313badc08ec50e81c948
impala/_thrift_gen/hive_metastore/ThriftHiveMetastore.py
python
get_table_column_statistics_args.__init__
(self, db_name=None, tbl_name=None, col_name=None,)
[]
def __init__(self, db_name=None, tbl_name=None, col_name=None,): self.db_name = db_name self.tbl_name = tbl_name self.col_name = col_name
[ "def", "__init__", "(", "self", ",", "db_name", "=", "None", ",", "tbl_name", "=", "None", ",", "col_name", "=", "None", ",", ")", ":", "self", ".", "db_name", "=", "db_name", "self", ".", "tbl_name", "=", "tbl_name", "self", ".", "col_name", "=", "c...
https://github.com/cloudera/impyla/blob/0c736af4cad2bade9b8e313badc08ec50e81c948/impala/_thrift_gen/hive_metastore/ThriftHiveMetastore.py#L25945-L25948
docker/docker-py
a48a5a9647761406d66e8271f19fab7fa0c5f582
docker/models/plugins.py
python
Plugin.remove
(self, force=False)
return self.client.api.remove_plugin(self.name, force=force)
Remove the plugin from the server. Args: force (bool): Remove even if the plugin is enabled. Default: False Raises: :py:class:`docker.errors.APIError` If the server returns an error.
Remove the plugin from the server.
[ "Remove", "the", "plugin", "from", "the", "server", "." ]
def remove(self, force=False): """ Remove the plugin from the server. Args: force (bool): Remove even if the plugin is enabled. Default: False Raises: :py:class:`docker.errors.APIError` If the server returns an error. """ return self.client.api.remove_plugin(self.name, force=force)
[ "def", "remove", "(", "self", ",", "force", "=", "False", ")", ":", "return", "self", ".", "client", ".", "api", ".", "remove_plugin", "(", "self", ".", "name", ",", "force", "=", "force", ")" ]
https://github.com/docker/docker-py/blob/a48a5a9647761406d66e8271f19fab7fa0c5f582/docker/models/plugins.py#L86-L98
bdarnell/plop
1f026fce98d52508f42e67444c1a3a046f4901db
plop/callgraph.py
python
Node.__repr__
(self)
return 'Node(%s)' % (self.id,)
[]
def __repr__(self): return 'Node(%s)' % (self.id,)
[ "def", "__repr__", "(", "self", ")", ":", "return", "'Node(%s)'", "%", "(", "self", ".", "id", ",", ")" ]
https://github.com/bdarnell/plop/blob/1f026fce98d52508f42e67444c1a3a046f4901db/plop/callgraph.py#L17-L18
kanzure/nanoengineer
874e4c9f8a9190f093625b267f9767e19f82e6c4
cad/src/dna/commands/InsertDna/InsertDna_PropertyManager.py
python
InsertDna_PropertyManager.__init__
( self, command )
Constructor for the DNA Duplex property manager.
Constructor for the DNA Duplex property manager.
[ "Constructor", "for", "the", "DNA", "Duplex", "property", "manager", "." ]
def __init__( self, command ): """ Constructor for the DNA Duplex property manager. """ self.endPoint1 = None self.endPoint2 = None self._conformation = "B-DNA" self._numberOfBases = 0 self._basesPerTurn = getDuplexBasesPerTurn(self._conformation) self._duplexRise = getDuplexRise(self._conformation) self._duplexLength = getDuplexLength(self._conformation, self._numberOfBases) _superclass.__init__( self, command) self.showTopRowButtons( PM_DONE_BUTTON | \ PM_CANCEL_BUTTON | \ PM_WHATS_THIS_BUTTON)
[ "def", "__init__", "(", "self", ",", "command", ")", ":", "self", ".", "endPoint1", "=", "None", "self", ".", "endPoint2", "=", "None", "self", ".", "_conformation", "=", "\"B-DNA\"", "self", ".", "_numberOfBases", "=", "0", "self", ".", "_basesPerTurn", ...
https://github.com/kanzure/nanoengineer/blob/874e4c9f8a9190f093625b267f9767e19f82e6c4/cad/src/dna/commands/InsertDna/InsertDna_PropertyManager.py#L78-L97
davidbau/ganseeing
93cea2c8f391aef001ddf9dcb35c43990681a47c
seeing/workerpool.py
python
WorkerPool.__init__
(self, worker=WorkerBase, process_count=None, **initargs)
[]
def __init__(self, worker=WorkerBase, process_count=None, **initargs): global active_pools if process_count is None: process_count = cpu_count() if process_count == 0: # zero process_count uses only main process, for debugging. self.queue = None self.processes = None self.worker = worker(None, 0, None, initargs) return # Ctrl-C strategy: worker processes should ignore ctrl-C. Set # this up to be inherited by child processes before forking. original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) active_pools[id(self)] = self self.queue = Queue(maxsize=(process_count * 3)) self.processes = None # Initialize before trying to construct workers self.processes = [worker(i, process_count, self.queue, initargs) for i in range(process_count)] for p in self.processes: p.start() # The main process should handle ctrl-C. Restore this now. signal.signal(signal.SIGINT, original_sigint_handler)
[ "def", "__init__", "(", "self", ",", "worker", "=", "WorkerBase", ",", "process_count", "=", "None", ",", "*", "*", "initargs", ")", ":", "global", "active_pools", "if", "process_count", "is", "None", ":", "process_count", "=", "cpu_count", "(", ")", "if",...
https://github.com/davidbau/ganseeing/blob/93cea2c8f391aef001ddf9dcb35c43990681a47c/seeing/workerpool.py#L82-L103
jython/jython3
def4f8ec47cb7a9c799ea4c745f12badf92c5769
lib-python/3.5.1/tkinter/__init__.py
python
Canvas.icursor
(self, *args)
Set cursor at position POS in the item identified by TAGORID. In ARGS TAGORID must be first.
Set cursor at position POS in the item identified by TAGORID. In ARGS TAGORID must be first.
[ "Set", "cursor", "at", "position", "POS", "in", "the", "item", "identified", "by", "TAGORID", ".", "In", "ARGS", "TAGORID", "must", "be", "first", "." ]
def icursor(self, *args): """Set cursor at position POS in the item identified by TAGORID. In ARGS TAGORID must be first.""" self.tk.call((self._w, 'icursor') + args)
[ "def", "icursor", "(", "self", ",", "*", "args", ")", ":", "self", ".", "tk", ".", "call", "(", "(", "self", ".", "_w", ",", "'icursor'", ")", "+", "args", ")" ]
https://github.com/jython/jython3/blob/def4f8ec47cb7a9c799ea4c745f12badf92c5769/lib-python/3.5.1/tkinter/__init__.py#L2395-L2398
Fantomas42/django-blog-zinnia
881101a9d1d455b2fc581d6f4ae0947cdd8126c6
zinnia/feeds.py
python
DiscussionFeed.item_link
(self, item)
return item.get_absolute_url()
URL of the discussion item.
URL of the discussion item.
[ "URL", "of", "the", "discussion", "item", "." ]
def item_link(self, item): """ URL of the discussion item. """ return item.get_absolute_url()
[ "def", "item_link", "(", "self", ",", "item", ")", ":", "return", "item", ".", "get_absolute_url", "(", ")" ]
https://github.com/Fantomas42/django-blog-zinnia/blob/881101a9d1d455b2fc581d6f4ae0947cdd8126c6/zinnia/feeds.py#L364-L368
nosmokingbandit/Watcher3
0217e75158b563bdefc8e01c3be7620008cf3977
lib/sqlalchemy/orm/events.py
python
MapperEvents.before_insert
(self, mapper, connection, target)
Receive an object instance before an INSERT statement is emitted corresponding to that instance. This event is used to modify local, non-object related attributes on the instance before an INSERT occurs, as well as to emit additional SQL statements on the given connection. The event is often called for a batch of objects of the same class before their INSERT statements are emitted at once in a later step. In the extremely rare case that this is not desirable, the :func:`.mapper` can be configured with ``batch=False``, which will cause batches of instances to be broken up into individual (and more poorly performing) event->persist->event steps. .. warning:: Mapper-level flush events only allow **very limited operations**, on attributes local to the row being operated upon only, as well as allowing any SQL to be emitted on the given :class:`.Connection`. **Please read fully** the notes at :ref:`session_persistence_mapper` for guidelines on using these methods; generally, the :meth:`.SessionEvents.before_flush` method should be preferred for general on-flush changes. :param mapper: the :class:`.Mapper` which is the target of this event. :param connection: the :class:`.Connection` being used to emit INSERT statements for this instance. This provides a handle into the current transaction on the target database specific to this instance. :param target: the mapped instance being persisted. If the event is configured with ``raw=True``, this will instead be the :class:`.InstanceState` state-management object associated with the instance. :return: No return value is supported by this event. .. seealso:: :ref:`session_persistence_events`
Receive an object instance before an INSERT statement is emitted corresponding to that instance.
[ "Receive", "an", "object", "instance", "before", "an", "INSERT", "statement", "is", "emitted", "corresponding", "to", "that", "instance", "." ]
def before_insert(self, mapper, connection, target): """Receive an object instance before an INSERT statement is emitted corresponding to that instance. This event is used to modify local, non-object related attributes on the instance before an INSERT occurs, as well as to emit additional SQL statements on the given connection. The event is often called for a batch of objects of the same class before their INSERT statements are emitted at once in a later step. In the extremely rare case that this is not desirable, the :func:`.mapper` can be configured with ``batch=False``, which will cause batches of instances to be broken up into individual (and more poorly performing) event->persist->event steps. .. warning:: Mapper-level flush events only allow **very limited operations**, on attributes local to the row being operated upon only, as well as allowing any SQL to be emitted on the given :class:`.Connection`. **Please read fully** the notes at :ref:`session_persistence_mapper` for guidelines on using these methods; generally, the :meth:`.SessionEvents.before_flush` method should be preferred for general on-flush changes. :param mapper: the :class:`.Mapper` which is the target of this event. :param connection: the :class:`.Connection` being used to emit INSERT statements for this instance. This provides a handle into the current transaction on the target database specific to this instance. :param target: the mapped instance being persisted. If the event is configured with ``raw=True``, this will instead be the :class:`.InstanceState` state-management object associated with the instance. :return: No return value is supported by this event. .. seealso:: :ref:`session_persistence_events` """
[ "def", "before_insert", "(", "self", ",", "mapper", ",", "connection", ",", "target", ")", ":" ]
https://github.com/nosmokingbandit/Watcher3/blob/0217e75158b563bdefc8e01c3be7620008cf3977/lib/sqlalchemy/orm/events.py#L812-L856
theAIGuysCode/yolov3_deepsort
a325e9f93d406b2e137e5e071b4b350ca9380545
deep_sort/kalman_filter.py
python
KalmanFilter.predict
(self, mean, covariance)
return mean, covariance
Run Kalman filter prediction step. Parameters ---------- mean : ndarray The 8 dimensional mean vector of the object state at the previous time step. covariance : ndarray The 8x8 dimensional covariance matrix of the object state at the previous time step. Returns ------- (ndarray, ndarray) Returns the mean vector and covariance matrix of the predicted state. Unobserved velocities are initialized to 0 mean.
Run Kalman filter prediction step.
[ "Run", "Kalman", "filter", "prediction", "step", "." ]
def predict(self, mean, covariance): """Run Kalman filter prediction step. Parameters ---------- mean : ndarray The 8 dimensional mean vector of the object state at the previous time step. covariance : ndarray The 8x8 dimensional covariance matrix of the object state at the previous time step. Returns ------- (ndarray, ndarray) Returns the mean vector and covariance matrix of the predicted state. Unobserved velocities are initialized to 0 mean. """ std_pos = [ self._std_weight_position * mean[3], self._std_weight_position * mean[3], 1e-2, self._std_weight_position * mean[3]] std_vel = [ self._std_weight_velocity * mean[3], self._std_weight_velocity * mean[3], 1e-5, self._std_weight_velocity * mean[3]] motion_cov = np.diag(np.square(np.r_[std_pos, std_vel])) mean = np.dot(self._motion_mat, mean) covariance = np.linalg.multi_dot(( self._motion_mat, covariance, self._motion_mat.T)) + motion_cov return mean, covariance
[ "def", "predict", "(", "self", ",", "mean", ",", "covariance", ")", ":", "std_pos", "=", "[", "self", ".", "_std_weight_position", "*", "mean", "[", "3", "]", ",", "self", ".", "_std_weight_position", "*", "mean", "[", "3", "]", ",", "1e-2", ",", "se...
https://github.com/theAIGuysCode/yolov3_deepsort/blob/a325e9f93d406b2e137e5e071b4b350ca9380545/deep_sort/kalman_filter.py#L88-L123
adamcaudill/EquationGroupLeak
52fa871c89008566c27159bd48f2a8641260c984
windows/Resources/Python/Override/Lib/multiprocessing/sharedctypes.py
python
Value
(typecode_or_type, *args, **kwds)
return synchronized(obj, lock)
Return a synchronization wrapper for a Value
Return a synchronization wrapper for a Value
[ "Return", "a", "synchronization", "wrapper", "for", "a", "Value" ]
def Value(typecode_or_type, *args, **kwds): ''' Return a synchronization wrapper for a Value ''' lock = kwds.pop('lock', None) if kwds: raise ValueError('unrecognized keyword argument(s): %s' % kwds.keys()) obj = RawValue(typecode_or_type, *args) if lock is False: return obj if lock in (True, None): lock = RLock() if not hasattr(lock, 'acquire'): raise AttributeError("'%r' has no method 'acquire'" % lock) return synchronized(obj, lock)
[ "def", "Value", "(", "typecode_or_type", ",", "*", "args", ",", "*", "*", "kwds", ")", ":", "lock", "=", "kwds", ".", "pop", "(", "'lock'", ",", "None", ")", "if", "kwds", ":", "raise", "ValueError", "(", "'unrecognized keyword argument(s): %s'", "%", "k...
https://github.com/adamcaudill/EquationGroupLeak/blob/52fa871c89008566c27159bd48f2a8641260c984/windows/Resources/Python/Override/Lib/multiprocessing/sharedctypes.py#L92-L106
boxeehacks/boxeehack
bdfa63187f662b542261dce64aff68548f63ecaf
hack/boxee/scripts/OpenSubtitles/resources/lib/plugins/BeautifulSoup.py
python
BeautifulStoneSoup.handle_decl
(self, data)
Handle DOCTYPEs and the like as Declaration objects.
Handle DOCTYPEs and the like as Declaration objects.
[ "Handle", "DOCTYPEs", "and", "the", "like", "as", "Declaration", "objects", "." ]
def handle_decl(self, data): "Handle DOCTYPEs and the like as Declaration objects." self._toStringSubclass(data, Declaration)
[ "def", "handle_decl", "(", "self", ",", "data", ")", ":", "self", ".", "_toStringSubclass", "(", "data", ",", "Declaration", ")" ]
https://github.com/boxeehacks/boxeehack/blob/bdfa63187f662b542261dce64aff68548f63ecaf/hack/boxee/scripts/OpenSubtitles/resources/lib/plugins/BeautifulSoup.py#L1446-L1448
google-research/mixmatch
1011a1d51eaa9ca6f5dba02096a848d1fe3fc38e
libml/utils.py
python
ilog2
(x)
return int(np.ceil(np.log2(x)))
Integer log2.
Integer log2.
[ "Integer", "log2", "." ]
def ilog2(x): """Integer log2.""" return int(np.ceil(np.log2(x)))
[ "def", "ilog2", "(", "x", ")", ":", "return", "int", "(", "np", ".", "ceil", "(", "np", ".", "log2", "(", "x", ")", ")", ")" ]
https://github.com/google-research/mixmatch/blob/1011a1d51eaa9ca6f5dba02096a848d1fe3fc38e/libml/utils.py#L51-L53
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/groups/generic.py
python
structure_description
(G, latex=False)
return description
r""" Return a string that tries to describe the structure of ``G``. This methods wraps GAP's ``StructureDescription`` method. For full details, including the form of the returned string and the algorithm to build it, see `GAP's documentation <https://www.gap-system.org/Manuals/doc/ref/chap39.html>`_. INPUT: - ``latex`` -- a boolean (default: ``False``). If ``True`` return a LaTeX formatted string. OUTPUT: - string .. WARNING:: From GAP's documentation: The string returned by ``StructureDescription`` is **not** an isomorphism invariant: non-isomorphic groups can have the same string value, and two isomorphic groups in different representations can produce different strings. EXAMPLES:: sage: G = CyclicPermutationGroup(6) sage: G.structure_description() 'C6' sage: G.structure_description(latex=True) 'C_{6}' sage: G2 = G.direct_product(G, maps=False) sage: LatexExpr(G2.structure_description(latex=True)) C_{6} \times C_{6} This method is mainly intended for small groups or groups with few normal subgroups. Even then there are some surprises:: sage: D3 = DihedralGroup(3) sage: D3.structure_description() 'S3' We use the Sage notation for the degree of dihedral groups:: sage: D4 = DihedralGroup(4) sage: D4.structure_description() 'D4' Works for finitely presented groups (:trac:`17573`):: sage: F.<x, y> = FreeGroup() sage: G=F / [x^2*y^-1, x^3*y^2, x*y*x^-1*y^-1] sage: G.structure_description() 'C7' And matrix groups (:trac:`17573`):: sage: groups.matrix.GL(4,2).structure_description() 'A8'
r""" Return a string that tries to describe the structure of ``G``.
[ "r", "Return", "a", "string", "that", "tries", "to", "describe", "the", "structure", "of", "G", "." ]
def structure_description(G, latex=False): r""" Return a string that tries to describe the structure of ``G``. This methods wraps GAP's ``StructureDescription`` method. For full details, including the form of the returned string and the algorithm to build it, see `GAP's documentation <https://www.gap-system.org/Manuals/doc/ref/chap39.html>`_. INPUT: - ``latex`` -- a boolean (default: ``False``). If ``True`` return a LaTeX formatted string. OUTPUT: - string .. WARNING:: From GAP's documentation: The string returned by ``StructureDescription`` is **not** an isomorphism invariant: non-isomorphic groups can have the same string value, and two isomorphic groups in different representations can produce different strings. EXAMPLES:: sage: G = CyclicPermutationGroup(6) sage: G.structure_description() 'C6' sage: G.structure_description(latex=True) 'C_{6}' sage: G2 = G.direct_product(G, maps=False) sage: LatexExpr(G2.structure_description(latex=True)) C_{6} \times C_{6} This method is mainly intended for small groups or groups with few normal subgroups. Even then there are some surprises:: sage: D3 = DihedralGroup(3) sage: D3.structure_description() 'S3' We use the Sage notation for the degree of dihedral groups:: sage: D4 = DihedralGroup(4) sage: D4.structure_description() 'D4' Works for finitely presented groups (:trac:`17573`):: sage: F.<x, y> = FreeGroup() sage: G=F / [x^2*y^-1, x^3*y^2, x*y*x^-1*y^-1] sage: G.structure_description() 'C7' And matrix groups (:trac:`17573`):: sage: groups.matrix.GL(4,2).structure_description() 'A8' """ import re def correct_dihedral_degree(match): return "%sD%d" % (match.group(1), int(match.group(2)) // 2) description = str(G._gap_().StructureDescription()) description = re.sub(r"(\A|\W)D(\d+)", correct_dihedral_degree, description) if not latex: return description description = description.replace("x", r"\times").replace(":", r"\rtimes") description = re.sub(r"([A-Za-z]+)([0-9]+)", r"\g<1>_{\g<2>}", description) description = re.sub(r"O([+-])", r"O^{\g<1>}", description) return description
[ "def", "structure_description", "(", "G", ",", "latex", "=", "False", ")", ":", "import", "re", "def", "correct_dihedral_degree", "(", "match", ")", ":", "return", "\"%sD%d\"", "%", "(", "match", ".", "group", "(", "1", ")", ",", "int", "(", "match", "...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/groups/generic.py#L1351-L1428
AutodeskRoboticsLab/Mimic
85447f0d346be66988303a6a054473d92f1ed6f4
mFIZ/scripts/mFIZ_extern/serial/serialcli.py
python
Serial.reset_output_buffer
(self)
\ Clear output buffer, aborting the current output and discarding all that is in the buffer.
\ Clear output buffer, aborting the current output and discarding all that is in the buffer.
[ "\\", "Clear", "output", "buffer", "aborting", "the", "current", "output", "and", "discarding", "all", "that", "is", "in", "the", "buffer", "." ]
def reset_output_buffer(self): """\ Clear output buffer, aborting the current output and discarding all that is in the buffer. """ if not self.is_open: raise portNotOpenError self._port_handle.DiscardOutBuffer()
[ "def", "reset_output_buffer", "(", "self", ")", ":", "if", "not", "self", ".", "is_open", ":", "raise", "portNotOpenError", "self", ".", "_port_handle", ".", "DiscardOutBuffer", "(", ")" ]
https://github.com/AutodeskRoboticsLab/Mimic/blob/85447f0d346be66988303a6a054473d92f1ed6f4/mFIZ/scripts/mFIZ_extern/serial/serialcli.py#L192-L199
openedx/edx-platform
68dd185a0ab45862a2a61e0f803d7e03d2be71b5
common/lib/xmodule/xmodule/modulestore/__init__.py
python
BulkOperationsMixin._start_outermost_bulk_operation
(self, bulk_ops_record, course_key, ignore_case=False)
The outermost nested bulk_operation call: do the actual begin 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 begin of the bulk operation.
[ "The", "outermost", "nested", "bulk_operation", "call", ":", "do", "the", "actual", "begin", "of", "the", "bulk", "operation", "." ]
def _start_outermost_bulk_operation(self, bulk_ops_record, course_key, ignore_case=False): """ The outermost nested bulk_operation call: do the actual begin of the bulk operation. Implementing classes must override this method; otherwise, the bulk operations are a noop """ pass
[ "def", "_start_outermost_bulk_operation", "(", "self", ",", "bulk_ops_record", ",", "course_key", ",", "ignore_case", "=", "False", ")", ":", "pass" ]
https://github.com/openedx/edx-platform/blob/68dd185a0ab45862a2a61e0f803d7e03d2be71b5/common/lib/xmodule/xmodule/modulestore/__init__.py#L231-L237
CedricGuillemet/Imogen
ee417b42747ed5b46cb11b02ef0c3630000085b3
bin/Lib/http/server.py
python
CGIHTTPRequestHandler.do_POST
(self)
Serve a POST request. This is only implemented for CGI scripts.
Serve a POST request.
[ "Serve", "a", "POST", "request", "." ]
def do_POST(self): """Serve a POST request. This is only implemented for CGI scripts. """ if self.is_cgi(): self.run_cgi() else: self.send_error( HTTPStatus.NOT_IMPLEMENTED, "Can only POST to CGI scripts")
[ "def", "do_POST", "(", "self", ")", ":", "if", "self", ".", "is_cgi", "(", ")", ":", "self", ".", "run_cgi", "(", ")", "else", ":", "self", ".", "send_error", "(", "HTTPStatus", ".", "NOT_IMPLEMENTED", ",", "\"Can only POST to CGI scripts\"", ")" ]
https://github.com/CedricGuillemet/Imogen/blob/ee417b42747ed5b46cb11b02ef0c3630000085b3/bin/Lib/http/server.py#L971-L983
buke/GreenOdoo
3d8c55d426fb41fdb3f2f5a1533cfe05983ba1df
source/addons/account/account_bank_statement.py
python
account_bank_statement_line._get_exchange_lines
(self, cr, uid, st_line, mv_line, currency_diff, currency_id, move_id, context=None)
return (move_line, move_line_counterpart)
Prepare the two lines in company currency due to currency rate difference. :param line: browse record of the voucher.line for which we want to create currency rate difference accounting entries :param move_id: Account move wher the move lines will be. :param currency_diff: Amount to be posted. :param company_currency: id of currency of the company to which the voucher belong :param current_currency: id of currency of the voucher :return: the account move line and its counterpart to create, depicted as mapping between fieldname and value :rtype: tuple of dict
Prepare the two lines in company currency due to currency rate difference.
[ "Prepare", "the", "two", "lines", "in", "company", "currency", "due", "to", "currency", "rate", "difference", "." ]
def _get_exchange_lines(self, cr, uid, st_line, mv_line, currency_diff, currency_id, move_id, context=None): ''' Prepare the two lines in company currency due to currency rate difference. :param line: browse record of the voucher.line for which we want to create currency rate difference accounting entries :param move_id: Account move wher the move lines will be. :param currency_diff: Amount to be posted. :param company_currency: id of currency of the company to which the voucher belong :param current_currency: id of currency of the voucher :return: the account move line and its counterpart to create, depicted as mapping between fieldname and value :rtype: tuple of dict ''' if currency_diff > 0: exchange_account_id = st_line.company_id.expense_currency_exchange_account_id.id else: exchange_account_id = st_line.company_id.income_currency_exchange_account_id.id # Even if the amount_currency is never filled, we need to pass the foreign currency because otherwise # the receivable/payable account may have a secondary currency, which render this field mandatory if mv_line.account_id.currency_id: account_currency_id = mv_line.account_id.currency_id.id else: account_currency_id = st_line.company_id.currency_id.id != currency_id and currency_id or False move_line = { 'journal_id': st_line.journal_id.id, 'period_id': st_line.statement_id.period_id.id, 'name': _('change') + ': ' + (st_line.name or '/'), 'account_id': mv_line.account_id.id, 'move_id': move_id, 'partner_id': st_line.partner_id.id, 'currency_id': account_currency_id, 'amount_currency': 0.0, 'quantity': 1, 'credit': currency_diff > 0 and currency_diff or 0.0, 'debit': currency_diff < 0 and -currency_diff or 0.0, 'date': st_line.date, 'counterpart_move_line_id': mv_line.id, } move_line_counterpart = { 'journal_id': st_line.journal_id.id, 'period_id': st_line.statement_id.period_id.id, 'name': _('change') + ': ' + (st_line.name or '/'), 'account_id': exchange_account_id, 'move_id': move_id, 'amount_currency': 0.0, 'partner_id': st_line.partner_id.id, 'currency_id': account_currency_id, 'quantity': 1, 'debit': currency_diff > 0 and currency_diff or 0.0, 'credit': currency_diff < 0 and -currency_diff or 0.0, 'date': st_line.date, } return (move_line, move_line_counterpart)
[ "def", "_get_exchange_lines", "(", "self", ",", "cr", ",", "uid", ",", "st_line", ",", "mv_line", ",", "currency_diff", ",", "currency_id", ",", "move_id", ",", "context", "=", "None", ")", ":", "if", "currency_diff", ">", "0", ":", "exchange_account_id", ...
https://github.com/buke/GreenOdoo/blob/3d8c55d426fb41fdb3f2f5a1533cfe05983ba1df/source/addons/account/account_bank_statement.py#L729-L781
hustlzp/Flask-Boost
d0308408ebb248dd752b77123b845f8ec637fab2
flask_boost/project/application/controllers/account.py
python
signup
()
return render_template('account/signup/signup.html', form=form)
Signup
Signup
[ "Signup" ]
def signup(): """Signup""" form = SignupForm() if form.validate_on_submit(): params = form.data.copy() params.pop('repassword') user = User(**params) db.session.add(user) db.session.commit() signin_user(user) return redirect(url_for('site.index')) return render_template('account/signup/signup.html', form=form)
[ "def", "signup", "(", ")", ":", "form", "=", "SignupForm", "(", ")", "if", "form", ".", "validate_on_submit", "(", ")", ":", "params", "=", "form", ".", "data", ".", "copy", "(", ")", "params", ".", "pop", "(", "'repassword'", ")", "user", "=", "Us...
https://github.com/hustlzp/Flask-Boost/blob/d0308408ebb248dd752b77123b845f8ec637fab2/flask_boost/project/application/controllers/account.py#L24-L35
yuxiaokui/Intranet-Penetration
f57678a204840c83cbf3308e3470ae56c5ff514b
proxy/XX-Net/code/default/python27/1.0/lib/urllib2.py
python
parse_http_list
(s)
return [part.strip() for part in res]
Parse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Neither commas nor quotes count if they are escaped. Only double-quotes count, not single-quotes.
Parse lists as described by RFC 2068 Section 2.
[ "Parse", "lists", "as", "described", "by", "RFC", "2068", "Section", "2", "." ]
def parse_http_list(s): """Parse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Neither commas nor quotes count if they are escaped. Only double-quotes count, not single-quotes. """ res = [] part = '' escape = quote = False for cur in s: if escape: part += cur escape = False continue if quote: if cur == '\\': escape = True continue elif cur == '"': quote = False part += cur continue if cur == ',': res.append(part) part = '' continue if cur == '"': quote = True part += cur # append last part if part: res.append(part) return [part.strip() for part in res]
[ "def", "parse_http_list", "(", "s", ")", ":", "res", "=", "[", "]", "part", "=", "''", "escape", "=", "quote", "=", "False", "for", "cur", "in", "s", ":", "if", "escape", ":", "part", "+=", "cur", "escape", "=", "False", "continue", "if", "quote", ...
https://github.com/yuxiaokui/Intranet-Penetration/blob/f57678a204840c83cbf3308e3470ae56c5ff514b/proxy/XX-Net/code/default/python27/1.0/lib/urllib2.py#L1277-L1318
ehForwarderBot/efb-wechat-slave
36a94c5e5f2fe5dc7247448cf37d5e8b653e8990
efb_wechat_slave/vendor/itchat/core.py
python
Core.set_alias
(self, userName, alias)
set alias for a friend for options - userName: 'UserName' key of info dict - alias: new alias it is defined in components/contact.py
set alias for a friend for options - userName: 'UserName' key of info dict - alias: new alias it is defined in components/contact.py
[ "set", "alias", "for", "a", "friend", "for", "options", "-", "userName", ":", "UserName", "key", "of", "info", "dict", "-", "alias", ":", "new", "alias", "it", "is", "defined", "in", "components", "/", "contact", ".", "py" ]
def set_alias(self, userName, alias): """ set alias for a friend for options - userName: 'UserName' key of info dict - alias: new alias it is defined in components/contact.py """ raise NotImplementedError()
[ "def", "set_alias", "(", "self", ",", "userName", ",", "alias", ")", ":", "raise", "NotImplementedError", "(", ")" ]
https://github.com/ehForwarderBot/efb-wechat-slave/blob/36a94c5e5f2fe5dc7247448cf37d5e8b653e8990/efb_wechat_slave/vendor/itchat/core.py#L227-L234
facebookresearch/pytext
1a4e184b233856fcfb9997d74f167cbf5bbbfb8d
pytext/models/semantic_parsers/rnng/rnng_parser.py
python
RNNGParserBase.__init__
( self, ablation: Config.AblationParams, constraints: Config.RNNGConstraints, lstm_num_layers: int, lstm_dim: int, max_open_NT: int, dropout: float, actions_vocab, shift_idx: int, reduce_idx: int, ignore_subNTs_roots: List[int], valid_NT_idxs: List[int], valid_IN_idxs: List[int], valid_SL_idxs: List[int], embedding: EmbeddingList, p_compositional, )
Initialize the model Args: ablation : AblationParams Features/RNNs to use constraints : RNNGConstraints Constraints to use when computing valid actions lstm_num_layers : int number of layers in the LSTMs lstm_dim : int size of LSTM max_open_NT : int number of maximum open non-terminals allowed on the stack. After that, the only valid actions are SHIFT and REDUCE dropout : float dropout parameter beam_size : int beam size for beam search; run only during inference top_k : int top k results from beam search actions_vocab : Vocab (right now torchtext.vocab.Vocab) dictionary of actions shift_idx : int index of shift action reduce_idx : int index of reduce action ignore_subNTs_roots : List[int] for these top non-terminals, ignore loss for all subsequent actions valid_NT_idxs : List[int] indices of all non-terminals valid_IN_idxs : List[int] indices of intent non-terminals valid_SL_idxs : List[int] indices of slot non-terminals embedding : EmbeddingList embeddings for the tokens p_compositional : CompositionFunction Composition function to use to get embedding of a sub-tree Returns: None
Initialize the model
[ "Initialize", "the", "model" ]
def __init__( self, ablation: Config.AblationParams, constraints: Config.RNNGConstraints, lstm_num_layers: int, lstm_dim: int, max_open_NT: int, dropout: float, actions_vocab, shift_idx: int, reduce_idx: int, ignore_subNTs_roots: List[int], valid_NT_idxs: List[int], valid_IN_idxs: List[int], valid_SL_idxs: List[int], embedding: EmbeddingList, p_compositional, ) -> None: """ Initialize the model Args: ablation : AblationParams Features/RNNs to use constraints : RNNGConstraints Constraints to use when computing valid actions lstm_num_layers : int number of layers in the LSTMs lstm_dim : int size of LSTM max_open_NT : int number of maximum open non-terminals allowed on the stack. After that, the only valid actions are SHIFT and REDUCE dropout : float dropout parameter beam_size : int beam size for beam search; run only during inference top_k : int top k results from beam search actions_vocab : Vocab (right now torchtext.vocab.Vocab) dictionary of actions shift_idx : int index of shift action reduce_idx : int index of reduce action ignore_subNTs_roots : List[int] for these top non-terminals, ignore loss for all subsequent actions valid_NT_idxs : List[int] indices of all non-terminals valid_IN_idxs : List[int] indices of intent non-terminals valid_SL_idxs : List[int] indices of slot non-terminals embedding : EmbeddingList embeddings for the tokens p_compositional : CompositionFunction Composition function to use to get embedding of a sub-tree Returns: None """ super().__init__() self.embedding = embedding # self.embedding.config: FeatureConfig object cannot be pickled but, # we require the model to be pickled for passing from one worker process # for Hogwild training. Hence, setting the config to None self.embedding.config = None self.p_compositional = p_compositional self.ablation_use_last_open_NT_feature = ablation.use_last_open_NT_feature self.ablation_use_buffer = ablation.use_buffer self.ablation_use_stack = ablation.use_stack self.ablation_use_action = ablation.use_action self.constraints_intent_slot_nesting = constraints.intent_slot_nesting self.constraints_no_slots_inside_unsupported = ( constraints.no_slots_inside_unsupported ) self.constraints_ignore_loss_for_unsupported = ( constraints.ignore_loss_for_unsupported ) self.lstm_num_layers = lstm_num_layers self.lstm_dim = lstm_dim self.max_open_NT = max_open_NT self.actions_vocab = actions_vocab self.shift_idx = shift_idx self.reduce_idx = reduce_idx self.ignore_subNTs_roots = ignore_subNTs_roots self.valid_NT_idxs = valid_NT_idxs self.valid_IN_idxs = valid_IN_idxs self.valid_SL_idxs = valid_SL_idxs num_actions = len(actions_vocab) lstm_count = ablation.use_buffer + ablation.use_stack + ablation.use_action if lstm_count == 0: raise ValueError("Need at least one of the LSTMs to be true") self.action_linear = nn.Sequential( nn.Linear( lstm_count * lstm_dim + num_actions * ablation.use_last_open_NT_feature, lstm_dim, ), nn.ReLU(), nn.Linear(lstm_dim, num_actions), ) self.dropout_layer = nn.Dropout(p=dropout) self.buff_rnn = nn.LSTM( embedding.embedding_dim, lstm_dim, num_layers=lstm_num_layers, dropout=dropout, ) self.stack_rnn = nn.LSTM( lstm_dim, lstm_dim, num_layers=lstm_num_layers, dropout=dropout ) self.action_rnn = nn.LSTM( lstm_dim, lstm_dim, num_layers=lstm_num_layers, dropout=dropout ) self.actions_lookup = nn.Embedding(num_actions, lstm_dim) self.loss_func = nn.CrossEntropyLoss() log_class_usage(__class__)
[ "def", "__init__", "(", "self", ",", "ablation", ":", "Config", ".", "AblationParams", ",", "constraints", ":", "Config", ".", "RNNGConstraints", ",", "lstm_num_layers", ":", "int", ",", "lstm_dim", ":", "int", ",", "max_open_NT", ":", "int", ",", "dropout",...
https://github.com/facebookresearch/pytext/blob/1a4e184b233856fcfb9997d74f167cbf5bbbfb8d/pytext/models/semantic_parsers/rnng/rnng_parser.py#L166-L293
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/models/albert/modeling_flax_albert.py
python
FlaxAlbertLayer.__call__
( self, hidden_states, attention_mask, deterministic: bool = True, output_attentions: bool = False, )
return outputs
[]
def __call__( self, hidden_states, attention_mask, deterministic: bool = True, output_attentions: bool = False, ): attention_outputs = self.attention( hidden_states, attention_mask, deterministic=deterministic, output_attentions=output_attentions ) attention_output = attention_outputs[0] ffn_output = self.ffn(attention_output) ffn_output = self.activation(ffn_output) ffn_output = self.ffn_output(ffn_output) ffn_output = self.dropout(ffn_output, deterministic=deterministic) hidden_states = self.full_layer_layer_norm(ffn_output + attention_output) outputs = (hidden_states,) if output_attentions: outputs += (attention_outputs[1],) return outputs
[ "def", "__call__", "(", "self", ",", "hidden_states", ",", "attention_mask", ",", "deterministic", ":", "bool", "=", "True", ",", "output_attentions", ":", "bool", "=", "False", ",", ")", ":", "attention_outputs", "=", "self", ".", "attention", "(", "hidden_...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/models/albert/modeling_flax_albert.py#L299-L320
beancount/beancount
cb3526a1af95b3b5be70347470c381b5a86055fe
beancount/core/position.py
python
Position.__str__
(self)
return self.to_string()
Return a string representation of the position. Returns: A string, a printable representation of the position.
Return a string representation of the position.
[ "Return", "a", "string", "representation", "of", "the", "position", "." ]
def __str__(self): """Return a string representation of the position. Returns: A string, a printable representation of the position. """ return self.to_string()
[ "def", "__str__", "(", "self", ")", ":", "return", "self", ".", "to_string", "(", ")" ]
https://github.com/beancount/beancount/blob/cb3526a1af95b3b5be70347470c381b5a86055fe/beancount/core/position.py#L192-L198
jlhutch/pylru
6411a3cf50ea96f513784c49b7154e49f54df3e8
pylru.py
python
lrucache.get
(self, key, default=None)
return self[key]
Get an item - return default (None) if not present
Get an item - return default (None) if not present
[ "Get", "an", "item", "-", "return", "default", "(", "None", ")", "if", "not", "present" ]
def get(self, key, default=None): """Get an item - return default (None) if not present""" if key not in self.table: return default return self[key]
[ "def", "get", "(", "self", ",", "key", ",", "default", "=", "None", ")", ":", "if", "key", "not", "in", "self", ".", "table", ":", "return", "default", "return", "self", "[", "key", "]" ]
https://github.com/jlhutch/pylru/blob/6411a3cf50ea96f513784c49b7154e49f54df3e8/pylru.py#L101-L106
goace/personal-file-sharing-center
4a5b903b003f2db1306e77c5e51b6660fc5dbc6a
web/webapi.py
python
UnsupportedMediaType.__init__
(self, message=None)
[]
def __init__(self, message=None): status = "415 Unsupported Media Type" headers = {'Content-Type': 'text/html'} HTTPError.__init__(self, status, headers, message or self.message)
[ "def", "__init__", "(", "self", ",", "message", "=", "None", ")", ":", "status", "=", "\"415 Unsupported Media Type\"", "headers", "=", "{", "'Content-Type'", ":", "'text/html'", "}", "HTTPError", ".", "__init__", "(", "self", ",", "status", ",", "headers", ...
https://github.com/goace/personal-file-sharing-center/blob/4a5b903b003f2db1306e77c5e51b6660fc5dbc6a/web/webapi.py#L232-L235
happinesslz/TANet
2d4b2ab99b8e57c03671b0f1531eab7dca8f3c1f
second.pytorch_with_TANet/second/kittiviewer/control_panel.py
python
QColorButton.setColor
(self, color)
[]
def setColor(self, color): if color != self._color: self._color = color self.colorChanged.emit() if self._color is not None: self.setStyleSheet(f"background-color: {QColor(self._color).name()};") else: self.setStyleSheet("")
[ "def", "setColor", "(", "self", ",", "color", ")", ":", "if", "color", "!=", "self", ".", "_color", ":", "self", ".", "_color", "=", "color", "self", ".", "colorChanged", ".", "emit", "(", ")", "if", "self", ".", "_color", "is", "not", "None", ":",...
https://github.com/happinesslz/TANet/blob/2d4b2ab99b8e57c03671b0f1531eab7dca8f3c1f/second.pytorch_with_TANet/second/kittiviewer/control_panel.py#L139-L147
F8LEFT/DecLLVM
d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c
python/idaapi.py
python
cfuncptr_t.set_user_cmt
(self, *args)
return _idaapi.cfuncptr_t_set_user_cmt(self, *args)
set_user_cmt(self, loc, cmt)
set_user_cmt(self, loc, cmt)
[ "set_user_cmt", "(", "self", "loc", "cmt", ")" ]
def set_user_cmt(self, *args): """ set_user_cmt(self, loc, cmt) """ return _idaapi.cfuncptr_t_set_user_cmt(self, *args)
[ "def", "set_user_cmt", "(", "self", ",", "*", "args", ")", ":", "return", "_idaapi", ".", "cfuncptr_t_set_user_cmt", "(", "self", ",", "*", "args", ")" ]
https://github.com/F8LEFT/DecLLVM/blob/d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c/python/idaapi.py#L34145-L34149
jaraco/irc
19859340b2ad3bffc58d842a7657fae9ec3563f8
irc/client.py
python
ServerConnection.get_server_name
(self)
return self.real_server_name or ""
Get the (real) server name. This method returns the (real) server name, or, more specifically, what the server calls itself.
Get the (real) server name.
[ "Get", "the", "(", "real", ")", "server", "name", "." ]
def get_server_name(self): """Get the (real) server name. This method returns the (real) server name, or, more specifically, what the server calls itself. """ return self.real_server_name or ""
[ "def", "get_server_name", "(", "self", ")", ":", "return", "self", ".", "real_server_name", "or", "\"\"" ]
https://github.com/jaraco/irc/blob/19859340b2ad3bffc58d842a7657fae9ec3563f8/irc/client.py#L217-L223
datactive/bigbang
d4fef7eb41ae04e51f4e369de5a721c66231202b
bigbang/ingress/utils.py
python
get_website_content
( url: str, session: Optional[requests.Session] = None, )
Get HTML code from website Note ---- Servers don't like it when one is sending too many requests from same ip address in short period of time. Therefore we need to: a) catch 'requests.exceptions.RequestException' errors (includes all possible errors to be on the safe side), b) safe intermediate results, c) continue where we left off at a later stage.
Get HTML code from website
[ "Get", "HTML", "code", "from", "website" ]
def get_website_content( url: str, session: Optional[requests.Session] = None, ) -> Union[str, BeautifulSoup]: """ Get HTML code from website Note ---- Servers don't like it when one is sending too many requests from same ip address in short period of time. Therefore we need to: a) catch 'requests.exceptions.RequestException' errors (includes all possible errors to be on the safe side), b) safe intermediate results, c) continue where we left off at a later stage. """ # TODO: include option to change BeautifulSoup args try: if session is None: sauce = requests.get(url) if sauce.status_code == 200: soup = BeautifulSoup(sauce.content, "html.parser") return soup elif sauce.status_code == 404: logger.exception(f"HTTP 404 Error for {url}.") return "RequestException" else: sauce = session.get(url) soup = BeautifulSoup(sauce.text, "html.parser") return soup except requests.exceptions.RequestException as e: if "A2=" in url: # if URL of mboxMessage logger.exception(f"{e} for {url}.") return "RequestException" else: SystemExit()
[ "def", "get_website_content", "(", "url", ":", "str", ",", "session", ":", "Optional", "[", "requests", ".", "Session", "]", "=", "None", ",", ")", "->", "Union", "[", "str", ",", "BeautifulSoup", "]", ":", "# TODO: include option to change BeautifulSoup args", ...
https://github.com/datactive/bigbang/blob/d4fef7eb41ae04e51f4e369de5a721c66231202b/bigbang/ingress/utils.py#L30-L66
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/combinat/permutation.py
python
Permutation.retract_plain
(self, m)
return Permutations(m)(p[:m])
r""" Return the plain retract of the permutation ``self`` in `S_n` to `S_m`, where `m \leq n`. If this retract is undefined, then ``None`` is returned. If `p \in S_n` is a permutation, and `m` is a nonnegative integer less or equal to `n`, then the plain retract of `p` to `S_m` is defined only if every `i > m` satisfies `p(i) = i`. In this case, it is defined as the permutation written `(p(1), p(2), \ldots, p(m))` in one-line notation. EXAMPLES:: sage: Permutation([4,1,2,3,5]).retract_plain(4) [4, 1, 2, 3] sage: Permutation([4,1,2,3,5]).retract_plain(3) sage: Permutation([1,3,2,4,5,6]).retract_plain(3) [1, 3, 2] sage: Permutation([1,3,2,4,5,6]).retract_plain(2) sage: Permutation([1,2,3,4,5]).retract_plain(1) [1] sage: Permutation([1,2,3,4,5]).retract_plain(0) [] sage: all( p.retract_plain(3) == p for p in Permutations(3) ) True .. SEEALSO:: :meth:`retract_direct_product`, :meth:`retract_okounkov_vershik`, :meth:`remove_extra_fixed_points`
r""" Return the plain retract of the permutation ``self`` in `S_n` to `S_m`, where `m \leq n`. If this retract is undefined, then ``None`` is returned.
[ "r", "Return", "the", "plain", "retract", "of", "the", "permutation", "self", "in", "S_n", "to", "S_m", "where", "m", "\\", "leq", "n", ".", "If", "this", "retract", "is", "undefined", "then", "None", "is", "returned", "." ]
def retract_plain(self, m): r""" Return the plain retract of the permutation ``self`` in `S_n` to `S_m`, where `m \leq n`. If this retract is undefined, then ``None`` is returned. If `p \in S_n` is a permutation, and `m` is a nonnegative integer less or equal to `n`, then the plain retract of `p` to `S_m` is defined only if every `i > m` satisfies `p(i) = i`. In this case, it is defined as the permutation written `(p(1), p(2), \ldots, p(m))` in one-line notation. EXAMPLES:: sage: Permutation([4,1,2,3,5]).retract_plain(4) [4, 1, 2, 3] sage: Permutation([4,1,2,3,5]).retract_plain(3) sage: Permutation([1,3,2,4,5,6]).retract_plain(3) [1, 3, 2] sage: Permutation([1,3,2,4,5,6]).retract_plain(2) sage: Permutation([1,2,3,4,5]).retract_plain(1) [1] sage: Permutation([1,2,3,4,5]).retract_plain(0) [] sage: all( p.retract_plain(3) == p for p in Permutations(3) ) True .. SEEALSO:: :meth:`retract_direct_product`, :meth:`retract_okounkov_vershik`, :meth:`remove_extra_fixed_points` """ n = len(self) p = list(self) for i in range(m, n): if p[i] != i + 1: return None return Permutations(m)(p[:m])
[ "def", "retract_plain", "(", "self", ",", "m", ")", ":", "n", "=", "len", "(", "self", ")", "p", "=", "list", "(", "self", ")", "for", "i", "in", "range", "(", "m", ",", "n", ")", ":", "if", "p", "[", "i", "]", "!=", "i", "+", "1", ":", ...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/combinat/permutation.py#L4778-L4818
napari/napari
dbf4158e801fa7a429de8ef1cdee73bf6d64c61e
napari/utils/colormaps/vendored/colors.py
python
LightSource.__init__
(self, azdeg=315, altdeg=45, hsv_min_val=0, hsv_max_val=1, hsv_min_sat=1, hsv_max_sat=0)
Specify the azimuth (measured clockwise from south) and altitude (measured up from the plane of the surface) of the light source in degrees. Parameters ---------- azdeg : number, optional The azimuth (0-360, degrees clockwise from North) of the light source. Defaults to 315 degrees (from the northwest). altdeg : number, optional The altitude (0-90, degrees up from horizontal) of the light source. Defaults to 45 degrees from horizontal. Notes ----- For backwards compatibility, the parameters *hsv_min_val*, *hsv_max_val*, *hsv_min_sat*, and *hsv_max_sat* may be supplied at initialization as well. However, these parameters will only be used if "blend_mode='hsv'" is passed into :meth:`shade` or :meth:`shade_rgb`. See the documentation for :meth:`blend_hsv` for more details.
Specify the azimuth (measured clockwise from south) and altitude (measured up from the plane of the surface) of the light source in degrees.
[ "Specify", "the", "azimuth", "(", "measured", "clockwise", "from", "south", ")", "and", "altitude", "(", "measured", "up", "from", "the", "plane", "of", "the", "surface", ")", "of", "the", "light", "source", "in", "degrees", "." ]
def __init__(self, azdeg=315, altdeg=45, hsv_min_val=0, hsv_max_val=1, hsv_min_sat=1, hsv_max_sat=0): """ Specify the azimuth (measured clockwise from south) and altitude (measured up from the plane of the surface) of the light source in degrees. Parameters ---------- azdeg : number, optional The azimuth (0-360, degrees clockwise from North) of the light source. Defaults to 315 degrees (from the northwest). altdeg : number, optional The altitude (0-90, degrees up from horizontal) of the light source. Defaults to 45 degrees from horizontal. Notes ----- For backwards compatibility, the parameters *hsv_min_val*, *hsv_max_val*, *hsv_min_sat*, and *hsv_max_sat* may be supplied at initialization as well. However, these parameters will only be used if "blend_mode='hsv'" is passed into :meth:`shade` or :meth:`shade_rgb`. See the documentation for :meth:`blend_hsv` for more details. """ self.azdeg = azdeg self.altdeg = altdeg self.hsv_min_val = hsv_min_val self.hsv_max_val = hsv_max_val self.hsv_min_sat = hsv_min_sat self.hsv_max_sat = hsv_max_sat
[ "def", "__init__", "(", "self", ",", "azdeg", "=", "315", ",", "altdeg", "=", "45", ",", "hsv_min_val", "=", "0", ",", "hsv_max_val", "=", "1", ",", "hsv_min_sat", "=", "1", ",", "hsv_max_sat", "=", "0", ")", ":", "self", ".", "azdeg", "=", "azdeg"...
https://github.com/napari/napari/blob/dbf4158e801fa7a429de8ef1cdee73bf6d64c61e/napari/utils/colormaps/vendored/colors.py#L1378-L1407
jparkhill/TensorMol
d52104dc7ee46eec8301d332a95d672270ac0bd1
TensorMol/Containers/TensorMolData.py
python
TensorMolData.RawBatch
(self,nmol = 4096)
return Ins,Outs
Shimmy Shimmy Ya Shimmy Ya Shimmy Yay. This type of batch is not built beforehand because there's no real digestion involved. Args: nmol: number of molecules to put in the output. Returns: Ins: a #atomsX4 tensor (AtNum,x,y,z) Outs: output of the digester Keys: (nmol)X(MaxNAtoms) tensor listing each molecule's place in the input.
Shimmy Shimmy Ya Shimmy Ya Shimmy Yay. This type of batch is not built beforehand because there's no real digestion involved.
[ "Shimmy", "Shimmy", "Ya", "Shimmy", "Ya", "Shimmy", "Yay", ".", "This", "type", "of", "batch", "is", "not", "built", "beforehand", "because", "there", "s", "no", "real", "digestion", "involved", "." ]
def RawBatch(self,nmol = 4096): """ Shimmy Shimmy Ya Shimmy Ya Shimmy Yay. This type of batch is not built beforehand because there's no real digestion involved. Args: nmol: number of molecules to put in the output. Returns: Ins: a #atomsX4 tensor (AtNum,x,y,z) Outs: output of the digester Keys: (nmol)X(MaxNAtoms) tensor listing each molecule's place in the input. """ ndone = 0 natdone = 0 self.MaxNAtoms = self.set.MaxNAtoms() Ins = np.zeros(tuple([nmol,self.MaxNAtoms,4])) Outs = np.zeros(tuple([nmol,self.MaxNAtoms,3])) while (ndone<nmol): try: m = next(self.raw_it) # print "m props", m.properties.keys() # print "m coords", m.coords ti, to = self.dig.Emb(m, True, False) n=ti.shape[0] Ins[ndone,:n,:] = ti.copy() Outs[ndone,:n,:] = to.copy() ndone += 1 natdone += n except StopIteration: self.raw_it = iter(self.set.mols) return Ins,Outs
[ "def", "RawBatch", "(", "self", ",", "nmol", "=", "4096", ")", ":", "ndone", "=", "0", "natdone", "=", "0", "self", ".", "MaxNAtoms", "=", "self", ".", "set", ".", "MaxNAtoms", "(", ")", "Ins", "=", "np", ".", "zeros", "(", "tuple", "(", "[", "...
https://github.com/jparkhill/TensorMol/blob/d52104dc7ee46eec8301d332a95d672270ac0bd1/TensorMol/Containers/TensorMolData.py#L139-L172
Pymol-Scripts/Pymol-script-repo
bcd7bb7812dc6db1595953dfa4471fa15fb68c77
modules/pdb2pqr/contrib/numpy-1.1.0/numpy/f2py/lib/extgen/setup_py.py
python
SetupPy.execute
(self, *args)
return r
Run generated setup.py file with given arguments.
Run generated setup.py file with given arguments.
[ "Run", "generated", "setup", ".", "py", "file", "with", "given", "arguments", "." ]
def execute(self, *args): """ Run generated setup.py file with given arguments. """ if not args: raise ValueError('need setup.py arguments') self.info(self.generate(dry_run=False)) cmd = [sys.executable,'setup.py'] + list(args) self.info('entering %r directory' % (self.path)) self.info('executing command %r' % (' '.join(cmd))) try: r = exec_command(cmd, execute_in=self.path, use_tee=False) except: self.info('leaving %r directory' % (self.path)) raise else: self.info('leaving %r directory' % (self.path)) return r
[ "def", "execute", "(", "self", ",", "*", "args", ")", ":", "if", "not", "args", ":", "raise", "ValueError", "(", "'need setup.py arguments'", ")", "self", ".", "info", "(", "self", ".", "generate", "(", "dry_run", "=", "False", ")", ")", "cmd", "=", ...
https://github.com/Pymol-Scripts/Pymol-script-repo/blob/bcd7bb7812dc6db1595953dfa4471fa15fb68c77/modules/pdb2pqr/contrib/numpy-1.1.0/numpy/f2py/lib/extgen/setup_py.py#L99-L116