id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
45,900 | django-fluent/django-fluent-blogs | fluent_blogs/models/query.py | _get_order_by | def _get_order_by(order, orderby, order_by_fields):
"""
Return the order by syntax for a model.
Checks whether use ascending or descending order, and maps the fieldnames.
"""
try:
# Find the actual database fieldnames for the keyword.
db_fieldnames = order_by_fields[orderby]
exce... | python | def _get_order_by(order, orderby, order_by_fields):
"""
Return the order by syntax for a model.
Checks whether use ascending or descending order, and maps the fieldnames.
"""
try:
# Find the actual database fieldnames for the keyword.
db_fieldnames = order_by_fields[orderby]
exce... | [
"def",
"_get_order_by",
"(",
"order",
",",
"orderby",
",",
"order_by_fields",
")",
":",
"try",
":",
"# Find the actual database fieldnames for the keyword.",
"db_fieldnames",
"=",
"order_by_fields",
"[",
"orderby",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
... | Return the order by syntax for a model.
Checks whether use ascending or descending order, and maps the fieldnames. | [
"Return",
"the",
"order",
"by",
"syntax",
"for",
"a",
"model",
".",
"Checks",
"whether",
"use",
"ascending",
"or",
"descending",
"order",
"and",
"maps",
"the",
"fieldnames",
"."
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L51-L69 |
45,901 | django-fluent/django-fluent-blogs | fluent_blogs/models/query.py | query_entries | def query_entries(
queryset=None,
year=None, month=None, day=None,
category=None, category_slug=None,
tag=None, tag_slug=None,
author=None, author_slug=None,
future=False,
order=None,
orderby=None,
limit=None,
):
"""
Query the entries using a set of predefined filters.
Th... | python | def query_entries(
queryset=None,
year=None, month=None, day=None,
category=None, category_slug=None,
tag=None, tag_slug=None,
author=None, author_slug=None,
future=False,
order=None,
orderby=None,
limit=None,
):
"""
Query the entries using a set of predefined filters.
Th... | [
"def",
"query_entries",
"(",
"queryset",
"=",
"None",
",",
"year",
"=",
"None",
",",
"month",
"=",
"None",
",",
"day",
"=",
"None",
",",
"category",
"=",
"None",
",",
"category_slug",
"=",
"None",
",",
"tag",
"=",
"None",
",",
"tag_slug",
"=",
"None"... | Query the entries using a set of predefined filters.
This interface is mainly used by the ``get_entries`` template tag. | [
"Query",
"the",
"entries",
"using",
"a",
"set",
"of",
"predefined",
"filters",
".",
"This",
"interface",
"is",
"mainly",
"used",
"by",
"the",
"get_entries",
"template",
"tag",
"."
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L72-L144 |
45,902 | django-fluent/django-fluent-blogs | fluent_blogs/models/query.py | query_tags | def query_tags(order=None, orderby=None, limit=None):
"""
Query the tags, with usage count included.
This interface is mainly used by the ``get_tags`` template tag.
"""
from taggit.models import Tag, TaggedItem # feature is still optional
# Get queryset filters for published entries
Entr... | python | def query_tags(order=None, orderby=None, limit=None):
"""
Query the tags, with usage count included.
This interface is mainly used by the ``get_tags`` template tag.
"""
from taggit.models import Tag, TaggedItem # feature is still optional
# Get queryset filters for published entries
Entr... | [
"def",
"query_tags",
"(",
"order",
"=",
"None",
",",
"orderby",
"=",
"None",
",",
"limit",
"=",
"None",
")",
":",
"from",
"taggit",
".",
"models",
"import",
"Tag",
",",
"TaggedItem",
"# feature is still optional",
"# Get queryset filters for published entries",
"E... | Query the tags, with usage count included.
This interface is mainly used by the ``get_tags`` template tag. | [
"Query",
"the",
"tags",
"with",
"usage",
"count",
"included",
".",
"This",
"interface",
"is",
"mainly",
"used",
"by",
"the",
"get_tags",
"template",
"tag",
"."
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L147-L184 |
45,903 | django-fluent/django-fluent-blogs | fluent_blogs/models/query.py | get_category_for_slug | def get_category_for_slug(slug, language_code=None):
"""
Find the category for a given slug
"""
Category = get_category_model()
if issubclass(Category, TranslatableModel):
return Category.objects.active_translations(language_code, slug=slug).get()
else:
return Category.objects.ge... | python | def get_category_for_slug(slug, language_code=None):
"""
Find the category for a given slug
"""
Category = get_category_model()
if issubclass(Category, TranslatableModel):
return Category.objects.active_translations(language_code, slug=slug).get()
else:
return Category.objects.ge... | [
"def",
"get_category_for_slug",
"(",
"slug",
",",
"language_code",
"=",
"None",
")",
":",
"Category",
"=",
"get_category_model",
"(",
")",
"if",
"issubclass",
"(",
"Category",
",",
"TranslatableModel",
")",
":",
"return",
"Category",
".",
"objects",
".",
"acti... | Find the category for a given slug | [
"Find",
"the",
"category",
"for",
"a",
"given",
"slug"
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L187-L195 |
45,904 | django-fluent/django-fluent-blogs | fluent_blogs/models/query.py | get_date_range | def get_date_range(year=None, month=None, day=None):
"""
Return a start..end range to query for a specific month, day or year.
"""
if year is None:
return None
if month is None:
# year only
start = datetime(year, 1, 1, 0, 0, 0, tzinfo=utc)
end = datetime(year, 12, 31... | python | def get_date_range(year=None, month=None, day=None):
"""
Return a start..end range to query for a specific month, day or year.
"""
if year is None:
return None
if month is None:
# year only
start = datetime(year, 1, 1, 0, 0, 0, tzinfo=utc)
end = datetime(year, 12, 31... | [
"def",
"get_date_range",
"(",
"year",
"=",
"None",
",",
"month",
"=",
"None",
",",
"day",
"=",
"None",
")",
":",
"if",
"year",
"is",
"None",
":",
"return",
"None",
"if",
"month",
"is",
"None",
":",
"# year only",
"start",
"=",
"datetime",
"(",
"year"... | Return a start..end range to query for a specific month, day or year. | [
"Return",
"a",
"start",
"..",
"end",
"range",
"to",
"query",
"for",
"a",
"specific",
"month",
"day",
"or",
"year",
"."
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/query.py#L198-L220 |
45,905 | mabuchilab/QNET | src/qnet/algebra/pattern_matching/__init__.py | pattern | def pattern(head, *args, mode=1, wc_name=None, conditions=None, **kwargs) \
-> Pattern:
"""'Flat' constructor for the Pattern class
Positional and keyword arguments are mapped into `args` and `kwargs`,
respectively. Useful for defining rules that match an instantiated
Expression with specific a... | python | def pattern(head, *args, mode=1, wc_name=None, conditions=None, **kwargs) \
-> Pattern:
"""'Flat' constructor for the Pattern class
Positional and keyword arguments are mapped into `args` and `kwargs`,
respectively. Useful for defining rules that match an instantiated
Expression with specific a... | [
"def",
"pattern",
"(",
"head",
",",
"*",
"args",
",",
"mode",
"=",
"1",
",",
"wc_name",
"=",
"None",
",",
"conditions",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
"->",
"Pattern",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"args",
"=",... | Flat' constructor for the Pattern class
Positional and keyword arguments are mapped into `args` and `kwargs`,
respectively. Useful for defining rules that match an instantiated
Expression with specific arguments | [
"Flat",
"constructor",
"for",
"the",
"Pattern",
"class"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L452-L465 |
45,906 | mabuchilab/QNET | src/qnet/algebra/pattern_matching/__init__.py | match_pattern | def match_pattern(expr_or_pattern: object, expr: object) -> MatchDict:
"""Recursively match `expr` with the given `expr_or_pattern`
Args:
expr_or_pattern: either a direct expression (equal to `expr` for a
successful match), or an instance of :class:`Pattern`.
expr: the expression to... | python | def match_pattern(expr_or_pattern: object, expr: object) -> MatchDict:
"""Recursively match `expr` with the given `expr_or_pattern`
Args:
expr_or_pattern: either a direct expression (equal to `expr` for a
successful match), or an instance of :class:`Pattern`.
expr: the expression to... | [
"def",
"match_pattern",
"(",
"expr_or_pattern",
":",
"object",
",",
"expr",
":",
"object",
")",
"->",
"MatchDict",
":",
"try",
":",
"# first try expr_or_pattern as a Pattern",
"return",
"expr_or_pattern",
".",
"match",
"(",
"expr",
")",
"except",
"AttributeError",
... | Recursively match `expr` with the given `expr_or_pattern`
Args:
expr_or_pattern: either a direct expression (equal to `expr` for a
successful match), or an instance of :class:`Pattern`.
expr: the expression to be matched | [
"Recursively",
"match",
"expr",
"with",
"the",
"given",
"expr_or_pattern"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L613-L631 |
45,907 | mabuchilab/QNET | src/qnet/algebra/pattern_matching/__init__.py | MatchDict.update | def update(self, *others):
"""Update dict with entries from `other`
If `other` has an attribute ``success=False`` and ``reason``, those
attributes are copied as well
"""
for other in others:
for key, val in other.items():
self[key] = val
t... | python | def update(self, *others):
"""Update dict with entries from `other`
If `other` has an attribute ``success=False`` and ``reason``, those
attributes are copied as well
"""
for other in others:
for key, val in other.items():
self[key] = val
t... | [
"def",
"update",
"(",
"self",
",",
"*",
"others",
")",
":",
"for",
"other",
"in",
"others",
":",
"for",
"key",
",",
"val",
"in",
"other",
".",
"items",
"(",
")",
":",
"self",
"[",
"key",
"]",
"=",
"val",
"try",
":",
"if",
"not",
"other",
".",
... | Update dict with entries from `other`
If `other` has an attribute ``success=False`` and ``reason``, those
attributes are copied as well | [
"Update",
"dict",
"with",
"entries",
"from",
"other"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L83-L97 |
45,908 | mabuchilab/QNET | src/qnet/algebra/pattern_matching/__init__.py | Pattern.extended_arg_patterns | def extended_arg_patterns(self):
"""Iterator over patterns for positional arguments to be matched
This yields the elements of :attr:`args`, extended by their `mode`
value
"""
for arg in self._arg_iterator(self.args):
if isinstance(arg, Pattern):
if ar... | python | def extended_arg_patterns(self):
"""Iterator over patterns for positional arguments to be matched
This yields the elements of :attr:`args`, extended by their `mode`
value
"""
for arg in self._arg_iterator(self.args):
if isinstance(arg, Pattern):
if ar... | [
"def",
"extended_arg_patterns",
"(",
"self",
")",
":",
"for",
"arg",
"in",
"self",
".",
"_arg_iterator",
"(",
"self",
".",
"args",
")",
":",
"if",
"isinstance",
"(",
"arg",
",",
"Pattern",
")",
":",
"if",
"arg",
".",
"mode",
">",
"self",
".",
"single... | Iterator over patterns for positional arguments to be matched
This yields the elements of :attr:`args`, extended by their `mode`
value | [
"Iterator",
"over",
"patterns",
"for",
"positional",
"arguments",
"to",
"be",
"matched"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L232-L246 |
45,909 | mabuchilab/QNET | src/qnet/algebra/pattern_matching/__init__.py | Pattern.finditer | def finditer(self, expr):
"""Return an iterator over all matches in `expr`
Iterate over all :class:`MatchDict` results of matches for any
matching (sub-)expressions in `expr`. The order of the matches conforms
to the equivalent matched expressions returned by :meth:`findall`.
""... | python | def finditer(self, expr):
"""Return an iterator over all matches in `expr`
Iterate over all :class:`MatchDict` results of matches for any
matching (sub-)expressions in `expr`. The order of the matches conforms
to the equivalent matched expressions returned by :meth:`findall`.
""... | [
"def",
"finditer",
"(",
"self",
",",
"expr",
")",
":",
"try",
":",
"for",
"arg",
"in",
"expr",
".",
"args",
":",
"for",
"m",
"in",
"self",
".",
"finditer",
"(",
"arg",
")",
":",
"yield",
"m",
"for",
"arg",
"in",
"expr",
".",
"kwargs",
".",
"val... | Return an iterator over all matches in `expr`
Iterate over all :class:`MatchDict` results of matches for any
matching (sub-)expressions in `expr`. The order of the matches conforms
to the equivalent matched expressions returned by :meth:`findall`. | [
"Return",
"an",
"iterator",
"over",
"all",
"matches",
"in",
"expr"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L370-L388 |
45,910 | mabuchilab/QNET | src/qnet/algebra/pattern_matching/__init__.py | Pattern.wc_names | def wc_names(self):
"""Set of all wildcard names occurring in the pattern"""
if self.wc_name is None:
res = set()
else:
res = set([self.wc_name])
if self.args is not None:
for arg in self.args:
if isinstance(arg, Pattern):
... | python | def wc_names(self):
"""Set of all wildcard names occurring in the pattern"""
if self.wc_name is None:
res = set()
else:
res = set([self.wc_name])
if self.args is not None:
for arg in self.args:
if isinstance(arg, Pattern):
... | [
"def",
"wc_names",
"(",
"self",
")",
":",
"if",
"self",
".",
"wc_name",
"is",
"None",
":",
"res",
"=",
"set",
"(",
")",
"else",
":",
"res",
"=",
"set",
"(",
"[",
"self",
".",
"wc_name",
"]",
")",
"if",
"self",
".",
"args",
"is",
"not",
"None",
... | Set of all wildcard names occurring in the pattern | [
"Set",
"of",
"all",
"wildcard",
"names",
"occurring",
"in",
"the",
"pattern"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L391-L405 |
45,911 | mabuchilab/QNET | src/qnet/algebra/pattern_matching/__init__.py | ProtoExpr.from_expr | def from_expr(cls, expr):
"""Instantiate proto-expression from the given Expression"""
return cls(expr.args, expr.kwargs, cls=expr.__class__) | python | def from_expr(cls, expr):
"""Instantiate proto-expression from the given Expression"""
return cls(expr.args, expr.kwargs, cls=expr.__class__) | [
"def",
"from_expr",
"(",
"cls",
",",
"expr",
")",
":",
"return",
"cls",
"(",
"expr",
".",
"args",
",",
"expr",
".",
"kwargs",
",",
"cls",
"=",
"expr",
".",
"__class__",
")"
] | Instantiate proto-expression from the given Expression | [
"Instantiate",
"proto",
"-",
"expression",
"from",
"the",
"given",
"Expression"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/pattern_matching/__init__.py#L604-L606 |
45,912 | django-fluent/django-fluent-blogs | fluent_blogs/models/db.py | get_entry_model | def get_entry_model():
"""
Return the actual entry model that is in use.
This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model.
The model is automatically registered with *django-fluent-comments*
and *django-any-urlfield* when it's installed.
"""
global _EntryMod... | python | def get_entry_model():
"""
Return the actual entry model that is in use.
This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model.
The model is automatically registered with *django-fluent-comments*
and *django-any-urlfield* when it's installed.
"""
global _EntryMod... | [
"def",
"get_entry_model",
"(",
")",
":",
"global",
"_EntryModel",
"if",
"_EntryModel",
"is",
"None",
":",
"# This method is likely called the first time when the admin initializes, the sitemaps module is imported, or BaseBlogMixin is used.",
"# Either way, it needs to happen after all apps... | Return the actual entry model that is in use.
This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model.
The model is automatically registered with *django-fluent-comments*
and *django-any-urlfield* when it's installed. | [
"Return",
"the",
"actual",
"entry",
"model",
"that",
"is",
"in",
"use",
"."
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/db.py#L43-L80 |
45,913 | django-fluent/django-fluent-blogs | fluent_blogs/models/db.py | get_category_model | def get_category_model():
"""
Return the category model to use.
This function reads the :ref:`FLUENT_BLOGS_CATEGORY_MODEL` setting to find the model.
"""
app_label, model_name = appsettings.FLUENT_BLOGS_CATEGORY_MODEL.rsplit('.', 1)
try:
return apps.get_model(app_label, model_name)
... | python | def get_category_model():
"""
Return the category model to use.
This function reads the :ref:`FLUENT_BLOGS_CATEGORY_MODEL` setting to find the model.
"""
app_label, model_name = appsettings.FLUENT_BLOGS_CATEGORY_MODEL.rsplit('.', 1)
try:
return apps.get_model(app_label, model_name)
... | [
"def",
"get_category_model",
"(",
")",
":",
"app_label",
",",
"model_name",
"=",
"appsettings",
".",
"FLUENT_BLOGS_CATEGORY_MODEL",
".",
"rsplit",
"(",
"'.'",
",",
"1",
")",
"try",
":",
"return",
"apps",
".",
"get_model",
"(",
"app_label",
",",
"model_name",
... | Return the category model to use.
This function reads the :ref:`FLUENT_BLOGS_CATEGORY_MODEL` setting to find the model. | [
"Return",
"the",
"category",
"model",
"to",
"use",
"."
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/models/db.py#L83-L95 |
45,914 | django-fluent/django-fluent-blogs | fluent_blogs/urlresolvers.py | blog_reverse | def blog_reverse(viewname, args=None, kwargs=None, current_app='fluent_blogs', **page_kwargs):
"""
Reverse a URL to the blog, taking various configuration options into account.
This is a compatibility function to allow django-fluent-blogs to operate stand-alone.
Either the app can be hooked in the URLc... | python | def blog_reverse(viewname, args=None, kwargs=None, current_app='fluent_blogs', **page_kwargs):
"""
Reverse a URL to the blog, taking various configuration options into account.
This is a compatibility function to allow django-fluent-blogs to operate stand-alone.
Either the app can be hooked in the URLc... | [
"def",
"blog_reverse",
"(",
"viewname",
",",
"args",
"=",
"None",
",",
"kwargs",
"=",
"None",
",",
"current_app",
"=",
"'fluent_blogs'",
",",
"*",
"*",
"page_kwargs",
")",
":",
"return",
"mixed_reverse",
"(",
"viewname",
",",
"args",
"=",
"args",
",",
"k... | Reverse a URL to the blog, taking various configuration options into account.
This is a compatibility function to allow django-fluent-blogs to operate stand-alone.
Either the app can be hooked in the URLconf directly, or it can be added as a pagetype of *django-fluent-pages*. | [
"Reverse",
"a",
"URL",
"to",
"the",
"blog",
"taking",
"various",
"configuration",
"options",
"into",
"account",
"."
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/urlresolvers.py#L4-L11 |
45,915 | mabuchilab/QNET | src/qnet/algebra/toolbox/commutator_manipulation.py | expand_commutators_leibniz | def expand_commutators_leibniz(expr, expand_expr=True):
"""Recursively expand commutators in `expr` according to the Leibniz rule.
.. math::
[A B, C] = A [B, C] + [A, C] B
.. math::
[A, B C] = [A, B] C + B [A, C]
If `expand_expr` is True, expand products of sums in `expr`, as well a... | python | def expand_commutators_leibniz(expr, expand_expr=True):
"""Recursively expand commutators in `expr` according to the Leibniz rule.
.. math::
[A B, C] = A [B, C] + [A, C] B
.. math::
[A, B C] = [A, B] C + B [A, C]
If `expand_expr` is True, expand products of sums in `expr`, as well a... | [
"def",
"expand_commutators_leibniz",
"(",
"expr",
",",
"expand_expr",
"=",
"True",
")",
":",
"recurse",
"=",
"partial",
"(",
"expand_commutators_leibniz",
",",
"expand_expr",
"=",
"expand_expr",
")",
"A",
"=",
"wc",
"(",
"'A'",
",",
"head",
"=",
"Operator",
... | Recursively expand commutators in `expr` according to the Leibniz rule.
.. math::
[A B, C] = A [B, C] + [A, C] B
.. math::
[A, B C] = [A, B] C + B [A, C]
If `expand_expr` is True, expand products of sums in `expr`, as well as in
the result. | [
"Recursively",
"expand",
"commutators",
"in",
"expr",
"according",
"to",
"the",
"Leibniz",
"rule",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/toolbox/commutator_manipulation.py#L14-L58 |
45,916 | mabuchilab/QNET | src/qnet/printing/__init__.py | init_printing | def init_printing(*, reset=False, init_sympy=True, **kwargs):
"""Initialize the printing system.
This determines the behavior of the :func:`ascii`, :func:`unicode`,
and :func:`latex` functions, as well as the ``__str__`` and ``__repr__`` of
any :class:`.Expression`.
The routine may be called in on... | python | def init_printing(*, reset=False, init_sympy=True, **kwargs):
"""Initialize the printing system.
This determines the behavior of the :func:`ascii`, :func:`unicode`,
and :func:`latex` functions, as well as the ``__str__`` and ``__repr__`` of
any :class:`.Expression`.
The routine may be called in on... | [
"def",
"init_printing",
"(",
"*",
",",
"reset",
"=",
"False",
",",
"init_sympy",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"# return either None (default) or a dict of frozen attributes if",
"# ``_freeze=True`` is given as a keyword argument (internal use in",
"# `confi... | Initialize the printing system.
This determines the behavior of the :func:`ascii`, :func:`unicode`,
and :func:`latex` functions, as well as the ``__str__`` and ``__repr__`` of
any :class:`.Expression`.
The routine may be called in one of two forms. First,
::
init_printing(
st... | [
"Initialize",
"the",
"printing",
"system",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/printing/__init__.py#L47-L143 |
45,917 | mabuchilab/QNET | src/qnet/printing/__init__.py | configure_printing | def configure_printing(**kwargs):
"""Context manager for temporarily changing the printing system.
This takes the same parameters as :func:`init_printing`
Example:
>>> A = OperatorSymbol('A', hs=1); B = OperatorSymbol('B', hs=1)
>>> with configure_printing(show_hs_label=False):
..... | python | def configure_printing(**kwargs):
"""Context manager for temporarily changing the printing system.
This takes the same parameters as :func:`init_printing`
Example:
>>> A = OperatorSymbol('A', hs=1); B = OperatorSymbol('B', hs=1)
>>> with configure_printing(show_hs_label=False):
..... | [
"def",
"configure_printing",
"(",
"*",
"*",
"kwargs",
")",
":",
"freeze",
"=",
"init_printing",
"(",
"_freeze",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
"try",
":",
"yield",
"finally",
":",
"for",
"obj",
",",
"attr_map",
"in",
"freeze",
".",
"items",... | Context manager for temporarily changing the printing system.
This takes the same parameters as :func:`init_printing`
Example:
>>> A = OperatorSymbol('A', hs=1); B = OperatorSymbol('B', hs=1)
>>> with configure_printing(show_hs_label=False):
... print(ascii(A + B))
A + B
... | [
"Context",
"manager",
"for",
"temporarily",
"changing",
"the",
"printing",
"system",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/printing/__init__.py#L272-L292 |
45,918 | mabuchilab/QNET | src/qnet/convert/to_qutip.py | convert_to_qutip | def convert_to_qutip(expr, full_space=None, mapping=None):
"""Convert a QNET expression to a qutip object
Args:
expr: a QNET expression
full_space (HilbertSpace): The
Hilbert space in which `expr` is defined. If not given,
``expr.space`` is used. The Hilbert space must h... | python | def convert_to_qutip(expr, full_space=None, mapping=None):
"""Convert a QNET expression to a qutip object
Args:
expr: a QNET expression
full_space (HilbertSpace): The
Hilbert space in which `expr` is defined. If not given,
``expr.space`` is used. The Hilbert space must h... | [
"def",
"convert_to_qutip",
"(",
"expr",
",",
"full_space",
"=",
"None",
",",
"mapping",
"=",
"None",
")",
":",
"if",
"full_space",
"is",
"None",
":",
"full_space",
"=",
"expr",
".",
"space",
"if",
"not",
"expr",
".",
"space",
".",
"is_tensor_factor_of",
... | Convert a QNET expression to a qutip object
Args:
expr: a QNET expression
full_space (HilbertSpace): The
Hilbert space in which `expr` is defined. If not given,
``expr.space`` is used. The Hilbert space must have a well-defined
basis.
mapping (dict): A ma... | [
"Convert",
"a",
"QNET",
"expression",
"to",
"a",
"qutip",
"object"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/convert/to_qutip.py#L44-L118 |
45,919 | mabuchilab/QNET | src/qnet/convert/to_qutip.py | _convert_local_operator_to_qutip | def _convert_local_operator_to_qutip(expr, full_space, mapping):
"""Convert a LocalOperator instance to qutip"""
n = full_space.dimension
if full_space != expr.space:
all_spaces = full_space.local_factors
own_space_index = all_spaces.index(expr.space)
return qutip.tensor(
... | python | def _convert_local_operator_to_qutip(expr, full_space, mapping):
"""Convert a LocalOperator instance to qutip"""
n = full_space.dimension
if full_space != expr.space:
all_spaces = full_space.local_factors
own_space_index = all_spaces.index(expr.space)
return qutip.tensor(
... | [
"def",
"_convert_local_operator_to_qutip",
"(",
"expr",
",",
"full_space",
",",
"mapping",
")",
":",
"n",
"=",
"full_space",
".",
"dimension",
"if",
"full_space",
"!=",
"expr",
".",
"space",
":",
"all_spaces",
"=",
"full_space",
".",
"local_factors",
"own_space_... | Convert a LocalOperator instance to qutip | [
"Convert",
"a",
"LocalOperator",
"instance",
"to",
"qutip"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/convert/to_qutip.py#L181-L226 |
45,920 | mabuchilab/QNET | src/qnet/convert/to_qutip.py | _time_dependent_to_qutip | def _time_dependent_to_qutip(
op, full_space=None, time_symbol=symbols("t", real=True),
convert_as='pyfunc'):
"""Convert a possiblty time-dependent operator into the nested-list
structure required by QuTiP"""
if full_space is None:
full_space = op.space
if time_symbol in op.free_... | python | def _time_dependent_to_qutip(
op, full_space=None, time_symbol=symbols("t", real=True),
convert_as='pyfunc'):
"""Convert a possiblty time-dependent operator into the nested-list
structure required by QuTiP"""
if full_space is None:
full_space = op.space
if time_symbol in op.free_... | [
"def",
"_time_dependent_to_qutip",
"(",
"op",
",",
"full_space",
"=",
"None",
",",
"time_symbol",
"=",
"symbols",
"(",
"\"t\"",
",",
"real",
"=",
"True",
")",
",",
"convert_as",
"=",
"'pyfunc'",
")",
":",
"if",
"full_space",
"is",
"None",
":",
"full_space"... | Convert a possiblty time-dependent operator into the nested-list
structure required by QuTiP | [
"Convert",
"a",
"possiblty",
"time",
"-",
"dependent",
"operator",
"into",
"the",
"nested",
"-",
"list",
"structure",
"required",
"by",
"QuTiP"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/convert/to_qutip.py#L412-L463 |
45,921 | mabuchilab/QNET | src/qnet/utils/unicode.py | ljust | def ljust(text, width, fillchar=' '):
"""Left-justify text to a total of `width`
The `width` is based on graphemes::
>>> s = 'Â'
>>> s.ljust(2)
'Â'
>>> ljust(s, 2)
'Â '
"""
len_text = grapheme_len(text)
return text + fillchar * (width - len_text) | python | def ljust(text, width, fillchar=' '):
"""Left-justify text to a total of `width`
The `width` is based on graphemes::
>>> s = 'Â'
>>> s.ljust(2)
'Â'
>>> ljust(s, 2)
'Â '
"""
len_text = grapheme_len(text)
return text + fillchar * (width - len_text) | [
"def",
"ljust",
"(",
"text",
",",
"width",
",",
"fillchar",
"=",
"' '",
")",
":",
"len_text",
"=",
"grapheme_len",
"(",
"text",
")",
"return",
"text",
"+",
"fillchar",
"*",
"(",
"width",
"-",
"len_text",
")"
] | Left-justify text to a total of `width`
The `width` is based on graphemes::
>>> s = 'Â'
>>> s.ljust(2)
'Â'
>>> ljust(s, 2)
'Â ' | [
"Left",
"-",
"justify",
"text",
"to",
"a",
"total",
"of",
"width"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/unicode.py#L21-L33 |
45,922 | mabuchilab/QNET | src/qnet/utils/unicode.py | rjust | def rjust(text, width, fillchar=' '):
"""Right-justify text for a total of `width` graphemes
The `width` is based on graphemes::
>>> s = 'Â'
>>> s.rjust(2)
'Â'
>>> rjust(s, 2)
' Â'
"""
len_text = grapheme_len(text)
return fillchar * (width - len_text) + t... | python | def rjust(text, width, fillchar=' '):
"""Right-justify text for a total of `width` graphemes
The `width` is based on graphemes::
>>> s = 'Â'
>>> s.rjust(2)
'Â'
>>> rjust(s, 2)
' Â'
"""
len_text = grapheme_len(text)
return fillchar * (width - len_text) + t... | [
"def",
"rjust",
"(",
"text",
",",
"width",
",",
"fillchar",
"=",
"' '",
")",
":",
"len_text",
"=",
"grapheme_len",
"(",
"text",
")",
"return",
"fillchar",
"*",
"(",
"width",
"-",
"len_text",
")",
"+",
"text"
] | Right-justify text for a total of `width` graphemes
The `width` is based on graphemes::
>>> s = 'Â'
>>> s.rjust(2)
'Â'
>>> rjust(s, 2)
' Â' | [
"Right",
"-",
"justify",
"text",
"for",
"a",
"total",
"of",
"width",
"graphemes"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/unicode.py#L36-L48 |
45,923 | mabuchilab/QNET | src/qnet/algebra/core/scalar_algebra.py | KroneckerDelta | def KroneckerDelta(i, j, simplify=True):
"""Kronecker delta symbol
Return :class:`One` (`i` equals `j`)), :class:`Zero` (`i` and `j` are
non-symbolic an unequal), or a :class:`ScalarValue` wrapping SymPy's
:class:`~sympy.functions.special.tensor_functions.KroneckerDelta`.
>>> i, j = IdxSym('i'... | python | def KroneckerDelta(i, j, simplify=True):
"""Kronecker delta symbol
Return :class:`One` (`i` equals `j`)), :class:`Zero` (`i` and `j` are
non-symbolic an unequal), or a :class:`ScalarValue` wrapping SymPy's
:class:`~sympy.functions.special.tensor_functions.KroneckerDelta`.
>>> i, j = IdxSym('i'... | [
"def",
"KroneckerDelta",
"(",
"i",
",",
"j",
",",
"simplify",
"=",
"True",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"scalar_algebra",
"import",
"ScalarValue",
",",
"One",
"if",
"not",
"isinstance",
"(",
"i",
",",
"(",
"int",
",",
"... | Kronecker delta symbol
Return :class:`One` (`i` equals `j`)), :class:`Zero` (`i` and `j` are
non-symbolic an unequal), or a :class:`ScalarValue` wrapping SymPy's
:class:`~sympy.functions.special.tensor_functions.KroneckerDelta`.
>>> i, j = IdxSym('i'), IdxSym('j')
>>> KroneckerDelta(i, i)
... | [
"Kronecker",
"delta",
"symbol"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L1106-L1148 |
45,924 | mabuchilab/QNET | src/qnet/algebra/core/scalar_algebra.py | ScalarTimes.create | def create(cls, *operands, **kwargs):
"""Instantiate the product while applying simplification rules"""
converted_operands = []
for op in operands:
if not isinstance(op, Scalar):
op = ScalarValue.create(op)
converted_operands.append(op)
return supe... | python | def create(cls, *operands, **kwargs):
"""Instantiate the product while applying simplification rules"""
converted_operands = []
for op in operands:
if not isinstance(op, Scalar):
op = ScalarValue.create(op)
converted_operands.append(op)
return supe... | [
"def",
"create",
"(",
"cls",
",",
"*",
"operands",
",",
"*",
"*",
"kwargs",
")",
":",
"converted_operands",
"=",
"[",
"]",
"for",
"op",
"in",
"operands",
":",
"if",
"not",
"isinstance",
"(",
"op",
",",
"Scalar",
")",
":",
"op",
"=",
"ScalarValue",
... | Instantiate the product while applying simplification rules | [
"Instantiate",
"the",
"product",
"while",
"applying",
"simplification",
"rules"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L898-L905 |
45,925 | mabuchilab/QNET | src/qnet/algebra/core/scalar_algebra.py | ScalarTimes.conjugate | def conjugate(self):
"""Complex conjugate of of the product"""
return self.__class__.create(
*[arg.conjugate() for arg in reversed(self.args)]) | python | def conjugate(self):
"""Complex conjugate of of the product"""
return self.__class__.create(
*[arg.conjugate() for arg in reversed(self.args)]) | [
"def",
"conjugate",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
".",
"create",
"(",
"*",
"[",
"arg",
".",
"conjugate",
"(",
")",
"for",
"arg",
"in",
"reversed",
"(",
"self",
".",
"args",
")",
"]",
")"
] | Complex conjugate of of the product | [
"Complex",
"conjugate",
"of",
"of",
"the",
"product"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L907-L910 |
45,926 | mabuchilab/QNET | src/qnet/algebra/core/scalar_algebra.py | ScalarIndexedSum.create | def create(cls, term, *ranges):
"""Instantiate the indexed sum while applying simplification rules"""
if not isinstance(term, Scalar):
term = ScalarValue.create(term)
return super().create(term, *ranges) | python | def create(cls, term, *ranges):
"""Instantiate the indexed sum while applying simplification rules"""
if not isinstance(term, Scalar):
term = ScalarValue.create(term)
return super().create(term, *ranges) | [
"def",
"create",
"(",
"cls",
",",
"term",
",",
"*",
"ranges",
")",
":",
"if",
"not",
"isinstance",
"(",
"term",
",",
"Scalar",
")",
":",
"term",
"=",
"ScalarValue",
".",
"create",
"(",
"term",
")",
"return",
"super",
"(",
")",
".",
"create",
"(",
... | Instantiate the indexed sum while applying simplification rules | [
"Instantiate",
"the",
"indexed",
"sum",
"while",
"applying",
"simplification",
"rules"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L950-L954 |
45,927 | mabuchilab/QNET | src/qnet/algebra/core/scalar_algebra.py | ScalarIndexedSum.conjugate | def conjugate(self):
"""Complex conjugate of of the indexed sum"""
return self.__class__.create(self.term.conjugate(), *self.ranges) | python | def conjugate(self):
"""Complex conjugate of of the indexed sum"""
return self.__class__.create(self.term.conjugate(), *self.ranges) | [
"def",
"conjugate",
"(",
"self",
")",
":",
"return",
"self",
".",
"__class__",
".",
"create",
"(",
"self",
".",
"term",
".",
"conjugate",
"(",
")",
",",
"*",
"self",
".",
"ranges",
")"
] | Complex conjugate of of the indexed sum | [
"Complex",
"conjugate",
"of",
"of",
"the",
"indexed",
"sum"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/scalar_algebra.py#L961-L963 |
45,928 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | collect_summands | def collect_summands(cls, ops, kwargs):
"""Collect summands that occur multiple times into a single summand
Also filters out zero-summands.
Example:
>>> A, B, C = (OperatorSymbol(s, hs=0) for s in ('A', 'B', 'C'))
>>> collect_summands(
... OperatorPlus, (A, B, C, ZeroOperator, ... | python | def collect_summands(cls, ops, kwargs):
"""Collect summands that occur multiple times into a single summand
Also filters out zero-summands.
Example:
>>> A, B, C = (OperatorSymbol(s, hs=0) for s in ('A', 'B', 'C'))
>>> collect_summands(
... OperatorPlus, (A, B, C, ZeroOperator, ... | [
"def",
"collect_summands",
"(",
"cls",
",",
"ops",
",",
"kwargs",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"abstract_quantum_algebra",
"import",
"(",
"ScalarTimesQuantumExpression",
")",
"coeff_map",
"=",
"OrderedDict",
"(",
")",
"for",
"op"... | Collect summands that occur multiple times into a single summand
Also filters out zero-summands.
Example:
>>> A, B, C = (OperatorSymbol(s, hs=0) for s in ('A', 'B', 'C'))
>>> collect_summands(
... OperatorPlus, (A, B, C, ZeroOperator, 2 * A, B, -C) , {})
((3 * A^(0), 2 * B^... | [
"Collect",
"summands",
"that",
"occur",
"multiple",
"times",
"into",
"a",
"single",
"summand"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L147-L184 |
45,929 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | _get_binary_replacement | def _get_binary_replacement(first, second, cls):
"""Helper function for match_replace_binary"""
expr = ProtoExpr([first, second], {})
if LOG:
logger = logging.getLogger('QNET.create')
for key, rule in cls._binary_rules.items():
pat, replacement = rule
match_dict = match_pattern(p... | python | def _get_binary_replacement(first, second, cls):
"""Helper function for match_replace_binary"""
expr = ProtoExpr([first, second], {})
if LOG:
logger = logging.getLogger('QNET.create')
for key, rule in cls._binary_rules.items():
pat, replacement = rule
match_dict = match_pattern(p... | [
"def",
"_get_binary_replacement",
"(",
"first",
",",
"second",
",",
"cls",
")",
":",
"expr",
"=",
"ProtoExpr",
"(",
"[",
"first",
",",
"second",
"]",
",",
"{",
"}",
")",
"if",
"LOG",
":",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"'QNET.create'"... | Helper function for match_replace_binary | [
"Helper",
"function",
"for",
"match_replace_binary"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L323-L350 |
45,930 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | _match_replace_binary | def _match_replace_binary(cls, ops: list) -> list:
"""Reduce list of `ops`"""
n = len(ops)
if n <= 1:
return ops
ops_left = ops[:n // 2]
ops_right = ops[n // 2:]
return _match_replace_binary_combine(
cls,
_match_replace_binary(cls, ops_left),
_match_replace_binary... | python | def _match_replace_binary(cls, ops: list) -> list:
"""Reduce list of `ops`"""
n = len(ops)
if n <= 1:
return ops
ops_left = ops[:n // 2]
ops_right = ops[n // 2:]
return _match_replace_binary_combine(
cls,
_match_replace_binary(cls, ops_left),
_match_replace_binary... | [
"def",
"_match_replace_binary",
"(",
"cls",
",",
"ops",
":",
"list",
")",
"->",
"list",
":",
"n",
"=",
"len",
"(",
"ops",
")",
"if",
"n",
"<=",
"1",
":",
"return",
"ops",
"ops_left",
"=",
"ops",
"[",
":",
"n",
"//",
"2",
"]",
"ops_right",
"=",
... | Reduce list of `ops` | [
"Reduce",
"list",
"of",
"ops"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L392-L402 |
45,931 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | _match_replace_binary_combine | def _match_replace_binary_combine(cls, a: list, b: list) -> list:
"""combine two fully reduced lists a, b"""
if len(a) == 0 or len(b) == 0:
return a + b
r = _get_binary_replacement(a[-1], b[0], cls)
if r is None:
return a + b
if r == cls._neutral_element:
return _match_replac... | python | def _match_replace_binary_combine(cls, a: list, b: list) -> list:
"""combine two fully reduced lists a, b"""
if len(a) == 0 or len(b) == 0:
return a + b
r = _get_binary_replacement(a[-1], b[0], cls)
if r is None:
return a + b
if r == cls._neutral_element:
return _match_replac... | [
"def",
"_match_replace_binary_combine",
"(",
"cls",
",",
"a",
":",
"list",
",",
"b",
":",
"list",
")",
"->",
"list",
":",
"if",
"len",
"(",
"a",
")",
"==",
"0",
"or",
"len",
"(",
"b",
")",
"==",
"0",
":",
"return",
"a",
"+",
"b",
"r",
"=",
"_... | combine two fully reduced lists a, b | [
"combine",
"two",
"fully",
"reduced",
"lists",
"a",
"b"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L405-L421 |
45,932 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | empty_trivial | def empty_trivial(cls, ops, kwargs):
"""A ProductSpace of zero Hilbert spaces should yield the TrivialSpace"""
from qnet.algebra.core.hilbert_space_algebra import TrivialSpace
if len(ops) == 0:
return TrivialSpace
else:
return ops, kwargs | python | def empty_trivial(cls, ops, kwargs):
"""A ProductSpace of zero Hilbert spaces should yield the TrivialSpace"""
from qnet.algebra.core.hilbert_space_algebra import TrivialSpace
if len(ops) == 0:
return TrivialSpace
else:
return ops, kwargs | [
"def",
"empty_trivial",
"(",
"cls",
",",
"ops",
",",
"kwargs",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"hilbert_space_algebra",
"import",
"TrivialSpace",
"if",
"len",
"(",
"ops",
")",
"==",
"0",
":",
"return",
"TrivialSpace",
"else",
... | A ProductSpace of zero Hilbert spaces should yield the TrivialSpace | [
"A",
"ProductSpace",
"of",
"zero",
"Hilbert",
"spaces",
"should",
"yield",
"the",
"TrivialSpace"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L460-L466 |
45,933 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | disjunct_hs_zero | def disjunct_hs_zero(cls, ops, kwargs):
"""Return ZeroOperator if all the operators in `ops` have a disjunct
Hilbert space, or an unchanged `ops`, `kwargs` otherwise
"""
from qnet.algebra.core.hilbert_space_algebra import TrivialSpace
from qnet.algebra.core.operator_algebra import ZeroOperator
h... | python | def disjunct_hs_zero(cls, ops, kwargs):
"""Return ZeroOperator if all the operators in `ops` have a disjunct
Hilbert space, or an unchanged `ops`, `kwargs` otherwise
"""
from qnet.algebra.core.hilbert_space_algebra import TrivialSpace
from qnet.algebra.core.operator_algebra import ZeroOperator
h... | [
"def",
"disjunct_hs_zero",
"(",
"cls",
",",
"ops",
",",
"kwargs",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"hilbert_space_algebra",
"import",
"TrivialSpace",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"operator_algebra",
"import",
"... | Return ZeroOperator if all the operators in `ops` have a disjunct
Hilbert space, or an unchanged `ops`, `kwargs` otherwise | [
"Return",
"ZeroOperator",
"if",
"all",
"the",
"operators",
"in",
"ops",
"have",
"a",
"disjunct",
"Hilbert",
"space",
"or",
"an",
"unchanged",
"ops",
"kwargs",
"otherwise"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L576-L592 |
45,934 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | commutator_order | def commutator_order(cls, ops, kwargs):
"""Apply anti-commutative property of the commutator to apply a standard
ordering of the commutator arguments
"""
from qnet.algebra.core.operator_algebra import Commutator
assert len(ops) == 2
if cls.order_key(ops[1]) < cls.order_key(ops[0]):
retur... | python | def commutator_order(cls, ops, kwargs):
"""Apply anti-commutative property of the commutator to apply a standard
ordering of the commutator arguments
"""
from qnet.algebra.core.operator_algebra import Commutator
assert len(ops) == 2
if cls.order_key(ops[1]) < cls.order_key(ops[0]):
retur... | [
"def",
"commutator_order",
"(",
"cls",
",",
"ops",
",",
"kwargs",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"operator_algebra",
"import",
"Commutator",
"assert",
"len",
"(",
"ops",
")",
"==",
"2",
"if",
"cls",
".",
"order_key",
"(",
"... | Apply anti-commutative property of the commutator to apply a standard
ordering of the commutator arguments | [
"Apply",
"anti",
"-",
"commutative",
"property",
"of",
"the",
"commutator",
"to",
"apply",
"a",
"standard",
"ordering",
"of",
"the",
"commutator",
"arguments"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L595-L604 |
45,935 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | accept_bras | def accept_bras(cls, ops, kwargs):
"""Accept operands that are all bras, and turn that into to bra of the
operation applied to all corresponding kets"""
from qnet.algebra.core.state_algebra import Bra
kets = []
for bra in ops:
if isinstance(bra, Bra):
kets.append(bra.ket)
... | python | def accept_bras(cls, ops, kwargs):
"""Accept operands that are all bras, and turn that into to bra of the
operation applied to all corresponding kets"""
from qnet.algebra.core.state_algebra import Bra
kets = []
for bra in ops:
if isinstance(bra, Bra):
kets.append(bra.ket)
... | [
"def",
"accept_bras",
"(",
"cls",
",",
"ops",
",",
"kwargs",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"state_algebra",
"import",
"Bra",
"kets",
"=",
"[",
"]",
"for",
"bra",
"in",
"ops",
":",
"if",
"isinstance",
"(",
"bra",
",",
"... | Accept operands that are all bras, and turn that into to bra of the
operation applied to all corresponding kets | [
"Accept",
"operands",
"that",
"are",
"all",
"bras",
"and",
"turn",
"that",
"into",
"to",
"bra",
"of",
"the",
"operation",
"applied",
"to",
"all",
"corresponding",
"kets"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L607-L617 |
45,936 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | _ranges_key | def _ranges_key(r, delta_indices):
"""Sorting key for ranges.
When used with ``reverse=True``, this can be used to sort index ranges into
the order we would prefer to eliminate them by evaluating KroneckerDeltas:
First, eliminate primed indices, then indices names higher in the alphabet.
"""
id... | python | def _ranges_key(r, delta_indices):
"""Sorting key for ranges.
When used with ``reverse=True``, this can be used to sort index ranges into
the order we would prefer to eliminate them by evaluating KroneckerDeltas:
First, eliminate primed indices, then indices names higher in the alphabet.
"""
id... | [
"def",
"_ranges_key",
"(",
"r",
",",
"delta_indices",
")",
":",
"idx",
"=",
"r",
".",
"index_symbol",
"if",
"idx",
"in",
"delta_indices",
":",
"return",
"(",
"r",
".",
"index_symbol",
".",
"primed",
",",
"r",
".",
"index_symbol",
".",
"name",
")",
"els... | Sorting key for ranges.
When used with ``reverse=True``, this can be used to sort index ranges into
the order we would prefer to eliminate them by evaluating KroneckerDeltas:
First, eliminate primed indices, then indices names higher in the alphabet. | [
"Sorting",
"key",
"for",
"ranges",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L666-L679 |
45,937 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | _factors_for_expand_delta | def _factors_for_expand_delta(expr):
"""Yield factors from expr, mixing sympy and QNET
Auxiliary routine for :func:`_expand_delta`.
"""
from qnet.algebra.core.scalar_algebra import ScalarValue
from qnet.algebra.core.abstract_quantum_algebra import (
ScalarTimesQuantumExpression)
if isin... | python | def _factors_for_expand_delta(expr):
"""Yield factors from expr, mixing sympy and QNET
Auxiliary routine for :func:`_expand_delta`.
"""
from qnet.algebra.core.scalar_algebra import ScalarValue
from qnet.algebra.core.abstract_quantum_algebra import (
ScalarTimesQuantumExpression)
if isin... | [
"def",
"_factors_for_expand_delta",
"(",
"expr",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"scalar_algebra",
"import",
"ScalarValue",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"abstract_quantum_algebra",
"import",
"(",
"ScalarTimesQuantum... | Yield factors from expr, mixing sympy and QNET
Auxiliary routine for :func:`_expand_delta`. | [
"Yield",
"factors",
"from",
"expr",
"mixing",
"sympy",
"and",
"QNET"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L740-L756 |
45,938 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | _split_sympy_quantum_factor | def _split_sympy_quantum_factor(expr):
"""Split a product into sympy and qnet factors
This is a helper routine for applying some sympy transformation on an
arbitrary product-like expression in QNET. The idea is this::
expr -> sympy_factor, quantum_factor
sympy_factor -> sympy_function(symp... | python | def _split_sympy_quantum_factor(expr):
"""Split a product into sympy and qnet factors
This is a helper routine for applying some sympy transformation on an
arbitrary product-like expression in QNET. The idea is this::
expr -> sympy_factor, quantum_factor
sympy_factor -> sympy_function(symp... | [
"def",
"_split_sympy_quantum_factor",
"(",
"expr",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"abstract_quantum_algebra",
"import",
"(",
"QuantumExpression",
",",
"ScalarTimesQuantumExpression",
")",
"from",
"qnet",
".",
"algebra",
".",
"core",
".... | Split a product into sympy and qnet factors
This is a helper routine for applying some sympy transformation on an
arbitrary product-like expression in QNET. The idea is this::
expr -> sympy_factor, quantum_factor
sympy_factor -> sympy_function(sympy_factor)
expr -> sympy_factor * quant... | [
"Split",
"a",
"product",
"into",
"sympy",
"and",
"qnet",
"factors"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L793-L827 |
45,939 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | _extract_delta | def _extract_delta(expr, idx):
"""Extract a "simple" Kronecker delta containing `idx` from `expr`.
Assuming `expr` can be written as the product of a Kronecker Delta and a
`new_expr`, return a tuple of the sympy.KroneckerDelta instance and
`new_expr`. Otherwise, return a tuple of None and the original ... | python | def _extract_delta(expr, idx):
"""Extract a "simple" Kronecker delta containing `idx` from `expr`.
Assuming `expr` can be written as the product of a Kronecker Delta and a
`new_expr`, return a tuple of the sympy.KroneckerDelta instance and
`new_expr`. Otherwise, return a tuple of None and the original ... | [
"def",
"_extract_delta",
"(",
"expr",
",",
"idx",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"abstract_quantum_algebra",
"import",
"QuantumExpression",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"scalar_algebra",
"import",
"ScalarValue",
... | Extract a "simple" Kronecker delta containing `idx` from `expr`.
Assuming `expr` can be written as the product of a Kronecker Delta and a
`new_expr`, return a tuple of the sympy.KroneckerDelta instance and
`new_expr`. Otherwise, return a tuple of None and the original `expr`
(possibly converted to a :c... | [
"Extract",
"a",
"simple",
"Kronecker",
"delta",
"containing",
"idx",
"from",
"expr",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L830-L853 |
45,940 | mabuchilab/QNET | src/qnet/algebra/core/algebraic_properties.py | _deltasummation | def _deltasummation(term, ranges, i_range):
"""Partially execute a summation for `term` with a Kronecker Delta for one
of the summation indices.
This implements the solution to the core sub-problem in
:func:`indexed_sum_over_kronecker`
Args:
term (QuantumExpression): term of the sum
... | python | def _deltasummation(term, ranges, i_range):
"""Partially execute a summation for `term` with a Kronecker Delta for one
of the summation indices.
This implements the solution to the core sub-problem in
:func:`indexed_sum_over_kronecker`
Args:
term (QuantumExpression): term of the sum
... | [
"def",
"_deltasummation",
"(",
"term",
",",
"ranges",
",",
"i_range",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"abstract_quantum_algebra",
"import",
"QuantumExpression",
"idx",
"=",
"ranges",
"[",
"i_range",
"]",
".",
"index_symbol",
"summan... | Partially execute a summation for `term` with a Kronecker Delta for one
of the summation indices.
This implements the solution to the core sub-problem in
:func:`indexed_sum_over_kronecker`
Args:
term (QuantumExpression): term of the sum
ranges (list): list of all summation index ranges... | [
"Partially",
"execute",
"a",
"summation",
"for",
"term",
"with",
"a",
"Kronecker",
"Delta",
"for",
"one",
"of",
"the",
"summation",
"indices",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/algebraic_properties.py#L856-L944 |
45,941 | mabuchilab/QNET | src/qnet/utils/permutations.py | invert_permutation | def invert_permutation(permutation):
"""Compute the image tuple of the inverse permutation.
:param permutation: A valid (cf. :py:func:check_permutation) permutation.
:return: The inverse permutation tuple
:rtype: tuple
"""
return tuple([permutation.index(p) for p in range(len(permutation))]) | python | def invert_permutation(permutation):
"""Compute the image tuple of the inverse permutation.
:param permutation: A valid (cf. :py:func:check_permutation) permutation.
:return: The inverse permutation tuple
:rtype: tuple
"""
return tuple([permutation.index(p) for p in range(len(permutation))]) | [
"def",
"invert_permutation",
"(",
"permutation",
")",
":",
"return",
"tuple",
"(",
"[",
"permutation",
".",
"index",
"(",
"p",
")",
"for",
"p",
"in",
"range",
"(",
"len",
"(",
"permutation",
")",
")",
"]",
")"
] | Compute the image tuple of the inverse permutation.
:param permutation: A valid (cf. :py:func:check_permutation) permutation.
:return: The inverse permutation tuple
:rtype: tuple | [
"Compute",
"the",
"image",
"tuple",
"of",
"the",
"inverse",
"permutation",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/permutations.py#L32-L39 |
45,942 | mabuchilab/QNET | src/qnet/utils/permutations.py | permutation_to_block_permutations | def permutation_to_block_permutations(permutation):
"""If possible, decompose a permutation into a sequence of permutations
each acting on individual ranges of the full range of indices.
E.g.
``(1,2,0,3,5,4) --> (1,2,0) [+] (0,2,1)``
:param permutation: A valid permutation image tuple ``s = (s... | python | def permutation_to_block_permutations(permutation):
"""If possible, decompose a permutation into a sequence of permutations
each acting on individual ranges of the full range of indices.
E.g.
``(1,2,0,3,5,4) --> (1,2,0) [+] (0,2,1)``
:param permutation: A valid permutation image tuple ``s = (s... | [
"def",
"permutation_to_block_permutations",
"(",
"permutation",
")",
":",
"if",
"len",
"(",
"permutation",
")",
"==",
"0",
"or",
"not",
"check_permutation",
"(",
"permutation",
")",
":",
"raise",
"BadPermutationError",
"(",
")",
"cycles",
"=",
"permutation_to_disj... | If possible, decompose a permutation into a sequence of permutations
each acting on individual ranges of the full range of indices.
E.g.
``(1,2,0,3,5,4) --> (1,2,0) [+] (0,2,1)``
:param permutation: A valid permutation image tuple ``s = (s_0,...s_n)`` with ``n > 0``
:type permutation: tuple
... | [
"If",
"possible",
"decompose",
"a",
"permutation",
"into",
"a",
"sequence",
"of",
"permutations",
"each",
"acting",
"on",
"individual",
"ranges",
"of",
"the",
"full",
"range",
"of",
"indices",
".",
"E",
".",
"g",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/permutations.py#L122-L163 |
45,943 | mabuchilab/QNET | src/qnet/utils/permutations.py | block_perm_and_perms_within_blocks | def block_perm_and_perms_within_blocks(permutation, block_structure):
"""Decompose a permutation into a block permutation and into permutations
acting within each block.
:param permutation: The overall permutation to be factored.
:type permutation: tuple
:param block_structure: The channel dimensio... | python | def block_perm_and_perms_within_blocks(permutation, block_structure):
"""Decompose a permutation into a block permutation and into permutations
acting within each block.
:param permutation: The overall permutation to be factored.
:type permutation: tuple
:param block_structure: The channel dimensio... | [
"def",
"block_perm_and_perms_within_blocks",
"(",
"permutation",
",",
"block_structure",
")",
":",
"nblocks",
"=",
"len",
"(",
"block_structure",
")",
"offsets",
"=",
"[",
"sum",
"(",
"block_structure",
"[",
":",
"k",
"]",
")",
"for",
"k",
"in",
"range",
"("... | Decompose a permutation into a block permutation and into permutations
acting within each block.
:param permutation: The overall permutation to be factored.
:type permutation: tuple
:param block_structure: The channel dimensions of the blocks
:type block_structure: tuple
:return: ``(block_permu... | [
"Decompose",
"a",
"permutation",
"into",
"a",
"block",
"permutation",
"and",
"into",
"permutations",
"acting",
"within",
"each",
"block",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/permutations.py#L269-L312 |
45,944 | mabuchilab/QNET | src/qnet/algebra/core/state_algebra.py | _check_kets | def _check_kets(*ops, same_space=False, disjunct_space=False):
"""Check that all operands are Kets from the same Hilbert space."""
if not all([(isinstance(o, State) and o.isket) for o in ops]):
raise TypeError("All operands must be Kets")
if same_space:
if not len({o.space for o in ops if o ... | python | def _check_kets(*ops, same_space=False, disjunct_space=False):
"""Check that all operands are Kets from the same Hilbert space."""
if not all([(isinstance(o, State) and o.isket) for o in ops]):
raise TypeError("All operands must be Kets")
if same_space:
if not len({o.space for o in ops if o ... | [
"def",
"_check_kets",
"(",
"*",
"ops",
",",
"same_space",
"=",
"False",
",",
"disjunct_space",
"=",
"False",
")",
":",
"if",
"not",
"all",
"(",
"[",
"(",
"isinstance",
"(",
"o",
",",
"State",
")",
"and",
"o",
".",
"isket",
")",
"for",
"o",
"in",
... | Check that all operands are Kets from the same Hilbert space. | [
"Check",
"that",
"all",
"operands",
"are",
"Kets",
"from",
"the",
"same",
"Hilbert",
"space",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/state_algebra.py#L732-L744 |
45,945 | mabuchilab/QNET | src/qnet/algebra/core/state_algebra.py | BasisKet.args | def args(self):
"""Tuple containing `label_or_index` as its only element."""
if self.space.has_basis or isinstance(self.label, SymbolicLabelBase):
return (self.label, )
else:
return (self.index, ) | python | def args(self):
"""Tuple containing `label_or_index` as its only element."""
if self.space.has_basis or isinstance(self.label, SymbolicLabelBase):
return (self.label, )
else:
return (self.index, ) | [
"def",
"args",
"(",
"self",
")",
":",
"if",
"self",
".",
"space",
".",
"has_basis",
"or",
"isinstance",
"(",
"self",
".",
"label",
",",
"SymbolicLabelBase",
")",
":",
"return",
"(",
"self",
".",
"label",
",",
")",
"else",
":",
"return",
"(",
"self",
... | Tuple containing `label_or_index` as its only element. | [
"Tuple",
"containing",
"label_or_index",
"as",
"its",
"only",
"element",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/state_algebra.py#L291-L296 |
45,946 | mabuchilab/QNET | src/qnet/algebra/core/state_algebra.py | CoherentStateKet.to_fock_representation | def to_fock_representation(self, index_symbol='n', max_terms=None):
"""Return the coherent state written out as an indexed sum over Fock
basis states"""
phase_factor = sympy.exp(
sympy.Rational(-1, 2) * self.ampl * self.ampl.conjugate())
if not isinstance(index_symbol, IdxSym... | python | def to_fock_representation(self, index_symbol='n', max_terms=None):
"""Return the coherent state written out as an indexed sum over Fock
basis states"""
phase_factor = sympy.exp(
sympy.Rational(-1, 2) * self.ampl * self.ampl.conjugate())
if not isinstance(index_symbol, IdxSym... | [
"def",
"to_fock_representation",
"(",
"self",
",",
"index_symbol",
"=",
"'n'",
",",
"max_terms",
"=",
"None",
")",
":",
"phase_factor",
"=",
"sympy",
".",
"exp",
"(",
"sympy",
".",
"Rational",
"(",
"-",
"1",
",",
"2",
")",
"*",
"self",
".",
"ampl",
"... | Return the coherent state written out as an indexed sum over Fock
basis states | [
"Return",
"the",
"coherent",
"state",
"written",
"out",
"as",
"an",
"indexed",
"sum",
"over",
"Fock",
"basis",
"states"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/state_algebra.py#L398-L413 |
45,947 | sveetch/djangocodemirror | djangocodemirror/widgets.py | CodeMirrorWidget.codemirror_script | def codemirror_script(self, inputid):
"""
Build CodeMirror HTML script tag which contains CodeMirror init.
Arguments:
inputid (string): Input id.
Returns:
string: HTML for field CodeMirror instance.
"""
varname = "{}_codemirror".format(inputid)
... | python | def codemirror_script(self, inputid):
"""
Build CodeMirror HTML script tag which contains CodeMirror init.
Arguments:
inputid (string): Input id.
Returns:
string: HTML for field CodeMirror instance.
"""
varname = "{}_codemirror".format(inputid)
... | [
"def",
"codemirror_script",
"(",
"self",
",",
"inputid",
")",
":",
"varname",
"=",
"\"{}_codemirror\"",
".",
"format",
"(",
"inputid",
")",
"html",
"=",
"self",
".",
"get_codemirror_field_js",
"(",
")",
"opts",
"=",
"self",
".",
"codemirror_config",
"(",
")"... | Build CodeMirror HTML script tag which contains CodeMirror init.
Arguments:
inputid (string): Input id.
Returns:
string: HTML for field CodeMirror instance. | [
"Build",
"CodeMirror",
"HTML",
"script",
"tag",
"which",
"contains",
"CodeMirror",
"init",
"."
] | 7d556eec59861b2f619398e837bdd089b3a8a7d7 | https://github.com/sveetch/djangocodemirror/blob/7d556eec59861b2f619398e837bdd089b3a8a7d7/djangocodemirror/widgets.py#L75-L90 |
45,948 | mabuchilab/QNET | src/qnet/algebra/_rules.py | _algebraic_rules_scalar | def _algebraic_rules_scalar():
"""Set the default algebraic rules for scalars"""
a = wc("a", head=SCALAR_VAL_TYPES)
b = wc("b", head=SCALAR_VAL_TYPES)
x = wc("x", head=SCALAR_TYPES)
y = wc("y", head=SCALAR_TYPES)
z = wc("z", head=SCALAR_TYPES)
indranges__ = wc("indranges__", head=IndexRange... | python | def _algebraic_rules_scalar():
"""Set the default algebraic rules for scalars"""
a = wc("a", head=SCALAR_VAL_TYPES)
b = wc("b", head=SCALAR_VAL_TYPES)
x = wc("x", head=SCALAR_TYPES)
y = wc("y", head=SCALAR_TYPES)
z = wc("z", head=SCALAR_TYPES)
indranges__ = wc("indranges__", head=IndexRange... | [
"def",
"_algebraic_rules_scalar",
"(",
")",
":",
"a",
"=",
"wc",
"(",
"\"a\"",
",",
"head",
"=",
"SCALAR_VAL_TYPES",
")",
"b",
"=",
"wc",
"(",
"\"b\"",
",",
"head",
"=",
"SCALAR_VAL_TYPES",
")",
"x",
"=",
"wc",
"(",
"\"x\"",
",",
"head",
"=",
"SCALAR... | Set the default algebraic rules for scalars | [
"Set",
"the",
"default",
"algebraic",
"rules",
"for",
"scalars"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L42-L105 |
45,949 | mabuchilab/QNET | src/qnet/algebra/_rules.py | _tensor_decompose_series | def _tensor_decompose_series(lhs, rhs):
"""Simplification method for lhs << rhs
Decompose a series product of two reducible circuits with compatible block
structures into a concatenation of individual series products between
subblocks. This method raises CannotSimplify when rhs is a CPermutation in
... | python | def _tensor_decompose_series(lhs, rhs):
"""Simplification method for lhs << rhs
Decompose a series product of two reducible circuits with compatible block
structures into a concatenation of individual series products between
subblocks. This method raises CannotSimplify when rhs is a CPermutation in
... | [
"def",
"_tensor_decompose_series",
"(",
"lhs",
",",
"rhs",
")",
":",
"if",
"isinstance",
"(",
"rhs",
",",
"CPermutation",
")",
":",
"raise",
"CannotSimplify",
"(",
")",
"lhs_structure",
"=",
"lhs",
".",
"block_structure",
"rhs_structure",
"=",
"rhs",
".",
"b... | Simplification method for lhs << rhs
Decompose a series product of two reducible circuits with compatible block
structures into a concatenation of individual series products between
subblocks. This method raises CannotSimplify when rhs is a CPermutation in
order not to conflict with other _rules. | [
"Simplification",
"method",
"for",
"lhs",
"<<",
"rhs"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L867-L887 |
45,950 | mabuchilab/QNET | src/qnet/algebra/_rules.py | _factor_permutation_for_blocks | def _factor_permutation_for_blocks(cperm, rhs):
"""Simplification method for cperm << rhs.
Decompose a series product of a channel permutation and a reducible circuit
with appropriate block structure by decomposing the permutation into a
permutation within each block of rhs and a block permutation and a... | python | def _factor_permutation_for_blocks(cperm, rhs):
"""Simplification method for cperm << rhs.
Decompose a series product of a channel permutation and a reducible circuit
with appropriate block structure by decomposing the permutation into a
permutation within each block of rhs and a block permutation and a... | [
"def",
"_factor_permutation_for_blocks",
"(",
"cperm",
",",
"rhs",
")",
":",
"rbs",
"=",
"rhs",
".",
"block_structure",
"if",
"rhs",
"==",
"cid",
"(",
"rhs",
".",
"cdim",
")",
":",
"return",
"cperm",
"if",
"len",
"(",
"rbs",
")",
">",
"1",
":",
"resi... | Simplification method for cperm << rhs.
Decompose a series product of a channel permutation and a reducible circuit
with appropriate block structure by decomposing the permutation into a
permutation within each block of rhs and a block permutation and a residual
part. This allows for achieving somethin... | [
"Simplification",
"method",
"for",
"cperm",
"<<",
"rhs",
".",
"Decompose",
"a",
"series",
"product",
"of",
"a",
"channel",
"permutation",
"and",
"a",
"reducible",
"circuit",
"with",
"appropriate",
"block",
"structure",
"by",
"decomposing",
"the",
"permutation",
... | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L890-L908 |
45,951 | mabuchilab/QNET | src/qnet/algebra/_rules.py | _pull_out_perm_lhs | def _pull_out_perm_lhs(lhs, rest, out_port, in_port):
"""Pull out a permutation from the Feedback of a SeriesProduct with itself.
Args:
lhs (CPermutation): The permutation circuit
rest (tuple): The other SeriesProduct operands
out_port (int): The feedback output port index
in_po... | python | def _pull_out_perm_lhs(lhs, rest, out_port, in_port):
"""Pull out a permutation from the Feedback of a SeriesProduct with itself.
Args:
lhs (CPermutation): The permutation circuit
rest (tuple): The other SeriesProduct operands
out_port (int): The feedback output port index
in_po... | [
"def",
"_pull_out_perm_lhs",
"(",
"lhs",
",",
"rest",
",",
"out_port",
",",
"in_port",
")",
":",
"out_inv",
",",
"lhs_red",
"=",
"lhs",
".",
"_factor_lhs",
"(",
"out_port",
")",
"return",
"lhs_red",
"<<",
"Feedback",
".",
"create",
"(",
"SeriesProduct",
".... | Pull out a permutation from the Feedback of a SeriesProduct with itself.
Args:
lhs (CPermutation): The permutation circuit
rest (tuple): The other SeriesProduct operands
out_port (int): The feedback output port index
in_port (int): The feedback input port index
Returns:
... | [
"Pull",
"out",
"a",
"permutation",
"from",
"the",
"Feedback",
"of",
"a",
"SeriesProduct",
"with",
"itself",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L911-L925 |
45,952 | mabuchilab/QNET | src/qnet/algebra/_rules.py | _pull_out_unaffected_blocks_lhs | def _pull_out_unaffected_blocks_lhs(lhs, rest, out_port, in_port):
"""In a self-Feedback of a series product, where the left-most operand is
reducible, pull all non-trivial blocks outside of the feedback.
Args:
lhs (Circuit): The reducible circuit
rest (tuple): The other SeriesProduct operands... | python | def _pull_out_unaffected_blocks_lhs(lhs, rest, out_port, in_port):
"""In a self-Feedback of a series product, where the left-most operand is
reducible, pull all non-trivial blocks outside of the feedback.
Args:
lhs (Circuit): The reducible circuit
rest (tuple): The other SeriesProduct operands... | [
"def",
"_pull_out_unaffected_blocks_lhs",
"(",
"lhs",
",",
"rest",
",",
"out_port",
",",
"in_port",
")",
":",
"_",
",",
"block_index",
"=",
"lhs",
".",
"index_in_block",
"(",
"out_port",
")",
"bs",
"=",
"lhs",
".",
"block_structure",
"nbefore",
",",
"nblock"... | In a self-Feedback of a series product, where the left-most operand is
reducible, pull all non-trivial blocks outside of the feedback.
Args:
lhs (Circuit): The reducible circuit
rest (tuple): The other SeriesProduct operands
out_port (int): The feedback output port index
in_port (int... | [
"In",
"a",
"self",
"-",
"Feedback",
"of",
"a",
"series",
"product",
"where",
"the",
"left",
"-",
"most",
"operand",
"is",
"reducible",
"pull",
"all",
"non",
"-",
"trivial",
"blocks",
"outside",
"of",
"the",
"feedback",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L928-L962 |
45,953 | mabuchilab/QNET | src/qnet/algebra/_rules.py | _series_feedback | def _series_feedback(series, out_port, in_port):
"""Invert a series self-feedback twice to get rid of unnecessary
permutations."""
series_s = series.series_inverse().series_inverse()
if series_s == series:
raise CannotSimplify()
return series_s.feedback(out_port=out_port, in_port=in_port) | python | def _series_feedback(series, out_port, in_port):
"""Invert a series self-feedback twice to get rid of unnecessary
permutations."""
series_s = series.series_inverse().series_inverse()
if series_s == series:
raise CannotSimplify()
return series_s.feedback(out_port=out_port, in_port=in_port) | [
"def",
"_series_feedback",
"(",
"series",
",",
"out_port",
",",
"in_port",
")",
":",
"series_s",
"=",
"series",
".",
"series_inverse",
"(",
")",
".",
"series_inverse",
"(",
")",
"if",
"series_s",
"==",
"series",
":",
"raise",
"CannotSimplify",
"(",
")",
"r... | Invert a series self-feedback twice to get rid of unnecessary
permutations. | [
"Invert",
"a",
"series",
"self",
"-",
"feedback",
"twice",
"to",
"get",
"rid",
"of",
"unnecessary",
"permutations",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/_rules.py#L997-L1003 |
45,954 | mabuchilab/QNET | src/qnet/utils/properties_for_args.py | properties_for_args | def properties_for_args(cls, arg_names='_arg_names'):
"""For a class with an attribute `arg_names` containing a list of names,
add a property for every name in that list.
It is assumed that there is an instance attribute ``self._<arg_name>``,
which is returned by the `arg_name` property. The decorator... | python | def properties_for_args(cls, arg_names='_arg_names'):
"""For a class with an attribute `arg_names` containing a list of names,
add a property for every name in that list.
It is assumed that there is an instance attribute ``self._<arg_name>``,
which is returned by the `arg_name` property. The decorator... | [
"def",
"properties_for_args",
"(",
"cls",
",",
"arg_names",
"=",
"'_arg_names'",
")",
":",
"from",
"qnet",
".",
"algebra",
".",
"core",
".",
"scalar_algebra",
"import",
"Scalar",
"scalar_args",
"=",
"False",
"if",
"hasattr",
"(",
"cls",
",",
"'_scalar_args'",
... | For a class with an attribute `arg_names` containing a list of names,
add a property for every name in that list.
It is assumed that there is an instance attribute ``self._<arg_name>``,
which is returned by the `arg_name` property. The decorator also adds a
class attribute :attr:`_has_properties_for_a... | [
"For",
"a",
"class",
"with",
"an",
"attribute",
"arg_names",
"containing",
"a",
"list",
"of",
"names",
"add",
"a",
"property",
"for",
"every",
"name",
"in",
"that",
"list",
"."
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/utils/properties_for_args.py#L8-L36 |
45,955 | django-fluent/django-fluent-blogs | fluent_blogs/views/entries.py | EntryCategoryArchive.get_category | def get_category(self, slug):
"""
Get the category object
"""
try:
return get_category_for_slug(slug)
except ObjectDoesNotExist as e:
raise Http404(str(e)) | python | def get_category(self, slug):
"""
Get the category object
"""
try:
return get_category_for_slug(slug)
except ObjectDoesNotExist as e:
raise Http404(str(e)) | [
"def",
"get_category",
"(",
"self",
",",
"slug",
")",
":",
"try",
":",
"return",
"get_category_for_slug",
"(",
"slug",
")",
"except",
"ObjectDoesNotExist",
"as",
"e",
":",
"raise",
"Http404",
"(",
"str",
"(",
"e",
")",
")"
] | Get the category object | [
"Get",
"the",
"category",
"object"
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/views/entries.py#L190-L197 |
45,956 | django-fluent/django-fluent-blogs | fluent_blogs/admin/forms.py | AbstractEntryBaseAdminForm.validate_unique_slug | def validate_unique_slug(self, cleaned_data):
"""
Test whether the slug is unique within a given time period.
"""
date_kwargs = {}
error_msg = _("The slug is not unique")
# The /year/month/slug/ URL determines when a slug can be unique.
pubdate = cleaned_data['pu... | python | def validate_unique_slug(self, cleaned_data):
"""
Test whether the slug is unique within a given time period.
"""
date_kwargs = {}
error_msg = _("The slug is not unique")
# The /year/month/slug/ URL determines when a slug can be unique.
pubdate = cleaned_data['pu... | [
"def",
"validate_unique_slug",
"(",
"self",
",",
"cleaned_data",
")",
":",
"date_kwargs",
"=",
"{",
"}",
"error_msg",
"=",
"_",
"(",
"\"The slug is not unique\"",
")",
"# The /year/month/slug/ URL determines when a slug can be unique.",
"pubdate",
"=",
"cleaned_data",
"["... | Test whether the slug is unique within a given time period. | [
"Test",
"whether",
"the",
"slug",
"is",
"unique",
"within",
"a",
"given",
"time",
"period",
"."
] | 86b148549a010eaca9a2ea987fe43be250e06c50 | https://github.com/django-fluent/django-fluent-blogs/blob/86b148549a010eaca9a2ea987fe43be250e06c50/fluent_blogs/admin/forms.py#L50-L84 |
45,957 | mabuchilab/QNET | src/qnet/algebra/core/abstract_algebra.py | _apply_rules_no_recurse | def _apply_rules_no_recurse(expr, rules):
"""Non-recursively match expr again all rules"""
try:
# `rules` is an OrderedDict key => (pattern, replacement)
items = rules.items()
except AttributeError:
# `rules` is a list of (pattern, replacement) tuples
items = enumerate(rules)... | python | def _apply_rules_no_recurse(expr, rules):
"""Non-recursively match expr again all rules"""
try:
# `rules` is an OrderedDict key => (pattern, replacement)
items = rules.items()
except AttributeError:
# `rules` is a list of (pattern, replacement) tuples
items = enumerate(rules)... | [
"def",
"_apply_rules_no_recurse",
"(",
"expr",
",",
"rules",
")",
":",
"try",
":",
"# `rules` is an OrderedDict key => (pattern, replacement)",
"items",
"=",
"rules",
".",
"items",
"(",
")",
"except",
"AttributeError",
":",
"# `rules` is a list of (pattern, replacement) tup... | Non-recursively match expr again all rules | [
"Non",
"-",
"recursively",
"match",
"expr",
"again",
"all",
"rules"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L694-L709 |
45,958 | mabuchilab/QNET | src/qnet/algebra/core/abstract_algebra.py | Expression.create | def create(cls, *args, **kwargs):
"""Instantiate while applying automatic simplifications
Instead of directly instantiating `cls`, it is recommended to use
:meth:`create`, which applies simplifications to the args and keyword
arguments according to the :attr:`simplifications` class attr... | python | def create(cls, *args, **kwargs):
"""Instantiate while applying automatic simplifications
Instead of directly instantiating `cls`, it is recommended to use
:meth:`create`, which applies simplifications to the args and keyword
arguments according to the :attr:`simplifications` class attr... | [
"def",
"create",
"(",
"cls",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"LEVEL",
"if",
"LOG",
":",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"'QNET.create'",
")",
"logger",
".",
"debug",
"(",
"\"%s%s.create(*args, **kwargs); args... | Instantiate while applying automatic simplifications
Instead of directly instantiating `cls`, it is recommended to use
:meth:`create`, which applies simplifications to the args and keyword
arguments according to the :attr:`simplifications` class attribute, and
returns an appropriate obj... | [
"Instantiate",
"while",
"applying",
"automatic",
"simplifications"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L104-L186 |
45,959 | mabuchilab/QNET | src/qnet/algebra/core/abstract_algebra.py | Expression.kwargs | def kwargs(self):
"""The dictionary of keyword-only arguments for the instantiation of
the Expression"""
# Subclasses must override this property if and only if they define
# keyword-only arguments in their __init__ method
if hasattr(self, '_has_kwargs') and self._has_kwargs:
... | python | def kwargs(self):
"""The dictionary of keyword-only arguments for the instantiation of
the Expression"""
# Subclasses must override this property if and only if they define
# keyword-only arguments in their __init__ method
if hasattr(self, '_has_kwargs') and self._has_kwargs:
... | [
"def",
"kwargs",
"(",
"self",
")",
":",
"# Subclasses must override this property if and only if they define",
"# keyword-only arguments in their __init__ method",
"if",
"hasattr",
"(",
"self",
",",
"'_has_kwargs'",
")",
"and",
"self",
".",
"_has_kwargs",
":",
"raise",
"Not... | The dictionary of keyword-only arguments for the instantiation of
the Expression | [
"The",
"dictionary",
"of",
"keyword",
"-",
"only",
"arguments",
"for",
"the",
"instantiation",
"of",
"the",
"Expression"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L346-L355 |
45,960 | mabuchilab/QNET | src/qnet/algebra/core/abstract_algebra.py | Expression.substitute | def substitute(self, var_map):
"""Substitute sub-expressions
Args:
var_map (dict): Dictionary with entries of the form
``{expr: substitution}``
"""
if self in var_map:
return var_map[self]
return self._substitute(var_map) | python | def substitute(self, var_map):
"""Substitute sub-expressions
Args:
var_map (dict): Dictionary with entries of the form
``{expr: substitution}``
"""
if self in var_map:
return var_map[self]
return self._substitute(var_map) | [
"def",
"substitute",
"(",
"self",
",",
"var_map",
")",
":",
"if",
"self",
"in",
"var_map",
":",
"return",
"var_map",
"[",
"self",
"]",
"return",
"self",
".",
"_substitute",
"(",
"var_map",
")"
] | Substitute sub-expressions
Args:
var_map (dict): Dictionary with entries of the form
``{expr: substitution}`` | [
"Substitute",
"sub",
"-",
"expressions"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L387-L396 |
45,961 | mabuchilab/QNET | src/qnet/algebra/core/abstract_algebra.py | Expression.apply_rules | def apply_rules(self, rules, recursive=True):
"""Rebuild the expression while applying a list of rules
The rules are applied against the instantiated expression, and any
sub-expressions if `recursive` is True. Rule application is best though
of as a pattern-based substitution. This is d... | python | def apply_rules(self, rules, recursive=True):
"""Rebuild the expression while applying a list of rules
The rules are applied against the instantiated expression, and any
sub-expressions if `recursive` is True. Rule application is best though
of as a pattern-based substitution. This is d... | [
"def",
"apply_rules",
"(",
"self",
",",
"rules",
",",
"recursive",
"=",
"True",
")",
":",
"if",
"recursive",
":",
"new_args",
"=",
"[",
"_apply_rules",
"(",
"arg",
",",
"rules",
")",
"for",
"arg",
"in",
"self",
".",
"args",
"]",
"new_kwargs",
"=",
"{... | Rebuild the expression while applying a list of rules
The rules are applied against the instantiated expression, and any
sub-expressions if `recursive` is True. Rule application is best though
of as a pattern-based substitution. This is different from the
*automatic* rules that :meth:`c... | [
"Rebuild",
"the",
"expression",
"while",
"applying",
"a",
"list",
"of",
"rules"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L532-L563 |
45,962 | mabuchilab/QNET | src/qnet/algebra/core/abstract_algebra.py | Expression.apply_rule | def apply_rule(self, pattern, replacement, recursive=True):
"""Apply a single rules to the expression
This is equivalent to :meth:`apply_rules` with
``rules=[(pattern, replacement)]``
Args:
pattern (.Pattern): A pattern containing one or more wildcards
replaceme... | python | def apply_rule(self, pattern, replacement, recursive=True):
"""Apply a single rules to the expression
This is equivalent to :meth:`apply_rules` with
``rules=[(pattern, replacement)]``
Args:
pattern (.Pattern): A pattern containing one or more wildcards
replaceme... | [
"def",
"apply_rule",
"(",
"self",
",",
"pattern",
",",
"replacement",
",",
"recursive",
"=",
"True",
")",
":",
"return",
"self",
".",
"apply_rules",
"(",
"[",
"(",
"pattern",
",",
"replacement",
")",
"]",
",",
"recursive",
"=",
"recursive",
")"
] | Apply a single rules to the expression
This is equivalent to :meth:`apply_rules` with
``rules=[(pattern, replacement)]``
Args:
pattern (.Pattern): A pattern containing one or more wildcards
replacement (callable): A callable that takes the wildcard names in
... | [
"Apply",
"a",
"single",
"rules",
"to",
"the",
"expression"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L565-L600 |
45,963 | mabuchilab/QNET | src/qnet/algebra/core/abstract_algebra.py | Expression.bound_symbols | def bound_symbols(self):
"""Set of bound SymPy symbols in the expression"""
if self._bound_symbols is None:
res = set.union(
set([]), # dummy arg (union fails without arguments)
*[_bound_symbols(val) for val in self.kwargs.values()])
res.update(
... | python | def bound_symbols(self):
"""Set of bound SymPy symbols in the expression"""
if self._bound_symbols is None:
res = set.union(
set([]), # dummy arg (union fails without arguments)
*[_bound_symbols(val) for val in self.kwargs.values()])
res.update(
... | [
"def",
"bound_symbols",
"(",
"self",
")",
":",
"if",
"self",
".",
"_bound_symbols",
"is",
"None",
":",
"res",
"=",
"set",
".",
"union",
"(",
"set",
"(",
"[",
"]",
")",
",",
"# dummy arg (union fails without arguments)",
"*",
"[",
"_bound_symbols",
"(",
"va... | Set of bound SymPy symbols in the expression | [
"Set",
"of",
"bound",
"SymPy",
"symbols",
"in",
"the",
"expression"
] | cc20d26dad78691d34c67173e5cd67dcac94208a | https://github.com/mabuchilab/QNET/blob/cc20d26dad78691d34c67173e5cd67dcac94208a/src/qnet/algebra/core/abstract_algebra.py#L642-L652 |
45,964 | daler/metaseq | metaseq/scripts/download_metaseq_example_data.py | download | def download(url, dest):
"""
Platform-agnostic downloader.
"""
u = urllib.FancyURLopener()
logger.info("Downloading %s..." % url)
u.retrieve(url, dest)
logger.info('Done, see %s' % dest)
return dest | python | def download(url, dest):
"""
Platform-agnostic downloader.
"""
u = urllib.FancyURLopener()
logger.info("Downloading %s..." % url)
u.retrieve(url, dest)
logger.info('Done, see %s' % dest)
return dest | [
"def",
"download",
"(",
"url",
",",
"dest",
")",
":",
"u",
"=",
"urllib",
".",
"FancyURLopener",
"(",
")",
"logger",
".",
"info",
"(",
"\"Downloading %s...\"",
"%",
"url",
")",
"u",
".",
"retrieve",
"(",
"url",
",",
"dest",
")",
"logger",
".",
"info"... | Platform-agnostic downloader. | [
"Platform",
"-",
"agnostic",
"downloader",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/scripts/download_metaseq_example_data.py#L35-L43 |
45,965 | daler/metaseq | metaseq/scripts/download_metaseq_example_data.py | logged_command | def logged_command(cmds):
"helper function to log a command and then run it"
logger.info(' '.join(cmds))
os.system(' '.join(cmds)) | python | def logged_command(cmds):
"helper function to log a command and then run it"
logger.info(' '.join(cmds))
os.system(' '.join(cmds)) | [
"def",
"logged_command",
"(",
"cmds",
")",
":",
"logger",
".",
"info",
"(",
"' '",
".",
"join",
"(",
"cmds",
")",
")",
"os",
".",
"system",
"(",
"' '",
".",
"join",
"(",
"cmds",
")",
")"
] | helper function to log a command and then run it | [
"helper",
"function",
"to",
"log",
"a",
"command",
"and",
"then",
"run",
"it"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/scripts/download_metaseq_example_data.py#L189-L192 |
45,966 | daler/metaseq | metaseq/scripts/download_metaseq_example_data.py | get_cufflinks | def get_cufflinks():
"Download cufflinks GTF files"
for size, md5, url in cufflinks:
cuff_gtf = os.path.join(args.data_dir, os.path.basename(url))
if not _up_to_date(md5, cuff_gtf):
download(url, cuff_gtf) | python | def get_cufflinks():
"Download cufflinks GTF files"
for size, md5, url in cufflinks:
cuff_gtf = os.path.join(args.data_dir, os.path.basename(url))
if not _up_to_date(md5, cuff_gtf):
download(url, cuff_gtf) | [
"def",
"get_cufflinks",
"(",
")",
":",
"for",
"size",
",",
"md5",
",",
"url",
"in",
"cufflinks",
":",
"cuff_gtf",
"=",
"os",
".",
"path",
".",
"join",
"(",
"args",
".",
"data_dir",
",",
"os",
".",
"path",
".",
"basename",
"(",
"url",
")",
")",
"i... | Download cufflinks GTF files | [
"Download",
"cufflinks",
"GTF",
"files"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/scripts/download_metaseq_example_data.py#L195-L200 |
45,967 | daler/metaseq | metaseq/scripts/download_metaseq_example_data.py | get_bams | def get_bams():
"""
Download BAM files if needed, extract only chr17 reads, and regenerate .bai
"""
for size, md5, url in bams:
bam = os.path.join(
args.data_dir,
os.path.basename(url).replace('.bam', '_%s.bam' % CHROM))
if not _up_to_date(md5, bam):
l... | python | def get_bams():
"""
Download BAM files if needed, extract only chr17 reads, and regenerate .bai
"""
for size, md5, url in bams:
bam = os.path.join(
args.data_dir,
os.path.basename(url).replace('.bam', '_%s.bam' % CHROM))
if not _up_to_date(md5, bam):
l... | [
"def",
"get_bams",
"(",
")",
":",
"for",
"size",
",",
"md5",
",",
"url",
"in",
"bams",
":",
"bam",
"=",
"os",
".",
"path",
".",
"join",
"(",
"args",
".",
"data_dir",
",",
"os",
".",
"path",
".",
"basename",
"(",
"url",
")",
".",
"replace",
"(",... | Download BAM files if needed, extract only chr17 reads, and regenerate .bai | [
"Download",
"BAM",
"files",
"if",
"needed",
"extract",
"only",
"chr17",
"reads",
"and",
"regenerate",
".",
"bai"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/scripts/download_metaseq_example_data.py#L203-L233 |
45,968 | daler/metaseq | metaseq/scripts/download_metaseq_example_data.py | get_gtf | def get_gtf():
"""
Download GTF file from Ensembl, only keeping the chr17 entries.
"""
size, md5, url = GTF
full_gtf = os.path.join(args.data_dir, os.path.basename(url))
subset_gtf = os.path.join(
args.data_dir,
os.path.basename(url).replace('.gtf.gz', '_%s.gtf' % CHROM))
if... | python | def get_gtf():
"""
Download GTF file from Ensembl, only keeping the chr17 entries.
"""
size, md5, url = GTF
full_gtf = os.path.join(args.data_dir, os.path.basename(url))
subset_gtf = os.path.join(
args.data_dir,
os.path.basename(url).replace('.gtf.gz', '_%s.gtf' % CHROM))
if... | [
"def",
"get_gtf",
"(",
")",
":",
"size",
",",
"md5",
",",
"url",
"=",
"GTF",
"full_gtf",
"=",
"os",
".",
"path",
".",
"join",
"(",
"args",
".",
"data_dir",
",",
"os",
".",
"path",
".",
"basename",
"(",
"url",
")",
")",
"subset_gtf",
"=",
"os",
... | Download GTF file from Ensembl, only keeping the chr17 entries. | [
"Download",
"GTF",
"file",
"from",
"Ensembl",
"only",
"keeping",
"the",
"chr17",
"entries",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/scripts/download_metaseq_example_data.py#L269-L288 |
45,969 | daler/metaseq | metaseq/scripts/download_metaseq_example_data.py | make_db | def make_db():
"""
Create gffutils database
"""
size, md5, fn = DB
if not _up_to_date(md5, fn):
gffutils.create_db(fn.replace('.db', ''), fn, verbose=True, force=True) | python | def make_db():
"""
Create gffutils database
"""
size, md5, fn = DB
if not _up_to_date(md5, fn):
gffutils.create_db(fn.replace('.db', ''), fn, verbose=True, force=True) | [
"def",
"make_db",
"(",
")",
":",
"size",
",",
"md5",
",",
"fn",
"=",
"DB",
"if",
"not",
"_up_to_date",
"(",
"md5",
",",
"fn",
")",
":",
"gffutils",
".",
"create_db",
"(",
"fn",
".",
"replace",
"(",
"'.db'",
",",
"''",
")",
",",
"fn",
",",
"verb... | Create gffutils database | [
"Create",
"gffutils",
"database"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/scripts/download_metaseq_example_data.py#L291-L297 |
45,970 | daler/metaseq | metaseq/scripts/download_metaseq_example_data.py | cufflinks_conversion | def cufflinks_conversion():
"""
convert Cufflinks output GTF files into tables of score and FPKM.
"""
for size, md5, fn in cufflinks_tables:
fn = os.path.join(args.data_dir, fn)
table = fn.replace('.gtf.gz', '.table')
if not _up_to_date(md5, table):
logger.info("Conve... | python | def cufflinks_conversion():
"""
convert Cufflinks output GTF files into tables of score and FPKM.
"""
for size, md5, fn in cufflinks_tables:
fn = os.path.join(args.data_dir, fn)
table = fn.replace('.gtf.gz', '.table')
if not _up_to_date(md5, table):
logger.info("Conve... | [
"def",
"cufflinks_conversion",
"(",
")",
":",
"for",
"size",
",",
"md5",
",",
"fn",
"in",
"cufflinks_tables",
":",
"fn",
"=",
"os",
".",
"path",
".",
"join",
"(",
"args",
".",
"data_dir",
",",
"fn",
")",
"table",
"=",
"fn",
".",
"replace",
"(",
"'.... | convert Cufflinks output GTF files into tables of score and FPKM. | [
"convert",
"Cufflinks",
"output",
"GTF",
"files",
"into",
"tables",
"of",
"score",
"and",
"FPKM",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/scripts/download_metaseq_example_data.py#L300-L319 |
45,971 | daler/metaseq | metaseq/minibrowser.py | BaseMiniBrowser.plot | def plot(self, feature):
"""
Spawns a new figure showing data for `feature`.
:param feature: A `pybedtools.Interval` object
Using the pybedtools.Interval `feature`, creates figure specified in
:meth:`BaseMiniBrowser.make_fig` and plots data on panels according to
`self.... | python | def plot(self, feature):
"""
Spawns a new figure showing data for `feature`.
:param feature: A `pybedtools.Interval` object
Using the pybedtools.Interval `feature`, creates figure specified in
:meth:`BaseMiniBrowser.make_fig` and plots data on panels according to
`self.... | [
"def",
"plot",
"(",
"self",
",",
"feature",
")",
":",
"if",
"isinstance",
"(",
"feature",
",",
"gffutils",
".",
"Feature",
")",
":",
"feature",
"=",
"asinterval",
"(",
"feature",
")",
"self",
".",
"make_fig",
"(",
")",
"axes",
"=",
"[",
"]",
"for",
... | Spawns a new figure showing data for `feature`.
:param feature: A `pybedtools.Interval` object
Using the pybedtools.Interval `feature`, creates figure specified in
:meth:`BaseMiniBrowser.make_fig` and plots data on panels according to
`self.panels()`. | [
"Spawns",
"a",
"new",
"figure",
"showing",
"data",
"for",
"feature",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/minibrowser.py#L82-L99 |
45,972 | daler/metaseq | metaseq/minibrowser.py | BaseMiniBrowser.example_panel | def example_panel(self, ax, feature):
"""
A example panel that just prints the text of the feature.
"""
txt = '%s:%s-%s' % (feature.chrom, feature.start, feature.stop)
ax.text(0.5, 0.5, txt, transform=ax.transAxes)
return feature | python | def example_panel(self, ax, feature):
"""
A example panel that just prints the text of the feature.
"""
txt = '%s:%s-%s' % (feature.chrom, feature.start, feature.stop)
ax.text(0.5, 0.5, txt, transform=ax.transAxes)
return feature | [
"def",
"example_panel",
"(",
"self",
",",
"ax",
",",
"feature",
")",
":",
"txt",
"=",
"'%s:%s-%s'",
"%",
"(",
"feature",
".",
"chrom",
",",
"feature",
".",
"start",
",",
"feature",
".",
"stop",
")",
"ax",
".",
"text",
"(",
"0.5",
",",
"0.5",
",",
... | A example panel that just prints the text of the feature. | [
"A",
"example",
"panel",
"that",
"just",
"prints",
"the",
"text",
"of",
"the",
"feature",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/minibrowser.py#L123-L129 |
45,973 | daler/metaseq | metaseq/minibrowser.py | SignalMiniBrowser.signal_panel | def signal_panel(self, ax, feature):
"""
Plots each genomic signal as a line using the corresponding
plotting_kwargs
"""
for gs, kwargs in zip(self.genomic_signal_objs, self.plotting_kwargs):
x, y = gs.local_coverage(feature, **self.local_coverage_kwargs)
... | python | def signal_panel(self, ax, feature):
"""
Plots each genomic signal as a line using the corresponding
plotting_kwargs
"""
for gs, kwargs in zip(self.genomic_signal_objs, self.plotting_kwargs):
x, y = gs.local_coverage(feature, **self.local_coverage_kwargs)
... | [
"def",
"signal_panel",
"(",
"self",
",",
"ax",
",",
"feature",
")",
":",
"for",
"gs",
",",
"kwargs",
"in",
"zip",
"(",
"self",
".",
"genomic_signal_objs",
",",
"self",
".",
"plotting_kwargs",
")",
":",
"x",
",",
"y",
"=",
"gs",
".",
"local_coverage",
... | Plots each genomic signal as a line using the corresponding
plotting_kwargs | [
"Plots",
"each",
"genomic",
"signal",
"as",
"a",
"line",
"using",
"the",
"corresponding",
"plotting_kwargs"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/minibrowser.py#L450-L459 |
45,974 | daler/metaseq | metaseq/minibrowser.py | GeneModelMiniBrowser.panels | def panels(self):
"""
Add 2 panels to the figure, top for signal and bottom for gene models
"""
ax1 = self.fig.add_subplot(211)
ax2 = self.fig.add_subplot(212, sharex=ax1)
return (ax2, self.gene_panel), (ax1, self.signal_panel) | python | def panels(self):
"""
Add 2 panels to the figure, top for signal and bottom for gene models
"""
ax1 = self.fig.add_subplot(211)
ax2 = self.fig.add_subplot(212, sharex=ax1)
return (ax2, self.gene_panel), (ax1, self.signal_panel) | [
"def",
"panels",
"(",
"self",
")",
":",
"ax1",
"=",
"self",
".",
"fig",
".",
"add_subplot",
"(",
"211",
")",
"ax2",
"=",
"self",
".",
"fig",
".",
"add_subplot",
"(",
"212",
",",
"sharex",
"=",
"ax1",
")",
"return",
"(",
"ax2",
",",
"self",
".",
... | Add 2 panels to the figure, top for signal and bottom for gene models | [
"Add",
"2",
"panels",
"to",
"the",
"figure",
"top",
"for",
"signal",
"and",
"bottom",
"for",
"gene",
"models"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/minibrowser.py#L475-L481 |
45,975 | hfaran/progressive | progressive/examples.py | simple | def simple():
"""Simple example using just the Bar class
This example is intended to show usage of the Bar class at the lowest
level.
"""
MAX_VALUE = 100
# Create our test progress bar
bar = Bar(max_value=MAX_VALUE, fallback=True)
bar.cursor.clear_lines(2)
# Before beginning to d... | python | def simple():
"""Simple example using just the Bar class
This example is intended to show usage of the Bar class at the lowest
level.
"""
MAX_VALUE = 100
# Create our test progress bar
bar = Bar(max_value=MAX_VALUE, fallback=True)
bar.cursor.clear_lines(2)
# Before beginning to d... | [
"def",
"simple",
"(",
")",
":",
"MAX_VALUE",
"=",
"100",
"# Create our test progress bar",
"bar",
"=",
"Bar",
"(",
"max_value",
"=",
"MAX_VALUE",
",",
"fallback",
"=",
"True",
")",
"bar",
".",
"cursor",
".",
"clear_lines",
"(",
"2",
")",
"# Before beginning ... | Simple example using just the Bar class
This example is intended to show usage of the Bar class at the lowest
level. | [
"Simple",
"example",
"using",
"just",
"the",
"Bar",
"class"
] | e39c7fb17405dbe997c3417a5993b94ef16dab0a | https://github.com/hfaran/progressive/blob/e39c7fb17405dbe997c3417a5993b94ef16dab0a/progressive/examples.py#L16-L37 |
45,976 | hfaran/progressive | progressive/examples.py | tree | def tree():
"""Example showing tree progress view"""
#############
# Test data #
#############
# For this example, we're obviously going to be feeding fictitious data
# to ProgressTree, so here it is
leaf_values = [Value(0) for i in range(6)]
bd_defaults = dict(type=Bar, kwargs=dict(... | python | def tree():
"""Example showing tree progress view"""
#############
# Test data #
#############
# For this example, we're obviously going to be feeding fictitious data
# to ProgressTree, so here it is
leaf_values = [Value(0) for i in range(6)]
bd_defaults = dict(type=Bar, kwargs=dict(... | [
"def",
"tree",
"(",
")",
":",
"#############",
"# Test data #",
"#############",
"# For this example, we're obviously going to be feeding fictitious data",
"# to ProgressTree, so here it is",
"leaf_values",
"=",
"[",
"Value",
"(",
"0",
")",
"for",
"i",
"in",
"range",
"(",... | Example showing tree progress view | [
"Example",
"showing",
"tree",
"progress",
"view"
] | e39c7fb17405dbe997c3417a5993b94ef16dab0a | https://github.com/hfaran/progressive/blob/e39c7fb17405dbe997c3417a5993b94ef16dab0a/progressive/examples.py#L40-L111 |
45,977 | daler/metaseq | metaseq/plotutils.py | ci_plot | def ci_plot(x, arr, conf=0.95, ax=None, line_kwargs=None, fill_kwargs=None):
"""
Plots the mean and 95% ci for the given array on the given axes
Parameters
----------
x : 1-D array-like
x values for the plot
arr : 2-D array-like
The array to calculate mean and std for
conf... | python | def ci_plot(x, arr, conf=0.95, ax=None, line_kwargs=None, fill_kwargs=None):
"""
Plots the mean and 95% ci for the given array on the given axes
Parameters
----------
x : 1-D array-like
x values for the plot
arr : 2-D array-like
The array to calculate mean and std for
conf... | [
"def",
"ci_plot",
"(",
"x",
",",
"arr",
",",
"conf",
"=",
"0.95",
",",
"ax",
"=",
"None",
",",
"line_kwargs",
"=",
"None",
",",
"fill_kwargs",
"=",
"None",
")",
":",
"if",
"ax",
"is",
"None",
":",
"fig",
"=",
"plt",
".",
"figure",
"(",
")",
"ax... | Plots the mean and 95% ci for the given array on the given axes
Parameters
----------
x : 1-D array-like
x values for the plot
arr : 2-D array-like
The array to calculate mean and std for
conf : float [.5 - 1]
Confidence interval to use
ax : matplotlib.Axes
Th... | [
"Plots",
"the",
"mean",
"and",
"95%",
"ci",
"for",
"the",
"given",
"array",
"on",
"the",
"given",
"axes"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L16-L50 |
45,978 | daler/metaseq | metaseq/plotutils.py | add_labels_to_subsets | def add_labels_to_subsets(ax, subset_by, subset_order, text_kwargs=None,
add_hlines=True, hline_kwargs=None):
"""
Helper function for adding labels to subsets within a heatmap.
Assumes that imshow() was called with `subsets` and `subset_order`.
Parameters
----------
a... | python | def add_labels_to_subsets(ax, subset_by, subset_order, text_kwargs=None,
add_hlines=True, hline_kwargs=None):
"""
Helper function for adding labels to subsets within a heatmap.
Assumes that imshow() was called with `subsets` and `subset_order`.
Parameters
----------
a... | [
"def",
"add_labels_to_subsets",
"(",
"ax",
",",
"subset_by",
",",
"subset_order",
",",
"text_kwargs",
"=",
"None",
",",
"add_hlines",
"=",
"True",
",",
"hline_kwargs",
"=",
"None",
")",
":",
"_text_kwargs",
"=",
"dict",
"(",
"transform",
"=",
"ax",
".",
"g... | Helper function for adding labels to subsets within a heatmap.
Assumes that imshow() was called with `subsets` and `subset_order`.
Parameters
----------
ax : matplotlib.Axes
The axes to label. Generally you can use `fig.array_axes` attribute of
the Figure object returned by `metaseq.p... | [
"Helper",
"function",
"for",
"adding",
"labels",
"to",
"subsets",
"within",
"a",
"heatmap",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L233-L269 |
45,979 | daler/metaseq | metaseq/plotutils.py | calculate_limits | def calculate_limits(array_dict, method='global', percentiles=None, limit=()):
"""
Calculate limits for a group of arrays in a flexible manner.
Returns a dictionary of calculated (vmin, vmax), with the same keys as
`array_dict`.
Useful for plotting heatmaps of multiple datasets, and the vmin/vmax ... | python | def calculate_limits(array_dict, method='global', percentiles=None, limit=()):
"""
Calculate limits for a group of arrays in a flexible manner.
Returns a dictionary of calculated (vmin, vmax), with the same keys as
`array_dict`.
Useful for plotting heatmaps of multiple datasets, and the vmin/vmax ... | [
"def",
"calculate_limits",
"(",
"array_dict",
",",
"method",
"=",
"'global'",
",",
"percentiles",
"=",
"None",
",",
"limit",
"=",
"(",
")",
")",
":",
"if",
"percentiles",
"is",
"not",
"None",
":",
"for",
"percentile",
"in",
"percentiles",
":",
"if",
"not... | Calculate limits for a group of arrays in a flexible manner.
Returns a dictionary of calculated (vmin, vmax), with the same keys as
`array_dict`.
Useful for plotting heatmaps of multiple datasets, and the vmin/vmax values
of the colormaps need to be matched across all (or a subset) of heatmaps.
P... | [
"Calculate",
"limits",
"for",
"a",
"group",
"of",
"arrays",
"in",
"a",
"flexible",
"manner",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L272-L338 |
45,980 | daler/metaseq | metaseq/plotutils.py | ci | def ci(arr, conf=0.95):
"""
Column-wise confidence interval.
Parameters
----------
arr : array-like
conf : float
Confidence interval
Returns
-------
m : array
column-wise mean
lower : array
lower column-wise confidence bound
upper : array
up... | python | def ci(arr, conf=0.95):
"""
Column-wise confidence interval.
Parameters
----------
arr : array-like
conf : float
Confidence interval
Returns
-------
m : array
column-wise mean
lower : array
lower column-wise confidence bound
upper : array
up... | [
"def",
"ci",
"(",
"arr",
",",
"conf",
"=",
"0.95",
")",
":",
"m",
"=",
"arr",
".",
"mean",
"(",
"axis",
"=",
"0",
")",
"n",
"=",
"len",
"(",
"arr",
")",
"se",
"=",
"arr",
".",
"std",
"(",
"axis",
"=",
"0",
")",
"/",
"np",
".",
"sqrt",
"... | Column-wise confidence interval.
Parameters
----------
arr : array-like
conf : float
Confidence interval
Returns
-------
m : array
column-wise mean
lower : array
lower column-wise confidence bound
upper : array
upper column-wise confidence bound | [
"Column",
"-",
"wise",
"confidence",
"interval",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L341-L365 |
45,981 | daler/metaseq | metaseq/plotutils.py | nice_log | def nice_log(x):
"""
Uses a log scale but with negative numbers.
:param x: NumPy array
"""
neg = x < 0
xi = np.log2(np.abs(x) + 1)
xi[neg] = -xi[neg]
return xi | python | def nice_log(x):
"""
Uses a log scale but with negative numbers.
:param x: NumPy array
"""
neg = x < 0
xi = np.log2(np.abs(x) + 1)
xi[neg] = -xi[neg]
return xi | [
"def",
"nice_log",
"(",
"x",
")",
":",
"neg",
"=",
"x",
"<",
"0",
"xi",
"=",
"np",
".",
"log2",
"(",
"np",
".",
"abs",
"(",
"x",
")",
"+",
"1",
")",
"xi",
"[",
"neg",
"]",
"=",
"-",
"xi",
"[",
"neg",
"]",
"return",
"xi"
] | Uses a log scale but with negative numbers.
:param x: NumPy array | [
"Uses",
"a",
"log",
"scale",
"but",
"with",
"negative",
"numbers",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L368-L377 |
45,982 | daler/metaseq | metaseq/plotutils.py | tip_fdr | def tip_fdr(a, alpha=0.05):
"""
Returns adjusted TIP p-values for a particular `alpha`.
(see :func:`tip_zscores` for more info)
:param a: NumPy array, where each row is the signal for a feature
:param alpha: False discovery rate
"""
zscores = tip_zscores(a)
pvals = stats.norm.pdf(zsco... | python | def tip_fdr(a, alpha=0.05):
"""
Returns adjusted TIP p-values for a particular `alpha`.
(see :func:`tip_zscores` for more info)
:param a: NumPy array, where each row is the signal for a feature
:param alpha: False discovery rate
"""
zscores = tip_zscores(a)
pvals = stats.norm.pdf(zsco... | [
"def",
"tip_fdr",
"(",
"a",
",",
"alpha",
"=",
"0.05",
")",
":",
"zscores",
"=",
"tip_zscores",
"(",
"a",
")",
"pvals",
"=",
"stats",
".",
"norm",
".",
"pdf",
"(",
"zscores",
")",
"rejected",
",",
"fdrs",
"=",
"fdrcorrection",
"(",
"pvals",
")",
"r... | Returns adjusted TIP p-values for a particular `alpha`.
(see :func:`tip_zscores` for more info)
:param a: NumPy array, where each row is the signal for a feature
:param alpha: False discovery rate | [
"Returns",
"adjusted",
"TIP",
"p",
"-",
"values",
"for",
"a",
"particular",
"alpha",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L469-L482 |
45,983 | daler/metaseq | metaseq/plotutils.py | prepare_logged | def prepare_logged(x, y):
"""
Transform `x` and `y` to a log scale while dealing with zeros.
This function scales `x` and `y` such that the points that are zero in one
array are set to the min of the other array.
When plotting expression data, frequently one sample will have reads in
a particu... | python | def prepare_logged(x, y):
"""
Transform `x` and `y` to a log scale while dealing with zeros.
This function scales `x` and `y` such that the points that are zero in one
array are set to the min of the other array.
When plotting expression data, frequently one sample will have reads in
a particu... | [
"def",
"prepare_logged",
"(",
"x",
",",
"y",
")",
":",
"xi",
"=",
"np",
".",
"log2",
"(",
"x",
")",
"yi",
"=",
"np",
".",
"log2",
"(",
"y",
")",
"xv",
"=",
"np",
".",
"isfinite",
"(",
"xi",
")",
"yv",
"=",
"np",
".",
"isfinite",
"(",
"yi",
... | Transform `x` and `y` to a log scale while dealing with zeros.
This function scales `x` and `y` such that the points that are zero in one
array are set to the min of the other array.
When plotting expression data, frequently one sample will have reads in
a particular feature but the other sample will ... | [
"Transform",
"x",
"and",
"y",
"to",
"a",
"log",
"scale",
"while",
"dealing",
"with",
"zeros",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L485-L512 |
45,984 | daler/metaseq | metaseq/plotutils.py | _updatecopy | def _updatecopy(orig, update_with, keys=None, override=False):
"""
Update a copy of dest with source. If `keys` is a list, then only update
with those keys.
"""
d = orig.copy()
if keys is None:
keys = update_with.keys()
for k in keys:
if k in update_with:
if k in... | python | def _updatecopy(orig, update_with, keys=None, override=False):
"""
Update a copy of dest with source. If `keys` is a list, then only update
with those keys.
"""
d = orig.copy()
if keys is None:
keys = update_with.keys()
for k in keys:
if k in update_with:
if k in... | [
"def",
"_updatecopy",
"(",
"orig",
",",
"update_with",
",",
"keys",
"=",
"None",
",",
"override",
"=",
"False",
")",
":",
"d",
"=",
"orig",
".",
"copy",
"(",
")",
"if",
"keys",
"is",
"None",
":",
"keys",
"=",
"update_with",
".",
"keys",
"(",
")",
... | Update a copy of dest with source. If `keys` is a list, then only update
with those keys. | [
"Update",
"a",
"copy",
"of",
"dest",
"with",
"source",
".",
"If",
"keys",
"is",
"a",
"list",
"then",
"only",
"update",
"with",
"those",
"keys",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L915-L928 |
45,985 | daler/metaseq | metaseq/plotutils.py | MarginalHistScatter.append | def append(self, x, y, scatter_kwargs, hist_kwargs=None, xhist_kwargs=None,
yhist_kwargs=None, num_ticks=3, labels=None, hist_share=False,
marginal_histograms=True):
"""
Adds a new scatter to self.scatter_ax as well as marginal histograms
for the same data, borrowin... | python | def append(self, x, y, scatter_kwargs, hist_kwargs=None, xhist_kwargs=None,
yhist_kwargs=None, num_ticks=3, labels=None, hist_share=False,
marginal_histograms=True):
"""
Adds a new scatter to self.scatter_ax as well as marginal histograms
for the same data, borrowin... | [
"def",
"append",
"(",
"self",
",",
"x",
",",
"y",
",",
"scatter_kwargs",
",",
"hist_kwargs",
"=",
"None",
",",
"xhist_kwargs",
"=",
"None",
",",
"yhist_kwargs",
"=",
"None",
",",
"num_ticks",
"=",
"3",
",",
"labels",
"=",
"None",
",",
"hist_share",
"="... | Adds a new scatter to self.scatter_ax as well as marginal histograms
for the same data, borrowing addtional room from the axes.
Parameters
----------
x, y : array-like
Data to be plotted
scatter_kwargs : dict
Keyword arguments that are passed directly t... | [
"Adds",
"a",
"new",
"scatter",
"to",
"self",
".",
"scatter_ax",
"as",
"well",
"as",
"marginal",
"histograms",
"for",
"the",
"same",
"data",
"borrowing",
"addtional",
"room",
"from",
"the",
"axes",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L980-L1089 |
45,986 | daler/metaseq | metaseq/plotutils.py | MarginalHistScatter.add_legends | def add_legends(self, xhists=True, yhists=False, scatter=True, **kwargs):
"""
Add legends to axes.
"""
axs = []
if xhists:
axs.extend(self.hxs)
if yhists:
axs.extend(self.hys)
if scatter:
axs.extend(self.ax)
for ax in a... | python | def add_legends(self, xhists=True, yhists=False, scatter=True, **kwargs):
"""
Add legends to axes.
"""
axs = []
if xhists:
axs.extend(self.hxs)
if yhists:
axs.extend(self.hys)
if scatter:
axs.extend(self.ax)
for ax in a... | [
"def",
"add_legends",
"(",
"self",
",",
"xhists",
"=",
"True",
",",
"yhists",
"=",
"False",
",",
"scatter",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"axs",
"=",
"[",
"]",
"if",
"xhists",
":",
"axs",
".",
"extend",
"(",
"self",
".",
"hxs",
... | Add legends to axes. | [
"Add",
"legends",
"to",
"axes",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/plotutils.py#L1091-L1104 |
45,987 | daler/metaseq | metaseq/_genomic_signal.py | genomic_signal | def genomic_signal(fn, kind):
"""
Factory function that makes the right class for the file format.
Typically you'll only need this function to create a new genomic signal
object.
:param fn: Filename
:param kind:
String. Format of the file; see
metaseq.genomic_signal._registry.... | python | def genomic_signal(fn, kind):
"""
Factory function that makes the right class for the file format.
Typically you'll only need this function to create a new genomic signal
object.
:param fn: Filename
:param kind:
String. Format of the file; see
metaseq.genomic_signal._registry.... | [
"def",
"genomic_signal",
"(",
"fn",
",",
"kind",
")",
":",
"try",
":",
"klass",
"=",
"_registry",
"[",
"kind",
".",
"lower",
"(",
")",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
"'No support for %s format, choices are %s'",
"%",
"(",
"kind",... | Factory function that makes the right class for the file format.
Typically you'll only need this function to create a new genomic signal
object.
:param fn: Filename
:param kind:
String. Format of the file; see
metaseq.genomic_signal._registry.keys() | [
"Factory",
"function",
"that",
"makes",
"the",
"right",
"class",
"for",
"the",
"file",
"format",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/_genomic_signal.py#L50-L70 |
45,988 | daler/metaseq | metaseq/_genomic_signal.py | BamSignal.genome | def genome(self):
"""
"genome" dictionary ready for pybedtools, based on the BAM header.
"""
# This gets the underlying pysam Samfile object
f = self.adapter.fileobj
d = {}
for ref, length in zip(f.references, f.lengths):
d[ref] = (0, length)
r... | python | def genome(self):
"""
"genome" dictionary ready for pybedtools, based on the BAM header.
"""
# This gets the underlying pysam Samfile object
f = self.adapter.fileobj
d = {}
for ref, length in zip(f.references, f.lengths):
d[ref] = (0, length)
r... | [
"def",
"genome",
"(",
"self",
")",
":",
"# This gets the underlying pysam Samfile object",
"f",
"=",
"self",
".",
"adapter",
".",
"fileobj",
"d",
"=",
"{",
"}",
"for",
"ref",
",",
"length",
"in",
"zip",
"(",
"f",
".",
"references",
",",
"f",
".",
"length... | "genome" dictionary ready for pybedtools, based on the BAM header. | [
"genome",
"dictionary",
"ready",
"for",
"pybedtools",
"based",
"on",
"the",
"BAM",
"header",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/_genomic_signal.py#L204-L213 |
45,989 | daler/metaseq | metaseq/_genomic_signal.py | BamSignal.mapped_read_count | def mapped_read_count(self, force=False):
"""
Counts total reads in a BAM file.
If a file self.bam + '.scale' exists, then just read the first line of
that file that doesn't start with a "#". If such a file doesn't exist,
then it will be created with the number of reads as the ... | python | def mapped_read_count(self, force=False):
"""
Counts total reads in a BAM file.
If a file self.bam + '.scale' exists, then just read the first line of
that file that doesn't start with a "#". If such a file doesn't exist,
then it will be created with the number of reads as the ... | [
"def",
"mapped_read_count",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"# Already run?",
"if",
"self",
".",
"_readcount",
"and",
"not",
"force",
":",
"return",
"self",
".",
"_readcount",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
... | Counts total reads in a BAM file.
If a file self.bam + '.scale' exists, then just read the first line of
that file that doesn't start with a "#". If such a file doesn't exist,
then it will be created with the number of reads as the first and only
line in the file.
The result i... | [
"Counts",
"total",
"reads",
"in",
"a",
"BAM",
"file",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/_genomic_signal.py#L215-L265 |
45,990 | daler/metaseq | metaseq/tableprinter.py | print_2x2_table | def print_2x2_table(table, row_labels, col_labels, fmt="%d"):
"""
Prints a table used for Fisher's exact test. Adds row, column, and grand
totals.
:param table: The four cells of a 2x2 table: [r1c1, r1c2, r2c1, r2c2]
:param row_labels: A length-2 list of row names
:param col_labels: A length-2 ... | python | def print_2x2_table(table, row_labels, col_labels, fmt="%d"):
"""
Prints a table used for Fisher's exact test. Adds row, column, and grand
totals.
:param table: The four cells of a 2x2 table: [r1c1, r1c2, r2c1, r2c2]
:param row_labels: A length-2 list of row names
:param col_labels: A length-2 ... | [
"def",
"print_2x2_table",
"(",
"table",
",",
"row_labels",
",",
"col_labels",
",",
"fmt",
"=",
"\"%d\"",
")",
":",
"grand",
"=",
"sum",
"(",
"table",
")",
"# Separate table into components and get row/col sums",
"t11",
",",
"t12",
",",
"t21",
",",
"t22",
"=",
... | Prints a table used for Fisher's exact test. Adds row, column, and grand
totals.
:param table: The four cells of a 2x2 table: [r1c1, r1c2, r2c1, r2c2]
:param row_labels: A length-2 list of row names
:param col_labels: A length-2 list of column names | [
"Prints",
"a",
"table",
"used",
"for",
"Fisher",
"s",
"exact",
"test",
".",
"Adds",
"row",
"column",
"and",
"grand",
"totals",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/tableprinter.py#L4-L60 |
45,991 | daler/metaseq | metaseq/tableprinter.py | print_row_perc_table | def print_row_perc_table(table, row_labels, col_labels):
"""
given a table, print the percentages rather than the totals
"""
r1c1, r1c2, r2c1, r2c2 = map(float, table)
row1 = r1c1 + r1c2
row2 = r2c1 + r2c2
blocks = [
(r1c1, row1),
(r1c2, row1),
(r2c1, row2),
... | python | def print_row_perc_table(table, row_labels, col_labels):
"""
given a table, print the percentages rather than the totals
"""
r1c1, r1c2, r2c1, r2c2 = map(float, table)
row1 = r1c1 + r1c2
row2 = r2c1 + r2c2
blocks = [
(r1c1, row1),
(r1c2, row1),
(r2c1, row2),
... | [
"def",
"print_row_perc_table",
"(",
"table",
",",
"row_labels",
",",
"col_labels",
")",
":",
"r1c1",
",",
"r1c2",
",",
"r2c1",
",",
"r2c2",
"=",
"map",
"(",
"float",
",",
"table",
")",
"row1",
"=",
"r1c1",
"+",
"r1c2",
"row2",
"=",
"r2c1",
"+",
"r2c2... | given a table, print the percentages rather than the totals | [
"given",
"a",
"table",
"print",
"the",
"percentages",
"rather",
"than",
"the",
"totals"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/tableprinter.py#L63-L89 |
45,992 | daler/metaseq | metaseq/tableprinter.py | print_col_perc_table | def print_col_perc_table(table, row_labels, col_labels):
"""
given a table, print the cols as percentages
"""
r1c1, r1c2, r2c1, r2c2 = map(float, table)
col1 = r1c1 + r2c1
col2 = r1c2 + r2c2
blocks = [
(r1c1, col1),
(r1c2, col2),
(r2c1, col1),
(r2c2, col2)]
... | python | def print_col_perc_table(table, row_labels, col_labels):
"""
given a table, print the cols as percentages
"""
r1c1, r1c2, r2c1, r2c2 = map(float, table)
col1 = r1c1 + r2c1
col2 = r1c2 + r2c2
blocks = [
(r1c1, col1),
(r1c2, col2),
(r2c1, col1),
(r2c2, col2)]
... | [
"def",
"print_col_perc_table",
"(",
"table",
",",
"row_labels",
",",
"col_labels",
")",
":",
"r1c1",
",",
"r1c2",
",",
"r2c1",
",",
"r2c2",
"=",
"map",
"(",
"float",
",",
"table",
")",
"col1",
"=",
"r1c1",
"+",
"r2c1",
"col2",
"=",
"r1c2",
"+",
"r2c2... | given a table, print the cols as percentages | [
"given",
"a",
"table",
"print",
"the",
"cols",
"as",
"percentages"
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/tableprinter.py#L92-L120 |
45,993 | hfaran/progressive | progressive/tree.py | ProgressTree.draw | def draw(self, tree, bar_desc=None, save_cursor=True, flush=True):
"""Draw ``tree`` to the terminal
:type tree: dict
:param tree: ``tree`` should be a tree representing a hierarchy; each
key should be a string describing that hierarchy level and value
should also be ``d... | python | def draw(self, tree, bar_desc=None, save_cursor=True, flush=True):
"""Draw ``tree`` to the terminal
:type tree: dict
:param tree: ``tree`` should be a tree representing a hierarchy; each
key should be a string describing that hierarchy level and value
should also be ``d... | [
"def",
"draw",
"(",
"self",
",",
"tree",
",",
"bar_desc",
"=",
"None",
",",
"save_cursor",
"=",
"True",
",",
"flush",
"=",
"True",
")",
":",
"if",
"save_cursor",
":",
"self",
".",
"cursor",
".",
"save",
"(",
")",
"tree",
"=",
"deepcopy",
"(",
"tree... | Draw ``tree`` to the terminal
:type tree: dict
:param tree: ``tree`` should be a tree representing a hierarchy; each
key should be a string describing that hierarchy level and value
should also be ``dict`` except for leaves which should be
``BarDescriptors``. See ``... | [
"Draw",
"tree",
"to",
"the",
"terminal"
] | e39c7fb17405dbe997c3417a5993b94ef16dab0a | https://github.com/hfaran/progressive/blob/e39c7fb17405dbe997c3417a5993b94ef16dab0a/progressive/tree.py#L73-L109 |
45,994 | hfaran/progressive | progressive/tree.py | ProgressTree.make_room | def make_room(self, tree):
"""Clear lines in terminal below current cursor position as required
This is important to do before drawing to ensure sufficient
room at the bottom of your terminal.
:type tree: dict
:param tree: tree as described in ``BarDescriptor``
"""
... | python | def make_room(self, tree):
"""Clear lines in terminal below current cursor position as required
This is important to do before drawing to ensure sufficient
room at the bottom of your terminal.
:type tree: dict
:param tree: tree as described in ``BarDescriptor``
"""
... | [
"def",
"make_room",
"(",
"self",
",",
"tree",
")",
":",
"lines_req",
"=",
"self",
".",
"lines_required",
"(",
"tree",
")",
"self",
".",
"cursor",
".",
"clear_lines",
"(",
"lines_req",
")"
] | Clear lines in terminal below current cursor position as required
This is important to do before drawing to ensure sufficient
room at the bottom of your terminal.
:type tree: dict
:param tree: tree as described in ``BarDescriptor`` | [
"Clear",
"lines",
"in",
"terminal",
"below",
"current",
"cursor",
"position",
"as",
"required"
] | e39c7fb17405dbe997c3417a5993b94ef16dab0a | https://github.com/hfaran/progressive/blob/e39c7fb17405dbe997c3417a5993b94ef16dab0a/progressive/tree.py#L111-L121 |
45,995 | hfaran/progressive | progressive/tree.py | ProgressTree.lines_required | def lines_required(self, tree, count=0):
"""Calculate number of lines required to draw ``tree``"""
if all([
isinstance(tree, dict),
type(tree) != BarDescriptor
]):
return sum(self.lines_required(v, count=count)
for v in tree.values()) + ... | python | def lines_required(self, tree, count=0):
"""Calculate number of lines required to draw ``tree``"""
if all([
isinstance(tree, dict),
type(tree) != BarDescriptor
]):
return sum(self.lines_required(v, count=count)
for v in tree.values()) + ... | [
"def",
"lines_required",
"(",
"self",
",",
"tree",
",",
"count",
"=",
"0",
")",
":",
"if",
"all",
"(",
"[",
"isinstance",
"(",
"tree",
",",
"dict",
")",
",",
"type",
"(",
"tree",
")",
"!=",
"BarDescriptor",
"]",
")",
":",
"return",
"sum",
"(",
"s... | Calculate number of lines required to draw ``tree`` | [
"Calculate",
"number",
"of",
"lines",
"required",
"to",
"draw",
"tree"
] | e39c7fb17405dbe997c3417a5993b94ef16dab0a | https://github.com/hfaran/progressive/blob/e39c7fb17405dbe997c3417a5993b94ef16dab0a/progressive/tree.py#L123-L135 |
45,996 | hfaran/progressive | progressive/tree.py | ProgressTree._calculate_values | def _calculate_values(self, tree, bar_d):
"""Calculate values for drawing bars of non-leafs in ``tree``
Recurses through ``tree``, replaces ``dict``s with
``(BarDescriptor, dict)`` so ``ProgressTree._draw`` can use
the ``BarDescriptor``s to draw the tree
"""
if a... | python | def _calculate_values(self, tree, bar_d):
"""Calculate values for drawing bars of non-leafs in ``tree``
Recurses through ``tree``, replaces ``dict``s with
``(BarDescriptor, dict)`` so ``ProgressTree._draw`` can use
the ``BarDescriptor``s to draw the tree
"""
if a... | [
"def",
"_calculate_values",
"(",
"self",
",",
"tree",
",",
"bar_d",
")",
":",
"if",
"all",
"(",
"[",
"isinstance",
"(",
"tree",
",",
"dict",
")",
",",
"type",
"(",
"tree",
")",
"!=",
"BarDescriptor",
"]",
")",
":",
"# Calculate value and max_value",
"max... | Calculate values for drawing bars of non-leafs in ``tree``
Recurses through ``tree``, replaces ``dict``s with
``(BarDescriptor, dict)`` so ``ProgressTree._draw`` can use
the ``BarDescriptor``s to draw the tree | [
"Calculate",
"values",
"for",
"drawing",
"bars",
"of",
"non",
"-",
"leafs",
"in",
"tree"
] | e39c7fb17405dbe997c3417a5993b94ef16dab0a | https://github.com/hfaran/progressive/blob/e39c7fb17405dbe997c3417a5993b94ef16dab0a/progressive/tree.py#L141-L177 |
45,997 | hfaran/progressive | progressive/tree.py | ProgressTree._draw | def _draw(self, tree, indent=0):
"""Recurse through ``tree`` and draw all nodes"""
if all([
isinstance(tree, dict),
type(tree) != BarDescriptor
]):
for k, v in sorted(tree.items()):
bar_desc, subdict = v[0], v[1]
args = [self.c... | python | def _draw(self, tree, indent=0):
"""Recurse through ``tree`` and draw all nodes"""
if all([
isinstance(tree, dict),
type(tree) != BarDescriptor
]):
for k, v in sorted(tree.items()):
bar_desc, subdict = v[0], v[1]
args = [self.c... | [
"def",
"_draw",
"(",
"self",
",",
"tree",
",",
"indent",
"=",
"0",
")",
":",
"if",
"all",
"(",
"[",
"isinstance",
"(",
"tree",
",",
"dict",
")",
",",
"type",
"(",
"tree",
")",
"!=",
"BarDescriptor",
"]",
")",
":",
"for",
"k",
",",
"v",
"in",
... | Recurse through ``tree`` and draw all nodes | [
"Recurse",
"through",
"tree",
"and",
"draw",
"all",
"nodes"
] | e39c7fb17405dbe997c3417a5993b94ef16dab0a | https://github.com/hfaran/progressive/blob/e39c7fb17405dbe997c3417a5993b94ef16dab0a/progressive/tree.py#L179-L195 |
45,998 | daler/metaseq | metaseq/persistence.py | load_features_and_arrays | def load_features_and_arrays(prefix, mmap_mode='r'):
"""
Returns the features and NumPy arrays that were saved with
save_features_and_arrays.
Parameters
----------
prefix : str
Path to where data are saved
mmap_mode : {None, 'r+', 'r', 'w+', 'c'}
Mode in which to memory-ma... | python | def load_features_and_arrays(prefix, mmap_mode='r'):
"""
Returns the features and NumPy arrays that were saved with
save_features_and_arrays.
Parameters
----------
prefix : str
Path to where data are saved
mmap_mode : {None, 'r+', 'r', 'w+', 'c'}
Mode in which to memory-ma... | [
"def",
"load_features_and_arrays",
"(",
"prefix",
",",
"mmap_mode",
"=",
"'r'",
")",
":",
"features",
"=",
"pybedtools",
".",
"BedTool",
"(",
"prefix",
"+",
"'.features'",
")",
"arrays",
"=",
"np",
".",
"load",
"(",
"prefix",
"+",
"'.npz'",
",",
"mmap_mode... | Returns the features and NumPy arrays that were saved with
save_features_and_arrays.
Parameters
----------
prefix : str
Path to where data are saved
mmap_mode : {None, 'r+', 'r', 'w+', 'c'}
Mode in which to memory-map the file. See np.load for details. | [
"Returns",
"the",
"features",
"and",
"NumPy",
"arrays",
"that",
"were",
"saved",
"with",
"save_features_and_arrays",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/persistence.py#L10-L26 |
45,999 | daler/metaseq | metaseq/persistence.py | save_features_and_arrays | def save_features_and_arrays(features, arrays, prefix, compressed=False,
link_features=False, overwrite=False):
"""
Saves NumPy arrays of processed data, along with the features that
correspond to each row, to files for later use.
Two files will be saved, both starting with... | python | def save_features_and_arrays(features, arrays, prefix, compressed=False,
link_features=False, overwrite=False):
"""
Saves NumPy arrays of processed data, along with the features that
correspond to each row, to files for later use.
Two files will be saved, both starting with... | [
"def",
"save_features_and_arrays",
"(",
"features",
",",
"arrays",
",",
"prefix",
",",
"compressed",
"=",
"False",
",",
"link_features",
"=",
"False",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"link_features",
":",
"if",
"isinstance",
"(",
"features",
... | Saves NumPy arrays of processed data, along with the features that
correspond to each row, to files for later use.
Two files will be saved, both starting with `prefix`:
prefix.features : a file of features. If GFF features were provided,
this will be in GFF format, if BED features were provid... | [
"Saves",
"NumPy",
"arrays",
"of",
"processed",
"data",
"along",
"with",
"the",
"features",
"that",
"correspond",
"to",
"each",
"row",
"to",
"files",
"for",
"later",
"use",
"."
] | fa875d1f72317aa7ef95cb128b739956b16eef9f | https://github.com/daler/metaseq/blob/fa875d1f72317aa7ef95cb128b739956b16eef9f/metaseq/persistence.py#L29-L92 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.