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
log2timeline/dftimewolf
18b4d0760d6a6ca378ac06c2242d04a0d8caf072
dftimewolf/lib/processors/workspace_audit_timesketch.py
python
WorkspaceAuditTimesketch._ExtractActorInformation
( self, actor_dict: Dict[str, str])
return { 'actor_email': actor_dict.get('email'), 'actor_profileId': actor_dict.get('profileId'), 'actor_callerType': actor_dict.get('callerType'), 'actor_key': actor_dict.get('key')}
Extracts actor information from a Workspace log record. Args: actor_dict (dict): contents of the 'actor' dict in a Workspace log record Returns: dict[str, str]: a dictionary containing actor information suitable for adding to a Timesketch record.
Extracts actor information from a Workspace log record.
[ "Extracts", "actor", "information", "from", "a", "Workspace", "log", "record", "." ]
def _ExtractActorInformation( self, actor_dict: Dict[str, str]) -> Dict[str, Optional[str]]: """Extracts actor information from a Workspace log record. Args: actor_dict (dict): contents of the 'actor' dict in a Workspace log record Returns: dict[str, str]: a dictionary containing actor information suitable for adding to a Timesketch record. """ return { 'actor_email': actor_dict.get('email'), 'actor_profileId': actor_dict.get('profileId'), 'actor_callerType': actor_dict.get('callerType'), 'actor_key': actor_dict.get('key')}
[ "def", "_ExtractActorInformation", "(", "self", ",", "actor_dict", ":", "Dict", "[", "str", ",", "str", "]", ")", "->", "Dict", "[", "str", ",", "Optional", "[", "str", "]", "]", ":", "return", "{", "'actor_email'", ":", "actor_dict", ".", "get", "(", ...
https://github.com/log2timeline/dftimewolf/blob/18b4d0760d6a6ca378ac06c2242d04a0d8caf072/dftimewolf/lib/processors/workspace_audit_timesketch.py#L42-L57
tendenci/tendenci
0f2c348cc0e7d41bc56f50b00ce05544b083bf1d
tendenci/apps/memberships/admin.py
python
NoticeAdmin.clone
(self, request, pk)
return redirect(reverse( 'admin:memberships_notice_change', args=[notice_clone.pk], ))
Make a clone of this notice.
Make a clone of this notice.
[ "Make", "a", "clone", "of", "this", "notice", "." ]
def clone(self, request, pk): """ Make a clone of this notice. """ notice = get_object_or_404(Notice, pk=pk) notice_clone = Notice() ignore_fields = ['guid', 'id', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username'] field_names = [field.name for field in notice.__class__._meta.fields if field.name not in ignore_fields] for name in field_names: setattr(notice_clone, name, getattr(notice, name)) notice_clone.notice_name = 'Clone of %s' % notice_clone.notice_name notice_clone.creator = request.user notice_clone.creator_username = request.user.username notice_clone.owner = request.user notice_clone.owner_username = request.user.username notice_clone.save() return redirect(reverse( 'admin:memberships_notice_change', args=[notice_clone.pk], ))
[ "def", "clone", "(", "self", ",", "request", ",", "pk", ")", ":", "notice", "=", "get_object_or_404", "(", "Notice", ",", "pk", "=", "pk", ")", "notice_clone", "=", "Notice", "(", ")", "ignore_fields", "=", "[", "'guid'", ",", "'id'", ",", "'create_dt'...
https://github.com/tendenci/tendenci/blob/0f2c348cc0e7d41bc56f50b00ce05544b083bf1d/tendenci/apps/memberships/admin.py#L876-L903
OpenZWave/python-openzwave
8be4c070294348f3fc268bc1d7ad2c535f352f5a
src-api/openzwave/node.py
python
ZWaveNode.is_beaming_device
(self)
return self._network.manager.isNodeBeamingDevice(self.home_id, self.object_id)
Is this node a beaming device. :rtype: bool
Is this node a beaming device.
[ "Is", "this", "node", "a", "beaming", "device", "." ]
def is_beaming_device(self): """ Is this node a beaming device. :rtype: bool """ return self._network.manager.isNodeBeamingDevice(self.home_id, self.object_id)
[ "def", "is_beaming_device", "(", "self", ")", ":", "return", "self", ".", "_network", ".", "manager", ".", "isNodeBeamingDevice", "(", "self", ".", "home_id", ",", "self", ".", "object_id", ")" ]
https://github.com/OpenZWave/python-openzwave/blob/8be4c070294348f3fc268bc1d7ad2c535f352f5a/src-api/openzwave/node.py#L657-L664
csparpa/pyowm
0474b61cc67fa3c95f9e572b96d3248031828fce
pyowm/airpollutionapi30/ozone.py
python
Ozone.reception_time
(self, timeformat='unix')
return formatting.timeformat(self.rec_time, timeformat)
Returns the GMT time telling when the O3 observation has been received from the OWM Weather API :param timeformat: the format for the time value. May be: '*unix*' (default) for UNIX time '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00:00`` '*date* for ``datetime.datetime`` object instance :type timeformat: str :returns: an int or a str :raises: ValueError when negative values are provided
Returns the GMT time telling when the O3 observation has been received from the OWM Weather API
[ "Returns", "the", "GMT", "time", "telling", "when", "the", "O3", "observation", "has", "been", "received", "from", "the", "OWM", "Weather", "API" ]
def reception_time(self, timeformat='unix'): """ Returns the GMT time telling when the O3 observation has been received from the OWM Weather API :param timeformat: the format for the time value. May be: '*unix*' (default) for UNIX time '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00:00`` '*date* for ``datetime.datetime`` object instance :type timeformat: str :returns: an int or a str :raises: ValueError when negative values are provided """ return formatting.timeformat(self.rec_time, timeformat)
[ "def", "reception_time", "(", "self", ",", "timeformat", "=", "'unix'", ")", ":", "return", "formatting", ".", "timeformat", "(", "self", ".", "rec_time", ",", "timeformat", ")" ]
https://github.com/csparpa/pyowm/blob/0474b61cc67fa3c95f9e572b96d3248031828fce/pyowm/airpollutionapi30/ozone.py#L60-L74
mthbernardes/ARTLAS
e5fdd8d6b01fb36adada8a79687597053b6b8332
artlas_datadog.py
python
display_logs
(self, query: str, start: datetime, end: datetime, limit: int = 1000, cli: bool = True)
[]
def display_logs(self, query: str, start: datetime, end: datetime, limit: int = 1000, cli: bool = True): logs = list_logs(self,query, start, end, limit) if cli: for log in logs: print(json.dumps(log)) else: sent_log=[] for log in logs: if "body" in log['content']['attributes']: if "errors" in log['content']['attributes']['body']: log['content']['attributes']['body']['errors'] = "" sent_log.append(log['content']) return sent_log
[ "def", "display_logs", "(", "self", ",", "query", ":", "str", ",", "start", ":", "datetime", ",", "end", ":", "datetime", ",", "limit", ":", "int", "=", "1000", ",", "cli", ":", "bool", "=", "True", ")", ":", "logs", "=", "list_logs", "(", "self", ...
https://github.com/mthbernardes/ARTLAS/blob/e5fdd8d6b01fb36adada8a79687597053b6b8332/artlas_datadog.py#L99-L116
microsoft/nlp-recipes
7db6d204e5116da07bb3c549df546e49cb7ab5a5
utils_nlp/models/transformers/extractive_summarization.py
python
ExtractiveSummarizer.__init__
( self, processor, model_name="distilbert-base-uncased", encoder="transformer", max_pos_length=512, cache_dir=".", )
Initialize a ExtractiveSummarizer. Args: model_name (str, optional): Transformer model name used in preprocessing. check MODEL_CLASS for supported models. Defaults to "distilbert-base-uncased". encoder (str, optional): Encoder algorithm used by summarization layer. There are four options: - baseline: it used a smaller transformer model to replace the bert model and with transformer summarization layer. - classifier: it uses pretrained BERT and fine-tune BERT with simple logistic classification summarization layer. - transformer: it uses pretrained BERT and fine-tune BERT with transformer summarization layer. - RNN: it uses pretrained BERT and fine-tune BERT with LSTM summarization layer. Defaults to "transformer". cache_dir (str, optional): Directory to cache the tokenizer. Defaults to ".".
Initialize a ExtractiveSummarizer.
[ "Initialize", "a", "ExtractiveSummarizer", "." ]
def __init__( self, processor, model_name="distilbert-base-uncased", encoder="transformer", max_pos_length=512, cache_dir=".", ): """Initialize a ExtractiveSummarizer. Args: model_name (str, optional): Transformer model name used in preprocessing. check MODEL_CLASS for supported models. Defaults to "distilbert-base-uncased". encoder (str, optional): Encoder algorithm used by summarization layer. There are four options: - baseline: it used a smaller transformer model to replace the bert model and with transformer summarization layer. - classifier: it uses pretrained BERT and fine-tune BERT with simple logistic classification summarization layer. - transformer: it uses pretrained BERT and fine-tune BERT with transformer summarization layer. - RNN: it uses pretrained BERT and fine-tune BERT with LSTM summarization layer. Defaults to "transformer". cache_dir (str, optional): Directory to cache the tokenizer. Defaults to ".". """ model = MODEL_CLASS[model_name].from_pretrained( model_name, cache_dir=cache_dir, num_labels=0, output_loading_info=False ) super().__init__(model_name=model_name, model=model, cache_dir=cache_dir) if model_name not in self.list_supported_models(): raise ValueError( "Model name {} is not supported by ExtractiveSummarizer. " "Call 'ExtractiveSummarizer.list_supported_models()' to get all " "supported model names.".format(model_name) ) self.processor = processor self.max_pos_length = max_pos_length self.model_class = MODEL_CLASS[model_name] default_summarizer_layer_parameters = { "ff_size": 512, "heads": 4, "dropout": 0.1, "inter_layers": 2, "hidden_size": 128, "rnn_size": 512, "param_init": 0.0, "param_init_glorot": True, } args = Bunch(default_summarizer_layer_parameters) self.model = BertSumExt( encoder, args, self.model_class, model_name, max_pos_length, None, cache_dir )
[ "def", "__init__", "(", "self", ",", "processor", ",", "model_name", "=", "\"distilbert-base-uncased\"", ",", "encoder", "=", "\"transformer\"", ",", "max_pos_length", "=", "512", ",", "cache_dir", "=", "\".\"", ",", ")", ":", "model", "=", "MODEL_CLASS", "[",...
https://github.com/microsoft/nlp-recipes/blob/7db6d204e5116da07bb3c549df546e49cb7ab5a5/utils_nlp/models/transformers/extractive_summarization.py#L560-L617
nladuo/taobao_bra_crawler
99b13b893b467c7c58ff5fd7367d197ccdfd7a44
lib/model.py
python
Item.dict
(self)
return { 'item_id': self.item_id, 'seller_id': self.seller_id, 'title': self.title, 'is_crawled': self.is_crawled }
将数据转化为字典
将数据转化为字典
[ "将数据转化为字典" ]
def dict(self): """ 将数据转化为字典 """ return { 'item_id': self.item_id, 'seller_id': self.seller_id, 'title': self.title, 'is_crawled': self.is_crawled }
[ "def", "dict", "(", "self", ")", ":", "return", "{", "'item_id'", ":", "self", ".", "item_id", ",", "'seller_id'", ":", "self", ".", "seller_id", ",", "'title'", ":", "self", ".", "title", ",", "'is_crawled'", ":", "self", ".", "is_crawled", "}" ]
https://github.com/nladuo/taobao_bra_crawler/blob/99b13b893b467c7c58ff5fd7367d197ccdfd7a44/lib/model.py#L12-L19
maxbbraun/trump2cash
0733b6cd2982cb626e0e69fd699eba539c1a35b4
trading.py
python
Trading.utc_to_market_time
(self, timestamp)
return market_time
Converts a UTC timestamp to local market time.
Converts a UTC timestamp to local market time.
[ "Converts", "a", "UTC", "timestamp", "to", "local", "market", "time", "." ]
def utc_to_market_time(self, timestamp): """Converts a UTC timestamp to local market time.""" utc_time = utc.localize(timestamp) market_time = utc_time.astimezone(MARKET_TIMEZONE) return market_time
[ "def", "utc_to_market_time", "(", "self", ",", "timestamp", ")", ":", "utc_time", "=", "utc", ".", "localize", "(", "timestamp", ")", "market_time", "=", "utc_time", ".", "astimezone", "(", "MARKET_TIMEZONE", ")", "return", "market_time" ]
https://github.com/maxbbraun/trump2cash/blob/0733b6cd2982cb626e0e69fd699eba539c1a35b4/trading.py#L328-L334
epi052/recon-pipeline
7659658ec706ff7a523231ca5bf04ec464b5ae49
pipeline/recon-pipeline.py
python
cluge_package_imports
(name, package)
project's module imports; need to cluge the package to handle relative imports at this level putting into a function for testability
project's module imports; need to cluge the package to handle relative imports at this level
[ "project", "s", "module", "imports", ";", "need", "to", "cluge", "the", "package", "to", "handle", "relative", "imports", "at", "this", "level" ]
def cluge_package_imports(name, package): """ project's module imports; need to cluge the package to handle relative imports at this level putting into a function for testability """ if name == "__main__" and package is None: file = Path(__file__).expanduser().resolve() parent, top = file.parent, file.parents[1] sys.path.append(str(top)) try: sys.path.remove(str(parent)) except ValueError: # already gone pass import pipeline # noqa: F401 sys.modules[name].__package__ = "pipeline"
[ "def", "cluge_package_imports", "(", "name", ",", "package", ")", ":", "if", "name", "==", "\"__main__\"", "and", "package", "is", "None", ":", "file", "=", "Path", "(", "__file__", ")", ".", "expanduser", "(", ")", ".", "resolve", "(", ")", "parent", ...
https://github.com/epi052/recon-pipeline/blob/7659658ec706ff7a523231ca5bf04ec464b5ae49/pipeline/recon-pipeline.py#L34-L51
zllrunning/video-object-removal
121f0b8359a534bae6afcd31fd0f486d10ee712a
get_mask/utils/bbox_helper.py
python
corner2center
(corner)
:param corner: Corner or np.array 4*N :return: Center or 4 np.array N
:param corner: Corner or np.array 4*N :return: Center or 4 np.array N
[ ":", "param", "corner", ":", "Corner", "or", "np", ".", "array", "4", "*", "N", ":", "return", ":", "Center", "or", "4", "np", ".", "array", "N" ]
def corner2center(corner): """ :param corner: Corner or np.array 4*N :return: Center or 4 np.array N """ if isinstance(corner, Corner): x1, y1, x2, y2 = corner return Center((x1 + x2) * 0.5, (y1 + y2) * 0.5, (x2 - x1), (y2 - y1)) else: x1, y1, x2, y2 = corner[0], corner[1], corner[2], corner[3] x = (x1 + x2) * 0.5 y = (y1 + y2) * 0.5 w = x2 - x1 h = y2 - y1 return x, y, w, h
[ "def", "corner2center", "(", "corner", ")", ":", "if", "isinstance", "(", "corner", ",", "Corner", ")", ":", "x1", ",", "y1", ",", "x2", ",", "y2", "=", "corner", "return", "Center", "(", "(", "x1", "+", "x2", ")", "*", "0.5", ",", "(", "y1", "...
https://github.com/zllrunning/video-object-removal/blob/121f0b8359a534bae6afcd31fd0f486d10ee712a/get_mask/utils/bbox_helper.py#L14-L28
alpacahq/pylivetrader
2d9bf97103814409ba8b56a4291f2655c59514ee
pylivetrader/protocol.py
python
_DeprecatedSidLookupPosition.__init__
(self, sid)
[]
def __init__(self, sid): self.sid = sid self.amount = 0 self.cost_basis = 0.0 # per share self.last_sale_price = 0.0 self.last_sale_date = None
[ "def", "__init__", "(", "self", ",", "sid", ")", ":", "self", ".", "sid", "=", "sid", "self", ".", "amount", "=", "0", "self", ".", "cost_basis", "=", "0.0", "# per share", "self", ".", "last_sale_price", "=", "0.0", "self", ".", "last_sale_date", "=",...
https://github.com/alpacahq/pylivetrader/blob/2d9bf97103814409ba8b56a4291f2655c59514ee/pylivetrader/protocol.py#L264-L269
zzzeek/sqlalchemy
fc5c54fcd4d868c2a4c7ac19668d72f506fe821e
examples/performance/short_selects.py
python
test_orm_query_new_style
(n)
new style ORM select() of the full entity.
new style ORM select() of the full entity.
[ "new", "style", "ORM", "select", "()", "of", "the", "full", "entity", "." ]
def test_orm_query_new_style(n): """new style ORM select() of the full entity.""" session = Session(bind=engine) for id_ in random.sample(ids, n): stmt = future_select(Customer).where(Customer.id == id_) session.execute(stmt).scalar_one()
[ "def", "test_orm_query_new_style", "(", "n", ")", ":", "session", "=", "Session", "(", "bind", "=", "engine", ")", "for", "id_", "in", "random", ".", "sample", "(", "ids", ",", "n", ")", ":", "stmt", "=", "future_select", "(", "Customer", ")", ".", "...
https://github.com/zzzeek/sqlalchemy/blob/fc5c54fcd4d868c2a4c7ac19668d72f506fe821e/examples/performance/short_selects.py#L77-L83
sosreport/sos
900e8bea7f3cd36c1dd48f3cbb351ab92f766654
sos/policies/runtimes/__init__.py
python
ContainerRuntime.fmt_container_cmd
(self, container, cmd, quotecmd)
return "%s %s %s" % (self.run_cmd, container, quoted_cmd)
Format a command to run inside a container using the runtime :param container: The name or ID of the container in which to run :type container: ``str`` :param cmd: The command to run inside `container` :type cmd: ``str`` :param quotecmd: Whether the cmd should be quoted. :type quotecmd: ``bool`` :returns: Formatted string to run `cmd` inside `container` :rtype: ``str``
Format a command to run inside a container using the runtime
[ "Format", "a", "command", "to", "run", "inside", "a", "container", "using", "the", "runtime" ]
def fmt_container_cmd(self, container, cmd, quotecmd): """Format a command to run inside a container using the runtime :param container: The name or ID of the container in which to run :type container: ``str`` :param cmd: The command to run inside `container` :type cmd: ``str`` :param quotecmd: Whether the cmd should be quoted. :type quotecmd: ``bool`` :returns: Formatted string to run `cmd` inside `container` :rtype: ``str`` """ if quotecmd: quoted_cmd = quote(cmd) else: quoted_cmd = cmd return "%s %s %s" % (self.run_cmd, container, quoted_cmd)
[ "def", "fmt_container_cmd", "(", "self", ",", "container", ",", "cmd", ",", "quotecmd", ")", ":", "if", "quotecmd", ":", "quoted_cmd", "=", "quote", "(", "cmd", ")", "else", ":", "quoted_cmd", "=", "cmd", "return", "\"%s %s %s\"", "%", "(", "self", ".", ...
https://github.com/sosreport/sos/blob/900e8bea7f3cd36c1dd48f3cbb351ab92f766654/sos/policies/runtimes/__init__.py#L144-L163
garywiz/chaperone
9ff2c3a5b9c6820f8750320a564ea214042df06f
chaperone/cutil/syslog.py
python
SyslogServer.__init__
(self, logsock = "/dev/log", datagram = True, **kwargs)
[]
def __init__(self, logsock = "/dev/log", datagram = True, **kwargs): super().__init__(**kwargs) self._datagram = datagram self._log_socket = logsock try: os.remove(logsock) except Exception: pass
[ "def", "__init__", "(", "self", ",", "logsock", "=", "\"/dev/log\"", ",", "datagram", "=", "True", ",", "*", "*", "kwargs", ")", ":", "super", "(", ")", ".", "__init__", "(", "*", "*", "kwargs", ")", "self", ".", "_datagram", "=", "datagram", "self",...
https://github.com/garywiz/chaperone/blob/9ff2c3a5b9c6820f8750320a564ea214042df06f/chaperone/cutil/syslog.py#L210-L219
CedricGuillemet/Imogen
ee417b42747ed5b46cb11b02ef0c3630000085b3
bin/Lib/email/iterators.py
python
walk
(self)
Walk over the message tree, yielding each subpart. The walk is performed in depth-first order. This method is a generator.
Walk over the message tree, yielding each subpart.
[ "Walk", "over", "the", "message", "tree", "yielding", "each", "subpart", "." ]
def walk(self): """Walk over the message tree, yielding each subpart. The walk is performed in depth-first order. This method is a generator. """ yield self if self.is_multipart(): for subpart in self.get_payload(): yield from subpart.walk()
[ "def", "walk", "(", "self", ")", ":", "yield", "self", "if", "self", ".", "is_multipart", "(", ")", ":", "for", "subpart", "in", "self", ".", "get_payload", "(", ")", ":", "yield", "from", "subpart", ".", "walk", "(", ")" ]
https://github.com/CedricGuillemet/Imogen/blob/ee417b42747ed5b46cb11b02ef0c3630000085b3/bin/Lib/email/iterators.py#L20-L29
allenai/allennlp
a3d71254fcc0f3615910e9c3d48874515edf53e0
allennlp/data/instance.py
python
Instance.add_field
(self, field_name: str, field: Field, vocab: Vocabulary = None)
Add the field to the existing fields mapping. If we have already indexed the Instance, then we also index `field`, so it is necessary to supply the vocab.
Add the field to the existing fields mapping. If we have already indexed the Instance, then we also index `field`, so it is necessary to supply the vocab.
[ "Add", "the", "field", "to", "the", "existing", "fields", "mapping", ".", "If", "we", "have", "already", "indexed", "the", "Instance", "then", "we", "also", "index", "field", "so", "it", "is", "necessary", "to", "supply", "the", "vocab", "." ]
def add_field(self, field_name: str, field: Field, vocab: Vocabulary = None) -> None: """ Add the field to the existing fields mapping. If we have already indexed the Instance, then we also index `field`, so it is necessary to supply the vocab. """ self.fields[field_name] = field if self.indexed and vocab is not None: field.index(vocab)
[ "def", "add_field", "(", "self", ",", "field_name", ":", "str", ",", "field", ":", "Field", ",", "vocab", ":", "Vocabulary", "=", "None", ")", "->", "None", ":", "self", ".", "fields", "[", "field_name", "]", "=", "field", "if", "self", ".", "indexed...
https://github.com/allenai/allennlp/blob/a3d71254fcc0f3615910e9c3d48874515edf53e0/allennlp/data/instance.py#L45-L53
dipy/dipy
be956a529465b28085f8fc435a756947ddee1c89
dipy/align/metrics.py
python
SimilarityMetric.__init__
(self, dim)
r""" Similarity Metric abstract class A similarity metric is in charge of keeping track of the numerical value of the similarity (or distance) between the two given images. It also computes the update field for the forward and inverse displacement fields to be used in a gradient-based optimization algorithm. Note that this metric does not depend on any transformation (affine or non-linear) so it assumes the static and moving images are already warped Parameters ---------- dim : int (either 2 or 3) the dimension of the image domain
r""" Similarity Metric abstract class
[ "r", "Similarity", "Metric", "abstract", "class" ]
def __init__(self, dim): r""" Similarity Metric abstract class A similarity metric is in charge of keeping track of the numerical value of the similarity (or distance) between the two given images. It also computes the update field for the forward and inverse displacement fields to be used in a gradient-based optimization algorithm. Note that this metric does not depend on any transformation (affine or non-linear) so it assumes the static and moving images are already warped Parameters ---------- dim : int (either 2 or 3) the dimension of the image domain """ self.dim = dim self.levels_above = None self.levels_below = None self.static_image = None self.static_affine = None self.static_spacing = None self.static_direction = None self.moving_image = None self.moving_affine = None self.moving_spacing = None self.moving_direction = None self.mask0 = False
[ "def", "__init__", "(", "self", ",", "dim", ")", ":", "self", ".", "dim", "=", "dim", "self", ".", "levels_above", "=", "None", "self", ".", "levels_below", "=", "None", "self", ".", "static_image", "=", "None", "self", ".", "static_affine", "=", "None...
https://github.com/dipy/dipy/blob/be956a529465b28085f8fc435a756947ddee1c89/dipy/align/metrics.py#L16-L45
trakt/Plex-Trakt-Scrobbler
aeb0bfbe62fad4b06c164f1b95581da7f35dce0b
Trakttv.bundle/Contents/Libraries/MacOSX/x86_64/ucs4/cryptography/x509/base.py
python
CertificateBuilder.add_extension
(self, extension, critical)
return CertificateBuilder( self._issuer_name, self._subject_name, self._public_key, self._serial_number, self._not_valid_before, self._not_valid_after, self._extensions + [extension] )
Adds an X.509 extension to the certificate.
Adds an X.509 extension to the certificate.
[ "Adds", "an", "X", ".", "509", "extension", "to", "the", "certificate", "." ]
def add_extension(self, extension, critical): """ Adds an X.509 extension to the certificate. """ if not isinstance(extension, ExtensionType): raise TypeError("extension must be an ExtensionType") extension = Extension(extension.oid, critical, extension) # TODO: This is quadratic in the number of extensions for e in self._extensions: if e.oid == extension.oid: raise ValueError('This extension has already been set.') return CertificateBuilder( self._issuer_name, self._subject_name, self._public_key, self._serial_number, self._not_valid_before, self._not_valid_after, self._extensions + [extension] )
[ "def", "add_extension", "(", "self", ",", "extension", ",", "critical", ")", ":", "if", "not", "isinstance", "(", "extension", ",", "ExtensionType", ")", ":", "raise", "TypeError", "(", "\"extension must be an ExtensionType\"", ")", "extension", "=", "Extension", ...
https://github.com/trakt/Plex-Trakt-Scrobbler/blob/aeb0bfbe62fad4b06c164f1b95581da7f35dce0b/Trakttv.bundle/Contents/Libraries/MacOSX/x86_64/ucs4/cryptography/x509/base.py#L503-L521
google/python-adb
f4e597fe55900651a8a91fccc1e09061fd96b5e9
adb/adb_protocol.py
python
AdbMessage.Open
(cls, usb, destination, timeout_ms=None)
return _AdbConnection(usb, local_id, remote_id, timeout_ms)
Opens a new connection to the device via an OPEN message. Not the same as the posix 'open' or any other google3 Open methods. Args: usb: USB device handle with BulkRead and BulkWrite methods. destination: The service:command string. timeout_ms: Timeout in milliseconds for USB packets. Raises: InvalidResponseError: Wrong local_id sent to us. InvalidCommandError: Didn't get a ready response. Returns: The local connection id.
Opens a new connection to the device via an OPEN message.
[ "Opens", "a", "new", "connection", "to", "the", "device", "via", "an", "OPEN", "message", "." ]
def Open(cls, usb, destination, timeout_ms=None): """Opens a new connection to the device via an OPEN message. Not the same as the posix 'open' or any other google3 Open methods. Args: usb: USB device handle with BulkRead and BulkWrite methods. destination: The service:command string. timeout_ms: Timeout in milliseconds for USB packets. Raises: InvalidResponseError: Wrong local_id sent to us. InvalidCommandError: Didn't get a ready response. Returns: The local connection id. """ local_id = 1 msg = cls( command=b'OPEN', arg0=local_id, arg1=0, data=destination + b'\0') msg.Send(usb, timeout_ms) cmd, remote_id, their_local_id, _ = cls.Read(usb, [b'CLSE', b'OKAY'], timeout_ms=timeout_ms) if local_id != their_local_id: raise InvalidResponseError( 'Expected the local_id to be {}, got {}'.format(local_id, their_local_id)) if cmd == b'CLSE': # Some devices seem to be sending CLSE once more after a request, this *should* handle it cmd, remote_id, their_local_id, _ = cls.Read(usb, [b'CLSE', b'OKAY'], timeout_ms=timeout_ms) # Device doesn't support this service. if cmd == b'CLSE': return None if cmd != b'OKAY': raise InvalidCommandError('Expected a ready response, got {}'.format(cmd), cmd, (remote_id, their_local_id)) return _AdbConnection(usb, local_id, remote_id, timeout_ms)
[ "def", "Open", "(", "cls", ",", "usb", ",", "destination", ",", "timeout_ms", "=", "None", ")", ":", "local_id", "=", "1", "msg", "=", "cls", "(", "command", "=", "b'OPEN'", ",", "arg0", "=", "local_id", ",", "arg1", "=", "0", ",", "data", "=", "...
https://github.com/google/python-adb/blob/f4e597fe55900651a8a91fccc1e09061fd96b5e9/adb/adb_protocol.py#L351-L388
Confusezius/Deep-Metric-Learning-Baselines
60772745e28bc90077831bb4c9f07a233e602797
losses.py
python
TupleSampler.distanceweightedsampling
(self, batch, labels, lower_cutoff=0.5, upper_cutoff=1.4)
return sampled_triplets
This methods finds all available triplets in a batch given by the classes provided in labels, and select triplets based on distance sampling introduced in 'Sampling Matters in Deep Embedding Learning'. Args: batch: np.ndarray or torch.Tensor, batch-wise embedded training samples. labels: np.ndarray or torch.Tensor, ground truth labels corresponding to batch. lower_cutoff: float, lower cutoff value for negatives that are too close to anchor embeddings. Set to literature value. They will be assigned a zero-sample probability. upper_cutoff: float, upper cutoff value for positives that are too far away from the anchor embeddings. Set to literature value. They will be assigned a zero-sample probability. Returns: list of sampled data tuples containing reference indices to the position IN THE BATCH.
This methods finds all available triplets in a batch given by the classes provided in labels, and select triplets based on distance sampling introduced in 'Sampling Matters in Deep Embedding Learning'.
[ "This", "methods", "finds", "all", "available", "triplets", "in", "a", "batch", "given", "by", "the", "classes", "provided", "in", "labels", "and", "select", "triplets", "based", "on", "distance", "sampling", "introduced", "in", "Sampling", "Matters", "in", "D...
def distanceweightedsampling(self, batch, labels, lower_cutoff=0.5, upper_cutoff=1.4): """ This methods finds all available triplets in a batch given by the classes provided in labels, and select triplets based on distance sampling introduced in 'Sampling Matters in Deep Embedding Learning'. Args: batch: np.ndarray or torch.Tensor, batch-wise embedded training samples. labels: np.ndarray or torch.Tensor, ground truth labels corresponding to batch. lower_cutoff: float, lower cutoff value for negatives that are too close to anchor embeddings. Set to literature value. They will be assigned a zero-sample probability. upper_cutoff: float, upper cutoff value for positives that are too far away from the anchor embeddings. Set to literature value. They will be assigned a zero-sample probability. Returns: list of sampled data tuples containing reference indices to the position IN THE BATCH. """ if isinstance(labels, torch.Tensor): labels = labels.detach().cpu().numpy() bs = batch.shape[0] distances = self.pdist(batch.detach()).clamp(min=lower_cutoff) positives, negatives = [],[] labels_visited = [] anchors = [] for i in range(bs): neg = labels!=labels[i]; pos = labels==labels[i] q_d_inv = self.inverse_sphere_distances(batch, distances[i], labels, labels[i]) #Sample positives randomly pos[i] = 0 positives.append(np.random.choice(np.where(pos)[0])) #Sample negatives by distance negatives.append(np.random.choice(bs,p=q_d_inv)) sampled_triplets = [[a,p,n] for a,p,n in zip(list(range(bs)), positives, negatives)] return sampled_triplets
[ "def", "distanceweightedsampling", "(", "self", ",", "batch", ",", "labels", ",", "lower_cutoff", "=", "0.5", ",", "upper_cutoff", "=", "1.4", ")", ":", "if", "isinstance", "(", "labels", ",", "torch", ".", "Tensor", ")", ":", "labels", "=", "labels", "....
https://github.com/Confusezius/Deep-Metric-Learning-Baselines/blob/60772745e28bc90077831bb4c9f07a233e602797/losses.py#L199-L233
numba/numba
bf480b9e0da858a65508c2b17759a72ee6a44c51
numba/cuda/cudadecl.py
python
_gen
(l_key, supported_types)
return Cuda_atomic
[]
def _gen(l_key, supported_types): @register class Cuda_atomic(AbstractTemplate): key = l_key def generic(self, args, kws): assert not kws ary, idx, val = args if ary.dtype not in supported_types: return if ary.ndim == 1: return signature(ary.dtype, ary, types.intp, ary.dtype) elif ary.ndim > 1: return signature(ary.dtype, ary, idx, ary.dtype) return Cuda_atomic
[ "def", "_gen", "(", "l_key", ",", "supported_types", ")", ":", "@", "register", "class", "Cuda_atomic", "(", "AbstractTemplate", ")", ":", "key", "=", "l_key", "def", "generic", "(", "self", ",", "args", ",", "kws", ")", ":", "assert", "not", "kws", "a...
https://github.com/numba/numba/blob/bf480b9e0da858a65508c2b17759a72ee6a44c51/numba/cuda/cudadecl.py#L366-L382
AstroPrint/AstroBox
e7e3b8a7d33ea85fcb6b2696869c0d719ceb8b75
src/ext/makerbot_pyserial/serialutil.py
python
SerialBase.getInterCharTimeout
(self)
return self._interCharTimeout
Get the current inter-character timeout setting.
Get the current inter-character timeout setting.
[ "Get", "the", "current", "inter", "-", "character", "timeout", "setting", "." ]
def getInterCharTimeout(self): """Get the current inter-character timeout setting.""" return self._interCharTimeout
[ "def", "getInterCharTimeout", "(", "self", ")", ":", "return", "self", ".", "_interCharTimeout" ]
https://github.com/AstroPrint/AstroBox/blob/e7e3b8a7d33ea85fcb6b2696869c0d719ceb8b75/src/ext/makerbot_pyserial/serialutil.py#L456-L458
CedricGuillemet/Imogen
ee417b42747ed5b46cb11b02ef0c3630000085b3
bin/Lib/pickletools.py
python
read_unicodestring1
(f)
r""" >>> import io >>> s = 'abcd\uabcd' >>> enc = s.encode('utf-8') >>> enc b'abcd\xea\xaf\x8d' >>> n = bytes([len(enc)]) # little-endian 1-byte length >>> t = read_unicodestring1(io.BytesIO(n + enc + b'junk')) >>> s == t True >>> read_unicodestring1(io.BytesIO(n + enc[:-1])) Traceback (most recent call last): ... ValueError: expected 7 bytes in a unicodestring1, but only 6 remain
r""" >>> import io >>> s = 'abcd\uabcd' >>> enc = s.encode('utf-8') >>> enc b'abcd\xea\xaf\x8d' >>> n = bytes([len(enc)]) # little-endian 1-byte length >>> t = read_unicodestring1(io.BytesIO(n + enc + b'junk')) >>> s == t True
[ "r", ">>>", "import", "io", ">>>", "s", "=", "abcd", "\\", "uabcd", ">>>", "enc", "=", "s", ".", "encode", "(", "utf", "-", "8", ")", ">>>", "enc", "b", "abcd", "\\", "xea", "\\", "xaf", "\\", "x8d", ">>>", "n", "=", "bytes", "(", "[", "len",...
def read_unicodestring1(f): r""" >>> import io >>> s = 'abcd\uabcd' >>> enc = s.encode('utf-8') >>> enc b'abcd\xea\xaf\x8d' >>> n = bytes([len(enc)]) # little-endian 1-byte length >>> t = read_unicodestring1(io.BytesIO(n + enc + b'junk')) >>> s == t True >>> read_unicodestring1(io.BytesIO(n + enc[:-1])) Traceback (most recent call last): ... ValueError: expected 7 bytes in a unicodestring1, but only 6 remain """ n = read_uint1(f) assert n >= 0 data = f.read(n) if len(data) == n: return str(data, 'utf-8', 'surrogatepass') raise ValueError("expected %d bytes in a unicodestring1, but only %d " "remain" % (n, len(data)))
[ "def", "read_unicodestring1", "(", "f", ")", ":", "n", "=", "read_uint1", "(", "f", ")", "assert", "n", ">=", "0", "data", "=", "f", ".", "read", "(", "n", ")", "if", "len", "(", "data", ")", "==", "n", ":", "return", "str", "(", "data", ",", ...
https://github.com/CedricGuillemet/Imogen/blob/ee417b42747ed5b46cb11b02ef0c3630000085b3/bin/Lib/pickletools.py#L594-L618
lad1337/XDM
0c1b7009fe00f06f102a6f67c793478f515e7efe
site-packages/logilab/common/configuration.py
python
OptionsProviderMixIn.get_option_def
(self, opt)
return the dictionary defining an option given it's name
return the dictionary defining an option given it's name
[ "return", "the", "dictionary", "defining", "an", "option", "given", "it", "s", "name" ]
def get_option_def(self, opt): """return the dictionary defining an option given it's name""" assert self.options for option in self.options: if option[0] == opt: return option[1] raise OptionError('no such option %s in section %r' % (opt, self.name), opt)
[ "def", "get_option_def", "(", "self", ",", "opt", ")", ":", "assert", "self", ".", "options", "for", "option", "in", "self", ".", "options", ":", "if", "option", "[", "0", "]", "==", "opt", ":", "return", "option", "[", "1", "]", "raise", "OptionErro...
https://github.com/lad1337/XDM/blob/0c1b7009fe00f06f102a6f67c793478f515e7efe/site-packages/logilab/common/configuration.py#L853-L860
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/numpy/oldnumeric/ma.py
python
_minimum_operation.reduce
(self, target, axis=0)
Reduce target along the given axis.
Reduce target along the given axis.
[ "Reduce", "target", "along", "the", "given", "axis", "." ]
def reduce (self, target, axis=0): """Reduce target along the given axis.""" m = getmask(target) if m is nomask: t = filled(target) return masked_array (umath.minimum.reduce (t, axis)) else: t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis) m = umath.logical_and.reduce(m, axis) return masked_array(t, m, get_fill_value(target))
[ "def", "reduce", "(", "self", ",", "target", ",", "axis", "=", "0", ")", ":", "m", "=", "getmask", "(", "target", ")", "if", "m", "is", "nomask", ":", "t", "=", "filled", "(", "target", ")", "return", "masked_array", "(", "umath", ".", "minimum", ...
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/numpy/oldnumeric/ma.py#L2000-L2009
materialsproject/pymatgen
8128f3062a334a2edd240e4062b5b9bdd1ae6f58
pymatgen/vis/structure_vtk.py
python
MultiStructuresVis.display_warning
(self, warning)
Args: warning (str): Warning
Args: warning (str): Warning
[ "Args", ":", "warning", "(", "str", ")", ":", "Warning" ]
def display_warning(self, warning): """ Args: warning (str): Warning """ self.warningtxt_mapper = vtk.vtkTextMapper() tprops = self.warningtxt_mapper.GetTextProperty() tprops.SetFontSize(14) tprops.SetFontFamilyToTimes() tprops.SetColor(1, 0, 0) tprops.BoldOn() tprops.SetJustificationToRight() self.warningtxt = f"WARNING : {warning}" self.warningtxt_actor = vtk.vtkActor2D() self.warningtxt_actor.VisibilityOn() self.warningtxt_actor.SetMapper(self.warningtxt_mapper) self.ren.AddActor(self.warningtxt_actor) self.warningtxt_mapper.SetInput(self.warningtxt) winsize = self.ren_win.GetSize() self.warningtxt_actor.SetPosition(winsize[0] - 10, 10) self.warningtxt_actor.VisibilityOn()
[ "def", "display_warning", "(", "self", ",", "warning", ")", ":", "self", ".", "warningtxt_mapper", "=", "vtk", ".", "vtkTextMapper", "(", ")", "tprops", "=", "self", ".", "warningtxt_mapper", ".", "GetTextProperty", "(", ")", "tprops", ".", "SetFontSize", "(...
https://github.com/materialsproject/pymatgen/blob/8128f3062a334a2edd240e4062b5b9bdd1ae6f58/pymatgen/vis/structure_vtk.py#L1151-L1171
wrobstory/vincent
c5a06e50179015fbb788a7a42e4570ff4467a9e9
vincent/scales.py
python
Scale.points
(value)
boolean : If True, distribute ordinal values over evenly spaced points between ``range_min`` and ``range_max`` Ignored for non-ordinal scales.
boolean : If True, distribute ordinal values over evenly spaced points between ``range_min`` and ``range_max``
[ "boolean", ":", "If", "True", "distribute", "ordinal", "values", "over", "evenly", "spaced", "points", "between", "range_min", "and", "range_max" ]
def points(value): """boolean : If True, distribute ordinal values over evenly spaced points between ``range_min`` and ``range_max`` Ignored for non-ordinal scales. """
[ "def", "points", "(", "value", ")", ":" ]
https://github.com/wrobstory/vincent/blob/c5a06e50179015fbb788a7a42e4570ff4467a9e9/vincent/scales.py#L128-L133
triaquae/triaquae
bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9
TriAquae/models/Ubuntu_12/paramiko/rsakey.py
python
RSAKey.get_bits
(self)
return self.size
[]
def get_bits(self): return self.size
[ "def", "get_bits", "(", "self", ")", ":", "return", "self", ".", "size" ]
https://github.com/triaquae/triaquae/blob/bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9/TriAquae/models/Ubuntu_12/paramiko/rsakey.py#L82-L83
Chaffelson/nipyapi
d3b186fd701ce308c2812746d98af9120955e810
nipyapi/nifi/models/node_event_dto.py
python
NodeEventDTO.to_dict
(self)
return result
Returns the model properties as a dict
Returns the model properties as a dict
[ "Returns", "the", "model", "properties", "as", "a", "dict" ]
def to_dict(self): """ Returns the model properties as a dict """ result = {} for attr, _ in iteritems(self.swagger_types): value = getattr(self, attr) if isinstance(value, list): result[attr] = list(map( lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value )) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): result[attr] = dict(map( lambda item: (item[0], item[1].to_dict()) if hasattr(item[1], "to_dict") else item, value.items() )) else: result[attr] = value return result
[ "def", "to_dict", "(", "self", ")", ":", "result", "=", "{", "}", "for", "attr", ",", "_", "in", "iteritems", "(", "self", ".", "swagger_types", ")", ":", "value", "=", "getattr", "(", "self", ",", "attr", ")", "if", "isinstance", "(", "value", ","...
https://github.com/Chaffelson/nipyapi/blob/d3b186fd701ce308c2812746d98af9120955e810/nipyapi/nifi/models/node_event_dto.py#L130-L154
asyml/texar
a23f021dae289a3d768dc099b220952111da04fd
examples/seq2seq_exposure_bias/interpolation_helper.py
python
calc_reward
(refs, hypo, unk_id, metric)
calculate the reward given hypo and refs and will return bleu score if metric is 'bleu' or return sum of (Rouge-1, Rouge-2, Rouge-L) if metric is 'rouge'
calculate the reward given hypo and refs and will return bleu score if metric is 'bleu' or return sum of (Rouge-1, Rouge-2, Rouge-L) if metric is 'rouge'
[ "calculate", "the", "reward", "given", "hypo", "and", "refs", "and", "will", "return", "bleu", "score", "if", "metric", "is", "bleu", "or", "return", "sum", "of", "(", "Rouge", "-", "1", "Rouge", "-", "2", "Rouge", "-", "L", ")", "if", "metric", "is"...
def calc_reward(refs, hypo, unk_id, metric): """ calculate the reward given hypo and refs and will return bleu score if metric is 'bleu' or return sum of (Rouge-1, Rouge-2, Rouge-L) if metric is 'rouge' """ if len(hypo) == 0 or len(refs[0]) == 0: return 0. for i in range(len(hypo)): assert isinstance(hypo[i], int) if hypo[i] == unk_id: hypo[i] = -1 if metric == 'bleu': return 0.01 * sentence_bleu( references=refs, hypothesis=hypo, smooth=True) else: ref_str = ' '.join([str(word) for word in refs[0]]) hypo_str = ' '.join([str(word) for word in hypo]) rouge_scores = \ rouge.get_scores(hyps=[hypo_str], refs=[ref_str], avg=True) return sum([value['f'] for key, value in rouge_scores.items()])
[ "def", "calc_reward", "(", "refs", ",", "hypo", ",", "unk_id", ",", "metric", ")", ":", "if", "len", "(", "hypo", ")", "==", "0", "or", "len", "(", "refs", "[", "0", "]", ")", "==", "0", ":", "return", "0.", "for", "i", "in", "range", "(", "l...
https://github.com/asyml/texar/blob/a23f021dae289a3d768dc099b220952111da04fd/examples/seq2seq_exposure_bias/interpolation_helper.py#L30-L52
eg4000/SKU110K_CVPR19
1fb83d6d0e5fd0fef8d53d25940ebd6f8d027020
object_detector_retinanet/keras_retinanet/utils/EmMerger.py
python
DuplicateMerger.get_contour_indexes
(self, contour, contour_bbox, x, y)
return original_indexes
[]
def get_contour_indexes(self, contour, contour_bbox, x, y): original_indexes = (contour_bbox[BOX.X1] <= x) & (x <= contour_bbox[BOX.X2]) & ( contour_bbox[BOX.Y1] <= y) & (y <= contour_bbox[BOX.Y2]) return original_indexes
[ "def", "get_contour_indexes", "(", "self", ",", "contour", ",", "contour_bbox", ",", "x", ",", "y", ")", ":", "original_indexes", "=", "(", "contour_bbox", "[", "BOX", ".", "X1", "]", "<=", "x", ")", "&", "(", "x", "<=", "contour_bbox", "[", "BOX", "...
https://github.com/eg4000/SKU110K_CVPR19/blob/1fb83d6d0e5fd0fef8d53d25940ebd6f8d027020/object_detector_retinanet/keras_retinanet/utils/EmMerger.py#L263-L266
enthought/mayavi
2103a273568b8f0bd62328801aafbd6252543ae8
mayavi/core/engine.py
python
Engine.add_scene
(self, scene, name=None)
Add given `scene` (a `pyface.tvtk.scene.Scene` instance) to the mayavi engine so that mayavi can manage the scene. This is used when the user creates a scene. Note that for the `EnvisageEngine` this is automatically taken care of when you create a new scene using the TVTK scene plugin. Parameters: ----------- scene - `pyface.tvtk.scene.Scene` The scene that needs to be managed from mayavi. name - `str` The name assigned to the scene. It tries to determine the name of the scene from the passed scene instance. If this is not possible it defaults to 'Mayavi Scene'.
Add given `scene` (a `pyface.tvtk.scene.Scene` instance) to the mayavi engine so that mayavi can manage the scene. This is used when the user creates a scene. Note that for the `EnvisageEngine` this is automatically taken care of when you create a new scene using the TVTK scene plugin.
[ "Add", "given", "scene", "(", "a", "pyface", ".", "tvtk", ".", "scene", ".", "Scene", "instance", ")", "to", "the", "mayavi", "engine", "so", "that", "mayavi", "can", "manage", "the", "scene", ".", "This", "is", "used", "when", "the", "user", "creates"...
def add_scene(self, scene, name=None): """Add given `scene` (a `pyface.tvtk.scene.Scene` instance) to the mayavi engine so that mayavi can manage the scene. This is used when the user creates a scene. Note that for the `EnvisageEngine` this is automatically taken care of when you create a new scene using the TVTK scene plugin. Parameters: ----------- scene - `pyface.tvtk.scene.Scene` The scene that needs to be managed from mayavi. name - `str` The name assigned to the scene. It tries to determine the name of the scene from the passed scene instance. If this is not possible it defaults to 'Mayavi Scene'. """ if name is None: if hasattr(scene, 'name'): name = scene.name else: name = 'Mayavi Scene %d'%next(scene_id_generator) s = Scene(scene=scene, name=name, parent=self) s.start() # We don't want the startup setup to be recorded. recorder = self.recorder self.scenes.append(s) self.current_scene = s if recorder is not None: recorder.register(s)
[ "def", "add_scene", "(", "self", ",", "scene", ",", "name", "=", "None", ")", ":", "if", "name", "is", "None", ":", "if", "hasattr", "(", "scene", ",", "'name'", ")", ":", "name", "=", "scene", ".", "name", "else", ":", "name", "=", "'Mayavi Scene ...
https://github.com/enthought/mayavi/blob/2103a273568b8f0bd62328801aafbd6252543ae8/mayavi/core/engine.py#L346-L379
numba/numba
bf480b9e0da858a65508c2b17759a72ee6a44c51
numba/core/analysis.py
python
compute_dead_maps
(cfg, blocks, live_map, var_def_map)
return _dead_maps_result(internal=internal_dead_map, escaping=escaping_dead_map, combined=combined)
Compute the end-of-live information for variables. `live_map` contains a mapping of block offset to all the living variables at the ENTRY of the block.
Compute the end-of-live information for variables. `live_map` contains a mapping of block offset to all the living variables at the ENTRY of the block.
[ "Compute", "the", "end", "-", "of", "-", "live", "information", "for", "variables", ".", "live_map", "contains", "a", "mapping", "of", "block", "offset", "to", "all", "the", "living", "variables", "at", "the", "ENTRY", "of", "the", "block", "." ]
def compute_dead_maps(cfg, blocks, live_map, var_def_map): """ Compute the end-of-live information for variables. `live_map` contains a mapping of block offset to all the living variables at the ENTRY of the block. """ # The following three dictionaries will be # { block offset -> set of variables to delete } # all vars that should be deleted at the start of the successors escaping_dead_map = defaultdict(set) # all vars that should be deleted within this block internal_dead_map = defaultdict(set) # all vars that should be deleted after the function exit exit_dead_map = defaultdict(set) for offset, ir_block in blocks.items(): # live vars WITHIN the block will include all the locally # defined variables cur_live_set = live_map[offset] | var_def_map[offset] # vars alive in the outgoing blocks outgoing_live_map = dict((out_blk, live_map[out_blk]) for out_blk, _data in cfg.successors(offset)) # vars to keep alive for the terminator terminator_liveset = set(v.name for v in ir_block.terminator.list_vars()) # vars to keep alive in the successors combined_liveset = reduce(operator.or_, outgoing_live_map.values(), set()) # include variables used in terminator combined_liveset |= terminator_liveset # vars that are dead within the block because they are not # propagated to any outgoing blocks internal_set = cur_live_set - combined_liveset internal_dead_map[offset] = internal_set # vars that escape this block escaping_live_set = cur_live_set - internal_set for out_blk, new_live_set in outgoing_live_map.items(): # successor should delete the unused escaped vars new_live_set = new_live_set | var_def_map[out_blk] escaping_dead_map[out_blk] |= escaping_live_set - new_live_set # if no outgoing blocks if not outgoing_live_map: # insert var used by terminator exit_dead_map[offset] = terminator_liveset # Verify that the dead maps cover all live variables all_vars = reduce(operator.or_, live_map.values(), set()) internal_dead_vars = reduce(operator.or_, internal_dead_map.values(), set()) escaping_dead_vars = reduce(operator.or_, escaping_dead_map.values(), set()) exit_dead_vars = reduce(operator.or_, exit_dead_map.values(), set()) dead_vars = (internal_dead_vars | escaping_dead_vars | exit_dead_vars) missing_vars = all_vars - dead_vars if missing_vars: # There are no exit points if not cfg.exit_points(): # We won't be able to verify this pass else: msg = 'liveness info missing for vars: {0}'.format(missing_vars) raise RuntimeError(msg) combined = dict((k, internal_dead_map[k] | escaping_dead_map[k]) for k in blocks) return _dead_maps_result(internal=internal_dead_map, escaping=escaping_dead_map, combined=combined)
[ "def", "compute_dead_maps", "(", "cfg", ",", "blocks", ",", "live_map", ",", "var_def_map", ")", ":", "# The following three dictionaries will be", "# { block offset -> set of variables to delete }", "# all vars that should be deleted at the start of the successors", "escaping_dead_map...
https://github.com/numba/numba/blob/bf480b9e0da858a65508c2b17759a72ee6a44c51/numba/core/analysis.py#L118-L187
FeiSun/BERT4Rec
615eaf2004abecda487a38d5b0c72f3dcfcae5b3
modeling.py
python
BertModel.__init__
(self, config, is_training, input_ids, input_mask=None, token_type_ids=None, use_one_hot_embeddings=True, scope=None)
Constructor for BertModel. Args: config: `BertConfig` instance. is_training: bool. rue for training model, false for eval model. Controls whether dropout will be applied. input_ids: int32 Tensor of shape [batch_size, seq_length]. input_mask: (optional) int32 Tensor of shape [batch_size, seq_length]. token_type_ids: (optional) int32 Tensor of shape [batch_size, seq_length]. use_one_hot_embeddings: (optional) bool. Whether to use one-hot word embeddings or tf.embedding_lookup() for the word embeddings. On the TPU, it is must faster if this is True, on the CPU or GPU, it is faster if this is False. scope: (optional) variable scope. Defaults to "bert". Raises: ValueError: The config is invalid or one of the input tensor shapes is invalid.
Constructor for BertModel.
[ "Constructor", "for", "BertModel", "." ]
def __init__(self, config, is_training, input_ids, input_mask=None, token_type_ids=None, use_one_hot_embeddings=True, scope=None): """Constructor for BertModel. Args: config: `BertConfig` instance. is_training: bool. rue for training model, false for eval model. Controls whether dropout will be applied. input_ids: int32 Tensor of shape [batch_size, seq_length]. input_mask: (optional) int32 Tensor of shape [batch_size, seq_length]. token_type_ids: (optional) int32 Tensor of shape [batch_size, seq_length]. use_one_hot_embeddings: (optional) bool. Whether to use one-hot word embeddings or tf.embedding_lookup() for the word embeddings. On the TPU, it is must faster if this is True, on the CPU or GPU, it is faster if this is False. scope: (optional) variable scope. Defaults to "bert". Raises: ValueError: The config is invalid or one of the input tensor shapes is invalid. """ config = copy.deepcopy(config) if not is_training: config.hidden_dropout_prob = 0.0 config.attention_probs_dropout_prob = 0.0 input_shape = get_shape_list(input_ids, expected_rank=2) batch_size = input_shape[0] seq_length = input_shape[1] if input_mask is None: input_mask = tf.ones( shape=[batch_size, seq_length], dtype=tf.int32) if token_type_ids is None: token_type_ids = tf.zeros( shape=[batch_size, seq_length], dtype=tf.int32) with tf.variable_scope(scope, default_name="bert"): with tf.variable_scope("embeddings"): # Perform embedding lookup on the word ids. (self.embedding_output, self.embedding_table) = embedding_lookup( input_ids=input_ids, vocab_size=config.vocab_size, embedding_size=config.hidden_size, initializer_range=config.initializer_range, word_embedding_name="word_embeddings", use_one_hot_embeddings=use_one_hot_embeddings) # Add positional embeddings and token type embeddings, then layer # normalize and perform dropout. self.embedding_output = embedding_postprocessor( input_tensor=self.embedding_output, use_token_type=True, token_type_ids=token_type_ids, token_type_vocab_size=config.type_vocab_size, token_type_embedding_name="token_type_embeddings", use_position_embeddings=True, position_embedding_name="position_embeddings", initializer_range=config.initializer_range, max_position_embeddings=config.max_position_embeddings, dropout_prob=config.hidden_dropout_prob) with tf.variable_scope("encoder"): # This converts a 2D mask of shape [batch_size, seq_length] to a 3D # mask of shape [batch_size, seq_length, seq_length] which is used # for the attention scores. attention_mask = create_attention_mask_from_input_mask( input_ids, input_mask) # Run the stacked transformer. # `sequence_output` shape = [batch_size, seq_length, hidden_size]. self.all_encoder_layers = transformer_model( input_tensor=self.embedding_output, attention_mask=attention_mask, hidden_size=config.hidden_size, num_hidden_layers=config.num_hidden_layers, num_attention_heads=config.num_attention_heads, intermediate_size=config.intermediate_size, intermediate_act_fn=get_activation(config.hidden_act), hidden_dropout_prob=config.hidden_dropout_prob, attention_probs_dropout_prob=config. attention_probs_dropout_prob, initializer_range=config.initializer_range, do_return_all_layers=True) self.sequence_output = self.all_encoder_layers[-1]
[ "def", "__init__", "(", "self", ",", "config", ",", "is_training", ",", "input_ids", ",", "input_mask", "=", "None", ",", "token_type_ids", "=", "None", ",", "use_one_hot_embeddings", "=", "True", ",", "scope", "=", "None", ")", ":", "config", "=", "copy",...
https://github.com/FeiSun/BERT4Rec/blob/615eaf2004abecda487a38d5b0c72f3dcfcae5b3/modeling.py#L116-L209
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_openshift/library/oc_adm_manage_node.py
python
Yedit.get_entry
(data, key, sep='.')
return data
Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c
Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c
[ "Get", "an", "item", "from", "a", "dictionary", "with", "key", "notation", "a", ".", "b", ".", "c", "d", "=", "{", "a", ":", "{", "b", ":", "c", "}}}", "key", "=", "a", ".", "b", "return", "c" ]
def get_entry(data, key, sep='.'): ''' Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c ''' if key == '': pass elif (not (key and Yedit.valid_key(key, sep)) and isinstance(data, (list, dict))): return None key_indexes = Yedit.parse_key(key, sep) for arr_ind, dict_key in key_indexes: if dict_key and isinstance(data, dict): data = data.get(dict_key) elif (arr_ind and isinstance(data, list) and int(arr_ind) <= len(data) - 1): data = data[int(arr_ind)] else: return None return data
[ "def", "get_entry", "(", "data", ",", "key", ",", "sep", "=", "'.'", ")", ":", "if", "key", "==", "''", ":", "pass", "elif", "(", "not", "(", "key", "and", "Yedit", ".", "valid_key", "(", "key", ",", "sep", ")", ")", "and", "isinstance", "(", "...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_openshift/library/oc_adm_manage_node.py#L330-L352
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_hxb2/lib/python3.5/site-packages/chardet/jpcntx.py
python
JapaneseContextAnalysis.got_enough_data
(self)
return self._total_rel > self.ENOUGH_REL_THRESHOLD
[]
def got_enough_data(self): return self._total_rel > self.ENOUGH_REL_THRESHOLD
[ "def", "got_enough_data", "(", "self", ")", ":", "return", "self", ".", "_total_rel", ">", "self", ".", "ENOUGH_REL_THRESHOLD" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/chardet/jpcntx.py#L170-L171
JimmXinu/FanFicFare
bc149a2deb2636320fe50a3e374af6eef8f61889
fanficfare/adapters/adapter_fictionlive.py
python
FictionLiveAdapter.add_chapters
(self, data)
[]
def add_chapters(self, data): ## chapter urls are for the api. they return json and aren't user-navigatable, or the same as on the website chunkrange_url = "https://fiction.live/api/anonkun/chapters/{s_id}/{start}/{end}/" ## api url to get content of a multi route chapter. requires only the route id and no timestamps route_chunkrange_url = "https://fiction.live/api/anonkun/route/{c_id}/chapters" def add_chapter_url(title, bounds): "Adds a chapter url based on the start/end chunk-range timestamps." start, end = bounds end -= 1 chapter_url = chunkrange_url.format(s_id = data['_id'], start = start, end = end) self.add_chapter(title, chapter_url) def add_route_chapter_url(title, route_id): "Adds a route chapter url based on the route id." chapter_url = route_chunkrange_url.format(c_id = route_id) self.add_chapter(title, chapter_url) def pair(iterable): "[1,2,3,4] -> [(1, 2), (2, 3), (3, 4)]" a, b = itertools.tee(iterable, 2) next(b, None) return list(zip(a, b)) ## first thing to do is seperate out the appendices appendices, maintext, routes = [], [], [] chapters = data['bm'] if 'bm' in data else [] ## not all stories use multiple routes. Those that do have a route id and a title for each route if 'route_metadata' in data and data['route_metadata']: for r in data['route_metadata']: # checking if route title even exists or is None, since most things in the api are optional if 't' in r and r['t'] is not None: title = r['t'] else: title = "" routes.append({"id": r['_id'], "title": title}) for c in chapters: appendices.append(c) if c['title'].startswith('#special') else maintext.append(c) ## main-text chapter extraction processing. *should* now handle all the edge cases. ## relies on fanficfare ignoring empty chapters! titles = [c['title'] for c in maintext] titles = ["Home"] + titles times = [c['ct'] for c in maintext] times = [data['ct']] + times + [self.most_recent_chunk + 2] # need to be 1 over, and add_url etc does -1 # doesn't actually run without the call to list. list(map(add_chapter_url, titles, pair(times))) for a in appendices: # add appendices afterwards chapter_start = a['ct'] chapter_title = "Appendix: " + a['title'][9:] # 'Appendix: ' rather than '#special' at beginning of name add_chapter_url(chapter_title, (chapter_start, chapter_start + 2)) # 1 msec range = this one chunk only for r in routes: # add route at the end, after appendices route_id = r['id'] # to get route chapter content, the route id is needed, not the timestamp chapter_title = "Route: " + r['title'] # 'Route: ' at beginning of name, since it's a multiroute chapter add_route_chapter_url(chapter_title, route_id)
[ "def", "add_chapters", "(", "self", ",", "data", ")", ":", "## chapter urls are for the api. they return json and aren't user-navigatable, or the same as on the website", "chunkrange_url", "=", "\"https://fiction.live/api/anonkun/chapters/{s_id}/{start}/{end}/\"", "## api url to get content ...
https://github.com/JimmXinu/FanFicFare/blob/bc149a2deb2636320fe50a3e374af6eef8f61889/fanficfare/adapters/adapter_fictionlive.py#L197-L260
mchristopher/PokemonGo-DesktopMap
ec37575f2776ee7d64456e2a1f6b6b78830b4fe0
app/pylibs/osx64/gevent/_socket3.py
python
socket.makefile
(self, mode="r", buffering=None, *, encoding=None, errors=None, newline=None)
return text
Return an I/O stream connected to the socket The arguments are as for io.open() after the filename, except the only mode characters supported are 'r', 'w' and 'b'. The semantics are similar too.
Return an I/O stream connected to the socket
[ "Return", "an", "I", "/", "O", "stream", "connected", "to", "the", "socket" ]
def makefile(self, mode="r", buffering=None, *, encoding=None, errors=None, newline=None): """Return an I/O stream connected to the socket The arguments are as for io.open() after the filename, except the only mode characters supported are 'r', 'w' and 'b'. The semantics are similar too. """ # (XXX refactor to share code?) for c in mode: if c not in {"r", "w", "b"}: raise ValueError("invalid mode %r (only r, w, b allowed)") writing = "w" in mode reading = "r" in mode or not writing assert reading or writing binary = "b" in mode rawmode = "" if reading: rawmode += "r" if writing: rawmode += "w" raw = SocketIO(self, rawmode) self._io_refs += 1 if buffering is None: buffering = -1 if buffering < 0: buffering = io.DEFAULT_BUFFER_SIZE if buffering == 0: if not binary: raise ValueError("unbuffered streams must be binary") return raw if reading and writing: buffer = io.BufferedRWPair(raw, raw, buffering) elif reading: buffer = io.BufferedReader(raw, buffering) else: assert writing buffer = io.BufferedWriter(raw, buffering) if binary: return buffer text = io.TextIOWrapper(buffer, encoding, errors, newline) text.mode = mode return text
[ "def", "makefile", "(", "self", ",", "mode", "=", "\"r\"", ",", "buffering", "=", "None", ",", "*", ",", "encoding", "=", "None", ",", "errors", "=", "None", ",", "newline", "=", "None", ")", ":", "# (XXX refactor to share code?)", "for", "c", "in", "m...
https://github.com/mchristopher/PokemonGo-DesktopMap/blob/ec37575f2776ee7d64456e2a1f6b6b78830b4fe0/app/pylibs/osx64/gevent/_socket3.py#L183-L225
JiYou/openstack
8607dd488bde0905044b303eb6e52bdea6806923
chap19/monitor/monitor/monitor/api/openstack/wsgi.py
python
XMLDeserializer.__init__
(self, metadata=None)
:param metadata: information needed to deserialize xml into a dictionary.
:param metadata: information needed to deserialize xml into a dictionary.
[ ":", "param", "metadata", ":", "information", "needed", "to", "deserialize", "xml", "into", "a", "dictionary", "." ]
def __init__(self, metadata=None): """ :param metadata: information needed to deserialize xml into a dictionary. """ super(XMLDeserializer, self).__init__() self.metadata = metadata or {}
[ "def", "__init__", "(", "self", ",", "metadata", "=", "None", ")", ":", "super", "(", "XMLDeserializer", ",", "self", ")", ".", "__init__", "(", ")", "self", ".", "metadata", "=", "metadata", "or", "{", "}" ]
https://github.com/JiYou/openstack/blob/8607dd488bde0905044b303eb6e52bdea6806923/chap19/monitor/monitor/monitor/api/openstack/wsgi.py#L143-L149
m-labs/artiq
eaa1505c947c7987cdbd31c24056823c740e84e0
artiq/coredevice/urukul.py
python
CPLD.cfg_switches
(self, state: TInt32)
Configure all four RF switches through the configuration register. :param state: RF switch state as a 4 bit integer.
Configure all four RF switches through the configuration register.
[ "Configure", "all", "four", "RF", "switches", "through", "the", "configuration", "register", "." ]
def cfg_switches(self, state: TInt32): """Configure all four RF switches through the configuration register. :param state: RF switch state as a 4 bit integer. """ self.cfg_write((self.cfg_reg & ~0xf) | state)
[ "def", "cfg_switches", "(", "self", ",", "state", ":", "TInt32", ")", ":", "self", ".", "cfg_write", "(", "(", "self", ".", "cfg_reg", "&", "~", "0xf", ")", "|", "state", ")" ]
https://github.com/m-labs/artiq/blob/eaa1505c947c7987cdbd31c24056823c740e84e0/artiq/coredevice/urukul.py#L280-L285
WPO-Foundation/wptagent
94470f007294213f900dcd9a207678b5b9fce5d3
internal/firefox_webdriver.py
python
FirefoxWebDriver.execute_js
(self, script)
return ret
Run JavaScript
Run JavaScript
[ "Run", "JavaScript" ]
def execute_js(self, script): """Run JavaScript""" if self.must_exit: return ret = None if self.driver is not None: try: self.driver.set_script_timeout(30) ret = self.driver.execute_script(script) except Exception: logging.exception('Error executing script') return ret
[ "def", "execute_js", "(", "self", ",", "script", ")", ":", "if", "self", ".", "must_exit", ":", "return", "ret", "=", "None", "if", "self", ".", "driver", "is", "not", "None", ":", "try", ":", "self", ".", "driver", ".", "set_script_timeout", "(", "3...
https://github.com/WPO-Foundation/wptagent/blob/94470f007294213f900dcd9a207678b5b9fce5d3/internal/firefox_webdriver.py#L126-L137
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_hxb2/lib/python3.5/site-packages/wagtail_bak/wagtailimages/wagtail_hooks.py
python
construct_admin_api
(router)
[]
def construct_admin_api(router): router.register_endpoint('images', ImagesAdminAPIEndpoint)
[ "def", "construct_admin_api", "(", "router", ")", ":", "router", ".", "register_endpoint", "(", "'images'", ",", "ImagesAdminAPIEndpoint", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/wagtail_bak/wagtailimages/wagtail_hooks.py#L30-L31
hugsy/gef
2975d5fc0307bdb4318d4d1c5e84f1d53246717e
gef.py
python
exit_handler
(event)
return
GDB event handler for exit cases.
GDB event handler for exit cases.
[ "GDB", "event", "handler", "for", "exit", "cases", "." ]
def exit_handler(event): """GDB event handler for exit cases.""" global __gef_remote__, __gef_qemu_mode__ reset_all_caches() __gef_qemu_mode__ = False if __gef_remote__ and get_gef_setting("gef-remote.clean_on_exit") is True: shutil.rmtree("/tmp/gef/{:d}".format(__gef_remote__)) __gef_remote__ = None return
[ "def", "exit_handler", "(", "event", ")", ":", "global", "__gef_remote__", ",", "__gef_qemu_mode__", "reset_all_caches", "(", ")", "__gef_qemu_mode__", "=", "False", "if", "__gef_remote__", "and", "get_gef_setting", "(", "\"gef-remote.clean_on_exit\"", ")", "is", "Tru...
https://github.com/hugsy/gef/blob/2975d5fc0307bdb4318d4d1c5e84f1d53246717e/gef.py#L3470-L3479
lisa-lab/pylearn2
af81e5c362f0df4df85c3e54e23b2adeec026055
pylearn2/models/dbm/layer.py
python
GaussianVisLayer.expected_energy_term
(self, state, average, state_below = None, average_below = None)
return rval
.. todo:: WRITEME
.. todo::
[ "..", "todo", "::" ]
def expected_energy_term(self, state, average, state_below = None, average_below = None): """ .. todo:: WRITEME """ assert state_below is None assert average_below is None self.space.validate(state) if average: raise NotImplementedError(str(type(self))+" doesn't support integrating out variational parameters yet.") else: rval = 0.5 * (self.beta * T.sqr(state - self.mu)).sum(axis=self.axes_to_sum) assert rval.ndim == 1 return rval
[ "def", "expected_energy_term", "(", "self", ",", "state", ",", "average", ",", "state_below", "=", "None", ",", "average_below", "=", "None", ")", ":", "assert", "state_below", "is", "None", "assert", "average_below", "is", "None", "self", ".", "space", ".",...
https://github.com/lisa-lab/pylearn2/blob/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/models/dbm/layer.py#L2286-L2300
4shadoww/hakkuframework
409a11fc3819d251f86faa3473439f8c19066a21
lib/scapy/contrib/lldp.py
python
LLDPDUPortID._check
(self)
run layer specific checks
run layer specific checks
[ "run", "layer", "specific", "checks" ]
def _check(self): """ run layer specific checks """ if conf.contribs['LLDP'].strict_mode() and not self.id: raise LLDPInvalidLengthField('id must be >= 1 characters long')
[ "def", "_check", "(", "self", ")", ":", "if", "conf", ".", "contribs", "[", "'LLDP'", "]", ".", "strict_mode", "(", ")", "and", "not", "self", ".", "id", ":", "raise", "LLDPInvalidLengthField", "(", "'id must be >= 1 characters long'", ")" ]
https://github.com/4shadoww/hakkuframework/blob/409a11fc3819d251f86faa3473439f8c19066a21/lib/scapy/contrib/lldp.py#L396-L401
krintoxi/NoobSec-Toolkit
38738541cbc03cedb9a3b3ed13b629f781ad64f6
NoobSecToolkit /scripts/sshbackdoors/backdoors/shell/pupy/pupy/packages/windows/amd64/psutil/_psbsd.py
python
Process.exe
(self)
return cext.proc_exe(self.pid)
[]
def exe(self): return cext.proc_exe(self.pid)
[ "def", "exe", "(", "self", ")", ":", "return", "cext", ".", "proc_exe", "(", "self", ".", "pid", ")" ]
https://github.com/krintoxi/NoobSec-Toolkit/blob/38738541cbc03cedb9a3b3ed13b629f781ad64f6/NoobSecToolkit /scripts/sshbackdoors/backdoors/shell/pupy/pupy/packages/windows/amd64/psutil/_psbsd.py#L276-L277
caiiiac/Machine-Learning-with-Python
1a26c4467da41ca4ebc3d5bd789ea942ef79422f
MachineLearning/venv/lib/python3.5/site-packages/pandas/plotting/_converter.py
python
TimeSeries_DateLocator.autoscale
(self)
return nonsingular(vmin, vmax)
Sets the view limits to the nearest multiples of base that contain the data.
Sets the view limits to the nearest multiples of base that contain the data.
[ "Sets", "the", "view", "limits", "to", "the", "nearest", "multiples", "of", "base", "that", "contain", "the", "data", "." ]
def autoscale(self): """ Sets the view limits to the nearest multiples of base that contain the data. """ # requires matplotlib >= 0.98.0 (vmin, vmax) = self.axis.get_data_interval() locs = self._get_default_locs(vmin, vmax) (vmin, vmax) = locs[[0, -1]] if vmin == vmax: vmin -= 1 vmax += 1 return nonsingular(vmin, vmax)
[ "def", "autoscale", "(", "self", ")", ":", "# requires matplotlib >= 0.98.0", "(", "vmin", ",", "vmax", ")", "=", "self", ".", "axis", ".", "get_data_interval", "(", ")", "locs", "=", "self", ".", "_get_default_locs", "(", "vmin", ",", "vmax", ")", "(", ...
https://github.com/caiiiac/Machine-Learning-with-Python/blob/1a26c4467da41ca4ebc3d5bd789ea942ef79422f/MachineLearning/venv/lib/python3.5/site-packages/pandas/plotting/_converter.py#L933-L946
spotify/luigi
c3b66f4a5fa7eaa52f9a72eb6704b1049035c789
luigi/scheduler.py
python
OrderedSet.peek
(self, last=True)
return key
[]
def peek(self, last=True): if not self: raise KeyError('set is empty') key = self.end[1][0] if last else self.end[2][0] return key
[ "def", "peek", "(", "self", ",", "last", "=", "True", ")", ":", "if", "not", "self", ":", "raise", "KeyError", "(", "'set is empty'", ")", "key", "=", "self", ".", "end", "[", "1", "]", "[", "0", "]", "if", "last", "else", "self", ".", "end", "...
https://github.com/spotify/luigi/blob/c3b66f4a5fa7eaa52f9a72eb6704b1049035c789/luigi/scheduler.py#L212-L216
log2timeline/plaso
fe2e316b8c76a0141760c0f2f181d84acb83abc2
plaso/parsers/plist_plugins/bluetooth.py
python
BluetoothPlugin._ParsePlist
(self, parser_mediator, match=None, **unused_kwargs)
Extracts relevant BT entries. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS.
Extracts relevant BT entries.
[ "Extracts", "relevant", "BT", "entries", "." ]
def _ParsePlist(self, parser_mediator, match=None, **unused_kwargs): """Extracts relevant BT entries. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS. """ device_cache = match.get('DeviceCache', {}) for device, value in device_cache.items(): name = value.get('Name', '') if name: name = ''.join(('Name:', name)) event_data = plist_event.PlistTimeEventData() event_data.root = '/DeviceCache' datetime_value = value.get('LastInquiryUpdate', None) if datetime_value: event_data.desc = ' '.join( filter(None, ('Bluetooth Discovery', name))) event_data.key = '{0:s}/LastInquiryUpdate'.format(device) date_time = dfdatetime_time_elements.TimeElementsInMicroseconds() date_time.CopyFromDatetime(datetime_value) event = time_events.DateTimeValuesEvent( date_time, definitions.TIME_DESCRIPTION_WRITTEN) parser_mediator.ProduceEventWithEventData(event, event_data) if device in match.get('PairedDevices', []): event_data.desc = 'Paired:True {0:s}'.format(name) event_data.key = device date_time = dfdatetime_time_elements.TimeElementsInMicroseconds() date_time.CopyFromDatetime(datetime_value) event = time_events.DateTimeValuesEvent( date_time, definitions.TIME_DESCRIPTION_WRITTEN) parser_mediator.ProduceEventWithEventData(event, event_data) datetime_value = value.get('LastNameUpdate', None) if datetime_value: event_data.desc = ' '.join(filter(None, ('Device Name Set', name))) event_data.key = '{0:s}/LastNameUpdate'.format(device) date_time = dfdatetime_time_elements.TimeElementsInMicroseconds() date_time.CopyFromDatetime(datetime_value) event = time_events.DateTimeValuesEvent( date_time, definitions.TIME_DESCRIPTION_WRITTEN) parser_mediator.ProduceEventWithEventData(event, event_data) datetime_value = value.get('LastServicesUpdate', None) if datetime_value: event_data.desc = ' '.join(filter(None, ('Services Updated', name))) event_data.key = '{0:s}/LastServicesUpdate'.format(device) date_time = dfdatetime_time_elements.TimeElementsInMicroseconds() date_time.CopyFromDatetime(datetime_value) event = time_events.DateTimeValuesEvent( date_time, definitions.TIME_DESCRIPTION_WRITTEN) parser_mediator.ProduceEventWithEventData(event, event_data)
[ "def", "_ParsePlist", "(", "self", ",", "parser_mediator", ",", "match", "=", "None", ",", "*", "*", "unused_kwargs", ")", ":", "device_cache", "=", "match", ".", "get", "(", "'DeviceCache'", ",", "{", "}", ")", "for", "device", ",", "value", "in", "de...
https://github.com/log2timeline/plaso/blob/fe2e316b8c76a0141760c0f2f181d84acb83abc2/plaso/parsers/plist_plugins/bluetooth.py#L41-L104
aestrivex/bctpy
32c7fe7345b281c2d4e184f5379c425c36f3bbc7
bct/algorithms/modularity.py
python
ci2ls
(ci)
return ls
Convert from a community index vector to a 2D python list of modules The list is a pure python list, not requiring numpy. Parameters ---------- ci : Nx1 np.ndarray the community index vector zeroindexed : bool If True, ci uses zero-indexing (lowest value is 0). Defaults to False. Returns ------- ls : listof(list) pure python list with lowest value zero-indexed (regardless of zero-indexing parameter)
Convert from a community index vector to a 2D python list of modules The list is a pure python list, not requiring numpy.
[ "Convert", "from", "a", "community", "index", "vector", "to", "a", "2D", "python", "list", "of", "modules", "The", "list", "is", "a", "pure", "python", "list", "not", "requiring", "numpy", "." ]
def ci2ls(ci): ''' Convert from a community index vector to a 2D python list of modules The list is a pure python list, not requiring numpy. Parameters ---------- ci : Nx1 np.ndarray the community index vector zeroindexed : bool If True, ci uses zero-indexing (lowest value is 0). Defaults to False. Returns ------- ls : listof(list) pure python list with lowest value zero-indexed (regardless of zero-indexing parameter) ''' if not np.size(ci): return ci # list is empty _, ci = np.unique(ci, return_inverse=True) ci += 1 nr_indices = int(max(ci)) ls = [] for c in range(nr_indices): ls.append([]) for i, x in enumerate(ci): ls[ci[i] - 1].append(i) return ls
[ "def", "ci2ls", "(", "ci", ")", ":", "if", "not", "np", ".", "size", "(", "ci", ")", ":", "return", "ci", "# list is empty", "_", ",", "ci", "=", "np", ".", "unique", "(", "ci", ",", "return_inverse", "=", "True", ")", "ci", "+=", "1", "nr_indice...
https://github.com/aestrivex/bctpy/blob/32c7fe7345b281c2d4e184f5379c425c36f3bbc7/bct/algorithms/modularity.py#L11-L39
omriher/CapTipper
3fb2836c0afe60eb6bd5902b4214f564268e9b4d
jsbeautifier/unpackers/packer.py
python
detect
(source)
return source.replace(' ', '').startswith('eval(function(p,a,c,k,e,r')
Detects whether `source` is P.A.C.K.E.R. coded.
Detects whether `source` is P.A.C.K.E.R. coded.
[ "Detects", "whether", "source", "is", "P", ".", "A", ".", "C", ".", "K", ".", "E", ".", "R", ".", "coded", "." ]
def detect(source): """Detects whether `source` is P.A.C.K.E.R. coded.""" return source.replace(' ', '').startswith('eval(function(p,a,c,k,e,r')
[ "def", "detect", "(", "source", ")", ":", "return", "source", ".", "replace", "(", "' '", ",", "''", ")", ".", "startswith", "(", "'eval(function(p,a,c,k,e,r'", ")" ]
https://github.com/omriher/CapTipper/blob/3fb2836c0afe60eb6bd5902b4214f564268e9b4d/jsbeautifier/unpackers/packer.py#L21-L23
lozuwa/impy
ddfaedf764c1cb2ced7f644a3a065715758874a5
impy/ImagePreprocess.py
python
ImagePreprocess.divideIntoPatches
(self, imageWidth = None, imageHeight = None, slideWindowSize = None, strideSize = None, padding = None, numberPatches = None)
Divides the image into NxM patches depending on the stride size, the sliding window size and the type of padding. Args: imageWidth: An int that represents the width of the image. imageHeight: An int that represents the height of the image. slideWindowSize: A tuple (width, height) that represents the size of the sliding window. strideSize: A tuple (width, height) that represents the amount of pixels to move on height and width direction. padding: A string ("VALID", "SAME", "VALID_FIT_ALL") that tells the type of padding. numberPatches: A tuple (numberWidth, numberHeight) that contains the number of patches in each axis. Return: A tuple containing the number of patches that fill the given parameters with the format(ix, iy, x, y), an int containing the number of row patches, an int containing the number of column patches
Divides the image into NxM patches depending on the stride size, the sliding window size and the type of padding. Args: imageWidth: An int that represents the width of the image. imageHeight: An int that represents the height of the image. slideWindowSize: A tuple (width, height) that represents the size of the sliding window. strideSize: A tuple (width, height) that represents the amount of pixels to move on height and width direction. padding: A string ("VALID", "SAME", "VALID_FIT_ALL") that tells the type of padding. numberPatches: A tuple (numberWidth, numberHeight) that contains the number of patches in each axis. Return: A tuple containing the number of patches that fill the given parameters with the format(ix, iy, x, y), an int containing the number of row patches, an int containing the number of column patches
[ "Divides", "the", "image", "into", "NxM", "patches", "depending", "on", "the", "stride", "size", "the", "sliding", "window", "size", "and", "the", "type", "of", "padding", ".", "Args", ":", "imageWidth", ":", "An", "int", "that", "represents", "the", "widt...
def divideIntoPatches(self, imageWidth = None, imageHeight = None, slideWindowSize = None, strideSize = None, padding = None, numberPatches = None): """ Divides the image into NxM patches depending on the stride size, the sliding window size and the type of padding. Args: imageWidth: An int that represents the width of the image. imageHeight: An int that represents the height of the image. slideWindowSize: A tuple (width, height) that represents the size of the sliding window. strideSize: A tuple (width, height) that represents the amount of pixels to move on height and width direction. padding: A string ("VALID", "SAME", "VALID_FIT_ALL") that tells the type of padding. numberPatches: A tuple (numberWidth, numberHeight) that contains the number of patches in each axis. Return: A tuple containing the number of patches that fill the given parameters with the format(ix, iy, x, y), an int containing the number of row patches, an int containing the number of column patches """ # Assertions if (imageWidth == None): raise Exception("Image width cannot be empty.") if (imageHeight == None): raise Exception("Image height cannot be empty.") if (slideWindowSize == None): slideWindowSize = (0, 0) if (strideSize == None): strideSize = (0, 0) if padding == None: padding = "VALID" if (numberPatches == None): numberPatches = (1, 1) # Get sliding window sizes slideWindowWidth, slideWindowHeight = slideWindowSize[0], slideWindowSize[1] if (slideWindowHeight > imageHeight): print("WARNING: Slide window for height is too big. Setting it to image's height.") slideWindowHeight = imageHeight - 1 # raise Exception("Slide window size is too big.") if (slideWindowWidth > imageWidth): print("WARNING: Slide window for width is too big. Setting it to image's width.") # raise Exception("Slide window size is too big.") slideWindowWidth = imageWidth - 1 # Get strides sizes strideWidth, strideHeight = strideSize[0], strideSize[1] if (strideHeight > imageHeight): print("WARNING: Stride height is too big. Setting it to image's height.") strideHeight = imageHeight - 1 # raise Exception("Stride size is too big.") if (strideWidth > imageWidth): print("WARNING: Stride width is too big. Setting it to image's width.") strideWidth = imageWidth - 1 # Start padding operation if padding == "VALID": startPixelsHeight = 0 endPixelsHeight = slideWindowHeight startPixelsWidth = 0 endPixelsWidth = slideWindowWidth patchesCoordinates = [] numberPatchesHeight, numberPatchesWidth = ImagePreprocess.get_valid_padding(slideWindowHeight, strideHeight, imageHeight, slideWindowWidth, strideWidth, imageWidth) # print("numberPatchesHeight: ", numberPatchesHeight, "numberPatchesWidth: ", numberPatchesWidth) for i in range(numberPatchesHeight): for j in range(numberPatchesWidth): patchesCoordinates.append([startPixelsWidth,\ startPixelsHeight,\ endPixelsWidth,\ endPixelsHeight]) # Update width with strides startPixelsWidth += strideWidth endPixelsWidth += strideWidth # Re-initialize the width parameters startPixelsWidth = 0 endPixelsWidth = slideWindowWidth # Update height with height stride size startPixelsHeight += strideHeight endPixelsHeight += strideHeight return patchesCoordinates,\ numberPatchesHeight,\ numberPatchesWidth elif padding == "SAME": startPixelsHeight = 0 endPixelsHeight = slideWindowHeight startPixelsWidth = 0 endPixelsWidth = slideWindowWidth patchesCoordinates = [] # Modify image tensor zeros_h, zeros_w = ImagePreprocess.get_same_padding(slideWindowHeight, strideHeight, imageHeight, slideWindowWidth, strideWidth, imageWidth) imageWidth += zeros_w imageHeight += zeros_h # Valid padding stride should fit exactly numberPatchesHeight, numberPatchesWidth = ImagePreprocess.get_valid_padding(slideWindowHeight, strideHeight, imageHeight, slideWindowWidth, strideWidth, imageWidth) for i in range(numberPatchesHeight): for j in range(numberPatchesWidth): patchesCoordinates.append([startPixelsWidth,\ startPixelsHeight,\ endPixelsWidth,\ endPixelsHeight]) # Update width with strides startPixelsWidth += strideWidth endPixelsWidth += strideWidth # Re-initialize the width parameters startPixelsWidth = 0 endPixelsWidth = slideWindowWidth # Update height with height stride size startPixelsHeight += strideHeight endPixelsHeight += strideHeight return patchesCoordinates,\ numberPatchesHeight,\ numberPatchesWidth,\ zeros_h,\ zeros_w elif padding == "VALID_FIT_ALL": # Get number of patches patchesCols = numberPatches[0] patchesRows = numberPatches[1] # Determine the size of the windows for the patches strideHeight = math.floor(imageHeight / patchesRows) slideWindowHeight = strideHeight strideWidth = math.floor(imageWidth / patchesCols) slideWindowWidth = strideWidth #print("Size: ", strideHeigth, slideWindowHeight, strideWidth, slideWindowWidth) # Get valid padding startPixelsHeight = 0 endPixelsHeight = slideWindowHeight startPixelsWidth = 0 endPixelsWidth = slideWindowWidth patchesCoordinates = [] numberPatchesHeight, numberPatchesWidth = ImagePreprocess.get_valid_padding(slideWindowHeight, strideHeight, imageHeight, slideWindowWidth, strideWidth, imageWidth) #print("numberPatchesHeight: ", numberPatchesHeight, "numberPatchesWidth: ", numberPatchesWidth) for i in range(numberPatchesHeight): for j in range(numberPatchesWidth): patchesCoordinates.append([startPixelsWidth,\ startPixelsHeight,\ endPixelsWidth,\ endPixelsHeight]) # Update width with strides startPixelsWidth += strideWidth endPixelsWidth += strideWidth # Re-initialize the width parameters startPixelsWidth = 0 endPixelsWidth = strideWidth # Update height with height stride size startPixelsHeight += strideHeight endPixelsHeight += strideHeight return patchesCoordinates,\ numberPatchesHeight,\ numberPatchesWidth else: raise Exception("Type of padding not understood.")
[ "def", "divideIntoPatches", "(", "self", ",", "imageWidth", "=", "None", ",", "imageHeight", "=", "None", ",", "slideWindowSize", "=", "None", ",", "strideSize", "=", "None", ",", "padding", "=", "None", ",", "numberPatches", "=", "None", ")", ":", "# Asse...
https://github.com/lozuwa/impy/blob/ddfaedf764c1cb2ced7f644a3a065715758874a5/impy/ImagePreprocess.py#L294-L463
GOATmessi7/RFBNet
88d5850761c0cc7ec5ca08ae67b1d4c3e3630f0f
data/coco.py
python
COCODetection.pull_tensor
(self, index)
return torch.Tensor(self.pull_image(index)).unsqueeze_(0)
Returns the original image at an index in tensor form Note: not using self.__getitem__(), as any transformations passed in could mess up this functionality. Argument: index (int): index of img to show Return: tensorized version of img, squeezed
Returns the original image at an index in tensor form
[ "Returns", "the", "original", "image", "at", "an", "index", "in", "tensor", "form" ]
def pull_tensor(self, index): '''Returns the original image at an index in tensor form Note: not using self.__getitem__(), as any transformations passed in could mess up this functionality. Argument: index (int): index of img to show Return: tensorized version of img, squeezed ''' to_tensor = transforms.ToTensor() return torch.Tensor(self.pull_image(index)).unsqueeze_(0)
[ "def", "pull_tensor", "(", "self", ",", "index", ")", ":", "to_tensor", "=", "transforms", ".", "ToTensor", "(", ")", "return", "torch", ".", "Tensor", "(", "self", ".", "pull_image", "(", "index", ")", ")", ".", "unsqueeze_", "(", "0", ")" ]
https://github.com/GOATmessi7/RFBNet/blob/88d5850761c0cc7ec5ca08ae67b1d4c3e3630f0f/data/coco.py#L201-L213
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
bin/x86/Debug/scripting_engine/Lib/mhlib.py
python
Folder.listallsubfolders
(self)
return self.mh.listallsubfolders(self.name)
Return list of all subfolders.
Return list of all subfolders.
[ "Return", "list", "of", "all", "subfolders", "." ]
def listallsubfolders(self): """Return list of all subfolders.""" return self.mh.listallsubfolders(self.name)
[ "def", "listallsubfolders", "(", "self", ")", ":", "return", "self", ".", "mh", ".", "listallsubfolders", "(", "self", ".", "name", ")" ]
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/bin/x86/Debug/scripting_engine/Lib/mhlib.py#L276-L278
slackapi/python-slack-sdk
2dee6656ffacb7de0c29bb2a6c2b51ec6b5dbce7
slack_sdk/web/client.py
python
WebClient.channels_info
( self, *, channel: str, **kwargs, )
return self.api_call("channels.info", http_verb="GET", params=kwargs)
Gets information about a channel.
Gets information about a channel.
[ "Gets", "information", "about", "a", "channel", "." ]
def channels_info( self, *, channel: str, **kwargs, ) -> SlackResponse: """Gets information about a channel.""" kwargs.update({"channel": channel}) return self.api_call("channels.info", http_verb="GET", params=kwargs)
[ "def", "channels_info", "(", "self", ",", "*", ",", "channel", ":", "str", ",", "*", "*", "kwargs", ",", ")", "->", "SlackResponse", ":", "kwargs", ".", "update", "(", "{", "\"channel\"", ":", "channel", "}", ")", "return", "self", ".", "api_call", "...
https://github.com/slackapi/python-slack-sdk/blob/2dee6656ffacb7de0c29bb2a6c2b51ec6b5dbce7/slack_sdk/web/client.py#L1697-L1705
ztosec/hunter
4ee5cca8dc5fc5d7e631e935517bd0f493c30a37
HunterAdminApi/parser/chrome_traffic_parser.py
python
ChromeTrafficParser.get_parameter
(url, data, http_method, content_type)
get和BaseTrafficParser一致, post不一致 :param url: :param data: :param http_method: :param content_type: :return:
get和BaseTrafficParser一致, post不一致 :param url: :param data: :param http_method: :param content_type: :return:
[ "get和BaseTrafficParser一致", "post不一致", ":", "param", "url", ":", ":", "param", "data", ":", ":", "param", "http_method", ":", ":", "param", "content_type", ":", ":", "return", ":" ]
def get_parameter(url, data, http_method, content_type): """ get和BaseTrafficParser一致, post不一致 :param url: :param data: :param http_method: :param content_type: :return: """ if (http_method and http_method.lower() == HttpMethod.GET) or content_type is None: return BaseTrafficParser.get_parameter(url=url, data=data, http_method=http_method, content_type=content_type) elif http_method and http_method == HttpMethod.POST: return ChromeTrafficParser._parse_post_parameter(data, content_type)
[ "def", "get_parameter", "(", "url", ",", "data", ",", "http_method", ",", "content_type", ")", ":", "if", "(", "http_method", "and", "http_method", ".", "lower", "(", ")", "==", "HttpMethod", ".", "GET", ")", "or", "content_type", "is", "None", ":", "ret...
https://github.com/ztosec/hunter/blob/4ee5cca8dc5fc5d7e631e935517bd0f493c30a37/HunterAdminApi/parser/chrome_traffic_parser.py#L191-L204
osmr/imgclsmob
f2993d3ce73a2f7ddba05da3891defb08547d504
pytorch/pytorchcv/models/dicenet.py
python
dicenet_wd5
(**kwargs)
return get_dicenet(width_scale=0.2, model_name="dicenet_wd5", **kwargs)
DiCENet x0.2 model from 'DiCENet: Dimension-wise Convolutions for Efficient Networks,' https://arxiv.org/abs/1906.03516. Parameters: ---------- pretrained : bool, default False Whether to load the pretrained weights for model. root : str, default '~/.torch/models' Location for keeping the model parameters.
DiCENet x0.2 model from 'DiCENet: Dimension-wise Convolutions for Efficient Networks,' https://arxiv.org/abs/1906.03516.
[ "DiCENet", "x0", ".", "2", "model", "from", "DiCENet", ":", "Dimension", "-", "wise", "Convolutions", "for", "Efficient", "Networks", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1906", ".", "03516", "." ]
def dicenet_wd5(**kwargs): """ DiCENet x0.2 model from 'DiCENet: Dimension-wise Convolutions for Efficient Networks,' https://arxiv.org/abs/1906.03516. Parameters: ---------- pretrained : bool, default False Whether to load the pretrained weights for model. root : str, default '~/.torch/models' Location for keeping the model parameters. """ return get_dicenet(width_scale=0.2, model_name="dicenet_wd5", **kwargs)
[ "def", "dicenet_wd5", "(", "*", "*", "kwargs", ")", ":", "return", "get_dicenet", "(", "width_scale", "=", "0.2", ",", "model_name", "=", "\"dicenet_wd5\"", ",", "*", "*", "kwargs", ")" ]
https://github.com/osmr/imgclsmob/blob/f2993d3ce73a2f7ddba05da3891defb08547d504/pytorch/pytorchcv/models/dicenet.py#L600-L612
GoogleCloudPlatform/PerfKitBenchmarker
6e3412d7d5e414b8ca30ed5eaf970cef1d919a67
perfkitbenchmarker/providers/gcp/gcp_tpu.py
python
GcpTpu._Exists
(self)
return retcode == 0
Returns true if the cloud TPU exists.
Returns true if the cloud TPU exists.
[ "Returns", "true", "if", "the", "cloud", "TPU", "exists", "." ]
def _Exists(self): """Returns true if the cloud TPU exists.""" _, retcode = self._GetTpuDescription() return retcode == 0
[ "def", "_Exists", "(", "self", ")", ":", "_", ",", "retcode", "=", "self", ".", "_GetTpuDescription", "(", ")", "return", "retcode", "==", "0" ]
https://github.com/GoogleCloudPlatform/PerfKitBenchmarker/blob/6e3412d7d5e414b8ca30ed5eaf970cef1d919a67/perfkitbenchmarker/providers/gcp/gcp_tpu.py#L107-L110
sxjscience/HKO-7
adeb05a366d4b57f94a5ddb814af57cc62ffe3c5
nowcasting/ops.py
python
fc_layer_bn_act
(data, num_hidden, no_bias=False, act_type="relu", momentum=0.9, eps=1e-5 + 1e-12, fix_gamma=True, name=None, use_global_stats=False, **kwargs)
return act
[]
def fc_layer_bn_act(data, num_hidden, no_bias=False, act_type="relu", momentum=0.9, eps=1e-5 + 1e-12, fix_gamma=True, name=None, use_global_stats=False, **kwargs): fc = fc_layer(data=data, num_hidden=num_hidden, no_bias=no_bias, name=name, **kwargs) assert name is not None global _params gamma = _params.get('%s_bn_gamma' % name, **kwargs) beta = _params.get('%s_bn_beta' % name, **kwargs) moving_mean = _params.get('%s_bn_moving_mean' % name, **kwargs) moving_var = _params.get('%s_bn_moving_var' % name, **kwargs) if fix_gamma: bn = mx.sym.BatchNorm(data=fc, beta=beta, gamma=gamma, moving_mean=moving_mean, moving_var=moving_var, fix_gamma=True, momentum=momentum, eps=eps, name='%s_bn' %name, use_global_stats=use_global_stats) else: bn = mx.sym.BatchNorm(data=fc, beta=beta, gamma=gamma, moving_mean=moving_mean, moving_var=moving_var, fix_gamma=False, momentum=momentum, eps=eps, name='%s_bn' % name, use_global_stats=use_global_stats) act = activation(bn, act_type=act_type, name=name) return act
[ "def", "fc_layer_bn_act", "(", "data", ",", "num_hidden", ",", "no_bias", "=", "False", ",", "act_type", "=", "\"relu\"", ",", "momentum", "=", "0.9", ",", "eps", "=", "1e-5", "+", "1e-12", ",", "fix_gamma", "=", "True", ",", "name", "=", "None", ",", ...
https://github.com/sxjscience/HKO-7/blob/adeb05a366d4b57f94a5ddb814af57cc62ffe3c5/nowcasting/ops.py#L321-L354
captainhammy/Houdini-Toolbox
a4e61c3c0296b3a3a153a8dd42297c316be1b0f3
python/houdini_toolbox/ui/aovs/widgets.py
python
AOVSelectTreeWidget.expand_selected
(self)
Expand selected folders and groups.
Expand selected folders and groups.
[ "Expand", "selected", "folders", "and", "groups", "." ]
def expand_selected(self): """Expand selected folders and groups.""" indexes = self.selectedIndexes() for index in reversed(indexes): self.expand(index)
[ "def", "expand_selected", "(", "self", ")", ":", "indexes", "=", "self", ".", "selectedIndexes", "(", ")", "for", "index", "in", "reversed", "(", "indexes", ")", ":", "self", ".", "expand", "(", "index", ")" ]
https://github.com/captainhammy/Houdini-Toolbox/blob/a4e61c3c0296b3a3a153a8dd42297c316be1b0f3/python/houdini_toolbox/ui/aovs/widgets.py#L340-L345
cocrawler/cocrawler
a9be74308fe666130cb9ca3dd64e18f4c30d2894
cocrawler/datalayer.py
python
Datalayer.add_seen
(self, url)
A "seen" url is one that we've done something with, such as having queued it or already crawled it.
A "seen" url is one that we've done something with, such as having queued it or already crawled it.
[ "A", "seen", "url", "is", "one", "that", "we", "ve", "done", "something", "with", "such", "as", "having", "queued", "it", "or", "already", "crawled", "it", "." ]
def add_seen(self, url): '''A "seen" url is one that we've done something with, such as having queued it or already crawled it.''' self.seen_set.add(url.surt)
[ "def", "add_seen", "(", "self", ",", "url", ")", ":", "self", ".", "seen_set", ".", "add", "(", "url", ".", "surt", ")" ]
https://github.com/cocrawler/cocrawler/blob/a9be74308fe666130cb9ca3dd64e18f4c30d2894/cocrawler/datalayer.py#L22-L25
mozman/ezdxf
59d0fc2ea63f5cf82293428f5931da7e9f9718e9
src/ezdxf/math/construct2d.py
python
ellipse_param_span
(start_param: float, end_param: float)
return arc_angle_span_rad(float(start_param), float(end_param))
Returns the counter clockwise params span of an elliptic arc from start- to end param. Returns the param span in the range [0, 2π], 2π is a full ellipse. Full ellipse handling is a special case, because normalization of params which describe a full ellipse would return 0 if treated as regular params. e.g. (0, 2π) → 2π, (0, -2π) → 2π, (π, -π) → 2π. Input params with the same value always return 0 by definition: (0, 0) → 0, (-π, -π) → 0, (2π, 2π) → 0. Alias to function: :func:`ezdxf.math.arc_angle_span_rad`
Returns the counter clockwise params span of an elliptic arc from start- to end param.
[ "Returns", "the", "counter", "clockwise", "params", "span", "of", "an", "elliptic", "arc", "from", "start", "-", "to", "end", "param", "." ]
def ellipse_param_span(start_param: float, end_param: float) -> float: """Returns the counter clockwise params span of an elliptic arc from start- to end param. Returns the param span in the range [0, 2π], 2π is a full ellipse. Full ellipse handling is a special case, because normalization of params which describe a full ellipse would return 0 if treated as regular params. e.g. (0, 2π) → 2π, (0, -2π) → 2π, (π, -π) → 2π. Input params with the same value always return 0 by definition: (0, 0) → 0, (-π, -π) → 0, (2π, 2π) → 0. Alias to function: :func:`ezdxf.math.arc_angle_span_rad` """ return arc_angle_span_rad(float(start_param), float(end_param))
[ "def", "ellipse_param_span", "(", "start_param", ":", "float", ",", "end_param", ":", "float", ")", "->", "float", ":", "return", "arc_angle_span_rad", "(", "float", "(", "start_param", ")", ",", "float", "(", "end_param", ")", ")" ]
https://github.com/mozman/ezdxf/blob/59d0fc2ea63f5cf82293428f5931da7e9f9718e9/src/ezdxf/math/construct2d.py#L113-L127
JiYou/openstack
8607dd488bde0905044b303eb6e52bdea6806923
packages/source/glance/glance/api/policy.py
python
Enforcer._check
(self, context, rule, target, *args, **kwargs)
return policy.check(rule, target, credentials, *args, **kwargs)
Verifies that the action is valid on the target in this context. :param context: Glance request context :param rule: String representing the action to be checked :param object: Dictionary representing the object of the action. :raises: `glance.common.exception.Forbidden` :returns: A non-False value if access is allowed.
Verifies that the action is valid on the target in this context.
[ "Verifies", "that", "the", "action", "is", "valid", "on", "the", "target", "in", "this", "context", "." ]
def _check(self, context, rule, target, *args, **kwargs): """Verifies that the action is valid on the target in this context. :param context: Glance request context :param rule: String representing the action to be checked :param object: Dictionary representing the object of the action. :raises: `glance.common.exception.Forbidden` :returns: A non-False value if access is allowed. """ self.load_rules() credentials = { 'roles': context.roles, 'user': context.user, 'tenant': context.tenant, } return policy.check(rule, target, credentials, *args, **kwargs)
[ "def", "_check", "(", "self", ",", "context", ",", "rule", ",", "target", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "load_rules", "(", ")", "credentials", "=", "{", "'roles'", ":", "context", ".", "roles", ",", "'user'", ":"...
https://github.com/JiYou/openstack/blob/8607dd488bde0905044b303eb6e52bdea6806923/packages/source/glance/glance/api/policy.py#L103-L120
WZMIAOMIAO/deep-learning-for-image-processing
a4502c284958d4bf78fb77b089a90e7688ddc196
others_project/draw_dilated_conv/main.py
python
dilated_conv_all_map
(dilated_map: np.ndarray, k: int = 3, r: int = 1)
return new_map
根据输出特征矩阵中哪些像素被使用以及使用次数, 配合膨胀卷积k和r计算输入特征矩阵哪些像素被使用以及使用次数 Args: dilated_map: 记录输出特征矩阵中每个像素被使用次数的特征图 k: 膨胀卷积核的kernel大小 r: 膨胀卷积的dilation rate
根据输出特征矩阵中哪些像素被使用以及使用次数, 配合膨胀卷积k和r计算输入特征矩阵哪些像素被使用以及使用次数 Args: dilated_map: 记录输出特征矩阵中每个像素被使用次数的特征图 k: 膨胀卷积核的kernel大小 r: 膨胀卷积的dilation rate
[ "根据输出特征矩阵中哪些像素被使用以及使用次数,", "配合膨胀卷积k和r计算输入特征矩阵哪些像素被使用以及使用次数", "Args", ":", "dilated_map", ":", "记录输出特征矩阵中每个像素被使用次数的特征图", "k", ":", "膨胀卷积核的kernel大小", "r", ":", "膨胀卷积的dilation", "rate" ]
def dilated_conv_all_map(dilated_map: np.ndarray, k: int = 3, r: int = 1): """ 根据输出特征矩阵中哪些像素被使用以及使用次数, 配合膨胀卷积k和r计算输入特征矩阵哪些像素被使用以及使用次数 Args: dilated_map: 记录输出特征矩阵中每个像素被使用次数的特征图 k: 膨胀卷积核的kernel大小 r: 膨胀卷积的dilation rate """ new_map = np.zeros_like(dilated_map) for i in range(dilated_map.shape[0]): for j in range(dilated_map.shape[1]): if dilated_map[i][j] > 0: dilated_conv_one_pixel((j, i), new_map, k=k, r=r, v=dilated_map[i][j]) return new_map
[ "def", "dilated_conv_all_map", "(", "dilated_map", ":", "np", ".", "ndarray", ",", "k", ":", "int", "=", "3", ",", "r", ":", "int", "=", "1", ")", ":", "new_map", "=", "np", ".", "zeros_like", "(", "dilated_map", ")", "for", "i", "in", "range", "("...
https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/a4502c284958d4bf78fb77b089a90e7688ddc196/others_project/draw_dilated_conv/main.py#L30-L47
FriedAppleTeam/FRAPL
89c14d57e0cc77b915fe1e95f60e9e1847699103
Framework/FridaLink/FridaLink/UI/PopupMenus.py
python
IdaPopupMenuActionHandler.__init__
(self, handler, action)
[]
def __init__(self, handler, action): action_handler_t.__init__(self) self.actionHandler = handler self.actionType = action
[ "def", "__init__", "(", "self", ",", "handler", ",", "action", ")", ":", "action_handler_t", ".", "__init__", "(", "self", ")", "self", ".", "actionHandler", "=", "handler", "self", ".", "actionType", "=", "action" ]
https://github.com/FriedAppleTeam/FRAPL/blob/89c14d57e0cc77b915fe1e95f60e9e1847699103/Framework/FridaLink/FridaLink/UI/PopupMenus.py#L123-L126
fmilthaler/FinQuant
38a2884663eea228540abd094b5c163f96c55aff
finquant/portfolio.py
python
Portfolio.ef_plot_efrontier
(self)
Interface to ``finquant.efficient_frontier.EfficientFrontier.plot_efrontier``. Plots the Efficient Frontier.
Interface to ``finquant.efficient_frontier.EfficientFrontier.plot_efrontier``.
[ "Interface", "to", "finquant", ".", "efficient_frontier", ".", "EfficientFrontier", ".", "plot_efrontier", "." ]
def ef_plot_efrontier(self): """Interface to ``finquant.efficient_frontier.EfficientFrontier.plot_efrontier``. Plots the Efficient Frontier.""" # let EfficientFrontier.efficient_frontier handle input arguments # get/create instance of EfficientFrontier ef = self._get_ef() # plot efficient frontier ef.plot_efrontier()
[ "def", "ef_plot_efrontier", "(", "self", ")", ":", "# let EfficientFrontier.efficient_frontier handle input arguments", "# get/create instance of EfficientFrontier", "ef", "=", "self", ".", "_get_ef", "(", ")", "# plot efficient frontier", "ef", ".", "plot_efrontier", "(", ")...
https://github.com/fmilthaler/FinQuant/blob/38a2884663eea228540abd094b5c163f96c55aff/finquant/portfolio.py#L573-L582
Xen0ph0n/YaraGenerator
48f529f0d85e7fff62405d9367901487e29aa28f
modules/pefile.py
python
Structure.sizeof
(self)
return self.__format_length__
Return size of the structure.
Return size of the structure.
[ "Return", "size", "of", "the", "structure", "." ]
def sizeof(self): """Return size of the structure.""" return self.__format_length__
[ "def", "sizeof", "(", "self", ")", ":", "return", "self", ".", "__format_length__" ]
https://github.com/Xen0ph0n/YaraGenerator/blob/48f529f0d85e7fff62405d9367901487e29aa28f/modules/pefile.py#L856-L859
blue-oil/blueoil
0c9160b524b17482d59ae48a0c11384f1d26dccc
blueoil/post_processor.py
python
FormatYoloV2._offset_boxes
(self, batch_size, num_cell_y, num_cell_x)
return offset_x, offset_y, offset_w, offset_h
Numpy implementing of offset_boxes. Return yolo space offset of x and y and w and h. Args: batch_size (int): batch size num_cell_y: Number of cell y. The spatial dimension of the final convolutional features. num_cell_x: Number of cell x. The spatial dimension of the final convolutional features.
Numpy implementing of offset_boxes. Return yolo space offset of x and y and w and h.
[ "Numpy", "implementing", "of", "offset_boxes", ".", "Return", "yolo", "space", "offset", "of", "x", "and", "y", "and", "w", "and", "h", "." ]
def _offset_boxes(self, batch_size, num_cell_y, num_cell_x): """Numpy implementing of offset_boxes. Return yolo space offset of x and y and w and h. Args: batch_size (int): batch size num_cell_y: Number of cell y. The spatial dimension of the final convolutional features. num_cell_x: Number of cell x. The spatial dimension of the final convolutional features. """ offset_y = np.arange(num_cell_y) offset_y = np.reshape(offset_y, (1, num_cell_y, 1, 1)) offset_y = np.broadcast_to(offset_y, [batch_size, num_cell_y, num_cell_x, self.boxes_per_cell]) offset_x = np.arange(num_cell_x) offset_x = np.reshape(offset_x, (1, 1, num_cell_x, 1)) offset_x = np.broadcast_to(offset_x, [batch_size, num_cell_y, num_cell_x, self.boxes_per_cell]) w_anchors = [anchor_w for anchor_w, anchor_h in self.anchors] offset_w = np.broadcast_to(w_anchors, (batch_size, num_cell_y, num_cell_x, self.boxes_per_cell)) offset_w = offset_w.astype(np.float32) h_anchors = [anchor_h for anchor_w, anchor_h in self.anchors] offset_h = np.broadcast_to(h_anchors, (batch_size, num_cell_y, num_cell_x, self.boxes_per_cell)) offset_h = offset_h.astype(np.float32) return offset_x, offset_y, offset_w, offset_h
[ "def", "_offset_boxes", "(", "self", ",", "batch_size", ",", "num_cell_y", ",", "num_cell_x", ")", ":", "offset_y", "=", "np", ".", "arange", "(", "num_cell_y", ")", "offset_y", "=", "np", ".", "reshape", "(", "offset_y", ",", "(", "1", ",", "num_cell_y"...
https://github.com/blue-oil/blueoil/blob/0c9160b524b17482d59ae48a0c11384f1d26dccc/blueoil/post_processor.py#L74-L101
ProgVal/Limnoria
181e34baf90a8cabc281e8349da6e36e1e558608
src/irclib.py
python
ChannelState.isOp
(self, nick)
return nick in self.ops
Returns whether the given nick is an op.
Returns whether the given nick is an op.
[ "Returns", "whether", "the", "given", "nick", "is", "an", "op", "." ]
def isOp(self, nick): """Returns whether the given nick is an op.""" return nick in self.ops
[ "def", "isOp", "(", "self", ",", "nick", ")", ":", "return", "nick", "in", "self", ".", "ops" ]
https://github.com/ProgVal/Limnoria/blob/181e34baf90a8cabc281e8349da6e36e1e558608/src/irclib.py#L369-L371
microsoft/azure-devops-python-api
451cade4c475482792cbe9e522c1fee32393139e
azure-devops/azure/devops/released/policy/policy_client.py
python
PolicyClient.get_policy_configuration
(self, project, configuration_id)
return self._deserialize('PolicyConfiguration', response)
GetPolicyConfiguration. Get a policy configuration by its ID. :param str project: Project ID or project name :param int configuration_id: ID of the policy configuration :rtype: :class:`<PolicyConfiguration> <azure.devops.v5_1.policy.models.PolicyConfiguration>`
GetPolicyConfiguration. Get a policy configuration by its ID. :param str project: Project ID or project name :param int configuration_id: ID of the policy configuration :rtype: :class:`<PolicyConfiguration> <azure.devops.v5_1.policy.models.PolicyConfiguration>`
[ "GetPolicyConfiguration", ".", "Get", "a", "policy", "configuration", "by", "its", "ID", ".", ":", "param", "str", "project", ":", "Project", "ID", "or", "project", "name", ":", "param", "int", "configuration_id", ":", "ID", "of", "the", "policy", "configura...
def get_policy_configuration(self, project, configuration_id): """GetPolicyConfiguration. Get a policy configuration by its ID. :param str project: Project ID or project name :param int configuration_id: ID of the policy configuration :rtype: :class:`<PolicyConfiguration> <azure.devops.v5_1.policy.models.PolicyConfiguration>` """ route_values = {} if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') if configuration_id is not None: route_values['configurationId'] = self._serialize.url('configuration_id', configuration_id, 'int') response = self._send(http_method='GET', location_id='dad91cbe-d183-45f8-9c6e-9c1164472121', version='5.1', route_values=route_values) return self._deserialize('PolicyConfiguration', response)
[ "def", "get_policy_configuration", "(", "self", ",", "project", ",", "configuration_id", ")", ":", "route_values", "=", "{", "}", "if", "project", "is", "not", "None", ":", "route_values", "[", "'project'", "]", "=", "self", ".", "_serialize", ".", "url", ...
https://github.com/microsoft/azure-devops-python-api/blob/451cade4c475482792cbe9e522c1fee32393139e/azure-devops/azure/devops/released/policy/policy_client.py#L65-L81
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/bmlb/v20180625/models.py
python
ModifyLoadBalancerChargeModeResponse.__init__
(self)
r""" :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
r""" :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
[ "r", ":", "param", "RequestId", ":", "唯一请求", "ID,每次请求都会返回。定位问题时需要提供该次请求的", "RequestId。", ":", "type", "RequestId", ":", "str" ]
def __init__(self): r""" :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str """ self.RequestId = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "RequestId", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/bmlb/v20180625/models.py#L4472-L4477
n1nj4sec/pupy
a5d766ea81fdfe3bc2c38c9bdaf10e9b75af3b39
pupy/packages/all/pupyutils/safepopen.py
python
SafePopen.write
(self, data)
[]
def write(self, data): if self.returncode or not self._pipe or not self._interactive: return self._pipe.stdin.write(data) self._pipe.stdin.flush()
[ "def", "write", "(", "self", ",", "data", ")", ":", "if", "self", ".", "returncode", "or", "not", "self", ".", "_pipe", "or", "not", "self", ".", "_interactive", ":", "return", "self", ".", "_pipe", ".", "stdin", ".", "write", "(", "data", ")", "se...
https://github.com/n1nj4sec/pupy/blob/a5d766ea81fdfe3bc2c38c9bdaf10e9b75af3b39/pupy/packages/all/pupyutils/safepopen.py#L299-L304
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/bz2.py
python
BZ2File.closed
(self)
return self._mode == _MODE_CLOSED
True if this file is closed.
True if this file is closed.
[ "True", "if", "this", "file", "is", "closed", "." ]
def closed(self): """True if this file is closed.""" return self._mode == _MODE_CLOSED
[ "def", "closed", "(", "self", ")", ":", "return", "self", ".", "_mode", "==", "_MODE_CLOSED" ]
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/bz2.py#L137-L139
google/prettytensor
75daa0b11252590f548da5647addc0ea610c4c45
prettytensor/bookkeeper.py
python
apply_optimizer
(optimizer, losses, regularize=True, include_marked=True, clip_gradients_by_norm=None, **kwargs)
return books.with_update_ops(train_op)
Apply an optimizer to the graph and returns a train_op. The resulting operation will minimize the specified losses, plus the regularization losses that have been collected during graph construction and the losses that were marked by calling `mark_as_required`. It will also apply any updates that have been collected (e.g. for moving average summaries). This is equivalent to: total_loss = prettytensor.create_composite_loss( losses=losses, regularize=regularize, include_marked=include_marked) train_op_without_updates = optimizer.minimize(total_loss) train_op = prettytensor.with_update_ops(train_op_without_updates) N.B. Pay special attention to the `gate_gradients` argument to the optimizer. If your graph is large, it will likely train unacceptably slow if you don't specify it as GATE_NONE. Args: optimizer: The optimizer the minimize. losses: A list of losses to apply. regularize: Whether or not to include the regularization losses. include_marked: Whether or not to use the marked losses. clip_gradients_by_norm: If not None, clip gradients by the norm using `tf.clip_by_norm`. **kwargs: Additional arguments to pass into the optimizer. Returns: An operation to use for training that also updates any required ops such as moving averages.
Apply an optimizer to the graph and returns a train_op.
[ "Apply", "an", "optimizer", "to", "the", "graph", "and", "returns", "a", "train_op", "." ]
def apply_optimizer(optimizer, losses, regularize=True, include_marked=True, clip_gradients_by_norm=None, **kwargs): """Apply an optimizer to the graph and returns a train_op. The resulting operation will minimize the specified losses, plus the regularization losses that have been collected during graph construction and the losses that were marked by calling `mark_as_required`. It will also apply any updates that have been collected (e.g. for moving average summaries). This is equivalent to: total_loss = prettytensor.create_composite_loss( losses=losses, regularize=regularize, include_marked=include_marked) train_op_without_updates = optimizer.minimize(total_loss) train_op = prettytensor.with_update_ops(train_op_without_updates) N.B. Pay special attention to the `gate_gradients` argument to the optimizer. If your graph is large, it will likely train unacceptably slow if you don't specify it as GATE_NONE. Args: optimizer: The optimizer the minimize. losses: A list of losses to apply. regularize: Whether or not to include the regularization losses. include_marked: Whether or not to use the marked losses. clip_gradients_by_norm: If not None, clip gradients by the norm using `tf.clip_by_norm`. **kwargs: Additional arguments to pass into the optimizer. Returns: An operation to use for training that also updates any required ops such as moving averages. """ books = for_default_graph() g_step = kwargs.pop('global_step', books.global_step) total_loss = books.create_composite_loss(losses=losses, regularize=regularize, include_marked=include_marked) grads_and_vars = optimizer.compute_gradients(total_loss, **kwargs) if clip_gradients_by_norm is not None: clipped_grads_and_vars = [] for g, v in grads_and_vars: if isinstance(g, tf.SparseTensor): cg = tf.SparseTensor( tf.clip_by_norm(g.values, clip_gradients_by_norm), g.indices, g.dense_shape) elif isinstance(g, tf.IndexedSlices): cg = tf.IndexedSlices( tf.clip_by_norm(g.values, clip_gradients_by_norm), g.indices) else: cg = tf.clip_by_norm(g, clip_gradients_by_norm) clipped_grads_and_vars.append((cg, v)) grads_and_vars = clipped_grads_and_vars train_op = optimizer.apply_gradients(grads_and_vars, global_step=g_step) return books.with_update_ops(train_op)
[ "def", "apply_optimizer", "(", "optimizer", ",", "losses", ",", "regularize", "=", "True", ",", "include_marked", "=", "True", ",", "clip_gradients_by_norm", "=", "None", ",", "*", "*", "kwargs", ")", ":", "books", "=", "for_default_graph", "(", ")", "g_step...
https://github.com/google/prettytensor/blob/75daa0b11252590f548da5647addc0ea610c4c45/prettytensor/bookkeeper.py#L586-L649
IJDykeman/wangTiles
7c1ee2095ebdf7f72bce07d94c6484915d5cae8b
experimental_code/tiles_3d/venv_mac/lib/python2.7/site-packages/pip/_vendor/pyparsing.py
python
ParserElement.parseWithTabs
( self )
return self
Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string. Must be called before C{parseString} when the input grammar contains elements that match C{<TAB>} characters.
Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string. Must be called before C{parseString} when the input grammar contains elements that match C{<TAB>} characters.
[ "Overrides", "default", "behavior", "to", "expand", "C", "{", "<TAB", ">", "}", "s", "to", "spaces", "before", "parsing", "the", "input", "string", ".", "Must", "be", "called", "before", "C", "{", "parseString", "}", "when", "the", "input", "grammar", "c...
def parseWithTabs( self ): """ Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string. Must be called before C{parseString} when the input grammar contains elements that match C{<TAB>} characters. """ self.keepTabs = True return self
[ "def", "parseWithTabs", "(", "self", ")", ":", "self", ".", "keepTabs", "=", "True", "return", "self" ]
https://github.com/IJDykeman/wangTiles/blob/7c1ee2095ebdf7f72bce07d94c6484915d5cae8b/experimental_code/tiles_3d/venv_mac/lib/python2.7/site-packages/pip/_vendor/pyparsing.py#L2029-L2036
sxjscience/HKO-7
adeb05a366d4b57f94a5ddb814af57cc62ffe3c5
nowcasting/operators/conv_rnn.py
python
ConvRNN.state_info
(self)
return [{'shape': (self._batch_size, self._num_filter, self._state_height, self._state_width), '__layout__': "NCHW"}]
[]
def state_info(self): return [{'shape': (self._batch_size, self._num_filter, self._state_height, self._state_width), '__layout__': "NCHW"}]
[ "def", "state_info", "(", "self", ")", ":", "return", "[", "{", "'shape'", ":", "(", "self", ".", "_batch_size", ",", "self", ".", "_num_filter", ",", "self", ".", "_state_height", ",", "self", ".", "_state_width", ")", ",", "'__layout__'", ":", "\"NCHW\...
https://github.com/sxjscience/HKO-7/blob/adeb05a366d4b57f94a5ddb814af57cc62ffe3c5/nowcasting/operators/conv_rnn.py#L67-L70
har07/PySastrawi
01afc81c579bde14dcb41c33686b26af8afab121
src/Sastrawi/Stemmer/Context/Context.py
python
Context.is_suffix_removal
(self, removal)
return removal.get_affix_type() == 'DS' \ or removal.get_affix_type() == 'PP' \ or removal.get_affix_type() == 'P'
Check wether the removed part is a suffix
Check wether the removed part is a suffix
[ "Check", "wether", "the", "removed", "part", "is", "a", "suffix" ]
def is_suffix_removal(self, removal): """Check wether the removed part is a suffix""" return removal.get_affix_type() == 'DS' \ or removal.get_affix_type() == 'PP' \ or removal.get_affix_type() == 'P'
[ "def", "is_suffix_removal", "(", "self", ",", "removal", ")", ":", "return", "removal", ".", "get_affix_type", "(", ")", "==", "'DS'", "or", "removal", ".", "get_affix_type", "(", ")", "==", "'PP'", "or", "removal", ".", "get_affix_type", "(", ")", "==", ...
https://github.com/har07/PySastrawi/blob/01afc81c579bde14dcb41c33686b26af8afab121/src/Sastrawi/Stemmer/Context/Context.py#L148-L152
nextcloud/appstore
bd7682d3e176b904e0e5dfc31a09650ddac5cdf0
nextcloudappstore/core/models.py
python
AppManager.search
(self, terms, lang)
return queryset.filter(query)
[]
def search(self, terms, lang): queryset = self.get_queryset().active_translations(lang).language( lang).distinct() predicates = map(lambda t: (Q(translations__name__icontains=t) | Q(translations__summary__icontains=t) | Q(translations__description__icontains=t)), terms) query = reduce(lambda x, y: x & y, predicates, Q()) return queryset.filter(query)
[ "def", "search", "(", "self", ",", "terms", ",", "lang", ")", ":", "queryset", "=", "self", ".", "get_queryset", "(", ")", ".", "active_translations", "(", "lang", ")", ".", "language", "(", "lang", ")", ".", "distinct", "(", ")", "predicates", "=", ...
https://github.com/nextcloud/appstore/blob/bd7682d3e176b904e0e5dfc31a09650ddac5cdf0/nextcloudappstore/core/models.py#L28-L36
sony/nnabla
5b022f309bf2fa3ade0b6cb9bf05da9ddc67f104
python/src/nnabla/backward_function/rand_binomial.py
python
rand_binomial_backward
(inputs, n=1, p=0.5, shape=[], seed=-1)
return [None] * len(inputs)
Args: inputs (list of nn.Variable): Incomming grads/inputs to/of the forward function. kwargs (dict of arguments): Dictionary of the corresponding function arguments. Return: list of Variable: Return the gradients wrt inputs of the corresponding function.
Args: inputs (list of nn.Variable): Incomming grads/inputs to/of the forward function. kwargs (dict of arguments): Dictionary of the corresponding function arguments.
[ "Args", ":", "inputs", "(", "list", "of", "nn", ".", "Variable", ")", ":", "Incomming", "grads", "/", "inputs", "to", "/", "of", "the", "forward", "function", ".", "kwargs", "(", "dict", "of", "arguments", ")", ":", "Dictionary", "of", "the", "correspo...
def rand_binomial_backward(inputs, n=1, p=0.5, shape=[], seed=-1): """ Args: inputs (list of nn.Variable): Incomming grads/inputs to/of the forward function. kwargs (dict of arguments): Dictionary of the corresponding function arguments. Return: list of Variable: Return the gradients wrt inputs of the corresponding function. """ return [None] * len(inputs)
[ "def", "rand_binomial_backward", "(", "inputs", ",", "n", "=", "1", ",", "p", "=", "0.5", ",", "shape", "=", "[", "]", ",", "seed", "=", "-", "1", ")", ":", "return", "[", "None", "]", "*", "len", "(", "inputs", ")" ]
https://github.com/sony/nnabla/blob/5b022f309bf2fa3ade0b6cb9bf05da9ddc67f104/python/src/nnabla/backward_function/rand_binomial.py#L16-L25
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
check_server/check.py
python
write_score
(scores)
[]
def write_score(scores): scores = '|'.join(scores) res = http('get',flag_server,8080,'/score.php?key=%s&write=1&score=%s'%(key,scores),'',headers) if res == "success": return True else: print res raise ValueError
[ "def", "write_score", "(", "scores", ")", ":", "scores", "=", "'|'", ".", "join", "(", "scores", ")", "res", "=", "http", "(", "'get'", ",", "flag_server", ",", "8080", ",", "'/score.php?key=%s&write=1&score=%s'", "%", "(", "key", ",", "scores", ")", ","...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/check_server/check.py#L67-L74
mozilla/elasticutils
b880cc5d51fb1079b0581255ec664c1ec934656e
elasticutils/__init__.py
python
Indexable.refresh_index
(cls, es=None, index=None)
Refreshes the index. Elasticsearch will update the index periodically automatically. If you need to see the documents you just indexed in your search results right now, you should call `refresh_index` as soon as you're done indexing. This is particularly helpful for unit tests. :arg es: The `Elasticsearch` to use. If you don't specify an `Elasticsearch`, it'll use `cls.get_es()`. :arg index: The name of the index to use. If you don't specify one it'll use `cls.get_index()`.
Refreshes the index.
[ "Refreshes", "the", "index", "." ]
def refresh_index(cls, es=None, index=None): """Refreshes the index. Elasticsearch will update the index periodically automatically. If you need to see the documents you just indexed in your search results right now, you should call `refresh_index` as soon as you're done indexing. This is particularly helpful for unit tests. :arg es: The `Elasticsearch` to use. If you don't specify an `Elasticsearch`, it'll use `cls.get_es()`. :arg index: The name of the index to use. If you don't specify one it'll use `cls.get_index()`. """ if es is None: es = cls.get_es() if index is None: index = cls.get_index() es.indices.refresh(index=index)
[ "def", "refresh_index", "(", "cls", ",", "es", "=", "None", ",", "index", "=", "None", ")", ":", "if", "es", "is", "None", ":", "es", "=", "cls", ".", "get_es", "(", ")", "if", "index", "is", "None", ":", "index", "=", "cls", ".", "get_index", ...
https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L2295-L2317
aws-quickstart/quickstart-git2s3
1d6ccea93889d8f105a2deb5a34cc2c6a7ca41c9
functions/source/GitPullS3/ipaddress.py
python
_split_optional_netmask
(address)
return addr
Helper to split the netmask and raise AddressValueError if needed
Helper to split the netmask and raise AddressValueError if needed
[ "Helper", "to", "split", "the", "netmask", "and", "raise", "AddressValueError", "if", "needed" ]
def _split_optional_netmask(address): """Helper to split the netmask and raise AddressValueError if needed""" addr = _compat_str(address).split('/') if len(addr) > 2: raise AddressValueError("Only one '/' permitted in %r" % address) return addr
[ "def", "_split_optional_netmask", "(", "address", ")", ":", "addr", "=", "_compat_str", "(", "address", ")", ".", "split", "(", "'/'", ")", "if", "len", "(", "addr", ")", ">", "2", ":", "raise", "AddressValueError", "(", "\"Only one '/' permitted in %r\"", "...
https://github.com/aws-quickstart/quickstart-git2s3/blob/1d6ccea93889d8f105a2deb5a34cc2c6a7ca41c9/functions/source/GitPullS3/ipaddress.py#L276-L281
zbyte64/django-hyperadmin
9ac2ae284b76efb3c50a1c2899f383a27154cb54
hyperadmin/endpoints.py
python
BaseEndpoint.create_link_collection
(self)
return LinkCollection(endpoint=self)
Returns an instantiated LinkCollection object :rtype: LinkCollection
Returns an instantiated LinkCollection object
[ "Returns", "an", "instantiated", "LinkCollection", "object" ]
def create_link_collection(self): """ Returns an instantiated LinkCollection object :rtype: LinkCollection """ return LinkCollection(endpoint=self)
[ "def", "create_link_collection", "(", "self", ")", ":", "return", "LinkCollection", "(", "endpoint", "=", "self", ")" ]
https://github.com/zbyte64/django-hyperadmin/blob/9ac2ae284b76efb3c50a1c2899f383a27154cb54/hyperadmin/endpoints.py#L239-L245
tuckerbalch/QSTK
4981506c37227a72404229d5e1e0887f797a5d57
epydoc-3.0.1/epydoc/markup/restructuredtext.py
python
_construct_classtree
(docindex, context, linker, arguments, options)
return class_tree_graph(bases, linker, context, **options)
Graph generator for L{classtree_directive}
Graph generator for L{classtree_directive}
[ "Graph", "generator", "for", "L", "{", "classtree_directive", "}" ]
def _construct_classtree(docindex, context, linker, arguments, options): """Graph generator for L{classtree_directive}""" if len(arguments) == 1: bases = [docindex.find(name, context) for name in arguments[0].replace(',',' ').split()] bases = [d for d in bases if isinstance(d, ClassDoc)] elif isinstance(context, ClassDoc): bases = [context] else: log.warning("Could not construct class tree: you must " "specify one or more base classes.") return None return class_tree_graph(bases, linker, context, **options)
[ "def", "_construct_classtree", "(", "docindex", ",", "context", ",", "linker", ",", "arguments", ",", "options", ")", ":", "if", "len", "(", "arguments", ")", "==", "1", ":", "bases", "=", "[", "docindex", ".", "find", "(", "name", ",", "context", ")",...
https://github.com/tuckerbalch/QSTK/blob/4981506c37227a72404229d5e1e0887f797a5d57/epydoc-3.0.1/epydoc/markup/restructuredtext.py#L815-L828
brainiak/brainiak
ee093597c6c11597b0a59e95b48d2118e40394a5
brainiak/reprsimil/brsa.py
python
BRSA._initial_fit_singpara
(self, XTX, XTDX, XTFX, YTY_diag, YTDY_diag, YTFY_diag, XTY, XTDY, XTFY, X0TX0, X0TDX0, X0TFX0, XTX0, XTDX0, XTFX0, X0TY, X0TDY, X0TFY, X, Y, X0, idx_param_sing, l_idx, n_C, n_T, n_V, n_l, n_run, n_X0, rank)
return current_vec_U_chlsk_l, current_a1, log_sigma2
Perform initial fitting of a simplified model, which assumes that all voxels share exactly the same temporal covariance matrix for their noise (the same noise variance and auto-correlation). The SNR is implicitly assumed to be 1 for all voxels.
Perform initial fitting of a simplified model, which assumes that all voxels share exactly the same temporal covariance matrix for their noise (the same noise variance and auto-correlation). The SNR is implicitly assumed to be 1 for all voxels.
[ "Perform", "initial", "fitting", "of", "a", "simplified", "model", "which", "assumes", "that", "all", "voxels", "share", "exactly", "the", "same", "temporal", "covariance", "matrix", "for", "their", "noise", "(", "the", "same", "noise", "variance", "and", "aut...
def _initial_fit_singpara(self, XTX, XTDX, XTFX, YTY_diag, YTDY_diag, YTFY_diag, XTY, XTDY, XTFY, X0TX0, X0TDX0, X0TFX0, XTX0, XTDX0, XTFX0, X0TY, X0TDY, X0TFY, X, Y, X0, idx_param_sing, l_idx, n_C, n_T, n_V, n_l, n_run, n_X0, rank): """ Perform initial fitting of a simplified model, which assumes that all voxels share exactly the same temporal covariance matrix for their noise (the same noise variance and auto-correlation). The SNR is implicitly assumed to be 1 for all voxels. """ logger.info('Initial fitting assuming single parameter of ' 'noise for all voxels') X_joint = np.concatenate((X0, X), axis=1) beta_hat = np.linalg.lstsq(X_joint, Y, rcond=None)[0] residual = Y - np.dot(X_joint, beta_hat) # point estimates of betas and fitting residuals without assuming # the Bayesian model underlying RSA. # There are several possible ways of initializing the covariance. # (1) start from the point estimation of covariance cov_point_est = np.cov(beta_hat[n_X0:, :]) / np.var(residual) current_vec_U_chlsk_l = \ np.linalg.cholesky((cov_point_est + np.eye(n_C)) / 2)[l_idx] # We use the average of covariance of point estimation and an identity # matrix as the initial value of the covariance matrix, just in case # the user provides data in which n_V is smaller than n_C. # (2) start from identity matrix # current_vec_U_chlsk_l = np.eye(n_C)[l_idx] # (3) random initialization # current_vec_U_chlsk_l = self.random_state_.randn(n_l) # vectorized version of L, Cholesky factor of U, the shared # covariance matrix of betas across voxels. rho1 = np.sum( residual[0:-1, :] * residual[1:, :], axis=0) / \ np.sum(residual[0:-1, :] * residual[0:-1, :], axis=0) # Estimate of auto correlation assuming data includes pure noise. log_sigma2 = np.log(np.var( residual[1:, :] - residual[0:-1, :] * rho1, axis=0)) # log of estimates of the variance of the "innovation" noise # of AR(1) process at each time point. param0 = np.empty(np.sum(np.fromiter( (np.size(v) for v in idx_param_sing.values()), int))) # Initial parameter # Then we fill each part of the original guess of parameters param0[idx_param_sing['Cholesky']] = current_vec_U_chlsk_l param0[idx_param_sing['a1']] = np.median(np.tan(rho1 * np.pi / 2)) # Fit it. res = scipy.optimize.minimize( self._loglike_AR1_singpara, param0, args=(XTX, XTDX, XTFX, YTY_diag, YTDY_diag, YTFY_diag, XTY, XTDY, XTFY, X0TX0, X0TDX0, X0TFX0, XTX0, XTDX0, XTFX0, X0TY, X0TDY, X0TFY, l_idx, n_C, n_T, n_V, n_run, n_X0, idx_param_sing, rank), method=self.optimizer, jac=True, tol=self.tol, options={'disp': self.minimize_options['disp'], 'maxiter': 100}) current_vec_U_chlsk_l = res.x[idx_param_sing['Cholesky']] current_a1 = res.x[idx_param_sing['a1']] * np.ones(n_V) # log(sigma^2) assuming the data include no signal is returned, # as a starting point for the iteration in the next step. # Although it should overestimate the variance, # setting it this way might allow it to track log(sigma^2) # more closely for each voxel. return current_vec_U_chlsk_l, current_a1, log_sigma2
[ "def", "_initial_fit_singpara", "(", "self", ",", "XTX", ",", "XTDX", ",", "XTFX", ",", "YTY_diag", ",", "YTDY_diag", ",", "YTFY_diag", ",", "XTY", ",", "XTDY", ",", "XTFY", ",", "X0TX0", ",", "X0TDX0", ",", "X0TFX0", ",", "XTX0", ",", "XTDX0", ",", ...
https://github.com/brainiak/brainiak/blob/ee093597c6c11597b0a59e95b48d2118e40394a5/brainiak/reprsimil/brsa.py#L1772-L1847
PacktPublishing/Deep-Reinforcement-Learning-Hands-On
baa9d013596ea8ea8ed6826b9de6679d98b897ca
Chapter07/lib/common.py
python
distr_projection
(next_distr, rewards, dones, Vmin, Vmax, n_atoms, gamma)
return proj_distr
Perform distribution projection aka Catergorical Algorithm from the "A Distributional Perspective on RL" paper
Perform distribution projection aka Catergorical Algorithm from the "A Distributional Perspective on RL" paper
[ "Perform", "distribution", "projection", "aka", "Catergorical", "Algorithm", "from", "the", "A", "Distributional", "Perspective", "on", "RL", "paper" ]
def distr_projection(next_distr, rewards, dones, Vmin, Vmax, n_atoms, gamma): """ Perform distribution projection aka Catergorical Algorithm from the "A Distributional Perspective on RL" paper """ batch_size = len(rewards) proj_distr = np.zeros((batch_size, n_atoms), dtype=np.float32) delta_z = (Vmax - Vmin) / (n_atoms - 1) for atom in range(n_atoms): tz_j = np.minimum(Vmax, np.maximum(Vmin, rewards + (Vmin + atom * delta_z) * gamma)) b_j = (tz_j - Vmin) / delta_z l = np.floor(b_j).astype(np.int64) u = np.ceil(b_j).astype(np.int64) eq_mask = u == l proj_distr[eq_mask, l[eq_mask]] += next_distr[eq_mask, atom] ne_mask = u != l proj_distr[ne_mask, l[ne_mask]] += next_distr[ne_mask, atom] * (u - b_j)[ne_mask] proj_distr[ne_mask, u[ne_mask]] += next_distr[ne_mask, atom] * (b_j - l)[ne_mask] if dones.any(): proj_distr[dones] = 0.0 tz_j = np.minimum(Vmax, np.maximum(Vmin, rewards[dones])) b_j = (tz_j - Vmin) / delta_z l = np.floor(b_j).astype(np.int64) u = np.ceil(b_j).astype(np.int64) eq_mask = u == l eq_dones = dones.copy() eq_dones[dones] = eq_mask if eq_dones.any(): proj_distr[eq_dones, l[eq_mask]] = 1.0 ne_mask = u != l ne_dones = dones.copy() ne_dones[dones] = ne_mask if ne_dones.any(): proj_distr[ne_dones, l[ne_mask]] = (u - b_j)[ne_mask] proj_distr[ne_dones, u[ne_mask]] = (b_j - l)[ne_mask] return proj_distr
[ "def", "distr_projection", "(", "next_distr", ",", "rewards", ",", "dones", ",", "Vmin", ",", "Vmax", ",", "n_atoms", ",", "gamma", ")", ":", "batch_size", "=", "len", "(", "rewards", ")", "proj_distr", "=", "np", ".", "zeros", "(", "(", "batch_size", ...
https://github.com/PacktPublishing/Deep-Reinforcement-Learning-Hands-On/blob/baa9d013596ea8ea8ed6826b9de6679d98b897ca/Chapter07/lib/common.py#L150-L185
playframework/play1
0ecac3bc2421ae2dbec27a368bf671eda1c9cba5
python/Lib/fnmatch.py
python
_purge
()
Clear the pattern cache
Clear the pattern cache
[ "Clear", "the", "pattern", "cache" ]
def _purge(): """Clear the pattern cache""" _cache.clear()
[ "def", "_purge", "(", ")", ":", "_cache", ".", "clear", "(", ")" ]
https://github.com/playframework/play1/blob/0ecac3bc2421ae2dbec27a368bf671eda1c9cba5/python/Lib/fnmatch.py#L20-L22
mlcommons/ck
558a22c5970eb0d6708d0edc080e62a92566bab0
ck/repo/module/program/module.py
python
copy_file_to_remote
(i)
return {'return':0}
Input: { host_os_dict target_os_dict device_id file1 (file1s) file2 } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 }
Input: { host_os_dict target_os_dict device_id file1 (file1s) file2 }
[ "Input", ":", "{", "host_os_dict", "target_os_dict", "device_id", "file1", "(", "file1s", ")", "file2", "}" ]
def copy_file_to_remote(i): """ Input: { host_os_dict target_os_dict device_id file1 (file1s) file2 } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 } """ import os o=i.get('out','') hosd=i['host_os_dict'] host_hash_cmd = hosd.get('md5sum', 'md5sum') tosd=i['target_os_dict'] tdid=i.get('device_id','') xtdid='' if tdid!='': xtdid=' -s '+tdid file1=i['file1'] file1s=i.get('file1s','') if file1s=='': file1s=file1 file2=i['file2'] if file1=='': return {'return':1, 'error':'file to be sent to remote device is not specified'} if not os.path.exists(file1): return {'return':1, 'error':'file to be sent to remote device ('+file1+') is not found'} # Check params of remote file rs=tosd['remote_shell'].replace('$#device#$',xtdid) rse=tosd.get('remote_shell_end','')+' ' x = rs + ' md5sum ' + file2 + rse shell='no' if x.startswith('ck'): shell='yes' ry=ck.run_and_get_stdout({'cmd':x, 'shell': shell}) if ry['return']>0: return ry so=ry['stdout'].lower() skip=False if 'no such file or directory' not in so: remote_hash = so.split(' ')[0] rz=ck.run_and_get_stdout({'cmd': host_hash_cmd+' '+file1 , 'shell': 'no'}) if rz['return']>0: return rz local_hash = rz['stdout'].lower().split(' ')[0] if remote_hash==local_hash: if o=='con': ck.out(sep) ck.out('Skipped copying file '+file1+' to remote (the same hash)') skip=True if not skip: y=tosd.get('remote_push_pre','').replace('$#device#$',xtdid) if y!='': y=y.replace('$#file1#$', file1).replace('$#file1s#$', file1s).replace('$#file2#$', file2) if o=='con': ck.out(sep) ck.out(y) ck.out('') ry=os.system(y) if ry>0: return {'return':1, 'error':'copying to remote device failed'} y=tosd['remote_push'].replace('$#device#$',xtdid) y=y.replace('$#file1#$', file1).replace('$#file1s#$', file1s).replace('$#file2#$', file2) if o=='con': ck.out(sep) ck.out(y) ck.out('') ry=os.system(y) if ry>0: return {'return':1, 'error':'copying to remote device failed'} return {'return':0}
[ "def", "copy_file_to_remote", "(", "i", ")", ":", "import", "os", "o", "=", "i", ".", "get", "(", "'out'", ",", "''", ")", "hosd", "=", "i", "[", "'host_os_dict'", "]", "host_hash_cmd", "=", "hosd", ".", "get", "(", "'md5sum'", ",", "'md5sum'", ")", ...
https://github.com/mlcommons/ck/blob/558a22c5970eb0d6708d0edc080e62a92566bab0/ck/repo/module/program/module.py#L6918-L7014
cgre-aachen/gempy
6ad16c46fc6616c9f452fba85d31ce32decd8b10
gempy/utils/input_manipulation.py
python
VanMisesFisher._sample_weight
(self)
Who likes documentation anyways. This is totally intuitive and trivial.
Who likes documentation anyways. This is totally intuitive and trivial.
[ "Who", "likes", "documentation", "anyways", ".", "This", "is", "totally", "intuitive", "and", "trivial", "." ]
def _sample_weight(self): """Who likes documentation anyways. This is totally intuitive and trivial.""" dim = self.dim - 1 # since S^{n-1} b = dim / (np.sqrt(4. * self.kappa ** 2 + dim ** 2) + 2 * self.kappa) x = (1. - b) / (1. + b) c = self.kappa * x + dim * np.log(1 - x ** 2) while True: z = np.random.beta(dim / 2., dim / 2.) w = (1. - (1. + b) * z) / (1. - (1. - b) * z) u = np.random.uniform(low=0, high=1) if self.kappa * w + dim * np.log(1. - x * w) - c >= np.log(u): return w
[ "def", "_sample_weight", "(", "self", ")", ":", "dim", "=", "self", ".", "dim", "-", "1", "# since S^{n-1}", "b", "=", "dim", "/", "(", "np", ".", "sqrt", "(", "4.", "*", "self", ".", "kappa", "**", "2", "+", "dim", "**", "2", ")", "+", "2", ...
https://github.com/cgre-aachen/gempy/blob/6ad16c46fc6616c9f452fba85d31ce32decd8b10/gempy/utils/input_manipulation.py#L166-L178
jython/frozen-mirror
b8d7aa4cee50c0c0fe2f4b235dd62922dd0f3f99
lib-python/2.7/httplib.py
python
HTTP.connect
(self, host=None, port=None)
Accept arguments to set the host/port, since the superclass doesn't.
Accept arguments to set the host/port, since the superclass doesn't.
[ "Accept", "arguments", "to", "set", "the", "host", "/", "port", "since", "the", "superclass", "doesn", "t", "." ]
def connect(self, host=None, port=None): "Accept arguments to set the host/port, since the superclass doesn't." if host is not None: (self._conn.host, self._conn.port) = self._conn._get_hostport(host, port) self._conn.connect()
[ "def", "connect", "(", "self", ",", "host", "=", "None", ",", "port", "=", "None", ")", ":", "if", "host", "is", "not", "None", ":", "(", "self", ".", "_conn", ".", "host", ",", "self", ".", "_conn", ".", "port", ")", "=", "self", ".", "_conn",...
https://github.com/jython/frozen-mirror/blob/b8d7aa4cee50c0c0fe2f4b235dd62922dd0f3f99/lib-python/2.7/httplib.py#L1175-L1180
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/IPython/nbformat/v2/rwbase.py
python
NotebookWriter.writes
(self, nb, **kwargs)
Write a notebook to a string.
Write a notebook to a string.
[ "Write", "a", "notebook", "to", "a", "string", "." ]
def writes(self, nb, **kwargs): """Write a notebook to a string.""" raise NotImplementedError("loads must be implemented in a subclass")
[ "def", "writes", "(", "self", ",", "nb", ",", "*", "*", "kwargs", ")", ":", "raise", "NotImplementedError", "(", "\"loads must be implemented in a subclass\"", ")" ]
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/IPython/nbformat/v2/rwbase.py#L156-L158
raiden-network/raiden
76c68b426a6f81f173b9a2c09bd88a610502c38b
raiden/network/proxies/token_network.py
python
TokenNetwork.channel_is_settled
( self, participant1: Address, participant2: Address, block_identifier: BlockIdentifier, channel_identifier: ChannelID, )
return channel_data.state >= ChannelState.SETTLED
Returns true if the channel is in a settled state, false otherwise.
Returns true if the channel is in a settled state, false otherwise.
[ "Returns", "true", "if", "the", "channel", "is", "in", "a", "settled", "state", "false", "otherwise", "." ]
def channel_is_settled( self, participant1: Address, participant2: Address, block_identifier: BlockIdentifier, channel_identifier: ChannelID, ) -> bool: """Returns true if the channel is in a settled state, false otherwise.""" try: channel_data = self._detail_channel( participant1=participant1, participant2=participant2, block_identifier=block_identifier, channel_identifier=channel_identifier, ) except RaidenRecoverableError: return False return channel_data.state >= ChannelState.SETTLED
[ "def", "channel_is_settled", "(", "self", ",", "participant1", ":", "Address", ",", "participant2", ":", "Address", ",", "block_identifier", ":", "BlockIdentifier", ",", "channel_identifier", ":", "ChannelID", ",", ")", "->", "bool", ":", "try", ":", "channel_da...
https://github.com/raiden-network/raiden/blob/76c68b426a6f81f173b9a2c09bd88a610502c38b/raiden/network/proxies/token_network.py#L633-L650
albertz/music-player
d23586f5bf657cbaea8147223be7814d117ae73d
mac/pyobjc-core/Lib/objc/_descriptors.py
python
accessor
(func, typeSignature=b'@')
Return an Objective-C method object that is conformant with key-value coding and key-value observing.
Return an Objective-C method object that is conformant with key-value coding and key-value observing.
[ "Return", "an", "Objective", "-", "C", "method", "object", "that", "is", "conformant", "with", "key", "-", "value", "coding", "and", "key", "-", "value", "observing", "." ]
def accessor(func, typeSignature=b'@'): """ Return an Objective-C method object that is conformant with key-value coding and key-value observing. """ args, varargs, varkw, defaults = getargspec(func) funcName = func.__name__ maxArgs = len(args) minArgs = maxArgs - len(defaults or ()) # implicit self selArgs = 1 + funcName.count('_') if varargs is not None or varkw is not None: raise TypeError('%s can not be an accessor because it accepts varargs or varkw' % (funcName,)) if not (minArgs <= selArgs <= maxArgs): if minArgs == maxArgs: raise TypeError('%s expected to take %d args, but must accept %d from Objective-C (implicit self plus count of underscores)' % (funcName, maxArgs, selArgs)) else: raise TypeError('%s expected to take between %d and %d args, but must accept %d from Objective-C (implicit self plus count of underscores)' % (funcName, minArgs, maxArgs, selArgs)) if selArgs == 3: if funcName.startswith('validate') and funcName.endswith('_error_'): return selector(func, signature=_C_NSBOOL + b'@:N^@o^@') if funcName.startswith('insertObject_in') and funcName.endswith('AtIndex_'): return selector(func, signature=b'v@:' + typeSignature + _C_NSUInteger) elif funcName.startswith('replaceObjectIn') and funcName.endswith('AtIndex_withObject_'): return selector(func, signature=b'v@:' + _C_NSUInteger + typeSignature) elif funcName.startswith('get') and funcName.endswith('_range_'): return selector(func, signature=b'v@:o^@' + _C_NSRange) elif funcName.startswith('insert') and funcName.endswith('_atIndexes_'): return selector(func, signature=b'v@:@@') elif funcName.startswith('replace') and 'AtIndexes_with' in funcName: return selector(func, signature=b'v@:@@') # pass through to "too many arguments" elif selArgs == 2: if funcName.startswith('objectIn') and funcName.endswith('AtIndex_'): return selector(func, signature=typeSignature + b'@:' + _C_NSUInteger) elif funcName.startswith('removeObjectFrom') and funcName.endswith('AtIndex_'): return selector(func, signature=b'v@:' + _C_NSUInteger) elif funcName.startswith('remove') and funcName.endswith('AtIndexes_'): return selector(func, signature=b"v@:@") elif funcName.endswith('AtIndexes_'): return selector(func, signature=b"@@:@") elif funcName.startswith('memberOf'): return selector(func, signature=_C_NSBOOL + b"@:" + typeSignature) elif funcName.startswith('add') and funcName.endswith('Object_'): return selector(func, signature=b"v@:" + typeSignature) elif funcName.startswith('add'): return selector(func, signature=b"v@:@") elif funcName.startswith('intersect'): return selector(func, signature=b"v@:@") return selector(func, signature=b"v@:" + typeSignature) elif selArgs == 1: if funcName.startswith('countOf'): typeSignature = _C_NSUInteger elif funcName.startswith('enumerator'): typeSignature = b"@" return selector(func, signature=typeSignature + b"@:") raise TypeError("%s not recognized as an accessor" % (funcName,))
[ "def", "accessor", "(", "func", ",", "typeSignature", "=", "b'@'", ")", ":", "args", ",", "varargs", ",", "varkw", ",", "defaults", "=", "getargspec", "(", "func", ")", "funcName", "=", "func", ".", "__name__", "maxArgs", "=", "len", "(", "args", ")", ...
https://github.com/albertz/music-player/blob/d23586f5bf657cbaea8147223be7814d117ae73d/mac/pyobjc-core/Lib/objc/_descriptors.py#L43-L112
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/isy994/binary_sensor.py
python
ISYBinarySensorHeartbeat.async_on_update
(self, event: object)
Ignore node status updates. We listen directly to the Control events for this device.
Ignore node status updates.
[ "Ignore", "node", "status", "updates", "." ]
def async_on_update(self, event: object) -> None: """Ignore node status updates. We listen directly to the Control events for this device. """
[ "def", "async_on_update", "(", "self", ",", "event", ":", "object", ")", "->", "None", ":" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/isy994/binary_sensor.py#L438-L442
ZKeeer/WeChatAssistant
6e9b597b94f92f23366de69279e6e14df32ea2e3
WebVersion/weixin/revo/signin.py
python
SignInMPS.IsSigned
(self)
return (last_date == str(time.localtime().tm_mday))
获取上次签到日期,并进行判断当天是否签到了 :return: True:两次日期相同,已经签到了
获取上次签到日期,并进行判断当天是否签到了 :return: True:两次日期相同,已经签到了
[ "获取上次签到日期", "并进行判断当天是否签到了", ":", "return", ":", "True", ":", "两次日期相同,已经签到了" ]
def IsSigned(self): """ 获取上次签到日期,并进行判断当天是否签到了 :return: True:两次日期相同,已经签到了 """ if not os.path.exists(self.Date_path): with open(self.Date_path, "w") as fw: fw.write(str(time.localtime().tm_mday)) last_date = str((time.localtime().tm_mday - 1)) else: with open(self.Date_path, 'r') as fr: last_date = fr.read() return (last_date == str(time.localtime().tm_mday))
[ "def", "IsSigned", "(", "self", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "Date_path", ")", ":", "with", "open", "(", "self", ".", "Date_path", ",", "\"w\"", ")", "as", "fw", ":", "fw", ".", "write", "(", "str", ...
https://github.com/ZKeeer/WeChatAssistant/blob/6e9b597b94f92f23366de69279e6e14df32ea2e3/WebVersion/weixin/revo/signin.py#L52-L65
hkust-vgd/scanobjectnn
fe60aeade9ceb8882bc3f1bc40612e65469d7e77
pointnet/models/transform_nets.py
python
input_transform_net
(point_cloud, is_training, bn_decay=None, K=3)
return transform
Input (XYZ) Transform Net, input is BxNx3 gray image Return: Transformation matrix of size 3xK
Input (XYZ) Transform Net, input is BxNx3 gray image Return: Transformation matrix of size 3xK
[ "Input", "(", "XYZ", ")", "Transform", "Net", "input", "is", "BxNx3", "gray", "image", "Return", ":", "Transformation", "matrix", "of", "size", "3xK" ]
def input_transform_net(point_cloud, is_training, bn_decay=None, K=3): """ Input (XYZ) Transform Net, input is BxNx3 gray image Return: Transformation matrix of size 3xK """ batch_size = point_cloud.get_shape()[0].value num_point = point_cloud.get_shape()[1].value input_image = tf.expand_dims(point_cloud, -1) net = tf_util.conv2d(input_image, 64, [1,3], padding='VALID', stride=[1,1], bn=True, is_training=is_training, scope='tconv1', bn_decay=bn_decay) net = tf_util.conv2d(net, 128, [1,1], padding='VALID', stride=[1,1], bn=True, is_training=is_training, scope='tconv2', bn_decay=bn_decay) net = tf_util.conv2d(net, 1024, [1,1], padding='VALID', stride=[1,1], bn=True, is_training=is_training, scope='tconv3', bn_decay=bn_decay) net = tf_util.max_pool2d(net, [num_point,1], padding='VALID', scope='tmaxpool') net = tf.reshape(net, [batch_size, -1]) net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='tfc1', bn_decay=bn_decay) net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='tfc2', bn_decay=bn_decay) with tf.variable_scope('transform_XYZ') as sc: assert(K==3) weights = tf.get_variable('weights', [256, 3*K], initializer=tf.constant_initializer(0.0), dtype=tf.float32) biases = tf.get_variable('biases', [3*K], initializer=tf.constant_initializer(0.0), dtype=tf.float32) biases += tf.constant([1,0,0,0,1,0,0,0,1], dtype=tf.float32) transform = tf.matmul(net, weights) transform = tf.nn.bias_add(transform, biases) transform = tf.reshape(transform, [batch_size, 3, K]) return transform
[ "def", "input_transform_net", "(", "point_cloud", ",", "is_training", ",", "bn_decay", "=", "None", ",", "K", "=", "3", ")", ":", "batch_size", "=", "point_cloud", ".", "get_shape", "(", ")", "[", "0", "]", ".", "value", "num_point", "=", "point_cloud", ...
https://github.com/hkust-vgd/scanobjectnn/blob/fe60aeade9ceb8882bc3f1bc40612e65469d7e77/pointnet/models/transform_nets.py#L10-L52
edgewall/trac
beb3e4eaf1e0a456d801a50a8614ecab06de29fc
trac/core.py
python
Component.__repr__
(self)
return '<Component %s.%s>' % (self.__class__.__module__, self.__class__.__name__)
Return a textual representation of the component.
Return a textual representation of the component.
[ "Return", "a", "textual", "representation", "of", "the", "component", "." ]
def __repr__(self): """Return a textual representation of the component.""" return '<Component %s.%s>' % (self.__class__.__module__, self.__class__.__name__)
[ "def", "__repr__", "(", "self", ")", ":", "return", "'<Component %s.%s>'", "%", "(", "self", ".", "__class__", ".", "__module__", ",", "self", ".", "__class__", ".", "__name__", ")" ]
https://github.com/edgewall/trac/blob/beb3e4eaf1e0a456d801a50a8614ecab06de29fc/trac/core.py#L200-L203
unknown-horizons/unknown-horizons
7397fb333006d26c3d9fe796c7bd9cb8c3b43a49
horizons/savegamemanager.py
python
SavegameManager.get_available_scenarios
(cls, include_displaynames=True, locales=False)
return translated_scenarios
Returns available scenarios.
Returns available scenarios.
[ "Returns", "available", "scenarios", "." ]
def get_available_scenarios(cls, include_displaynames=True, locales=False): """Returns available scenarios.""" translated_scenarios = defaultdict(list) scenarios = list(zip(*cls.get_scenarios(include_displaynames=True))) for filename, scenario in scenarios: if not os.path.exists(filename): continue if not os.stat(filename).st_size: # file seems empty continue _locale = cls.get_scenario_metadata(scenario=scenario).get('locale', 'en') # sort into dictionary by english filename (without language suffix) english_name = scenario.split('_' + _locale)[0] translated_scenarios[english_name].append((_locale, filename)) return translated_scenarios
[ "def", "get_available_scenarios", "(", "cls", ",", "include_displaynames", "=", "True", ",", "locales", "=", "False", ")", ":", "translated_scenarios", "=", "defaultdict", "(", "list", ")", "scenarios", "=", "list", "(", "zip", "(", "*", "cls", ".", "get_sce...
https://github.com/unknown-horizons/unknown-horizons/blob/7397fb333006d26c3d9fe796c7bd9cb8c3b43a49/horizons/savegamemanager.py#L362-L376
radlab/sparrow
afb8efadeb88524f1394d1abe4ea66c6fd2ac744
src/main/python/third_party/stats.py
python
lkendalltau
(x,y)
return tau, prob
Calculates Kendall's tau ... correlation of ordinal data. Adapted from function kendl1 in Numerical Recipies. Needs good test-routine.@@@ Usage: lkendalltau(x,y) Returns: Kendall's tau, two-tailed p-value
Calculates Kendall's tau ... correlation of ordinal data. Adapted from function kendl1 in Numerical Recipies. Needs good test-routine.@@@
[ "Calculates", "Kendall", "s", "tau", "...", "correlation", "of", "ordinal", "data", ".", "Adapted", "from", "function", "kendl1", "in", "Numerical", "Recipies", ".", "Needs", "good", "test", "-", "routine", ".", "@@@" ]
def lkendalltau(x,y): """ Calculates Kendall's tau ... correlation of ordinal data. Adapted from function kendl1 in Numerical Recipies. Needs good test-routine.@@@ Usage: lkendalltau(x,y) Returns: Kendall's tau, two-tailed p-value """ n1 = 0 n2 = 0 iss = 0 for j in range(len(x)-1): for k in range(j,len(y)): a1 = x[j] - x[k] a2 = y[j] - y[k] aa = a1 * a2 if (aa): # neither list has a tie n1 = n1 + 1 n2 = n2 + 1 if aa > 0: iss = iss + 1 else: iss = iss -1 else: if (a1): n1 = n1 + 1 else: n2 = n2 + 1 tau = iss / math.sqrt(n1*n2) svar = (4.0*len(x)+10.0) / (9.0*len(x)*(len(x)-1)) z = tau / math.sqrt(svar) prob = erfcc(abs(z)/1.4142136) return tau, prob
[ "def", "lkendalltau", "(", "x", ",", "y", ")", ":", "n1", "=", "0", "n2", "=", "0", "iss", "=", "0", "for", "j", "in", "range", "(", "len", "(", "x", ")", "-", "1", ")", ":", "for", "k", "in", "range", "(", "j", ",", "len", "(", "y", ")...
https://github.com/radlab/sparrow/blob/afb8efadeb88524f1394d1abe4ea66c6fd2ac744/src/main/python/third_party/stats.py#L930-L962
presslabs/gitfs
12886ec5b9c7e103bfcab0cd37a8333873382fae
gitfs/repository.py
python
Repository.get_git_object_type
(self, tree, path)
Returns the filemode of the git object with the relative path <path>. :param tree: a `pygit2.Tree` instance :param path: the relative path of the object :type entry_name: str :returns: the filemode for the entry in case of success (which can be one of the following) or None otherwise. 0 (0000000) GIT_FILEMODE_NEW 16384 (0040000) GIT_FILEMODE_TREE 33188 (0100644) GIT_FILEMODE_BLOB 33261 (0100755) GIT_FILEMODE_BLOB_EXECUTABLE 40960 (0120000) GIT_FILEMODE_LINK 57344 (0160000) GIT_FILEMODE_COMMIT :rtype: int, None
Returns the filemode of the git object with the relative path <path>.
[ "Returns", "the", "filemode", "of", "the", "git", "object", "with", "the", "relative", "path", "<path", ">", "." ]
def get_git_object_type(self, tree, path): """ Returns the filemode of the git object with the relative path <path>. :param tree: a `pygit2.Tree` instance :param path: the relative path of the object :type entry_name: str :returns: the filemode for the entry in case of success (which can be one of the following) or None otherwise. 0 (0000000) GIT_FILEMODE_NEW 16384 (0040000) GIT_FILEMODE_TREE 33188 (0100644) GIT_FILEMODE_BLOB 33261 (0100755) GIT_FILEMODE_BLOB_EXECUTABLE 40960 (0120000) GIT_FILEMODE_LINK 57344 (0160000) GIT_FILEMODE_COMMIT :rtype: int, None """ path_components = split_path_into_components(path) try: return self._get_git_object( tree, path_components[-1], path_components, lambda entry: entry.filemode ) except: return GIT_FILEMODE_TREE
[ "def", "get_git_object_type", "(", "self", ",", "tree", ",", "path", ")", ":", "path_components", "=", "split_path_into_components", "(", "path", ")", "try", ":", "return", "self", ".", "_get_git_object", "(", "tree", ",", "path_components", "[", "-", "1", "...
https://github.com/presslabs/gitfs/blob/12886ec5b9c7e103bfcab0cd37a8333873382fae/gitfs/repository.py#L264-L288