hexsha stringlengths 40 40 | repo stringlengths 7 114 | path stringlengths 4 124 | license listlengths 1 9 | language stringclasses 1
value | identifier stringlengths 1 71 | return_type stringlengths 1 749 ⌀ | original_string stringlengths 76 22.7k | original_docstring stringlengths 16 7.61k | docstring stringlengths 16 2.47k | docstring_tokens listlengths 6 477 | code stringlengths 14 10.2k | code_tokens listlengths 6 996 | short_docstring stringlengths 2 644 | short_docstring_tokens listlengths 1 116 | comment listlengths 1 89 | parameters listlengths 0 64 | docstring_params dict |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
71d8ce9b4beda07cb1798c46ad84b05919859d18 | TrialAndErrror/TnE_Assistant | src/Assistant.py | [
"MIT"
] | Python | perform_action | null | def perform_action(command_action):
"""
Process command and perform the corresponding action.
This is the core decision-making process behind the Assistant.
:param command_action: str
:return: None
"""
command_word, phrase = get_first_word_and_phrase_from(command_action)
"""
Get fi... |
Process command and perform the corresponding action.
This is the core decision-making process behind the Assistant.
:param command_action: str
:return: None
| Process command and perform the corresponding action.
This is the core decision-making process behind the Assistant. | [
"Process",
"command",
"and",
"perform",
"the",
"corresponding",
"action",
".",
"This",
"is",
"the",
"core",
"decision",
"-",
"making",
"process",
"behind",
"the",
"Assistant",
"."
] | def perform_action(command_action):
command_word, phrase = get_first_word_and_phrase_from(command_action)
chosen_action = determine_command_type(command_word)
if chosen_action == 'play':
logging.debug(f'Recognized {command_word} as Play; playing {phrase}')
play_youtube_video_for(phrase)
... | [
"def",
"perform_action",
"(",
"command_action",
")",
":",
"command_word",
",",
"phrase",
"=",
"get_first_word_and_phrase_from",
"(",
"command_action",
")",
"\"\"\"\n Get first word and phrase. \n 'phrase' has had helper words removed and whitespace stripped.\n \n Run the dete... | Process command and perform the corresponding action. | [
"Process",
"command",
"and",
"perform",
"the",
"corresponding",
"action",
"."
] | [
"\"\"\"\n Process command and perform the corresponding action.\n This is the core decision-making process behind the Assistant.\n\n :param command_action: str\n :return: None\n \"\"\"",
"\"\"\"\n Get first word and phrase. \n 'phrase' has had helper words removed and whitespace stripped.\n ... | [
{
"param": "command_action",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "command_action",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": nu... |
71d8ce9b4beda07cb1798c46ad84b05919859d18 | TrialAndErrror/TnE_Assistant | src/Assistant.py | [
"MIT"
] | Python | determine_command_type | <not_specific> | def determine_command_type(command_word):
"""
Check Settings to get the list of available commands (or default to these lists if no settings found).
By default, the
:param command_word:
:return:
"""
default_play_commands = ['play']
default_wiki_commands = ['wiki', 'what', 'who']
def... |
Check Settings to get the list of available commands (or default to these lists if no settings found).
By default, the
:param command_word:
:return:
| Check Settings to get the list of available commands (or default to these lists if no settings found).
By default, the | [
"Check",
"Settings",
"to",
"get",
"the",
"list",
"of",
"available",
"commands",
"(",
"or",
"default",
"to",
"these",
"lists",
"if",
"no",
"settings",
"found",
")",
".",
"By",
"default",
"the"
] | def determine_command_type(command_word):
default_play_commands = ['play']
default_wiki_commands = ['wiki', 'what', 'who']
default_search_commands = ['search', 'find', 'google']
default_open_commands = ['open']
chosen_action = 'catchall'
actions_list = [
PLAY_SETTINGS.get('Commands', def... | [
"def",
"determine_command_type",
"(",
"command_word",
")",
":",
"default_play_commands",
"=",
"[",
"'play'",
"]",
"default_wiki_commands",
"=",
"[",
"'wiki'",
",",
"'what'",
",",
"'who'",
"]",
"default_search_commands",
"=",
"[",
"'search'",
",",
"'find'",
",",
... | Check Settings to get the list of available commands (or default to these lists if no settings found). | [
"Check",
"Settings",
"to",
"get",
"the",
"list",
"of",
"available",
"commands",
"(",
"or",
"default",
"to",
"these",
"lists",
"if",
"no",
"settings",
"found",
")",
"."
] | [
"\"\"\"\n Check Settings to get the list of available commands (or default to these lists if no settings found).\n\n By default, the\n :param command_word:\n :return:\n \"\"\"",
"\"\"\"\n Actions list is a list of all of the options of command words that can trigger that particular action.\n ... | [
{
"param": "command_word",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "command_word",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null... |
b46707b42d15d184fe856fbf4ce278fd8f2d3fc4 | TrialAndErrror/TnE_Assistant | src/Tools/process_command.py | [
"MIT"
] | Python | cut_wake_word_from_command | <not_specific> | def cut_wake_word_from_command(command):
"""
Removes trigger from command using string split on the command string.
Converts command to lowercase.
Returns the rest of the command string after removing the trigger.
:param trigger: str
:param command: str
:return: str
"""
trigger = ... |
Removes trigger from command using string split on the command string.
Converts command to lowercase.
Returns the rest of the command string after removing the trigger.
:param trigger: str
:param command: str
:return: str
| Removes trigger from command using string split on the command string.
Converts command to lowercase.
Returns the rest of the command string after removing the trigger. | [
"Removes",
"trigger",
"from",
"command",
"using",
"string",
"split",
"on",
"the",
"command",
"string",
".",
"Converts",
"command",
"to",
"lowercase",
".",
"Returns",
"the",
"rest",
"of",
"the",
"command",
"string",
"after",
"removing",
"the",
"trigger",
"."
] | def cut_wake_word_from_command(command):
trigger = get_trigger_command()
command_action = command.split(f' {trigger} ')[1].lower()
logging.debug(f'Trigger command ({trigger}) removed from ({command})')
logging.debug(f'Returning {command_action} as command_action')
return command_action | [
"def",
"cut_wake_word_from_command",
"(",
"command",
")",
":",
"trigger",
"=",
"get_trigger_command",
"(",
")",
"command_action",
"=",
"command",
".",
"split",
"(",
"f' {trigger} '",
")",
"[",
"1",
"]",
".",
"lower",
"(",
")",
"logging",
".",
"debug",
"(",
... | Removes trigger from command using string split on the command string. | [
"Removes",
"trigger",
"from",
"command",
"using",
"string",
"split",
"on",
"the",
"command",
"string",
"."
] | [
"\"\"\"\n Removes trigger from command using string split on the command string.\n\n Converts command to lowercase.\n\n Returns the rest of the command string after removing the trigger.\n\n :param trigger: str\n :param command: str\n :return: str\n \"\"\""
] | [
{
"param": "command",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "command",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
b46707b42d15d184fe856fbf4ce278fd8f2d3fc4 | TrialAndErrror/TnE_Assistant | src/Tools/process_command.py | [
"MIT"
] | Python | remove_helper_words | <not_specific> | def remove_helper_words(phrase: str):
"""
Remove helper words from the beginning of param phrase.
Removes whitespace before and after removing words.
Returns cleaned phrase.
This is a part that could use some improvement or a new library integration.
:param phrase: str
:return: phrase: st... |
Remove helper words from the beginning of param phrase.
Removes whitespace before and after removing words.
Returns cleaned phrase.
This is a part that could use some improvement or a new library integration.
:param phrase: str
:return: phrase: str
| Remove helper words from the beginning of param phrase.
Removes whitespace before and after removing words.
Returns cleaned phrase.
This is a part that could use some improvement or a new library integration. | [
"Remove",
"helper",
"words",
"from",
"the",
"beginning",
"of",
"param",
"phrase",
".",
"Removes",
"whitespace",
"before",
"and",
"after",
"removing",
"words",
".",
"Returns",
"cleaned",
"phrase",
".",
"This",
"is",
"a",
"part",
"that",
"could",
"use",
"some"... | def remove_helper_words(phrase: str):
logging.debug(f'Removing helper words and whitespace from ({phrase})')
phrase = phrase.strip()
for word in ['for ', 'was ', 'were ', 'up ', 'to ', 'is ', 'are', 'the ']:
phrase = phrase.replace(word, '', 1) if phrase.startswith(word) else phrase
phrase = phr... | [
"def",
"remove_helper_words",
"(",
"phrase",
":",
"str",
")",
":",
"logging",
".",
"debug",
"(",
"f'Removing helper words and whitespace from ({phrase})'",
")",
"phrase",
"=",
"phrase",
".",
"strip",
"(",
")",
"for",
"word",
"in",
"[",
"'for '",
",",
"'was '",
... | Remove helper words from the beginning of param phrase. | [
"Remove",
"helper",
"words",
"from",
"the",
"beginning",
"of",
"param",
"phrase",
"."
] | [
"\"\"\"\n Remove helper words from the beginning of param phrase.\n Removes whitespace before and after removing words.\n\n Returns cleaned phrase.\n\n This is a part that could use some improvement or a new library integration.\n\n :param phrase: str\n :return: phrase: str\n \"\"\""
] | [
{
"param": "phrase",
"type": "str"
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "phrase",
"type": "str",
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
b46707b42d15d184fe856fbf4ce278fd8f2d3fc4 | TrialAndErrror/TnE_Assistant | src/Tools/process_command.py | [
"MIT"
] | Python | listen_for_commands | <not_specific> | def listen_for_commands():
"""
Listen for command;
use Google speech detection to extract command;
then return command
:return: command: str
"""
with sr.Microphone() as source:
print_custom_intro()
voice = listener.listen(source)
command: str = listener.recognize_goo... |
Listen for command;
use Google speech detection to extract command;
then return command
:return: command: str
| Listen for command;
use Google speech detection to extract command;
then return command | [
"Listen",
"for",
"command",
";",
"use",
"Google",
"speech",
"detection",
"to",
"extract",
"command",
";",
"then",
"return",
"command"
] | def listen_for_commands():
with sr.Microphone() as source:
print_custom_intro()
voice = listener.listen(source)
command: str = listener.recognize_google(voice)
return command | [
"def",
"listen_for_commands",
"(",
")",
":",
"with",
"sr",
".",
"Microphone",
"(",
")",
"as",
"source",
":",
"print_custom_intro",
"(",
")",
"voice",
"=",
"listener",
".",
"listen",
"(",
"source",
")",
"command",
":",
"str",
"=",
"listener",
".",
"recogn... | Listen for command;
use Google speech detection to extract command;
then return command | [
"Listen",
"for",
"command",
";",
"use",
"Google",
"speech",
"detection",
"to",
"extract",
"command",
";",
"then",
"return",
"command"
] | [
"\"\"\"\n Listen for command;\n use Google speech detection to extract command;\n then return command\n\n :return: command: str\n \"\"\""
] | [] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
b46d9db3d085964e5b118f75d4b572e1624f0907 | TrialAndErrror/TnE_Assistant | src/Actions/Open.py | [
"MIT"
] | Python | open_page_or_file | null | def open_page_or_file(phrase):
"""
Handles all routes based on the 'Open' first_word.
Currently only supports opening custom e-mail link.
Allows for custom commands to launch e-mail in the Settings file.
Link to E-mail provider also in Settings file
:param phrase: str
:return: None
""... |
Handles all routes based on the 'Open' first_word.
Currently only supports opening custom e-mail link.
Allows for custom commands to launch e-mail in the Settings file.
Link to E-mail provider also in Settings file
:param phrase: str
:return: None
| Handles all routes based on the 'Open' first_word.
Currently only supports opening custom e-mail link.
Allows for custom commands to launch e-mail in the Settings file.
Link to E-mail provider also in Settings file | [
"Handles",
"all",
"routes",
"based",
"on",
"the",
"'",
"Open",
"'",
"first_word",
".",
"Currently",
"only",
"supports",
"opening",
"custom",
"e",
"-",
"mail",
"link",
".",
"Allows",
"for",
"custom",
"commands",
"to",
"launch",
"e",
"-",
"mail",
"in",
"th... | def open_page_or_file(phrase):
default_email_commands = ['mail', 'message']
if phrase in OPEN_SETTINGS.get('Email', default_email_commands):
speak(f'Opening Mail')
open_mail_link()
else:
speak(f'I don\'t know how to open {phrase}') | [
"def",
"open_page_or_file",
"(",
"phrase",
")",
":",
"default_email_commands",
"=",
"[",
"'mail'",
",",
"'message'",
"]",
"if",
"phrase",
"in",
"OPEN_SETTINGS",
".",
"get",
"(",
"'Email'",
",",
"default_email_commands",
")",
":",
"speak",
"(",
"f'Opening Mail'",... | Handles all routes based on the 'Open' first_word. | [
"Handles",
"all",
"routes",
"based",
"on",
"the",
"'",
"Open",
"'",
"first_word",
"."
] | [
"\"\"\"\n Handles all routes based on the 'Open' first_word.\n\n Currently only supports opening custom e-mail link.\n\n Allows for custom commands to launch e-mail in the Settings file.\n Link to E-mail provider also in Settings file\n\n :param phrase: str\n :return: None\n \"\"\""
] | [
{
"param": "phrase",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "phrase",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
b46d9db3d085964e5b118f75d4b572e1624f0907 | TrialAndErrror/TnE_Assistant | src/Actions/Open.py | [
"MIT"
] | Python | open_mail_link | null | def open_mail_link():
"""
Get mail url from Settings file, then open in web browser.
Defaults to GMail if nothing provided in settings.
:return: None
"""
default_url = 'https://mail.google.com/mail/u/0/'
mail_url = OPEN_SETTINGS.get('Mail URL', default_url)
webbrowser.open(mail_url) |
Get mail url from Settings file, then open in web browser.
Defaults to GMail if nothing provided in settings.
:return: None
| Get mail url from Settings file, then open in web browser.
Defaults to GMail if nothing provided in settings. | [
"Get",
"mail",
"url",
"from",
"Settings",
"file",
"then",
"open",
"in",
"web",
"browser",
".",
"Defaults",
"to",
"GMail",
"if",
"nothing",
"provided",
"in",
"settings",
"."
] | def open_mail_link():
default_url = 'https://mail.google.com/mail/u/0/'
mail_url = OPEN_SETTINGS.get('Mail URL', default_url)
webbrowser.open(mail_url) | [
"def",
"open_mail_link",
"(",
")",
":",
"default_url",
"=",
"'https://mail.google.com/mail/u/0/'",
"mail_url",
"=",
"OPEN_SETTINGS",
".",
"get",
"(",
"'Mail URL'",
",",
"default_url",
")",
"webbrowser",
".",
"open",
"(",
"mail_url",
")"
] | Get mail url from Settings file, then open in web browser. | [
"Get",
"mail",
"url",
"from",
"Settings",
"file",
"then",
"open",
"in",
"web",
"browser",
"."
] | [
"\"\"\"\n Get mail url from Settings file, then open in web browser.\n\n Defaults to GMail if nothing provided in settings.\n :return: None\n \"\"\""
] | [] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
510d1c722161c6edcc22c253703fb7316e782400 | TrialAndErrror/TnE_Assistant | src/Actions/Wiki.py | [
"MIT"
] | Python | open_wiki_url | null | def open_wiki_url(phrase: str):
"""
Capitalize and parse phrase as web-friendly string;
open web browser to Wikipedia page for web-friendly string
:param phrase: str
:return: None
"""
webbrowser.open(f'https://en.wikipedia.org/wiki/{quote(phrase.capitalize())}') |
Capitalize and parse phrase as web-friendly string;
open web browser to Wikipedia page for web-friendly string
:param phrase: str
:return: None
| Capitalize and parse phrase as web-friendly string;
open web browser to Wikipedia page for web-friendly string | [
"Capitalize",
"and",
"parse",
"phrase",
"as",
"web",
"-",
"friendly",
"string",
";",
"open",
"web",
"browser",
"to",
"Wikipedia",
"page",
"for",
"web",
"-",
"friendly",
"string"
] | def open_wiki_url(phrase: str):
webbrowser.open(f'https://en.wikipedia.org/wiki/{quote(phrase.capitalize())}') | [
"def",
"open_wiki_url",
"(",
"phrase",
":",
"str",
")",
":",
"webbrowser",
".",
"open",
"(",
"f'https://en.wikipedia.org/wiki/{quote(phrase.capitalize())}'",
")"
] | Capitalize and parse phrase as web-friendly string;
open web browser to Wikipedia page for web-friendly string | [
"Capitalize",
"and",
"parse",
"phrase",
"as",
"web",
"-",
"friendly",
"string",
";",
"open",
"web",
"browser",
"to",
"Wikipedia",
"page",
"for",
"web",
"-",
"friendly",
"string"
] | [
"\"\"\"\n Capitalize and parse phrase as web-friendly string;\n open web browser to Wikipedia page for web-friendly string\n\n :param phrase: str\n :return: None\n \"\"\""
] | [
{
"param": "phrase",
"type": "str"
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "phrase",
"type": "str",
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
510d1c722161c6edcc22c253703fb7316e782400 | TrialAndErrror/TnE_Assistant | src/Actions/Wiki.py | [
"MIT"
] | Python | read_wiki_summary | null | def read_wiki_summary(phrase, lines_to_read):
"""
Read specific number of lines from the Summary of phrase on Wikipedia
:param phrase: str
:param lines_to_read: int
:return: None
"""
response = wikipedia.summary(phrase, lines_to_read)
speak(f'Here\'s what I found on Wikipedia for {phras... |
Read specific number of lines from the Summary of phrase on Wikipedia
:param phrase: str
:param lines_to_read: int
:return: None
| Read specific number of lines from the Summary of phrase on Wikipedia | [
"Read",
"specific",
"number",
"of",
"lines",
"from",
"the",
"Summary",
"of",
"phrase",
"on",
"Wikipedia"
] | def read_wiki_summary(phrase, lines_to_read):
response = wikipedia.summary(phrase, lines_to_read)
speak(f'Here\'s what I found on Wikipedia for {phrase}: {response}') | [
"def",
"read_wiki_summary",
"(",
"phrase",
",",
"lines_to_read",
")",
":",
"response",
"=",
"wikipedia",
".",
"summary",
"(",
"phrase",
",",
"lines_to_read",
")",
"speak",
"(",
"f'Here\\'s what I found on Wikipedia for {phrase}: {response}'",
")"
] | Read specific number of lines from the Summary of phrase on Wikipedia | [
"Read",
"specific",
"number",
"of",
"lines",
"from",
"the",
"Summary",
"of",
"phrase",
"on",
"Wikipedia"
] | [
"\"\"\"\n Read specific number of lines from the Summary of phrase on Wikipedia\n\n :param phrase: str\n :param lines_to_read: int\n :return: None\n \"\"\""
] | [
{
"param": "phrase",
"type": null
},
{
"param": "lines_to_read",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "phrase",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
510d1c722161c6edcc22c253703fb7316e782400 | TrialAndErrror/TnE_Assistant | src/Actions/Wiki.py | [
"MIT"
] | Python | open_wiki_results_for | null | def open_wiki_results_for(phrase):
"""
Open Wiki URL for phrase;
Read Wiki summary aloud based on number of lines specified in Settings.
:param phrase: str
:return: None
"""
open_wiki_url(phrase)
lines_to_read: int = WIKI_SETTINGS.get('Lines to Read', 1)
read_wiki_summary(phrase, l... |
Open Wiki URL for phrase;
Read Wiki summary aloud based on number of lines specified in Settings.
:param phrase: str
:return: None
| Open Wiki URL for phrase;
Read Wiki summary aloud based on number of lines specified in Settings. | [
"Open",
"Wiki",
"URL",
"for",
"phrase",
";",
"Read",
"Wiki",
"summary",
"aloud",
"based",
"on",
"number",
"of",
"lines",
"specified",
"in",
"Settings",
"."
] | def open_wiki_results_for(phrase):
open_wiki_url(phrase)
lines_to_read: int = WIKI_SETTINGS.get('Lines to Read', 1)
read_wiki_summary(phrase, lines_to_read) | [
"def",
"open_wiki_results_for",
"(",
"phrase",
")",
":",
"open_wiki_url",
"(",
"phrase",
")",
"lines_to_read",
":",
"int",
"=",
"WIKI_SETTINGS",
".",
"get",
"(",
"'Lines to Read'",
",",
"1",
")",
"read_wiki_summary",
"(",
"phrase",
",",
"lines_to_read",
")"
] | Open Wiki URL for phrase;
Read Wiki summary aloud based on number of lines specified in Settings. | [
"Open",
"Wiki",
"URL",
"for",
"phrase",
";",
"Read",
"Wiki",
"summary",
"aloud",
"based",
"on",
"number",
"of",
"lines",
"specified",
"in",
"Settings",
"."
] | [
"\"\"\"\n Open Wiki URL for phrase;\n Read Wiki summary aloud based on number of lines specified in Settings.\n\n :param phrase: str\n :return: None\n \"\"\""
] | [
{
"param": "phrase",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "phrase",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
da3e4205bb37ae0c21d1d31d422c8823d5f40a39 | TrialAndErrror/TnE_Assistant | src/Tools/wake_triggers.py | [
"MIT"
] | Python | check_for_wake_word | <not_specific> | def check_for_wake_word(command: str):
"""
Check if wake word is in param command.
:param command: str
:return: is_triggered: bool
"""
wake_word: str = ASSISTANT_SETTINGS.get('Wake Word')
logging.debug(f'Searching for wake word ({wake_word}) in command ({command})')
wake_word_found = b... |
Check if wake word is in param command.
:param command: str
:return: is_triggered: bool
| Check if wake word is in param command. | [
"Check",
"if",
"wake",
"word",
"is",
"in",
"param",
"command",
"."
] | def check_for_wake_word(command: str):
wake_word: str = ASSISTANT_SETTINGS.get('Wake Word')
logging.debug(f'Searching for wake word ({wake_word}) in command ({command})')
wake_word_found = bool(command.lower().startswith(wake_word.lower()))
if wake_word_found:
logging.debug(f'Assistant activated... | [
"def",
"check_for_wake_word",
"(",
"command",
":",
"str",
")",
":",
"wake_word",
":",
"str",
"=",
"ASSISTANT_SETTINGS",
".",
"get",
"(",
"'Wake Word'",
")",
"logging",
".",
"debug",
"(",
"f'Searching for wake word ({wake_word}) in command ({command})'",
")",
"wake_wor... | Check if wake word is in param command. | [
"Check",
"if",
"wake",
"word",
"is",
"in",
"param",
"command",
"."
] | [
"\"\"\"\n Check if wake word is in param command.\n\n :param command: str\n :return: is_triggered: bool\n \"\"\""
] | [
{
"param": "command",
"type": "str"
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "command",
"type": "str",
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
204f69399a2a212a16648b7ddd27efd5dcdff9d4 | TrialAndErrror/TnE_Assistant | src/Actions/Catchall.py | [
"MIT"
] | Python | do_catchall_action | null | def do_catchall_action(phrase, command_word):
"""
Log that the trigger word was not recognized, then perform default action.
Default: Search
:param phrase: str
:param command_word: str
:return:
"""
speak(f'The command word was {command_word}, but I don\'t know what that means.')
sp... |
Log that the trigger word was not recognized, then perform default action.
Default: Search
:param phrase: str
:param command_word: str
:return:
| Log that the trigger word was not recognized, then perform default action.
Default: Search | [
"Log",
"that",
"the",
"trigger",
"word",
"was",
"not",
"recognized",
"then",
"perform",
"default",
"action",
".",
"Default",
":",
"Search"
] | def do_catchall_action(phrase, command_word):
speak(f'The command word was {command_word}, but I don\'t know what that means.')
speak(f'I\'ll try to search Google for {phrase}.')
search_web_for(phrase) | [
"def",
"do_catchall_action",
"(",
"phrase",
",",
"command_word",
")",
":",
"speak",
"(",
"f'The command word was {command_word}, but I don\\'t know what that means.'",
")",
"speak",
"(",
"f'I\\'ll try to search Google for {phrase}.'",
")",
"search_web_for",
"(",
"phrase",
")"
] | Log that the trigger word was not recognized, then perform default action. | [
"Log",
"that",
"the",
"trigger",
"word",
"was",
"not",
"recognized",
"then",
"perform",
"default",
"action",
"."
] | [
"\"\"\"\n Log that the trigger word was not recognized, then perform default action.\n\n Default: Search\n\n :param phrase: str\n :param command_word: str\n :return:\n \"\"\""
] | [
{
"param": "phrase",
"type": null
},
{
"param": "command_word",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "phrase",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
3c346d9b4de17fb5d27193ee5c55df28a1eb38fc | Dhrumilsoni/Chess_Engine | chesslib/board.py | [
"WTFPL"
] | Python | _finish_move | null | def _finish_move(self, piece, dest, p1, p2):
'''
Set next player turn, count moves, log moves, etc.
'''
enemy = self.get_enemy(piece.color)
if piece.color == 'black':
self.fullmove_number += 1
self.halfmove_clock +=1
self.player_turn = enemy
... |
Set next player turn, count moves, log moves, etc.
| Set next player turn, count moves, log moves, etc. | [
"Set",
"next",
"player",
"turn",
"count",
"moves",
"log",
"moves",
"etc",
"."
] | def _finish_move(self, piece, dest, p1, p2):
enemy = self.get_enemy(piece.color)
if piece.color == 'black':
self.fullmove_number += 1
self.halfmove_clock +=1
self.player_turn = enemy
abbr = piece.abbriviation
if abbr == 'P':
abbr = ''
s... | [
"def",
"_finish_move",
"(",
"self",
",",
"piece",
",",
"dest",
",",
"p1",
",",
"p2",
")",
":",
"enemy",
"=",
"self",
".",
"get_enemy",
"(",
"piece",
".",
"color",
")",
"if",
"piece",
".",
"color",
"==",
"'black'",
":",
"self",
".",
"fullmove_number",... | Set next player turn, count moves, log moves, etc. | [
"Set",
"next",
"player",
"turn",
"count",
"moves",
"log",
"moves",
"etc",
"."
] | [
"'''\n Set next player turn, count moves, log moves, etc.\n '''",
"# Pawn has no letter",
"# Pawn resets halfmove_clock",
"# No capturing",
"# Capturing",
"# Capturing resets halfmove_clock"
] | [
{
"param": "self",
"type": null
},
{
"param": "piece",
"type": null
},
{
"param": "dest",
"type": null
},
{
"param": "p1",
"type": null
},
{
"param": "p2",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "piece",
"type": null,
"docstring": null,
"docstring_tokens": ... |
3c346d9b4de17fb5d27193ee5c55df28a1eb38fc | Dhrumilsoni/Chess_Engine | chesslib/board.py | [
"WTFPL"
] | Python | occupied | <not_specific> | def occupied(self, color):
'''
Return a list of coordinates occupied by `color`
'''
result = []
if(color not in ("black", "white")): raise InvalidColor
for coord in self:
if self[coord].color == color:
result.append(coord)
return r... |
Return a list of coordinates occupied by `color`
| Return a list of coordinates occupied by `color` | [
"Return",
"a",
"list",
"of",
"coordinates",
"occupied",
"by",
"`",
"color",
"`"
] | def occupied(self, color):
result = []
if(color not in ("black", "white")): raise InvalidColor
for coord in self:
if self[coord].color == color:
result.append(coord)
return result | [
"def",
"occupied",
"(",
"self",
",",
"color",
")",
":",
"result",
"=",
"[",
"]",
"if",
"(",
"color",
"not",
"in",
"(",
"\"black\"",
",",
"\"white\"",
")",
")",
":",
"raise",
"InvalidColor",
"for",
"coord",
"in",
"self",
":",
"if",
"self",
"[",
"coo... | Return a list of coordinates occupied by `color` | [
"Return",
"a",
"list",
"of",
"coordinates",
"occupied",
"by",
"`",
"color",
"`"
] | [
"'''\n Return a list of coordinates occupied by `color`\n '''"
] | [
{
"param": "self",
"type": null
},
{
"param": "color",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "color",
"type": null,
"docstring": null,
"docstring_tokens": ... |
9b8ed33c31a92c35f0ac07d1b5a8adeb51aa43dd | Dhrumilsoni/Chess_Engine | chesslib/gui_tkinter.py | [
"WTFPL"
] | Python | addpiece | null | def addpiece(self, name, image, row=0, column=0):
# print "addpiece"
'''Add a piece to the playing board'''
self.canvas.create_image(0, 0, image=image, tags=(name, "piece"), anchor="c")
self.placepiece(name, row, column) | Add a piece to the playing board | Add a piece to the playing board | [
"Add",
"a",
"piece",
"to",
"the",
"playing",
"board"
] | def addpiece(self, name, image, row=0, column=0):
self.canvas.create_image(0, 0, image=image, tags=(name, "piece"), anchor="c")
self.placepiece(name, row, column) | [
"def",
"addpiece",
"(",
"self",
",",
"name",
",",
"image",
",",
"row",
"=",
"0",
",",
"column",
"=",
"0",
")",
":",
"self",
".",
"canvas",
".",
"create_image",
"(",
"0",
",",
"0",
",",
"image",
"=",
"image",
",",
"tags",
"=",
"(",
"name",
",",
... | Add a piece to the playing board | [
"Add",
"a",
"piece",
"to",
"the",
"playing",
"board"
] | [
"# print \"addpiece\"",
"'''Add a piece to the playing board'''"
] | [
{
"param": "self",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "image",
"type": null
},
{
"param": "row",
"type": null
},
{
"param": "column",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": null,
"docstring": null,
"docstring_tokens": [... |
5fde0397ac04c1034ad4cc9498ebe9a635fffff5 | tobiascr/chess | game.py | [
"MIT"
] | Python | insufficient_material | <not_specific> | def insufficient_material(self):
"""Return true if and only if the position is king vs king or
king vs king and light piece."""
FEN_fields = self.FEN_string.split(" ")
board = FEN_fields[0]
pieces = ""
for c in board:
if c in "pnbrqkPNBRQK":
pi... | Return true if and only if the position is king vs king or
king vs king and light piece. | Return true if and only if the position is king vs king or
king vs king and light piece. | [
"Return",
"true",
"if",
"and",
"only",
"if",
"the",
"position",
"is",
"king",
"vs",
"king",
"or",
"king",
"vs",
"king",
"and",
"light",
"piece",
"."
] | def insufficient_material(self):
FEN_fields = self.FEN_string.split(" ")
board = FEN_fields[0]
pieces = ""
for c in board:
if c in "pnbrqkPNBRQK":
pieces += c
if len(pieces) > 3:
return False
for c in "prqPRQ":
if c in p... | [
"def",
"insufficient_material",
"(",
"self",
")",
":",
"FEN_fields",
"=",
"self",
".",
"FEN_string",
".",
"split",
"(",
"\" \"",
")",
"board",
"=",
"FEN_fields",
"[",
"0",
"]",
"pieces",
"=",
"\"\"",
"for",
"c",
"in",
"board",
":",
"if",
"c",
"in",
"... | Return true if and only if the position is king vs king or
king vs king and light piece. | [
"Return",
"true",
"if",
"and",
"only",
"if",
"the",
"position",
"is",
"king",
"vs",
"king",
"or",
"king",
"vs",
"king",
"and",
"light",
"piece",
"."
] | [
"\"\"\"Return true if and only if the position is king vs king or\n king vs king and light piece.\"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5fde0397ac04c1034ad4cc9498ebe9a635fffff5 | tobiascr/chess | game.py | [
"MIT"
] | Python | threefold_repetition | <not_specific> | def threefold_repetition(self):
"""Return True if and only if the current position has occured 2 times
earlier. Positions are considered the same if the same player has the move,
pieces of the same kind and color occupy the same squares, and the
possible moves of all the pieces of both p... | Return True if and only if the current position has occured 2 times
earlier. Positions are considered the same if the same player has the move,
pieces of the same kind and color occupy the same squares, and the
possible moves of all the pieces of both players are the same.
This is the ca... | Return True if and only if the current position has occured 2 times
earlier. Positions are considered the same if the same player has the move,
pieces of the same kind and color occupy the same squares, and the
possible moves of all the pieces of both players are the same.
This is the case if the FEN strings of the pos... | [
"Return",
"True",
"if",
"and",
"only",
"if",
"the",
"current",
"position",
"has",
"occured",
"2",
"times",
"earlier",
".",
"Positions",
"are",
"considered",
"the",
"same",
"if",
"the",
"same",
"player",
"has",
"the",
"move",
"pieces",
"of",
"the",
"same",
... | def threefold_repetition(self):
FEN_fields = self.FEN_string.split(" ")
partial_FEN_string = " ".join([FEN_fields[n] for n in range(4)])
repeat = 0
for FEN_string in self.FEN_string_history:
if partial_FEN_string in FEN_string:
repeat += 1
return repea... | [
"def",
"threefold_repetition",
"(",
"self",
")",
":",
"FEN_fields",
"=",
"self",
".",
"FEN_string",
".",
"split",
"(",
"\" \"",
")",
"partial_FEN_string",
"=",
"\" \"",
".",
"join",
"(",
"[",
"FEN_fields",
"[",
"n",
"]",
"for",
"n",
"in",
"range",
"(",
... | Return True if and only if the current position has occured 2 times
earlier. | [
"Return",
"True",
"if",
"and",
"only",
"if",
"the",
"current",
"position",
"has",
"occured",
"2",
"times",
"earlier",
"."
] | [
"\"\"\"Return True if and only if the current position has occured 2 times\n earlier. Positions are considered the same if the same player has the move,\n pieces of the same kind and color occupy the same squares, and the\n possible moves of all the pieces of both players are the same.\n ... | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5fde0397ac04c1034ad4cc9498ebe9a635fffff5 | tobiascr/chess | game.py | [
"MIT"
] | Python | possible_draw_by_50_move_rule | <not_specific> | def possible_draw_by_50_move_rule(self):
"""Return True if and only if 50 moves have been made by each player
without capturing or pushing a pawn."""
FEN_fields = self.FEN_string.split(" ")
if len(FEN_fields) <= 4:
return False
else:
return int(FEN_fields[... | Return True if and only if 50 moves have been made by each player
without capturing or pushing a pawn. | Return True if and only if 50 moves have been made by each player
without capturing or pushing a pawn. | [
"Return",
"True",
"if",
"and",
"only",
"if",
"50",
"moves",
"have",
"been",
"made",
"by",
"each",
"player",
"without",
"capturing",
"or",
"pushing",
"a",
"pawn",
"."
] | def possible_draw_by_50_move_rule(self):
FEN_fields = self.FEN_string.split(" ")
if len(FEN_fields) <= 4:
return False
else:
return int(FEN_fields[4]) >= 100 | [
"def",
"possible_draw_by_50_move_rule",
"(",
"self",
")",
":",
"FEN_fields",
"=",
"self",
".",
"FEN_string",
".",
"split",
"(",
"\" \"",
")",
"if",
"len",
"(",
"FEN_fields",
")",
"<=",
"4",
":",
"return",
"False",
"else",
":",
"return",
"int",
"(",
"FEN_... | Return True if and only if 50 moves have been made by each player
without capturing or pushing a pawn. | [
"Return",
"True",
"if",
"and",
"only",
"if",
"50",
"moves",
"have",
"been",
"made",
"by",
"each",
"player",
"without",
"capturing",
"or",
"pushing",
"a",
"pawn",
"."
] | [
"\"\"\"Return True if and only if 50 moves have been made by each player\n without capturing or pushing a pawn.\"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
5fde0397ac04c1034ad4cc9498ebe9a635fffff5 | tobiascr/chess | game.py | [
"MIT"
] | Python | FEN_string_board_part | <not_specific> | def FEN_string_board_part(self):
"""Use the data in this class to produce the part of a FEN string
that describe the placement of the pieces."""
def convert_to_FEN_row(row):
FEN_row = ""
empty_position_count = 0
for value in row:
if value == No... | Use the data in this class to produce the part of a FEN string
that describe the placement of the pieces. | Use the data in this class to produce the part of a FEN string
that describe the placement of the pieces. | [
"Use",
"the",
"data",
"in",
"this",
"class",
"to",
"produce",
"the",
"part",
"of",
"a",
"FEN",
"string",
"that",
"describe",
"the",
"placement",
"of",
"the",
"pieces",
"."
] | def FEN_string_board_part(self):
def convert_to_FEN_row(row):
FEN_row = ""
empty_position_count = 0
for value in row:
if value == None:
empty_position_count += 1
else:
if empty_position_count > 0:
... | [
"def",
"FEN_string_board_part",
"(",
"self",
")",
":",
"def",
"convert_to_FEN_row",
"(",
"row",
")",
":",
"FEN_row",
"=",
"\"\"",
"empty_position_count",
"=",
"0",
"for",
"value",
"in",
"row",
":",
"if",
"value",
"==",
"None",
":",
"empty_position_count",
"+... | Use the data in this class to produce the part of a FEN string
that describe the placement of the pieces. | [
"Use",
"the",
"data",
"in",
"this",
"class",
"to",
"produce",
"the",
"part",
"of",
"a",
"FEN",
"string",
"that",
"describe",
"the",
"placement",
"of",
"the",
"pieces",
"."
] | [
"\"\"\"Use the data in this class to produce the part of a FEN string\n that describe the placement of the pieces.\"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | computer_move_UCI | <not_specific> | def computer_move_UCI(FEN_string):
"""Return a move that is computed by the engine. The move is returned in the UCI format.
"""
game_state = GameState(FEN_string)
move = computer_move(game_state)
return move.UCI_move_format_string() | Return a move that is computed by the engine. The move is returned in the UCI format.
| Return a move that is computed by the engine. The move is returned in the UCI format. | [
"Return",
"a",
"move",
"that",
"is",
"computed",
"by",
"the",
"engine",
".",
"The",
"move",
"is",
"returned",
"in",
"the",
"UCI",
"format",
"."
] | def computer_move_UCI(FEN_string):
game_state = GameState(FEN_string)
move = computer_move(game_state)
return move.UCI_move_format_string() | [
"def",
"computer_move_UCI",
"(",
"FEN_string",
")",
":",
"game_state",
"=",
"GameState",
"(",
"FEN_string",
")",
"move",
"=",
"computer_move",
"(",
"game_state",
")",
"return",
"move",
".",
"UCI_move_format_string",
"(",
")"
] | Return a move that is computed by the engine. | [
"Return",
"a",
"move",
"that",
"is",
"computed",
"by",
"the",
"engine",
"."
] | [
"\"\"\"Return a move that is computed by the engine. The move is returned in the UCI format.\n \"\"\""
] | [
{
"param": "FEN_string",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "FEN_string",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | UCI_move_format_string | <not_specific> | def UCI_move_format_string(self):
"""Return the move in the UCI move format. For example like:
"e2e4", "e7e5", "e1g1" (white short castling), "e7e8q" (for promotion),
"c5b6" (en passant).
"""
if len(self.change_list) == 2:
# The position where the move starts is not e... | Return the move in the UCI move format. For example like:
"e2e4", "e7e5", "e1g1" (white short castling), "e7e8q" (for promotion),
"c5b6" (en passant).
| Return the move in the UCI move format. | [
"Return",
"the",
"move",
"in",
"the",
"UCI",
"move",
"format",
"."
] | def UCI_move_format_string(self):
if len(self.change_list) == 2:
if self.change_list[0][1] != None:
from_triple = self.change_list[0]
to_triple = self.change_list[1]
else:
from_triple = self.change_list[1]
to_triple = self.c... | [
"def",
"UCI_move_format_string",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"change_list",
")",
"==",
"2",
":",
"if",
"self",
".",
"change_list",
"[",
"0",
"]",
"[",
"1",
"]",
"!=",
"None",
":",
"from_triple",
"=",
"self",
".",
"change_lis... | Return the move in the UCI move format. | [
"Return",
"the",
"move",
"in",
"the",
"UCI",
"move",
"format",
"."
] | [
"\"\"\"Return the move in the UCI move format. For example like:\n \"e2e4\", \"e7e5\", \"e1g1\" (white short castling), \"e7e8q\" (for promotion),\n \"c5b6\" (en passant).\n \"\"\"",
"# The position where the move starts is not empty before the change.",
"# If promotion.",
"# En passants.... | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | possible_moves | <not_specific> | def possible_moves(self, game_state, from_position):
"""Return all moves except from castlings that this king can make if it's
located at from_position, including putting itself into check and capturing the
opponents king.
"""
capture_move_list = []
non_capture_move_list ... | Return all moves except from castlings that this king can make if it's
located at from_position, including putting itself into check and capturing the
opponents king.
| Return all moves except from castlings that this king can make if it's
located at from_position, including putting itself into check and capturing the
opponents king. | [
"Return",
"all",
"moves",
"except",
"from",
"castlings",
"that",
"this",
"king",
"can",
"make",
"if",
"it",
"'",
"s",
"located",
"at",
"from_position",
"including",
"putting",
"itself",
"into",
"check",
"and",
"capturing",
"the",
"opponents",
"king",
"."
] | def possible_moves(self, game_state, from_position):
capture_move_list = []
non_capture_move_list = []
for to_position in self.possible_moves_dict[from_position]:
piece = game_state.board[to_position]
if piece:
if piece.white != self.white:
... | [
"def",
"possible_moves",
"(",
"self",
",",
"game_state",
",",
"from_position",
")",
":",
"capture_move_list",
"=",
"[",
"]",
"non_capture_move_list",
"=",
"[",
"]",
"for",
"to_position",
"in",
"self",
".",
"possible_moves_dict",
"[",
"from_position",
"]",
":",
... | Return all moves except from castlings that this king can make if it's
located at from_position, including putting itself into check and capturing the
opponents king. | [
"Return",
"all",
"moves",
"except",
"from",
"castlings",
"that",
"this",
"king",
"can",
"make",
"if",
"it",
"'",
"s",
"located",
"at",
"from_position",
"including",
"putting",
"itself",
"into",
"check",
"and",
"capturing",
"the",
"opponents",
"king",
"."
] | [
"\"\"\"Return all moves except from castlings that this king can make if it's\n located at from_position, including putting itself into check and capturing the\n opponents king.\n \"\"\"",
"# If there is an opposite color piece on the target square.",
"# If the is no piece on the target squ... | [
{
"param": "self",
"type": null
},
{
"param": "game_state",
"type": null
},
{
"param": "from_position",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "game_state",
"type": null,
"docstring": null,
"docstring_toke... |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | possible_moves | <not_specific> | def possible_moves(self, game_state, from_position):
"""Return all moves that this piece can make if it's located at from_position."""
return (Rook.possible_moves(self, game_state, from_position)[0] +
Bishop.possible_moves(self, game_state, from_position)[0],
Rook.possibl... | Return all moves that this piece can make if it's located at from_position. | Return all moves that this piece can make if it's located at from_position. | [
"Return",
"all",
"moves",
"that",
"this",
"piece",
"can",
"make",
"if",
"it",
"'",
"s",
"located",
"at",
"from_position",
"."
] | def possible_moves(self, game_state, from_position):
return (Rook.possible_moves(self, game_state, from_position)[0] +
Bishop.possible_moves(self, game_state, from_position)[0],
Rook.possible_moves(self, game_state, from_position)[1] +
Bishop.possible_moves(self, ... | [
"def",
"possible_moves",
"(",
"self",
",",
"game_state",
",",
"from_position",
")",
":",
"return",
"(",
"Rook",
".",
"possible_moves",
"(",
"self",
",",
"game_state",
",",
"from_position",
")",
"[",
"0",
"]",
"+",
"Bishop",
".",
"possible_moves",
"(",
"sel... | Return all moves that this piece can make if it's located at from_position. | [
"Return",
"all",
"moves",
"that",
"this",
"piece",
"can",
"make",
"if",
"it",
"'",
"s",
"located",
"at",
"from_position",
"."
] | [
"\"\"\"Return all moves that this piece can make if it's located at from_position.\"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "game_state",
"type": null
},
{
"param": "from_position",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "game_state",
"type": null,
"docstring": null,
"docstring_toke... |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | possible_moves | <not_specific> | def possible_moves(self, game_state, from_position):
"""Return all moves except for castlings that this piece can make if it's
located at from_position."""
capture_move_list = []
non_capture_move_list = []
# Moves up.
for to_position in range(from_position + 8, 64, 8):
... | Return all moves except for castlings that this piece can make if it's
located at from_position. | Return all moves except for castlings that this piece can make if it's
located at from_position. | [
"Return",
"all",
"moves",
"except",
"for",
"castlings",
"that",
"this",
"piece",
"can",
"make",
"if",
"it",
"'",
"s",
"located",
"at",
"from_position",
"."
] | def possible_moves(self, game_state, from_position):
capture_move_list = []
non_capture_move_list = []
for to_position in range(from_position + 8, 64, 8):
piece = game_state.board[to_position]
if piece:
if piece.white != self.white:
mov... | [
"def",
"possible_moves",
"(",
"self",
",",
"game_state",
",",
"from_position",
")",
":",
"capture_move_list",
"=",
"[",
"]",
"non_capture_move_list",
"=",
"[",
"]",
"for",
"to_position",
"in",
"range",
"(",
"from_position",
"+",
"8",
",",
"64",
",",
"8",
"... | Return all moves except for castlings that this piece can make if it's
located at from_position. | [
"Return",
"all",
"moves",
"except",
"for",
"castlings",
"that",
"this",
"piece",
"can",
"make",
"if",
"it",
"'",
"s",
"located",
"at",
"from_position",
"."
] | [
"\"\"\"Return all moves except for castlings that this piece can make if it's\n located at from_position.\"\"\"",
"# Moves up.",
"# If capture.",
"# Moves down.",
"# If capture.",
"# Moves right.",
"# If capture.",
"# Moves left.",
"# If capture."
] | [
{
"param": "self",
"type": null
},
{
"param": "game_state",
"type": null
},
{
"param": "from_position",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "game_state",
"type": null,
"docstring": null,
"docstring_toke... |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | possible_moves | <not_specific> | def possible_moves(self, game_state, from_position):
"""Return all moves this piece can make if it's located at from_position"""
# Row and column for the position.
[from_r, from_c] = [from_position // 8, from_position % 8]
capture_move_list = []
non_capture_move_list = []
... | Return all moves this piece can make if it's located at from_position | Return all moves this piece can make if it's located at from_position | [
"Return",
"all",
"moves",
"this",
"piece",
"can",
"make",
"if",
"it",
"'",
"s",
"located",
"at",
"from_position"
] | def possible_moves(self, game_state, from_position):
[from_r, from_c] = [from_position // 8, from_position % 8]
capture_move_list = []
non_capture_move_list = []
r = from_r + 1
c = from_c + 1
while r < 8 and c < 8:
to_position = r * 8 + c
piece = g... | [
"def",
"possible_moves",
"(",
"self",
",",
"game_state",
",",
"from_position",
")",
":",
"[",
"from_r",
",",
"from_c",
"]",
"=",
"[",
"from_position",
"//",
"8",
",",
"from_position",
"%",
"8",
"]",
"capture_move_list",
"=",
"[",
"]",
"non_capture_move_list"... | Return all moves this piece can make if it's located at from_position | [
"Return",
"all",
"moves",
"this",
"piece",
"can",
"make",
"if",
"it",
"'",
"s",
"located",
"at",
"from_position"
] | [
"\"\"\"Return all moves this piece can make if it's located at from_position\"\"\"",
"# Row and column for the position.",
"# Moves up right.",
"# If capture.",
"# Moves up left.",
"# If capture.",
"# Moves down right.",
"# If capture.",
"# Moves down left.",
"# If capture."
] | [
{
"param": "self",
"type": null
},
{
"param": "game_state",
"type": null
},
{
"param": "from_position",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "game_state",
"type": null,
"docstring": null,
"docstring_toke... |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | pseudo_legal_moves_no_castlings | <not_specific> | def pseudo_legal_moves_no_castlings(self):
"""Return a list of Move-objects corresponding to all possible pseudo-legal moves
in this position, except for castlings and promotion to other pieces than
queens. The moves are sorted in such a way that the capture moves are preceding
the non c... | Return a list of Move-objects corresponding to all possible pseudo-legal moves
in this position, except for castlings and promotion to other pieces than
queens. The moves are sorted in such a way that the capture moves are preceding
the non capture moves. | Return a list of Move-objects corresponding to all possible pseudo-legal moves
in this position, except for castlings and promotion to other pieces than
queens. The moves are sorted in such a way that the capture moves are preceding
the non capture moves. | [
"Return",
"a",
"list",
"of",
"Move",
"-",
"objects",
"corresponding",
"to",
"all",
"possible",
"pseudo",
"-",
"legal",
"moves",
"in",
"this",
"position",
"except",
"for",
"castlings",
"and",
"promotion",
"to",
"other",
"pieces",
"than",
"queens",
".",
"The",... | def pseudo_legal_moves_no_castlings(self):
capture_move_list = []
non_capture_move_list = []
for position in range(64):
piece = self.board[position]
if piece:
if piece.white == self.white_to_play:
(c_move_list, non_c_move_list) = piece.... | [
"def",
"pseudo_legal_moves_no_castlings",
"(",
"self",
")",
":",
"capture_move_list",
"=",
"[",
"]",
"non_capture_move_list",
"=",
"[",
"]",
"for",
"position",
"in",
"range",
"(",
"64",
")",
":",
"piece",
"=",
"self",
".",
"board",
"[",
"position",
"]",
"i... | Return a list of Move-objects corresponding to all possible pseudo-legal moves
in this position, except for castlings and promotion to other pieces than
queens. | [
"Return",
"a",
"list",
"of",
"Move",
"-",
"objects",
"corresponding",
"to",
"all",
"possible",
"pseudo",
"-",
"legal",
"moves",
"in",
"this",
"position",
"except",
"for",
"castlings",
"and",
"promotion",
"to",
"other",
"pieces",
"than",
"queens",
"."
] | [
"\"\"\"Return a list of Move-objects corresponding to all possible pseudo-legal moves\n in this position, except for castlings and promotion to other pieces than\n queens. The moves are sorted in such a way that the capture moves are preceding\n the non capture moves.\"\"\"",
"# If there is a... | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | legal_moves_no_castlings | <not_specific> | def legal_moves_no_castlings(self):
"""Return a list of Move-objects corresponding to all possible legal moves
in this position, except for castlings and promotion to other pieces than
queens."""
move_list = []
moves = self.pseudo_legal_moves_no_castlings()
for move in mo... | Return a list of Move-objects corresponding to all possible legal moves
in this position, except for castlings and promotion to other pieces than
queens. | Return a list of Move-objects corresponding to all possible legal moves
in this position, except for castlings and promotion to other pieces than
queens. | [
"Return",
"a",
"list",
"of",
"Move",
"-",
"objects",
"corresponding",
"to",
"all",
"possible",
"legal",
"moves",
"in",
"this",
"position",
"except",
"for",
"castlings",
"and",
"promotion",
"to",
"other",
"pieces",
"than",
"queens",
"."
] | def legal_moves_no_castlings(self):
move_list = []
moves = self.pseudo_legal_moves_no_castlings()
for move in moves:
self.make_move(move)
if abs(minimax(self, 1)) < 500:
move_list.append(move)
self.undo_move(move)
return move_list | [
"def",
"legal_moves_no_castlings",
"(",
"self",
")",
":",
"move_list",
"=",
"[",
"]",
"moves",
"=",
"self",
".",
"pseudo_legal_moves_no_castlings",
"(",
")",
"for",
"move",
"in",
"moves",
":",
"self",
".",
"make_move",
"(",
"move",
")",
"if",
"abs",
"(",
... | Return a list of Move-objects corresponding to all possible legal moves
in this position, except for castlings and promotion to other pieces than
queens. | [
"Return",
"a",
"list",
"of",
"Move",
"-",
"objects",
"corresponding",
"to",
"all",
"possible",
"legal",
"moves",
"in",
"this",
"position",
"except",
"for",
"castlings",
"and",
"promotion",
"to",
"other",
"pieces",
"than",
"queens",
"."
] | [
"\"\"\"Return a list of Move-objects corresponding to all possible legal moves\n in this position, except for castlings and promotion to other pieces than\n queens.\"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | castlings | <not_specific> | def castlings(self):
"""Return a list of Move-objects corresponding to all possible castlings
in this position. It is assumed that no moves have been made to the game state
for while using this method."""
move_list = []
if self.castling_kingside_possible():
if self.wh... | Return a list of Move-objects corresponding to all possible castlings
in this position. It is assumed that no moves have been made to the game state
for while using this method. | Return a list of Move-objects corresponding to all possible castlings
in this position. It is assumed that no moves have been made to the game state
for while using this method. | [
"Return",
"a",
"list",
"of",
"Move",
"-",
"objects",
"corresponding",
"to",
"all",
"possible",
"castlings",
"in",
"this",
"position",
".",
"It",
"is",
"assumed",
"that",
"no",
"moves",
"have",
"been",
"made",
"to",
"the",
"game",
"state",
"for",
"while",
... | def castlings(self):
move_list = []
if self.castling_kingside_possible():
if self.white_to_play:
king = self.board[4]
rook = self.board[7]
move = Move()
move.add_change(4, king, None)
move.add_change(5, None, roo... | [
"def",
"castlings",
"(",
"self",
")",
":",
"move_list",
"=",
"[",
"]",
"if",
"self",
".",
"castling_kingside_possible",
"(",
")",
":",
"if",
"self",
".",
"white_to_play",
":",
"king",
"=",
"self",
".",
"board",
"[",
"4",
"]",
"rook",
"=",
"self",
"."... | Return a list of Move-objects corresponding to all possible castlings
in this position. | [
"Return",
"a",
"list",
"of",
"Move",
"-",
"objects",
"corresponding",
"to",
"all",
"possible",
"castlings",
"in",
"this",
"position",
"."
] | [
"\"\"\"Return a list of Move-objects corresponding to all possible castlings\n in this position. It is assumed that no moves have been made to the game state\n for while using this method.\"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | make_move | null | def make_move(self, move):
"""Make a change to the game_state described by the Move instance move.
The value of the game state is also updated.
"""
for triple in move.change_list:
self.board[triple[0]] = triple[2]
if triple[1]:
self.value -= triple... | Make a change to the game_state described by the Move instance move.
The value of the game state is also updated.
| Make a change to the game_state described by the Move instance move.
The value of the game state is also updated. | [
"Make",
"a",
"change",
"to",
"the",
"game_state",
"described",
"by",
"the",
"Move",
"instance",
"move",
".",
"The",
"value",
"of",
"the",
"game",
"state",
"is",
"also",
"updated",
"."
] | def make_move(self, move):
for triple in move.change_list:
self.board[triple[0]] = triple[2]
if triple[1]:
self.value -= triple[1].value
if triple[2]:
self.value += triple[2].value
self.en_passant_target_square_history.append(self.en_pa... | [
"def",
"make_move",
"(",
"self",
",",
"move",
")",
":",
"for",
"triple",
"in",
"move",
".",
"change_list",
":",
"self",
".",
"board",
"[",
"triple",
"[",
"0",
"]",
"]",
"=",
"triple",
"[",
"2",
"]",
"if",
"triple",
"[",
"1",
"]",
":",
"self",
"... | Make a change to the game_state described by the Move instance move. | [
"Make",
"a",
"change",
"to",
"the",
"game_state",
"described",
"by",
"the",
"Move",
"instance",
"move",
"."
] | [
"\"\"\"Make a change to the game_state described by the Move instance move.\n The value of the game state is also updated.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "move",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "move",
"type": null,
"docstring": null,
"docstring_tokens": [... |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | undo_move | null | def undo_move(self, move):
"""Make a change to the game_state that undo the move described by the
Move instance move. The value of the game state is also updated.
"""
for triple in move.change_list:
self.board[triple[0]] = triple[1]
if triple[1]:
s... | Make a change to the game_state that undo the move described by the
Move instance move. The value of the game state is also updated.
| Make a change to the game_state that undo the move described by the
Move instance move. The value of the game state is also updated. | [
"Make",
"a",
"change",
"to",
"the",
"game_state",
"that",
"undo",
"the",
"move",
"described",
"by",
"the",
"Move",
"instance",
"move",
".",
"The",
"value",
"of",
"the",
"game",
"state",
"is",
"also",
"updated",
"."
] | def undo_move(self, move):
for triple in move.change_list:
self.board[triple[0]] = triple[1]
if triple[1]:
self.value += triple[1].value
if triple[2]:
self.value -= triple[2].value
self.en_passant_target_square = self.en_passant_target_... | [
"def",
"undo_move",
"(",
"self",
",",
"move",
")",
":",
"for",
"triple",
"in",
"move",
".",
"change_list",
":",
"self",
".",
"board",
"[",
"triple",
"[",
"0",
"]",
"]",
"=",
"triple",
"[",
"1",
"]",
"if",
"triple",
"[",
"1",
"]",
":",
"self",
"... | Make a change to the game_state that undo the move described by the
Move instance move. | [
"Make",
"a",
"change",
"to",
"the",
"game_state",
"that",
"undo",
"the",
"move",
"described",
"by",
"the",
"Move",
"instance",
"move",
"."
] | [
"\"\"\"Make a change to the game_state that undo the move described by the\n Move instance move. The value of the game state is also updated.\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "move",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "move",
"type": null,
"docstring": null,
"docstring_tokens": [... |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | check | <not_specific> | def check(self):
"""Return True if the king of the player in turn is in check and
False if not.
"""
nullmove = Move()
self.make_move(nullmove)
result = abs(minimax(self, 1)) > 500
self.undo_move(nullmove)
return result | Return True if the king of the player in turn is in check and
False if not.
| Return True if the king of the player in turn is in check and
False if not. | [
"Return",
"True",
"if",
"the",
"king",
"of",
"the",
"player",
"in",
"turn",
"is",
"in",
"check",
"and",
"False",
"if",
"not",
"."
] | def check(self):
nullmove = Move()
self.make_move(nullmove)
result = abs(minimax(self, 1)) > 500
self.undo_move(nullmove)
return result | [
"def",
"check",
"(",
"self",
")",
":",
"nullmove",
"=",
"Move",
"(",
")",
"self",
".",
"make_move",
"(",
"nullmove",
")",
"result",
"=",
"abs",
"(",
"minimax",
"(",
"self",
",",
"1",
")",
")",
">",
"500",
"self",
".",
"undo_move",
"(",
"nullmove",
... | Return True if the king of the player in turn is in check and
False if not. | [
"Return",
"True",
"if",
"the",
"king",
"of",
"the",
"player",
"in",
"turn",
"is",
"in",
"check",
"and",
"False",
"if",
"not",
"."
] | [
"\"\"\"Return True if the king of the player in turn is in check and\n False if not.\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | castling_kingside_possible | <not_specific> | def castling_kingside_possible(self):
"""Return True if the player in turn can make kingside castling
and False if not. This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then.
"""
if self.chec... | Return True if the player in turn can make kingside castling
and False if not. This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then.
| Return True if the player in turn can make kingside castling
and False if not. This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then. | [
"Return",
"True",
"if",
"the",
"player",
"in",
"turn",
"can",
"make",
"kingside",
"castling",
"and",
"False",
"if",
"not",
".",
"This",
"function",
"is",
"assumed",
"to",
"only",
"be",
"used",
"if",
"no",
"moves",
"have",
"been",
"made",
"to",
"the",
"... | def castling_kingside_possible(self):
if self.check():
return False
if self.white_to_play:
if "K" in self.castling_possibilities:
if self.board[5] == self.board[6] == None:
king = self.board[4]
move = Move()
... | [
"def",
"castling_kingside_possible",
"(",
"self",
")",
":",
"if",
"self",
".",
"check",
"(",
")",
":",
"return",
"False",
"if",
"self",
".",
"white_to_play",
":",
"if",
"\"K\"",
"in",
"self",
".",
"castling_possibilities",
":",
"if",
"self",
".",
"board",
... | Return True if the player in turn can make kingside castling
and False if not. | [
"Return",
"True",
"if",
"the",
"player",
"in",
"turn",
"can",
"make",
"kingside",
"castling",
"and",
"False",
"if",
"not",
"."
] | [
"\"\"\"Return True if the player in turn can make kingside castling\n and False if not. This function is assumed to only be used if no moves\n have been made to the game_state object, since castling rights may not\n valid then.\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | castling_queenside_possible | <not_specific> | def castling_queenside_possible(self):
"""Return True if the player in turn can make queenside castling
and False if not. This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then."""
if self.check():
... | Return True if the player in turn can make queenside castling
and False if not. This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then. | Return True if the player in turn can make queenside castling
and False if not. This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then. | [
"Return",
"True",
"if",
"the",
"player",
"in",
"turn",
"can",
"make",
"queenside",
"castling",
"and",
"False",
"if",
"not",
".",
"This",
"function",
"is",
"assumed",
"to",
"only",
"be",
"used",
"if",
"no",
"moves",
"have",
"been",
"made",
"to",
"the",
... | def castling_queenside_possible(self):
if self.check():
return False
if self.white_to_play:
if "Q" in self.castling_possibilities:
if self.board[1] == self.board[2] == self.board[3] == None:
king = self.board[4]
move = Move(... | [
"def",
"castling_queenside_possible",
"(",
"self",
")",
":",
"if",
"self",
".",
"check",
"(",
")",
":",
"return",
"False",
"if",
"self",
".",
"white_to_play",
":",
"if",
"\"Q\"",
"in",
"self",
".",
"castling_possibilities",
":",
"if",
"self",
".",
"board",... | Return True if the player in turn can make queenside castling
and False if not. | [
"Return",
"True",
"if",
"the",
"player",
"in",
"turn",
"can",
"make",
"queenside",
"castling",
"and",
"False",
"if",
"not",
"."
] | [
"\"\"\"Return True if the player in turn can make queenside castling\n and False if not. This function is assumed to only be used if no moves\n have been made to the game_state object, since castling rights may not\n valid then.\"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | minimax | <not_specific> | def minimax(game_state, depth):
"""This function uses the minimax algorithm to analyze a game state.
White is the maximizing player and black the minimizing.
"""
# If max depth is reached or if king is captured.
if depth == 0 or abs(game_state.value) > 500:
return game_state.value
# Tes... | This function uses the minimax algorithm to analyze a game state.
White is the maximizing player and black the minimizing.
| This function uses the minimax algorithm to analyze a game state.
White is the maximizing player and black the minimizing. | [
"This",
"function",
"uses",
"the",
"minimax",
"algorithm",
"to",
"analyze",
"a",
"game",
"state",
".",
"White",
"is",
"the",
"maximizing",
"player",
"and",
"black",
"the",
"minimizing",
"."
] | def minimax(game_state, depth):
if depth == 0 or abs(game_state.value) > 500:
return game_state.value
moves = game_state.pseudo_legal_moves_no_castlings()
value_list = []
if moves == []:
return 0
for move in moves:
game_state.make_move(move)
value_list.append(minimax(... | [
"def",
"minimax",
"(",
"game_state",
",",
"depth",
")",
":",
"if",
"depth",
"==",
"0",
"or",
"abs",
"(",
"game_state",
".",
"value",
")",
">",
"500",
":",
"return",
"game_state",
".",
"value",
"moves",
"=",
"game_state",
".",
"pseudo_legal_moves_no_castlin... | This function uses the minimax algorithm to analyze a game state. | [
"This",
"function",
"uses",
"the",
"minimax",
"algorithm",
"to",
"analyze",
"a",
"game",
"state",
"."
] | [
"\"\"\"This function uses the minimax algorithm to analyze a game state.\n White is the maximizing player and black the minimizing.\n \"\"\"",
"# If max depth is reached or if king is captured.",
"# Test child nodes.",
"# If no moves were found.",
"# If maximizing player.",
"# If minimizing player."... | [
{
"param": "game_state",
"type": null
},
{
"param": "depth",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "game_state",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "depth",
"type": null,
"docstring": null,
"docstring_tok... |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | negamax | <not_specific> | def negamax(game_state, depth, alpha, beta):
"""Compute a value of game_state. The value is seen from the perspective of the
player in turn. A favorable position for that player is given a positive value.
"""
#global node_counter
#node_counter += 1
# If max depth is reached or if king is captu... | Compute a value of game_state. The value is seen from the perspective of the
player in turn. A favorable position for that player is given a positive value.
| Compute a value of game_state. The value is seen from the perspective of the
player in turn. A favorable position for that player is given a positive value. | [
"Compute",
"a",
"value",
"of",
"game_state",
".",
"The",
"value",
"is",
"seen",
"from",
"the",
"perspective",
"of",
"the",
"player",
"in",
"turn",
".",
"A",
"favorable",
"position",
"for",
"that",
"player",
"is",
"given",
"a",
"positive",
"value",
"."
] | def negamax(game_state, depth, alpha, beta):
if depth == 0 or abs(game_state.value) > 500:
if game_state.white_to_play:
return game_state.value
else:
return -game_state.value
moves = game_state.pseudo_legal_moves_no_castlings()
value_list = []
if moves == []:
... | [
"def",
"negamax",
"(",
"game_state",
",",
"depth",
",",
"alpha",
",",
"beta",
")",
":",
"if",
"depth",
"==",
"0",
"or",
"abs",
"(",
"game_state",
".",
"value",
")",
">",
"500",
":",
"if",
"game_state",
".",
"white_to_play",
":",
"return",
"game_state",... | Compute a value of game_state. | [
"Compute",
"a",
"value",
"of",
"game_state",
"."
] | [
"\"\"\"Compute a value of game_state. The value is seen from the perspective of the\n player in turn. A favorable position for that player is given a positive value.\n \"\"\"",
"#global node_counter",
"#node_counter += 1",
"# If max depth is reached or if king is captured.",
"# Test child nodes.",
"... | [
{
"param": "game_state",
"type": null
},
{
"param": "depth",
"type": null
},
{
"param": "alpha",
"type": null
},
{
"param": "beta",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "game_state",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "depth",
"type": null,
"docstring": null,
"docstring_tok... |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | convert_position_to_engine_format | <not_specific> | def convert_position_to_engine_format(position):
"""Convert conventional position format to engine format.
position can be for example "a1". For example "a1" is converted to 0.
"""
return "abcdefgh".find(position[0]) + (int(position[1]) - 1) * 8 | Convert conventional position format to engine format.
position can be for example "a1". For example "a1" is converted to 0.
| Convert conventional position format to engine format.
position can be for example "a1". For example "a1" is converted to 0. | [
"Convert",
"conventional",
"position",
"format",
"to",
"engine",
"format",
".",
"position",
"can",
"be",
"for",
"example",
"\"",
"a1",
"\"",
".",
"For",
"example",
"\"",
"a1",
"\"",
"is",
"converted",
"to",
"0",
"."
] | def convert_position_to_engine_format(position):
return "abcdefgh".find(position[0]) + (int(position[1]) - 1) * 8 | [
"def",
"convert_position_to_engine_format",
"(",
"position",
")",
":",
"return",
"\"abcdefgh\"",
".",
"find",
"(",
"position",
"[",
"0",
"]",
")",
"+",
"(",
"int",
"(",
"position",
"[",
"1",
"]",
")",
"-",
"1",
")",
"*",
"8"
] | Convert conventional position format to engine format. | [
"Convert",
"conventional",
"position",
"format",
"to",
"engine",
"format",
"."
] | [
"\"\"\"Convert conventional position format to engine format.\n position can be for example \"a1\". For example \"a1\" is converted to 0.\n \"\"\""
] | [
{
"param": "position",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "position",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | convert_position_to_conventional_format | <not_specific> | def convert_position_to_conventional_format(position):
"""Convert engine position format to conventional format.
position can be an integer from 0 to 63. For example 0 is converted to "a1".
"""
[r, c] = [position // 8 + 1, position % 8]
return "abcdefgh"[c] + str(r) | Convert engine position format to conventional format.
position can be an integer from 0 to 63. For example 0 is converted to "a1".
| Convert engine position format to conventional format.
position can be an integer from 0 to 63. For example 0 is converted to "a1". | [
"Convert",
"engine",
"position",
"format",
"to",
"conventional",
"format",
".",
"position",
"can",
"be",
"an",
"integer",
"from",
"0",
"to",
"63",
".",
"For",
"example",
"0",
"is",
"converted",
"to",
"\"",
"a1",
"\"",
"."
] | def convert_position_to_conventional_format(position):
[r, c] = [position // 8 + 1, position % 8]
return "abcdefgh"[c] + str(r) | [
"def",
"convert_position_to_conventional_format",
"(",
"position",
")",
":",
"[",
"r",
",",
"c",
"]",
"=",
"[",
"position",
"//",
"8",
"+",
"1",
",",
"position",
"%",
"8",
"]",
"return",
"\"abcdefgh\"",
"[",
"c",
"]",
"+",
"str",
"(",
"r",
")"
] | Convert engine position format to conventional format. | [
"Convert",
"engine",
"position",
"format",
"to",
"conventional",
"format",
"."
] | [
"\"\"\"Convert engine position format to conventional format.\n position can be an integer from 0 to 63. For example 0 is converted to \"a1\".\n \"\"\""
] | [
{
"param": "position",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "position",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6076811a884e2b208b811424dd7adf513aa3fa83 | tobiascr/chess | engine.py | [
"MIT"
] | Python | computer_move | <not_specific> | def computer_move(game_state):
"""Return a move that is computed with the minimax algorithm.
This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then."""
global node_counter
node_counter = 0
moves = game_state.le... | Return a move that is computed with the minimax algorithm.
This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then. | Return a move that is computed with the minimax algorithm.
This function is assumed to only be used if no moves
have been made to the game_state object, since castling rights may not
valid then. | [
"Return",
"a",
"move",
"that",
"is",
"computed",
"with",
"the",
"minimax",
"algorithm",
".",
"This",
"function",
"is",
"assumed",
"to",
"only",
"be",
"used",
"if",
"no",
"moves",
"have",
"been",
"made",
"to",
"the",
"game_state",
"object",
"since",
"castli... | def computer_move(game_state):
global node_counter
node_counter = 0
moves = game_state.legal_moves_no_castlings() + game_state.castlings()
number_of_pieces = 0
for s in range(64):
if game_state.board[s] != None:
number_of_pieces += 1
if number_of_pieces > 15:
depth = ... | [
"def",
"computer_move",
"(",
"game_state",
")",
":",
"global",
"node_counter",
"node_counter",
"=",
"0",
"moves",
"=",
"game_state",
".",
"legal_moves_no_castlings",
"(",
")",
"+",
"game_state",
".",
"castlings",
"(",
")",
"number_of_pieces",
"=",
"0",
"for",
... | Return a move that is computed with the minimax algorithm. | [
"Return",
"a",
"move",
"that",
"is",
"computed",
"with",
"the",
"minimax",
"algorithm",
"."
] | [
"\"\"\"Return a move that is computed with the minimax algorithm.\n This function is assumed to only be used if no moves\n have been made to the game_state object, since castling rights may not\n valid then.\"\"\"",
"# The move order is randomized in order to make opening move",
"# selection more natur... | [
{
"param": "game_state",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "game_state",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
df422f66e0e4fdc8145032278935ef89104f9c20 | moisesejimenezg/traffic_sign_classifier | src/layers.py | [
"MIT"
] | Python | linear_network | <not_specific> | def linear_network(x_in: int, in_dim: int, out_dim: int, mu_in=mu, sigma_in=sigma):
"""
Create a linear network layer with the input parameters provided.
"""
W = tf.Variable(
tf.truncated_normal(shape=(in_dim, out_dim), mean=mu_in, stddev=sigma_in)
)
B = tf.Variable(tf.zeros(shape=(1, ou... |
Create a linear network layer with the input parameters provided.
| Create a linear network layer with the input parameters provided. | [
"Create",
"a",
"linear",
"network",
"layer",
"with",
"the",
"input",
"parameters",
"provided",
"."
] | def linear_network(x_in: int, in_dim: int, out_dim: int, mu_in=mu, sigma_in=sigma):
W = tf.Variable(
tf.truncated_normal(shape=(in_dim, out_dim), mean=mu_in, stddev=sigma_in)
)
B = tf.Variable(tf.zeros(shape=(1, out_dim)))
y_out = tf.matmul(x_in, W) + B
return y_out | [
"def",
"linear_network",
"(",
"x_in",
":",
"int",
",",
"in_dim",
":",
"int",
",",
"out_dim",
":",
"int",
",",
"mu_in",
"=",
"mu",
",",
"sigma_in",
"=",
"sigma",
")",
":",
"W",
"=",
"tf",
".",
"Variable",
"(",
"tf",
".",
"truncated_normal",
"(",
"sh... | Create a linear network layer with the input parameters provided. | [
"Create",
"a",
"linear",
"network",
"layer",
"with",
"the",
"input",
"parameters",
"provided",
"."
] | [
"\"\"\"\n Create a linear network layer with the input parameters provided.\n \"\"\""
] | [
{
"param": "x_in",
"type": "int"
},
{
"param": "in_dim",
"type": "int"
},
{
"param": "out_dim",
"type": "int"
},
{
"param": "mu_in",
"type": null
},
{
"param": "sigma_in",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_in",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "in_dim",
"type": "int",
"docstring": null,
"docstring_tokens... |
df422f66e0e4fdc8145032278935ef89104f9c20 | moisesejimenezg/traffic_sign_classifier | src/layers.py | [
"MIT"
] | Python | convolutional_network | <not_specific> | def convolutional_network(
x_in: int, in_h_w: int, in_depth: int, filter_h_w: int, out_depth: int
):
"""
Create a convolutional network layer with the input parameters provided.
"""
out_h_w = (in_h_w - filter_h_w) + 1 # no padding, stride = 1
W = tf.Variable(
tf.truncated_normal(
... |
Create a convolutional network layer with the input parameters provided.
| Create a convolutional network layer with the input parameters provided. | [
"Create",
"a",
"convolutional",
"network",
"layer",
"with",
"the",
"input",
"parameters",
"provided",
"."
] | def convolutional_network(
x_in: int, in_h_w: int, in_depth: int, filter_h_w: int, out_depth: int
):
out_h_w = (in_h_w - filter_h_w) + 1
W = tf.Variable(
tf.truncated_normal(
shape=(filter_h_w, filter_h_w, in_depth, out_depth), mean=mu, stddev=sigma
)
)
B = tf.Variable(... | [
"def",
"convolutional_network",
"(",
"x_in",
":",
"int",
",",
"in_h_w",
":",
"int",
",",
"in_depth",
":",
"int",
",",
"filter_h_w",
":",
"int",
",",
"out_depth",
":",
"int",
")",
":",
"out_h_w",
"=",
"(",
"in_h_w",
"-",
"filter_h_w",
")",
"+",
"1",
"... | Create a convolutional network layer with the input parameters provided. | [
"Create",
"a",
"convolutional",
"network",
"layer",
"with",
"the",
"input",
"parameters",
"provided",
"."
] | [
"\"\"\"\n Create a convolutional network layer with the input parameters provided.\n \"\"\"",
"# no padding, stride = 1"
] | [
{
"param": "x_in",
"type": "int"
},
{
"param": "in_h_w",
"type": "int"
},
{
"param": "in_depth",
"type": "int"
},
{
"param": "filter_h_w",
"type": "int"
},
{
"param": "out_depth",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x_in",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "in_h_w",
"type": "int",
"docstring": null,
"docstring_tokens... |
20856dac91c1b9c08935540b13ec4b6b4437e837 | moisesejimenezg/traffic_sign_classifier | src/lenet.py | [
"MIT"
] | Python | network | <not_specific> | def network(
x: tf.placeholder,
grayscale: bool,
normalize: bool,
low_keep_prob: float,
high_keep_prob: float,
):
"""
Multilayer network to classify traffic sign images.
@param x: input images
@param grayscale: whether the images should be converted to grayscale
@param normalize:... |
Multilayer network to classify traffic sign images.
@param x: input images
@param grayscale: whether the images should be converted to grayscale
@param normalize: whether the converted images should be normalized
@param low_keep_prob: a lower probability of keeping values for the dropout regulariza... | Multilayer network to classify traffic sign images. | [
"Multilayer",
"network",
"to",
"classify",
"traffic",
"sign",
"images",
"."
] | def network(
x: tf.placeholder,
grayscale: bool,
normalize: bool,
low_keep_prob: float,
high_keep_prob: float,
):
depth = 3
if grayscale:
x = tf.image.rgb_to_grayscale(x)
depth = 1
if normalize:
x = ly.normalize_grayscale(x)
layer_1 = ly.convolutional_... | [
"def",
"network",
"(",
"x",
":",
"tf",
".",
"placeholder",
",",
"grayscale",
":",
"bool",
",",
"normalize",
":",
"bool",
",",
"low_keep_prob",
":",
"float",
",",
"high_keep_prob",
":",
"float",
",",
")",
":",
"depth",
"=",
"3",
"if",
"grayscale",
":",
... | Multilayer network to classify traffic sign images. | [
"Multilayer",
"network",
"to",
"classify",
"traffic",
"sign",
"images",
"."
] | [
"\"\"\"\n Multilayer network to classify traffic sign images.\n @param x: input images\n @param grayscale: whether the images should be converted to grayscale\n @param normalize: whether the converted images should be normalized\n @param low_keep_prob: a lower probability of keeping values for the dr... | [
{
"param": "x",
"type": "tf.placeholder"
},
{
"param": "grayscale",
"type": "bool"
},
{
"param": "normalize",
"type": "bool"
},
{
"param": "low_keep_prob",
"type": "float"
},
{
"param": "high_keep_prob",
"type": "float"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x",
"type": "tf.placeholder",
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"is_optional": false
},
{
"identifier": "grayscale",
"type": "bool",
"docstr... |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | is_fixture | <not_specific> | def is_fixture(fixture_fun # type: Any
):
"""
Returns True if the provided function is a fixture
:param fixture_fun:
:return:
"""
try:
fixture_fun._pytestfixturefunction # noqa
return True
except AttributeError:
# not a fixture ?
return False |
Returns True if the provided function is a fixture
:param fixture_fun:
:return:
| Returns True if the provided function is a fixture | [
"Returns",
"True",
"if",
"the",
"provided",
"function",
"is",
"a",
"fixture"
] | def is_fixture(fixture_fun
):
try:
fixture_fun._pytestfixturefunction
return True
except AttributeError:
return False | [
"def",
"is_fixture",
"(",
"fixture_fun",
")",
":",
"try",
":",
"fixture_fun",
".",
"_pytestfixturefunction",
"return",
"True",
"except",
"AttributeError",
":",
"return",
"False"
] | Returns True if the provided function is a fixture | [
"Returns",
"True",
"if",
"the",
"provided",
"function",
"is",
"a",
"fixture"
] | [
"# type: Any",
"\"\"\"\n Returns True if the provided function is a fixture\n\n :param fixture_fun:\n :return:\n \"\"\"",
"# noqa",
"# not a fixture ?"
] | [
{
"param": "fixture_fun",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "fixture_fun",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,... |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | safe_isclass | <not_specific> | def safe_isclass(obj # type: object
):
# type: (...) -> bool
"""Ignore any exception via isinstance on Python 3."""
try:
return isclass(obj)
except Exception: # noqa
return False | Ignore any exception via isinstance on Python 3. | Ignore any exception via isinstance on Python 3. | [
"Ignore",
"any",
"exception",
"via",
"isinstance",
"on",
"Python",
"3",
"."
] | def safe_isclass(obj
):
try:
return isclass(obj)
except Exception:
return False | [
"def",
"safe_isclass",
"(",
"obj",
")",
":",
"try",
":",
"return",
"isclass",
"(",
"obj",
")",
"except",
"Exception",
":",
"return",
"False"
] | Ignore any exception via isinstance on Python 3. | [
"Ignore",
"any",
"exception",
"via",
"isinstance",
"on",
"Python",
"3",
"."
] | [
"# type: object",
"# type: (...) -> bool",
"\"\"\"Ignore any exception via isinstance on Python 3.\"\"\"",
"# noqa"
] | [
{
"param": "obj",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | assert_is_fixture | null | def assert_is_fixture(fixture_fun # type: Any
):
"""
Raises a ValueError if the provided fixture function is not a fixture.
:param fixture_fun:
:return:
"""
if not is_fixture(fixture_fun):
raise ValueError("The provided fixture function does not seem to be a fixtu... |
Raises a ValueError if the provided fixture function is not a fixture.
:param fixture_fun:
:return:
| Raises a ValueError if the provided fixture function is not a fixture. | [
"Raises",
"a",
"ValueError",
"if",
"the",
"provided",
"fixture",
"function",
"is",
"not",
"a",
"fixture",
"."
] | def assert_is_fixture(fixture_fun
):
if not is_fixture(fixture_fun):
raise ValueError("The provided fixture function does not seem to be a fixture: %s. Did you properly decorate "
"it ?" % fixture_fun) | [
"def",
"assert_is_fixture",
"(",
"fixture_fun",
")",
":",
"if",
"not",
"is_fixture",
"(",
"fixture_fun",
")",
":",
"raise",
"ValueError",
"(",
"\"The provided fixture function does not seem to be a fixture: %s. Did you properly decorate \"",
"\"it ?\"",
"%",
"fixture_fun",
")... | Raises a ValueError if the provided fixture function is not a fixture. | [
"Raises",
"a",
"ValueError",
"if",
"the",
"provided",
"fixture",
"function",
"is",
"not",
"a",
"fixture",
"."
] | [
"# type: Any",
"\"\"\"\n Raises a ValueError if the provided fixture function is not a fixture.\n\n :param fixture_fun:\n :return:\n \"\"\""
] | [
{
"param": "fixture_fun",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "fixture_fun",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,... |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | combine_ids | <not_specific> | def combine_ids(paramid_tuples):
"""
Receives a list of tuples containing ids for each parameterset.
Returns the final ids, that are obtained by joining the various param ids by '-' for each test node
:param paramid_tuples:
:return:
"""
#
return ['-'.join(pid for pid in testid) for test... |
Receives a list of tuples containing ids for each parameterset.
Returns the final ids, that are obtained by joining the various param ids by '-' for each test node
:param paramid_tuples:
:return:
| Receives a list of tuples containing ids for each parameterset.
Returns the final ids, that are obtained by joining the various param ids by '-' for each test node | [
"Receives",
"a",
"list",
"of",
"tuples",
"containing",
"ids",
"for",
"each",
"parameterset",
".",
"Returns",
"the",
"final",
"ids",
"that",
"are",
"obtained",
"by",
"joining",
"the",
"various",
"param",
"ids",
"by",
"'",
"-",
"'",
"for",
"each",
"test",
... | def combine_ids(paramid_tuples):
return ['-'.join(pid for pid in testid) for testid in paramid_tuples] | [
"def",
"combine_ids",
"(",
"paramid_tuples",
")",
":",
"return",
"[",
"'-'",
".",
"join",
"(",
"pid",
"for",
"pid",
"in",
"testid",
")",
"for",
"testid",
"in",
"paramid_tuples",
"]"
] | Receives a list of tuples containing ids for each parameterset. | [
"Receives",
"a",
"list",
"of",
"tuples",
"containing",
"ids",
"for",
"each",
"parameterset",
"."
] | [
"\"\"\"\n Receives a list of tuples containing ids for each parameterset.\n Returns the final ids, that are obtained by joining the various param ids by '-' for each test node\n\n :param paramid_tuples:\n :return:\n \"\"\"",
"#"
] | [
{
"param": "paramid_tuples",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "paramid_tuples",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": nu... |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | analyze_parameter_set | <not_specific> | def analyze_parameter_set(pmark=None, argnames=None, argvalues=None, ids=None, check_nb=True):
"""
analyzes a parameter set passed either as a pmark or as distinct
(argnames, argvalues, ids) to extract/construct the various ids, marks, and
values
See also pytest.Metafunc.parametrize method, that ca... |
analyzes a parameter set passed either as a pmark or as distinct
(argnames, argvalues, ids) to extract/construct the various ids, marks, and
values
See also pytest.Metafunc.parametrize method, that calls in particular
pytest.ParameterSet._for_parametrize and _pytest.python._idvalset
:param pm... | analyzes a parameter set passed either as a pmark or as distinct
(argnames, argvalues, ids) to extract/construct the various ids, marks, and
values
| [
"analyzes",
"a",
"parameter",
"set",
"passed",
"either",
"as",
"a",
"pmark",
"or",
"as",
"distinct",
"(",
"argnames",
"argvalues",
"ids",
")",
"to",
"extract",
"/",
"construct",
"the",
"various",
"ids",
"marks",
"and",
"values"
] | def analyze_parameter_set(pmark=None, argnames=None, argvalues=None, ids=None, check_nb=True):
if pmark is not None:
if any(a is not None for a in (argnames, argvalues, ids)):
raise ValueError("Either provide a pmark OR the details")
argnames = pmark.param_names
argvalues = pmark... | [
"def",
"analyze_parameter_set",
"(",
"pmark",
"=",
"None",
",",
"argnames",
"=",
"None",
",",
"argvalues",
"=",
"None",
",",
"ids",
"=",
"None",
",",
"check_nb",
"=",
"True",
")",
":",
"if",
"pmark",
"is",
"not",
"None",
":",
"if",
"any",
"(",
"a",
... | analyzes a parameter set passed either as a pmark or as distinct
(argnames, argvalues, ids) to extract/construct the various ids, marks, and
values | [
"analyzes",
"a",
"parameter",
"set",
"passed",
"either",
"as",
"a",
"pmark",
"or",
"as",
"distinct",
"(",
"argnames",
"argvalues",
"ids",
")",
"to",
"extract",
"/",
"construct",
"the",
"various",
"ids",
"marks",
"and",
"values"
] | [
"\"\"\"\n analyzes a parameter set passed either as a pmark or as distinct\n (argnames, argvalues, ids) to extract/construct the various ids, marks, and\n values\n\n See also pytest.Metafunc.parametrize method, that calls in particular\n pytest.ParameterSet._for_parametrize and _pytest.python._idvals... | [
{
"param": "pmark",
"type": null
},
{
"param": "argnames",
"type": null
},
{
"param": "argvalues",
"type": null
},
{
"param": "ids",
"type": null
},
{
"param": "check_nb",
"type": null
}
] | {
"returns": [
{
"docstring": "ids, marks, values",
"docstring_tokens": [
"ids",
"marks",
"values"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "pmark",
"type": null,
"docstring": null,
"docstring_tokens": [
... |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | ParameterSet | <not_specific> | def ParameterSet(values,
id, # noqa
marks):
""" Dummy function (not a class) used only by parametrize_plus """
if id is not None:
raise ValueError("This should not happen as `pytest.param` does not exist in pytest 2")
# smart unpack is requ... | Dummy function (not a class) used only by parametrize_plus | Dummy function (not a class) used only by parametrize_plus | [
"Dummy",
"function",
"(",
"not",
"a",
"class",
")",
"used",
"only",
"by",
"parametrize_plus"
] | def ParameterSet(values,
id,
marks):
if id is not None:
raise ValueError("This should not happen as `pytest.param` does not exist in pytest 2")
val = values[0] if len(values) == 1 else values
nbmarks = len(marks)
if nbmarks == 0:
... | [
"def",
"ParameterSet",
"(",
"values",
",",
"id",
",",
"marks",
")",
":",
"if",
"id",
"is",
"not",
"None",
":",
"raise",
"ValueError",
"(",
"\"This should not happen as `pytest.param` does not exist in pytest 2\"",
")",
"val",
"=",
"values",
"[",
"0",
"]",
"if",
... | Dummy function (not a class) used only by parametrize_plus | [
"Dummy",
"function",
"(",
"not",
"a",
"class",
")",
"used",
"only",
"by",
"parametrize_plus"
] | [
"# noqa",
"\"\"\" Dummy function (not a class) used only by parametrize_plus \"\"\"",
"# smart unpack is required for compatibility",
"# decorate with the MarkDecorator"
] | [
{
"param": "values",
"type": null
},
{
"param": "id",
"type": null
},
{
"param": "marks",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "values",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "id",
"type": null,
"docstring": null,
"docstring_tokens": [... |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | mini_idval | <not_specific> | def mini_idval(
val, # type: object
argname, # type: str
idx, # type: int
):
"""
A simplified version of idval where idfn, item and config do not need to be passed.
:param val:
:param argname:
:param idx:
:return:
"""
return _idval(val=val, argname=arg... |
A simplified version of idval where idfn, item and config do not need to be passed.
:param val:
:param argname:
:param idx:
:return:
| A simplified version of idval where idfn, item and config do not need to be passed. | [
"A",
"simplified",
"version",
"of",
"idval",
"where",
"idfn",
"item",
"and",
"config",
"do",
"not",
"need",
"to",
"be",
"passed",
"."
] | def mini_idval(
val,
argname,
idx,
):
return _idval(val=val, argname=argname, idx=idx, **_idval_kwargs) | [
"def",
"mini_idval",
"(",
"val",
",",
"argname",
",",
"idx",
",",
")",
":",
"return",
"_idval",
"(",
"val",
"=",
"val",
",",
"argname",
"=",
"argname",
",",
"idx",
"=",
"idx",
",",
"**",
"_idval_kwargs",
")"
] | A simplified version of idval where idfn, item and config do not need to be passed. | [
"A",
"simplified",
"version",
"of",
"idval",
"where",
"idfn",
"item",
"and",
"config",
"do",
"not",
"need",
"to",
"be",
"passed",
"."
] | [
"# type: object",
"# type: str",
"# type: int",
"\"\"\"\n A simplified version of idval where idfn, item and config do not need to be passed.\n\n :param val:\n :param argname:\n :param idx:\n :return:\n \"\"\""
] | [
{
"param": "val",
"type": null
},
{
"param": "argname",
"type": null
},
{
"param": "idx",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "val",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"... |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | num_mock_patch_args | <not_specific> | def num_mock_patch_args(function):
""" return number of arguments used up by mock arguments (if any) """
patchings = getattr(function, "patchings", None)
if not patchings:
return 0
mock_sentinel = getattr(sys.modules.get("mock"), "DEFAULT", object())
ut_mock_sentinel... | return number of arguments used up by mock arguments (if any) | return number of arguments used up by mock arguments (if any) | [
"return",
"number",
"of",
"arguments",
"used",
"up",
"by",
"mock",
"arguments",
"(",
"if",
"any",
")"
] | def num_mock_patch_args(function):
patchings = getattr(function, "patchings", None)
if not patchings:
return 0
mock_sentinel = getattr(sys.modules.get("mock"), "DEFAULT", object())
ut_mock_sentinel = getattr(sys.modules.get("unittest.mock"), "DEFAULT", object())
retur... | [
"def",
"num_mock_patch_args",
"(",
"function",
")",
":",
"patchings",
"=",
"getattr",
"(",
"function",
",",
"\"patchings\"",
",",
"None",
")",
"if",
"not",
"patchings",
":",
"return",
"0",
"mock_sentinel",
"=",
"getattr",
"(",
"sys",
".",
"modules",
".",
"... | return number of arguments used up by mock arguments (if any) | [
"return",
"number",
"of",
"arguments",
"used",
"up",
"by",
"mock",
"arguments",
"(",
"if",
"any",
")"
] | [
"\"\"\" return number of arguments used up by mock arguments (if any) \"\"\""
] | [
{
"param": "function",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "function",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0f16fca2579b9784de152e49688ba6036bd85af | chinghwayu/python-pytest-cases | pytest_cases/common_pytest.py | [
"BSD-3-Clause"
] | Python | cart_product_pytest | <not_specific> | def cart_product_pytest(argnames, argvalues):
"""
- do NOT use `itertools.product` as it fails to handle MarkDecorators
- we also unpack tuples associated with several argnames ("a,b") if needed
- we also propagate marks
:param argnames:
:param argvalues:
:return:
"""
# transform... |
- do NOT use `itertools.product` as it fails to handle MarkDecorators
- we also unpack tuples associated with several argnames ("a,b") if needed
- we also propagate marks
:param argnames:
:param argvalues:
:return:
| do NOT use `itertools.product` as it fails to handle MarkDecorators
we also unpack tuples associated with several argnames ("a,b") if needed
we also propagate marks | [
"do",
"NOT",
"use",
"`",
"itertools",
".",
"product",
"`",
"as",
"it",
"fails",
"to",
"handle",
"MarkDecorators",
"we",
"also",
"unpack",
"tuples",
"associated",
"with",
"several",
"argnames",
"(",
"\"",
"a",
"b",
"\"",
")",
"if",
"needed",
"we",
"also",... | def cart_product_pytest(argnames, argvalues):
argnames_lists = [get_param_argnames_as_list(_argnames) if len(_argnames) > 0 else [] for _argnames in argnames]
argvalues_prod = _cart_product_pytest(argnames_lists, argvalues)
argnames_list = [n for nlist in argnames_lists for n in nlist]
argvalues_prod = ... | [
"def",
"cart_product_pytest",
"(",
"argnames",
",",
"argvalues",
")",
":",
"argnames_lists",
"=",
"[",
"get_param_argnames_as_list",
"(",
"_argnames",
")",
"if",
"len",
"(",
"_argnames",
")",
">",
"0",
"else",
"[",
"]",
"for",
"_argnames",
"in",
"argnames",
... | do NOT use `itertools.product` as it fails to handle MarkDecorators
we also unpack tuples associated with several argnames ("a,b") if needed
we also propagate marks | [
"do",
"NOT",
"use",
"`",
"itertools",
".",
"product",
"`",
"as",
"it",
"fails",
"to",
"handle",
"MarkDecorators",
"we",
"also",
"unpack",
"tuples",
"associated",
"with",
"several",
"argnames",
"(",
"\"",
"a",
"b",
"\"",
")",
"if",
"needed",
"we",
"also",... | [
"\"\"\"\n - do NOT use `itertools.product` as it fails to handle MarkDecorators\n - we also unpack tuples associated with several argnames (\"a,b\") if needed\n - we also propagate marks\n\n :param argnames:\n :param argvalues:\n :return:\n \"\"\"",
"# transform argnames into a list of lis... | [
{
"param": "argnames",
"type": null
},
{
"param": "argvalues",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "argnames",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
7ea54afc6a940c580f2f407dca31f64d154365e8 | chinghwayu/python-pytest-cases | pytest_cases/fixture_parametrize_plus.py | [
"BSD-3-Clause"
] | Python | _fixture_product | <not_specific> | def _fixture_product(caller_module,
name, # type: str
fixtures_or_values,
fixture_positions,
scope="function", # type: str
ids=None, # type: Union[Callable, List[str]]
... |
Internal implementation for fixture products created by pytest parametrize plus.
:param caller_module:
:param name:
:param fixtures_or_values:
:param fixture_positions:
:param idstyle:
:param scope:
:param ids:
:param unpack_into:
:param autouse:
:param kwargs:
:return:... | Internal implementation for fixture products created by pytest parametrize plus. | [
"Internal",
"implementation",
"for",
"fixture",
"products",
"created",
"by",
"pytest",
"parametrize",
"plus",
"."
] | def _fixture_product(caller_module,
name,
fixtures_or_values,
fixture_positions,
scope="function",
ids=None,
unpack_into=None,
autouse=Fa... | [
"def",
"_fixture_product",
"(",
"caller_module",
",",
"name",
",",
"fixtures_or_values",
",",
"fixture_positions",
",",
"scope",
"=",
"\"function\"",
",",
"ids",
"=",
"None",
",",
"unpack_into",
"=",
"None",
",",
"autouse",
"=",
"False",
",",
"hook",
"=",
"N... | Internal implementation for fixture products created by pytest parametrize plus. | [
"Internal",
"implementation",
"for",
"fixture",
"products",
"created",
"by",
"pytest",
"parametrize",
"plus",
"."
] | [
"# type: str",
"# type: str",
"# type: Union[Callable, List[str]]",
"# type: Iterable[str]",
"# type: bool",
"# type: Callable[[Callable], Callable]",
"# type: Callable",
"\"\"\"\n Internal implementation for fixture products created by pytest parametrize plus.\n\n :param caller_module:\n :pa... | [
{
"param": "caller_module",
"type": null
},
{
"param": "name",
"type": null
},
{
"param": "fixtures_or_values",
"type": null
},
{
"param": "fixture_positions",
"type": null
},
{
"param": "scope",
"type": null
},
{
"param": "ids",
"type": null
},
... | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "caller_module",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": nul... |
7ea54afc6a940c580f2f407dca31f64d154365e8 | chinghwayu/python-pytest-cases | pytest_cases/fixture_parametrize_plus.py | [
"BSD-3-Clause"
] | Python | parametrize_plus | <not_specific> | def parametrize_plus(argnames=None, # type: str
argvalues=None, # type: Iterable[Any]
indirect=False, # type: bool
ids=None, # type: Union[Callable, List[str]]
idstyle='explicit', # type: str
... |
Equivalent to `@pytest.mark.parametrize` but also supports
(1) new alternate style for argnames/argvalues. One can also use `**args` to pass additional `{argnames: argvalues}`
in the same parametrization call. This can be handy in combination with `idgen` to master the whole id template
associated wit... | Equivalent to `@pytest.mark.parametrize` but also supports
(1) new alternate style for argnames/argvalues. One can also use `**args` to pass additional `{argnames: argvalues}`
in the same parametrization call. This can be handy in combination with `idgen` to master the whole id template
associated with several paramete... | [
"Equivalent",
"to",
"`",
"@pytest",
".",
"mark",
".",
"parametrize",
"`",
"but",
"also",
"supports",
"(",
"1",
")",
"new",
"alternate",
"style",
"for",
"argnames",
"/",
"argvalues",
".",
"One",
"can",
"also",
"use",
"`",
"**",
"args",
"`",
"to",
"pass"... | def parametrize_plus(argnames=None,
argvalues=None,
indirect=False,
ids=None,
idstyle='explicit',
idgen=_IDGEN,
scope=None,
... | [
"def",
"parametrize_plus",
"(",
"argnames",
"=",
"None",
",",
"argvalues",
"=",
"None",
",",
"indirect",
"=",
"False",
",",
"ids",
"=",
"None",
",",
"idstyle",
"=",
"'explicit'",
",",
"idgen",
"=",
"_IDGEN",
",",
"scope",
"=",
"None",
",",
"hook",
"=",... | Equivalent to `@pytest.mark.parametrize` but also supports
(1) new alternate style for argnames/argvalues. | [
"Equivalent",
"to",
"`",
"@pytest",
".",
"mark",
".",
"parametrize",
"`",
"but",
"also",
"supports",
"(",
"1",
")",
"new",
"alternate",
"style",
"for",
"argnames",
"/",
"argvalues",
"."
] | [
"# type: str",
"# type: Iterable[Any]",
"# type: bool",
"# type: Union[Callable, List[str]]",
"# type: str",
"# type: Union[str, Callable]",
"# type: str",
"# type: Callable[[Callable], Callable]",
"# type: bool",
"\"\"\"\n Equivalent to `@pytest.mark.parametrize` but also supports\n\n (1) n... | [
{
"param": "argnames",
"type": null
},
{
"param": "argvalues",
"type": null
},
{
"param": "indirect",
"type": null
},
{
"param": "ids",
"type": null
},
{
"param": "idstyle",
"type": null
},
{
"param": "idgen",
"type": null
},
{
"param": "sc... | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "argnames",
"type": null,
"docstring": "same as in pytest.mark.parametrize",
"docstring_tokens": [
"same",
... |
7ea54afc6a940c580f2f407dca31f64d154365e8 | chinghwayu/python-pytest-cases | pytest_cases/fixture_parametrize_plus.py | [
"BSD-3-Clause"
] | Python | _create_params_alt | <not_specific> | def _create_params_alt(test_func_name, union_name, from_i, to_i, hook): # noqa
""" Routine that will be used to create a parameter fixture for argvalues between prev_i and i"""
# check if this is about a single value or several values
single_param_val = (to_i == from_i + 1)
... | Routine that will be used to create a parameter fixture for argvalues between prev_i and i | Routine that will be used to create a parameter fixture for argvalues between prev_i and i | [
"Routine",
"that",
"will",
"be",
"used",
"to",
"create",
"a",
"parameter",
"fixture",
"for",
"argvalues",
"between",
"prev_i",
"and",
"i"
] | def _create_params_alt(test_func_name, union_name, from_i, to_i, hook):
single_param_val = (to_i == from_i + 1)
if single_param_val:
i = from_i
p_fix_name = "%s_%s_P%s" % (test_func_name, param_names_str, i)
p_fix_name = check_name_available(ca... | [
"def",
"_create_params_alt",
"(",
"test_func_name",
",",
"union_name",
",",
"from_i",
",",
"to_i",
",",
"hook",
")",
":",
"single_param_val",
"=",
"(",
"to_i",
"==",
"from_i",
"+",
"1",
")",
"if",
"single_param_val",
":",
"i",
"=",
"from_i",
"p_fix_name",
... | Routine that will be used to create a parameter fixture for argvalues between prev_i and i | [
"Routine",
"that",
"will",
"be",
"used",
"to",
"create",
"a",
"parameter",
"fixture",
"for",
"argvalues",
"between",
"prev_i",
"and",
"i"
] | [
"# noqa",
"\"\"\" Routine that will be used to create a parameter fixture for argvalues between prev_i and i\"\"\"",
"# check if this is about a single value or several values",
"# noqa",
"# Create a unique fixture name",
"# Create the fixture that will return the unique parameter value (\"auto-simplify\"... | [
{
"param": "test_func_name",
"type": null
},
{
"param": "union_name",
"type": null
},
{
"param": "from_i",
"type": null
},
{
"param": "to_i",
"type": null
},
{
"param": "hook",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "test_func_name",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "union_name",
"type": null,
"docstring": null,
"docs... |
7ea54afc6a940c580f2f407dca31f64d154365e8 | chinghwayu/python-pytest-cases | pytest_cases/fixture_parametrize_plus.py | [
"BSD-3-Clause"
] | Python | parametrize_plus_decorate | <not_specific> | def parametrize_plus_decorate(test_func):
"""
A decorator that wraps the test function so that instead of receiving the parameter names, it receives the
new fixture. All other decorations are unchanged.
:param test_func:
:return:
"""
t... |
A decorator that wraps the test function so that instead of receiving the parameter names, it receives the
new fixture. All other decorations are unchanged.
:param test_func:
:return:
| A decorator that wraps the test function so that instead of receiving the parameter names, it receives the
new fixture. All other decorations are unchanged. | [
"A",
"decorator",
"that",
"wraps",
"the",
"test",
"function",
"so",
"that",
"instead",
"of",
"receiving",
"the",
"parameter",
"names",
"it",
"receives",
"the",
"new",
"fixture",
".",
"All",
"other",
"decorations",
"are",
"unchanged",
"."
] | def parametrize_plus_decorate(test_func):
test_func_name = test_func.__name__
try:
if len(ids) != len(argvalues):
raise ValueError("Explicit list of `ids` provided has a different length (%s) than the number of "
"parameter... | [
"def",
"parametrize_plus_decorate",
"(",
"test_func",
")",
":",
"test_func_name",
"=",
"test_func",
".",
"__name__",
"try",
":",
"if",
"len",
"(",
"ids",
")",
"!=",
"len",
"(",
"argvalues",
")",
":",
"raise",
"ValueError",
"(",
"\"Explicit list of `ids` provided... | A decorator that wraps the test function so that instead of receiving the parameter names, it receives the
new fixture. | [
"A",
"decorator",
"that",
"wraps",
"the",
"test",
"function",
"so",
"that",
"instead",
"of",
"receiving",
"the",
"parameter",
"names",
"it",
"receives",
"the",
"new",
"fixture",
"."
] | [
"\"\"\"\n A decorator that wraps the test function so that instead of receiving the parameter names, it receives the\n new fixture. All other decorations are unchanged.\n\n :param test_func:\n :return:\n \"\"\"",
"# Are there explicit ids provided ?",
"# fi... | [
{
"param": "test_func",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "test_func",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
7ea54afc6a940c580f2f407dca31f64d154365e8 | chinghwayu/python-pytest-cases | pytest_cases/fixture_parametrize_plus.py | [
"BSD-3-Clause"
] | Python | _process_argvalues | <not_specific> | def _process_argvalues(argnames, marked_argvalues, nb_params):
"""Internal method to use in _pytest_parametrize_plus
Processes the provided marked_argvalues (possibly marked with pytest.param) and returns
p_ids, p_marks, argvalues (not marked with pytest.param), fixture_indices
Note: `marked_argvalues... | Internal method to use in _pytest_parametrize_plus
Processes the provided marked_argvalues (possibly marked with pytest.param) and returns
p_ids, p_marks, argvalues (not marked with pytest.param), fixture_indices
Note: `marked_argvalues` is modified in the process if a `lazy_value` is found with a custom ... | Internal method to use in _pytest_parametrize_plus
Processes the provided marked_argvalues (possibly marked with pytest.param) and returns
p_ids, p_marks, argvalues (not marked with pytest.param), fixture_indices
`marked_argvalues` is modified in the process if a `lazy_value` is found with a custom id or marks. | [
"Internal",
"method",
"to",
"use",
"in",
"_pytest_parametrize_plus",
"Processes",
"the",
"provided",
"marked_argvalues",
"(",
"possibly",
"marked",
"with",
"pytest",
".",
"param",
")",
"and",
"returns",
"p_ids",
"p_marks",
"argvalues",
"(",
"not",
"marked",
"with"... | def _process_argvalues(argnames, marked_argvalues, nb_params):
p_ids, p_marks, argvalues = extract_parameterset_info(argnames, marked_argvalues, check_nb=False)
fixture_indices = []
if nb_params == 1:
for i, v in enumerate(argvalues):
if is_lazy_value(v):
_mks = v.get_mar... | [
"def",
"_process_argvalues",
"(",
"argnames",
",",
"marked_argvalues",
",",
"nb_params",
")",
":",
"p_ids",
",",
"p_marks",
",",
"argvalues",
"=",
"extract_parameterset_info",
"(",
"argnames",
",",
"marked_argvalues",
",",
"check_nb",
"=",
"False",
")",
"fixture_i... | Internal method to use in _pytest_parametrize_plus
Processes the provided marked_argvalues (possibly marked with pytest.param) and returns
p_ids, p_marks, argvalues (not marked with pytest.param), fixture_indices | [
"Internal",
"method",
"to",
"use",
"in",
"_pytest_parametrize_plus",
"Processes",
"the",
"provided",
"marked_argvalues",
"(",
"possibly",
"marked",
"with",
"pytest",
".",
"param",
")",
"and",
"returns",
"p_ids",
"p_marks",
"argvalues",
"(",
"not",
"marked",
"with"... | [
"\"\"\"Internal method to use in _pytest_parametrize_plus\n\n Processes the provided marked_argvalues (possibly marked with pytest.param) and returns\n p_ids, p_marks, argvalues (not marked with pytest.param), fixture_indices\n\n Note: `marked_argvalues` is modified in the process if a `lazy_value` is foun... | [
{
"param": "argnames",
"type": null
},
{
"param": "marked_argvalues",
"type": null
},
{
"param": "nb_params",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "argnames",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
... |
ab7434daee3f5d52f82bc375044d0ccce35ac6ab | chinghwayu/python-pytest-cases | pytest_cases/case_funcs_new.py | [
"BSD-3-Clause"
] | Python | matches_tag_query | <not_specific> | def matches_tag_query(case_fun,
has_tag=None, # type: Union[str, Iterable[str]]
filter=None, # type: Union[Callable[[Iterable[Any]], bool], Iterable[Callable[[Iterable[Any]], bool]]] # noqa
):
"""
Returns True if the case function is selected... |
Returns True if the case function is selected by the query:
- if `has_tag` contains one or several tags, they should ALL be present in the tags
set on `case_fun` (`case_fun._pytestcase.tags`)
- if `filter` contains one or several filter callables, they are all called in sequence and the
c... |
if `filter` contains one or several filter callables, they are all called in sequence and the
case_fun is only selected if ALL of them return a True truth value | [
"if",
"`",
"filter",
"`",
"contains",
"one",
"or",
"several",
"filter",
"callables",
"they",
"are",
"all",
"called",
"in",
"sequence",
"and",
"the",
"case_fun",
"is",
"only",
"selected",
"if",
"ALL",
"of",
"them",
"return",
"a",
"True",
"truth",
"value"
] | def matches_tag_query(case_fun,
has_tag=None,
filter=None,
):
selected = True
if has_tag is not None:
selected = selected and CaseInfo.get_from(case_fun).matches_tag_query(has_tag)
if filter is not None:
if not isinstance... | [
"def",
"matches_tag_query",
"(",
"case_fun",
",",
"has_tag",
"=",
"None",
",",
"filter",
"=",
"None",
",",
")",
":",
"selected",
"=",
"True",
"if",
"has_tag",
"is",
"not",
"None",
":",
"selected",
"=",
"selected",
"and",
"CaseInfo",
".",
"get_from",
"(",... | Returns True if the case function is selected by the query:
if `has_tag` contains one or several tags, they should ALL be present in the tags
set on `case_fun` (`case_fun._pytestcase.tags`) | [
"Returns",
"True",
"if",
"the",
"case",
"function",
"is",
"selected",
"by",
"the",
"query",
":",
"if",
"`",
"has_tag",
"`",
"contains",
"one",
"or",
"several",
"tags",
"they",
"should",
"ALL",
"be",
"present",
"in",
"the",
"tags",
"set",
"on",
"`",
"ca... | [
"# type: Union[str, Iterable[str]]",
"# type: Union[Callable[[Iterable[Any]], bool], Iterable[Callable[[Iterable[Any]], bool]]] # noqa",
"\"\"\"\n Returns True if the case function is selected by the query:\n\n - if `has_tag` contains one or several tags, they should ALL be present in the tags\n s... | [
{
"param": "case_fun",
"type": null
},
{
"param": "has_tag",
"type": null
},
{
"param": "filter",
"type": null
}
] | {
"returns": [
{
"docstring": "True if the case_fun is selected by the query.",
"docstring_tokens": [
"True",
"if",
"the",
"case_fun",
"is",
"selected",
"by",
"the",
"query",
"."
],
"type": null
}
],
"r... |
ab7434daee3f5d52f82bc375044d0ccce35ac6ab | chinghwayu/python-pytest-cases | pytest_cases/case_funcs_new.py | [
"BSD-3-Clause"
] | Python | case | <not_specific> | def case(id=None, # type: str # noqa
tags=None, # type: Union[Any, Iterable[Any]]
marks=(), # type: Union[MarkDecorator, Iterable[MarkDecorator]]
case_func=DECORATED # noqa
):
"""
Optional decorator for case functions so as to customize some... |
Optional decorator for case functions so as to customize some information.
```python
@case(id='hey')
def case_hi():
return 1
```
:param id: the custom pytest id that should be used when this case is active. Replaces the deprecated `@case_name`
decorator from v1. If no id is pr... | Optional decorator for case functions so as to customize some information. | [
"Optional",
"decorator",
"for",
"case",
"functions",
"so",
"as",
"to",
"customize",
"some",
"information",
"."
] | def case(id=None,
tags=None,
marks=(),
case_func=DECORATED
):
case_info = CaseInfo(id, marks, tags)
case_info.attach_to(case_func)
return case_func | [
"def",
"case",
"(",
"id",
"=",
"None",
",",
"tags",
"=",
"None",
",",
"marks",
"=",
"(",
")",
",",
"case_func",
"=",
"DECORATED",
")",
":",
"case_info",
"=",
"CaseInfo",
"(",
"id",
",",
"marks",
",",
"tags",
")",
"case_info",
".",
"attach_to",
"(",... | Optional decorator for case functions so as to customize some information. | [
"Optional",
"decorator",
"for",
"case",
"functions",
"so",
"as",
"to",
"customize",
"some",
"information",
"."
] | [
"# type: str # noqa",
"# type: Union[Any, Iterable[Any]]",
"# type: Union[MarkDecorator, Iterable[MarkDecorator]]",
"# noqa",
"\"\"\"\n Optional decorator for case functions so as to customize some information.\n\n ```python\n @case(id='hey')\n def case_hi():\n return 1\n ```\n\n :... | [
{
"param": "id",
"type": null
},
{
"param": "tags",
"type": null
},
{
"param": "marks",
"type": null
},
{
"param": "case_func",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "id",
"type": null,
"docstring": "the custom pytest id that should be used when this case is active. Replaces the deprecat... |
0757457b7be5da92371a9fdb26b80a3972256725 | zachjweiner/pystella | pystella/multigrid/transfer.py | [
"MIT"
] | Python | RestrictionBase | <not_specific> | def RestrictionBase(coefs, StencilKernel, halo_shape, **kwargs):
"""
A base function for generating a restriction kernel.
:arg coefs: The coefficients representing the restriction formula.
Follows the convention of :func:`pystella.derivs.centered_diff`
(since the restriction is applie... |
A base function for generating a restriction kernel.
:arg coefs: The coefficients representing the restriction formula.
Follows the convention of :func:`pystella.derivs.centered_diff`
(since the restriction is applied recursively in each dimension).
:arg StencilKernel: The stencil ... | A base function for generating a restriction kernel. | [
"A",
"base",
"function",
"for",
"generating",
"a",
"restriction",
"kernel",
"."
] | def RestrictionBase(coefs, StencilKernel, halo_shape, **kwargs):
lsize = kwargs.pop("lsize", (4, 4, 4))
for N in ["Nx", "Ny", "Nz"]:
_ = kwargs.pop(N, None)
restrict_coefs = {}
for a, c_a in coefs.items():
for b, c_b in coefs.items():
for c, c_c in coefs.items():
... | [
"def",
"RestrictionBase",
"(",
"coefs",
",",
"StencilKernel",
",",
"halo_shape",
",",
"**",
"kwargs",
")",
":",
"lsize",
"=",
"kwargs",
".",
"pop",
"(",
"\"lsize\"",
",",
"(",
"4",
",",
"4",
",",
"4",
")",
")",
"for",
"N",
"in",
"[",
"\"Nx\"",
",",... | A base function for generating a restriction kernel. | [
"A",
"base",
"function",
"for",
"generating",
"a",
"restriction",
"kernel",
"."
] | [
"\"\"\"\r\n A base function for generating a restriction kernel.\r\n\r\n :arg coefs: The coefficients representing the restriction formula.\r\n Follows the convention of :func:`pystella.derivs.centered_diff`\r\n (since the restriction is applied recursively in each dimension).\r\n\r\n :arg St... | [
{
"param": "coefs",
"type": null
},
{
"param": "StencilKernel",
"type": null
},
{
"param": "halo_shape",
"type": null
}
] | {
"returns": [
{
"docstring": "An instance of ``StencilKernel`` which executes the requested\nrestriction.",
"docstring_tokens": [
"An",
"instance",
"of",
"`",
"`",
"StencilKernel",
"`",
"`",
"which",
"executes",
"... |
0757457b7be5da92371a9fdb26b80a3972256725 | zachjweiner/pystella | pystella/multigrid/transfer.py | [
"MIT"
] | Python | FullWeighting | <not_specific> | def FullWeighting(StencilKernel=Stencil, **kwargs):
"""
Creates a full-weighting restriction kernel, which restricts in input array
:math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the
coarse grid by applying
.. math::
f^{(2 h)}_i
= \\frac{1}{4} f^{(h)}_... |
Creates a full-weighting restriction kernel, which restricts in input array
:math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the
coarse grid by applying
.. math::
f^{(2 h)}_i
= \\frac{1}{4} f^{(h)}_{2 i - 1}
+ \\frac{1}{2} f^{(h)}_{2 i}
... | Creates a full-weighting restriction kernel, which restricts in input array | [
"Creates",
"a",
"full",
"-",
"weighting",
"restriction",
"kernel",
"which",
"restricts",
"in",
"input",
"array"
] | def FullWeighting(StencilKernel=Stencil, **kwargs):
from pymbolic.primitives import Quotient
coefs = {-1: Quotient(1, 4), 0: Quotient(1, 2), 1: Quotient(1, 4)}
return RestrictionBase(coefs, StencilKernel, **kwargs) | [
"def",
"FullWeighting",
"(",
"StencilKernel",
"=",
"Stencil",
",",
"**",
"kwargs",
")",
":",
"from",
"pymbolic",
".",
"primitives",
"import",
"Quotient",
"coefs",
"=",
"{",
"-",
"1",
":",
"Quotient",
"(",
"1",
",",
"4",
")",
",",
"0",
":",
"Quotient",
... | Creates a full-weighting restriction kernel, which restricts in input array | [
"Creates",
"a",
"full",
"-",
"weighting",
"restriction",
"kernel",
"which",
"restricts",
"in",
"input",
"array"
] | [
"\"\"\"\r\n Creates a full-weighting restriction kernel, which restricts in input array\r\n :math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the\r\n coarse grid by applying\r\n\r\n .. math::\r\n\r\n f^{(2 h)}_i\r\n = \\\\frac{1}{4} f^{(h)}_{2 i - 1}\r\n + \\\\... | [
{
"param": "StencilKernel",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "StencilKernel",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": [
{
"identifier": "math",
"docstring": "`... |
0757457b7be5da92371a9fdb26b80a3972256725 | zachjweiner/pystella | pystella/multigrid/transfer.py | [
"MIT"
] | Python | Injection | <not_specific> | def Injection(StencilKernel=ElementWiseMap, **kwargs):
"""
Creates an injection kernel, which restricts in input array
:math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the
coarse grid by direct injection:
.. math::
f^{(2 h)}_{i, j ,k}
= f^{(h)}_{2 i, 2 j... |
Creates an injection kernel, which restricts in input array
:math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the
coarse grid by direct injection:
.. math::
f^{(2 h)}_{i, j ,k}
= f^{(h)}_{2 i, 2 j, 2 k}
See :class:`transfer.RestrictionBase`.
| Creates an injection kernel, which restricts in input array | [
"Creates",
"an",
"injection",
"kernel",
"which",
"restricts",
"in",
"input",
"array"
] | def Injection(StencilKernel=ElementWiseMap, **kwargs):
coefs = {0: 1}
return RestrictionBase(coefs, StencilKernel, **kwargs) | [
"def",
"Injection",
"(",
"StencilKernel",
"=",
"ElementWiseMap",
",",
"**",
"kwargs",
")",
":",
"coefs",
"=",
"{",
"0",
":",
"1",
"}",
"return",
"RestrictionBase",
"(",
"coefs",
",",
"StencilKernel",
",",
"**",
"kwargs",
")"
] | Creates an injection kernel, which restricts in input array | [
"Creates",
"an",
"injection",
"kernel",
"which",
"restricts",
"in",
"input",
"array"
] | [
"\"\"\"\r\n Creates an injection kernel, which restricts in input array\r\n :math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the\r\n coarse grid by direct injection:\r\n\r\n .. math::\r\n\r\n f^{(2 h)}_{i, j ,k}\r\n = f^{(h)}_{2 i, 2 j, 2 k}\r\n\r\n See :class:`transf... | [
{
"param": "StencilKernel",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "StencilKernel",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": [
{
"identifier": "math",
"docstring": "`... |
0757457b7be5da92371a9fdb26b80a3972256725 | zachjweiner/pystella | pystella/multigrid/transfer.py | [
"MIT"
] | Python | InterpolationBase | <not_specific> | def InterpolationBase(even_coefs, odd_coefs, StencilKernel, halo_shape, **kwargs):
"""
A base function for generating a restriction kernel.
:arg even_coefs: The coefficients representing the interpolation formula
for gridpoints on the coarse and fine grid which coincide in space.
Foll... |
A base function for generating a restriction kernel.
:arg even_coefs: The coefficients representing the interpolation formula
for gridpoints on the coarse and fine grid which coincide in space.
Follows the convention of :func:`pystella.derivs.centered_diff`
(since the restriction... | A base function for generating a restriction kernel. | [
"A",
"base",
"function",
"for",
"generating",
"a",
"restriction",
"kernel",
"."
] | def InterpolationBase(even_coefs, odd_coefs, StencilKernel, halo_shape, **kwargs):
from pymbolic import parse, var
i, j, k = parse("i, j, k")
f1 = Field("f1", offset="h")
tmp_insns = {}
tmp = var("tmp")
import itertools
for parity in tuple(itertools.product((0, 1), (0, 1), (0, 1))):
... | [
"def",
"InterpolationBase",
"(",
"even_coefs",
",",
"odd_coefs",
",",
"StencilKernel",
",",
"halo_shape",
",",
"**",
"kwargs",
")",
":",
"from",
"pymbolic",
"import",
"parse",
",",
"var",
"i",
",",
"j",
",",
"k",
"=",
"parse",
"(",
"\"i, j, k\"",
")",
"f... | A base function for generating a restriction kernel. | [
"A",
"base",
"function",
"for",
"generating",
"a",
"restriction",
"kernel",
"."
] | [
"\"\"\"\r\n A base function for generating a restriction kernel.\r\n\r\n :arg even_coefs: The coefficients representing the interpolation formula\r\n for gridpoints on the coarse and fine grid which coincide in space.\r\n Follows the convention of :func:`pystella.derivs.centered_diff`\r\n ... | [
{
"param": "even_coefs",
"type": null
},
{
"param": "odd_coefs",
"type": null
},
{
"param": "StencilKernel",
"type": null
},
{
"param": "halo_shape",
"type": null
}
] | {
"returns": [
{
"docstring": "An instance of ``StencilKernel`` which executes the requested\ninterpolation.",
"docstring_tokens": [
"An",
"instance",
"of",
"`",
"`",
"StencilKernel",
"`",
"`",
"which",
"executes",
... |
0757457b7be5da92371a9fdb26b80a3972256725 | zachjweiner/pystella | pystella/multigrid/transfer.py | [
"MIT"
] | Python | LinearInterpolation | <not_specific> | def LinearInterpolation(StencilKernel=Stencil, **kwargs):
"""
Creates an linear interpolation kernel, which interpolates in input array
:math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the
coarse grid via
.. math::
f^{(h)}_{2 i}
&= f^{(2 h)}_{i}
... |
Creates an linear interpolation kernel, which interpolates in input array
:math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the
coarse grid via
.. math::
f^{(h)}_{2 i}
&= f^{(2 h)}_{i}
f^{(h)}_{2 i + 1}
&= \\frac{1}{2} f^{(2 h)}_{i} + \\fr... | Creates an linear interpolation kernel, which interpolates in input array | [
"Creates",
"an",
"linear",
"interpolation",
"kernel",
"which",
"interpolates",
"in",
"input",
"array"
] | def LinearInterpolation(StencilKernel=Stencil, **kwargs):
from pymbolic.primitives import Quotient
odd_coefs = {-1: Quotient(1, 2), 1: Quotient(1, 2)}
even_coefs = {0: 1}
return InterpolationBase(even_coefs, odd_coefs, StencilKernel, **kwargs) | [
"def",
"LinearInterpolation",
"(",
"StencilKernel",
"=",
"Stencil",
",",
"**",
"kwargs",
")",
":",
"from",
"pymbolic",
".",
"primitives",
"import",
"Quotient",
"odd_coefs",
"=",
"{",
"-",
"1",
":",
"Quotient",
"(",
"1",
",",
"2",
")",
",",
"1",
":",
"Q... | Creates an linear interpolation kernel, which interpolates in input array | [
"Creates",
"an",
"linear",
"interpolation",
"kernel",
"which",
"interpolates",
"in",
"input",
"array"
] | [
"\"\"\"\r\n Creates an linear interpolation kernel, which interpolates in input array\r\n :math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the\r\n coarse grid via\r\n\r\n .. math::\r\n\r\n f^{(h)}_{2 i}\r\n &= f^{(2 h)}_{i}\r\n\r\n f^{(h)}_{2 i + 1}\r\n &= ... | [
{
"param": "StencilKernel",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "StencilKernel",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": [
{
"identifier": "math",
"docstring": "`... |
0757457b7be5da92371a9fdb26b80a3972256725 | zachjweiner/pystella | pystella/multigrid/transfer.py | [
"MIT"
] | Python | CubicInterpolation | <not_specific> | def CubicInterpolation(StencilKernel=Stencil, **kwargs):
"""
Creates an cubic interpolation kernel, which interpolates in input array
:math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the
coarse grid via
.. math::
f^{(h)}_{2 i}
&= f^{(2 h)}_{i}
... |
Creates an cubic interpolation kernel, which interpolates in input array
:math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the
coarse grid via
.. math::
f^{(h)}_{2 i}
&= f^{(2 h)}_{i}
f^{(h)}_{2 i + 1}
&= - \\frac{1}{16} f^{(2 h)}_{i - 1}
... | Creates an cubic interpolation kernel, which interpolates in input array | [
"Creates",
"an",
"cubic",
"interpolation",
"kernel",
"which",
"interpolates",
"in",
"input",
"array"
] | def CubicInterpolation(StencilKernel=Stencil, **kwargs):
if kwargs.get("halo_shape", 0) < 2:
raise ValueError("CubicInterpolation requires padding >= 2")
from pymbolic.primitives import Quotient
odd_coefs = {-3: Quotient(-1, 16), -1: Quotient(9, 16),
1: Quotient(9, 16), 3: Quotient(... | [
"def",
"CubicInterpolation",
"(",
"StencilKernel",
"=",
"Stencil",
",",
"**",
"kwargs",
")",
":",
"if",
"kwargs",
".",
"get",
"(",
"\"halo_shape\"",
",",
"0",
")",
"<",
"2",
":",
"raise",
"ValueError",
"(",
"\"CubicInterpolation requires padding >= 2\"",
")",
... | Creates an cubic interpolation kernel, which interpolates in input array | [
"Creates",
"an",
"cubic",
"interpolation",
"kernel",
"which",
"interpolates",
"in",
"input",
"array"
] | [
"\"\"\"\r\n Creates an cubic interpolation kernel, which interpolates in input array\r\n :math:`f^{(h)}` on the fine grid into an array :math:`f^{(2 h)}` on the\r\n coarse grid via\r\n\r\n .. math::\r\n\r\n f^{(h)}_{2 i}\r\n &= f^{(2 h)}_{i}\r\n\r\n f^{(h)}_{2 i + 1}\r\n &= -... | [
{
"param": "StencilKernel",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "StencilKernel",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": [
{
"identifier": "math",
"docstring": "`... |
46c229ed222c98cb727ba27dccbfd3e831bb211c | zachjweiner/pystella | pystella/fourier/projectors.py | [
"MIT"
] | Python | pol_to_vec | <not_specific> | def pol_to_vec(self, queue, plus, minus, vector):
"""
Projects the plus and minus polarizations of a vector field onto its
vector components.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg plus: The array containing the
momentum-space field of the plus p... |
Projects the plus and minus polarizations of a vector field onto its
vector components.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg plus: The array containing the
momentum-space field of the plus polarization.
:arg minus: The array containing the
... | Projects the plus and minus polarizations of a vector field onto its
vector components. | [
"Projects",
"the",
"plus",
"and",
"minus",
"polarizations",
"of",
"a",
"vector",
"field",
"onto",
"its",
"vector",
"components",
"."
] | def pol_to_vec(self, queue, plus, minus, vector):
evt, _ = self.pol_to_vec_knl(queue, **self.eff_mom,
vector=vector, plus=plus, minus=minus)
return evt | [
"def",
"pol_to_vec",
"(",
"self",
",",
"queue",
",",
"plus",
",",
"minus",
",",
"vector",
")",
":",
"evt",
",",
"_",
"=",
"self",
".",
"pol_to_vec_knl",
"(",
"queue",
",",
"**",
"self",
".",
"eff_mom",
",",
"vector",
"=",
"vector",
",",
"plus",
"="... | Projects the plus and minus polarizations of a vector field onto its
vector components. | [
"Projects",
"the",
"plus",
"and",
"minus",
"polarizations",
"of",
"a",
"vector",
"field",
"onto",
"its",
"vector",
"components",
"."
] | [
"\"\"\"\r\n Projects the plus and minus polarizations of a vector field onto its\r\n vector components.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg plus: The array containing the\r\n momentum-space field of the plus polarization.\r\n\r\n :arg minu... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "plus",
"type": null
},
{
"param": "minus",
"type": null
},
{
"param": "vector",
"type": null
}
] | {
"returns": [
{
"docstring": "The :class:`pyopencl.Event` associated with the kernel invocation.",
"docstring_tokens": [
"The",
":",
"class",
":",
"`",
"pyopencl",
".",
"Event",
"`",
"associated",
"with",
... |
46c229ed222c98cb727ba27dccbfd3e831bb211c | zachjweiner/pystella | pystella/fourier/projectors.py | [
"MIT"
] | Python | vec_to_pol | <not_specific> | def vec_to_pol(self, queue, plus, minus, vector):
"""
Projects the components of a vector field onto the basis of plus and
minus polarizations.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg plus: The array into which will be stored the
momentum-space fi... |
Projects the components of a vector field onto the basis of plus and
minus polarizations.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg plus: The array into which will be stored the
momentum-space field of the plus polarization.
:arg minus: The array... | Projects the components of a vector field onto the basis of plus and
minus polarizations. | [
"Projects",
"the",
"components",
"of",
"a",
"vector",
"field",
"onto",
"the",
"basis",
"of",
"plus",
"and",
"minus",
"polarizations",
"."
] | def vec_to_pol(self, queue, plus, minus, vector):
evt, _ = self.vec_to_pol_knl(queue, **self.eff_mom,
vector=vector, plus=plus, minus=minus)
return evt | [
"def",
"vec_to_pol",
"(",
"self",
",",
"queue",
",",
"plus",
",",
"minus",
",",
"vector",
")",
":",
"evt",
",",
"_",
"=",
"self",
".",
"vec_to_pol_knl",
"(",
"queue",
",",
"**",
"self",
".",
"eff_mom",
",",
"vector",
"=",
"vector",
",",
"plus",
"="... | Projects the components of a vector field onto the basis of plus and
minus polarizations. | [
"Projects",
"the",
"components",
"of",
"a",
"vector",
"field",
"onto",
"the",
"basis",
"of",
"plus",
"and",
"minus",
"polarizations",
"."
] | [
"\"\"\"\r\n Projects the components of a vector field onto the basis of plus and\r\n minus polarizations.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg plus: The array into which will be stored the\r\n momentum-space field of the plus polarization.\r\n\r\n... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "plus",
"type": null
},
{
"param": "minus",
"type": null
},
{
"param": "vector",
"type": null
}
] | {
"returns": [
{
"docstring": "The :class:`pyopencl.Event` associated with the kernel invocation.",
"docstring_tokens": [
"The",
":",
"class",
":",
"`",
"pyopencl",
".",
"Event",
"`",
"associated",
"with",
... |
46c229ed222c98cb727ba27dccbfd3e831bb211c | zachjweiner/pystella | pystella/fourier/projectors.py | [
"MIT"
] | Python | decompose_vector | <not_specific> | def decompose_vector(self, queue, vector, plus, minus, lng,
*, times_abs_k=False):
"""
Decomposes a vector field into its two transverse polarizations and
longitudinal component.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg vector: The arr... |
Decomposes a vector field into its two transverse polarizations and
longitudinal component.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg vector: The array whose polarization
components will be computed.
Must have shape ``(3,)+k_shape``, where ``k_... | Decomposes a vector field into its two transverse polarizations and
longitudinal component. | [
"Decomposes",
"a",
"vector",
"field",
"into",
"its",
"two",
"transverse",
"polarizations",
"and",
"longitudinal",
"component",
"."
] | def decompose_vector(self, queue, vector, plus, minus, lng,
*, times_abs_k=False):
if not times_abs_k:
evt, _ = self.vec_decomp_knl(
queue, **self.eff_mom, lng=lng, vector=vector,
plus=plus, minus=minus
)
else:
... | [
"def",
"decompose_vector",
"(",
"self",
",",
"queue",
",",
"vector",
",",
"plus",
",",
"minus",
",",
"lng",
",",
"*",
",",
"times_abs_k",
"=",
"False",
")",
":",
"if",
"not",
"times_abs_k",
":",
"evt",
",",
"_",
"=",
"self",
".",
"vec_decomp_knl",
"(... | Decomposes a vector field into its two transverse polarizations and
longitudinal component. | [
"Decomposes",
"a",
"vector",
"field",
"into",
"its",
"two",
"transverse",
"polarizations",
"and",
"longitudinal",
"component",
"."
] | [
"\"\"\"\r\n Decomposes a vector field into its two transverse polarizations and\r\n longitudinal component.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg vector: The array whose polarization\r\n components will be computed.\r\n Must have shape `... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "vector",
"type": null
},
{
"param": "plus",
"type": null
},
{
"param": "minus",
"type": null
},
{
"param": "lng",
"type": null
},
{
"param": "times_abs_k",
... | {
"returns": [
{
"docstring": "The :class:`pyopencl.Event` associated with the kernel invocation.",
"docstring_tokens": [
"The",
":",
"class",
":",
"`",
"pyopencl",
".",
"Event",
"`",
"associated",
"with",
... |
46c229ed222c98cb727ba27dccbfd3e831bb211c | zachjweiner/pystella | pystella/fourier/projectors.py | [
"MIT"
] | Python | transverse_traceless | <not_specific> | def transverse_traceless(self, queue, hij, hij_TT=None):
"""
Projects a tensor field to be transverse and traceless.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg hij: The array containing the
momentum-space tensor field to be projected.
Must have s... |
Projects a tensor field to be transverse and traceless.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg hij: The array containing the
momentum-space tensor field to be projected.
Must have shape ``(6,)+k_shape``, where
``k_shape`` is the shape of... | Projects a tensor field to be transverse and traceless. | [
"Projects",
"a",
"tensor",
"field",
"to",
"be",
"transverse",
"and",
"traceless",
"."
] | def transverse_traceless(self, queue, hij, hij_TT=None):
if hij_TT is None:
hij_TT = hij
evt, _ = self.tt_knl(queue, hij=hij, hij_TT=hij_TT, **self.eff_mom)
return evt | [
"def",
"transverse_traceless",
"(",
"self",
",",
"queue",
",",
"hij",
",",
"hij_TT",
"=",
"None",
")",
":",
"if",
"hij_TT",
"is",
"None",
":",
"hij_TT",
"=",
"hij",
"evt",
",",
"_",
"=",
"self",
".",
"tt_knl",
"(",
"queue",
",",
"hij",
"=",
"hij",
... | Projects a tensor field to be transverse and traceless. | [
"Projects",
"a",
"tensor",
"field",
"to",
"be",
"transverse",
"and",
"traceless",
"."
] | [
"\"\"\"\r\n Projects a tensor field to be transverse and traceless.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg hij: The array containing the\r\n momentum-space tensor field to be projected.\r\n Must have shape ``(6,)+k_shape``, where\r\n ... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "hij",
"type": null
},
{
"param": "hij_TT",
"type": null
}
] | {
"returns": [
{
"docstring": "The :class:`pyopencl.Event` associated with the kernel invocation.",
"docstring_tokens": [
"The",
":",
"class",
":",
"`",
"pyopencl",
".",
"Event",
"`",
"associated",
"with",
... |
46c229ed222c98cb727ba27dccbfd3e831bb211c | zachjweiner/pystella | pystella/fourier/projectors.py | [
"MIT"
] | Python | tensor_to_pol | <not_specific> | def tensor_to_pol(self, queue, plus, minus, hij):
"""
Projects the components of a rank-2 tensor field onto the basis of plus and
minus polarizations.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg plus: The array into which will be stored the
momentum-s... |
Projects the components of a rank-2 tensor field onto the basis of plus and
minus polarizations.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg plus: The array into which will be stored the
momentum-space field of the plus polarization.
:arg minus: Th... | Projects the components of a rank-2 tensor field onto the basis of plus and
minus polarizations. | [
"Projects",
"the",
"components",
"of",
"a",
"rank",
"-",
"2",
"tensor",
"field",
"onto",
"the",
"basis",
"of",
"plus",
"and",
"minus",
"polarizations",
"."
] | def tensor_to_pol(self, queue, plus, minus, hij):
evt, _ = self.tensor_to_pol_knl(queue, **self.eff_mom,
hij=hij, plus=plus, minus=minus)
return evt | [
"def",
"tensor_to_pol",
"(",
"self",
",",
"queue",
",",
"plus",
",",
"minus",
",",
"hij",
")",
":",
"evt",
",",
"_",
"=",
"self",
".",
"tensor_to_pol_knl",
"(",
"queue",
",",
"**",
"self",
".",
"eff_mom",
",",
"hij",
"=",
"hij",
",",
"plus",
"=",
... | Projects the components of a rank-2 tensor field onto the basis of plus and
minus polarizations. | [
"Projects",
"the",
"components",
"of",
"a",
"rank",
"-",
"2",
"tensor",
"field",
"onto",
"the",
"basis",
"of",
"plus",
"and",
"minus",
"polarizations",
"."
] | [
"\"\"\"\r\n Projects the components of a rank-2 tensor field onto the basis of plus and\r\n minus polarizations.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg plus: The array into which will be stored the\r\n momentum-space field of the plus polarization.\... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "plus",
"type": null
},
{
"param": "minus",
"type": null
},
{
"param": "hij",
"type": null
}
] | {
"returns": [
{
"docstring": "The :class:`pyopencl.Event` associated with the kernel invocation.",
"docstring_tokens": [
"The",
":",
"class",
":",
"`",
"pyopencl",
".",
"Event",
"`",
"associated",
"with",
... |
46c229ed222c98cb727ba27dccbfd3e831bb211c | zachjweiner/pystella | pystella/fourier/projectors.py | [
"MIT"
] | Python | pol_to_tensor | <not_specific> | def pol_to_tensor(self, queue, plus, minus, hij):
"""
Projects the plus and minus polarizations of a rank-2 tensor field onto its
tensor components.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg plus: The array into which will be stored the
momentum-spa... |
Projects the plus and minus polarizations of a rank-2 tensor field onto its
tensor components.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg plus: The array into which will be stored the
momentum-space field of the plus polarization.
:arg minus: The ... | Projects the plus and minus polarizations of a rank-2 tensor field onto its
tensor components. | [
"Projects",
"the",
"plus",
"and",
"minus",
"polarizations",
"of",
"a",
"rank",
"-",
"2",
"tensor",
"field",
"onto",
"its",
"tensor",
"components",
"."
] | def pol_to_tensor(self, queue, plus, minus, hij):
evt, _ = self.pol_to_tensor_knl(queue, **self.eff_mom,
hij=hij, plus=plus, minus=minus)
return evt | [
"def",
"pol_to_tensor",
"(",
"self",
",",
"queue",
",",
"plus",
",",
"minus",
",",
"hij",
")",
":",
"evt",
",",
"_",
"=",
"self",
".",
"pol_to_tensor_knl",
"(",
"queue",
",",
"**",
"self",
".",
"eff_mom",
",",
"hij",
"=",
"hij",
",",
"plus",
"=",
... | Projects the plus and minus polarizations of a rank-2 tensor field onto its
tensor components. | [
"Projects",
"the",
"plus",
"and",
"minus",
"polarizations",
"of",
"a",
"rank",
"-",
"2",
"tensor",
"field",
"onto",
"its",
"tensor",
"components",
"."
] | [
"\"\"\"\r\n Projects the plus and minus polarizations of a rank-2 tensor field onto its\r\n tensor components.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg plus: The array into which will be stored the\r\n momentum-space field of the plus polarization.\r\... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "plus",
"type": null
},
{
"param": "minus",
"type": null
},
{
"param": "hij",
"type": null
}
] | {
"returns": [
{
"docstring": "The :class:`pyopencl.Event` associated with the kernel invocation.",
"docstring_tokens": [
"The",
":",
"class",
":",
"`",
"pyopencl",
".",
"Event",
"`",
"associated",
"with",
... |
f90352419cf011537879d1ad4c80bbb1ce4f9775 | zachjweiner/pystella | pystella/fourier/derivs.py | [
"MIT"
] | Python | divergence | <not_specific> | def divergence(self, queue, vec, div, allocator=None):
"""
Computes the divergence of the input ``vec``.
Provides the same interface as
:meth:`pystella.FiniteDifferencer.divergence`, while additionally accepting
the following arguments:
:arg allocator: A :mod:`pyopencl` ... |
Computes the divergence of the input ``vec``.
Provides the same interface as
:meth:`pystella.FiniteDifferencer.divergence`, while additionally accepting
the following arguments:
:arg allocator: A :mod:`pyopencl` allocator used to allocate temporary
arrays, i.e., mos... | Computes the divergence of the input ``vec``.
Provides the same interface as | [
"Computes",
"the",
"divergence",
"of",
"the",
"input",
"`",
"`",
"vec",
"`",
"`",
".",
"Provides",
"the",
"same",
"interface",
"as"
] | def divergence(self, queue, vec, div, allocator=None):
from itertools import product
slices = list(product(*[range(n) for n in vec.shape[:-4]]))
for s in slices:
arguments = {"queue": queue, **self.momenta, "allocator": allocator}
fk = self.fft.dft(vec[s][0])
... | [
"def",
"divergence",
"(",
"self",
",",
"queue",
",",
"vec",
",",
"div",
",",
"allocator",
"=",
"None",
")",
":",
"from",
"itertools",
"import",
"product",
"slices",
"=",
"list",
"(",
"product",
"(",
"*",
"[",
"range",
"(",
"n",
")",
"for",
"n",
"in... | Computes the divergence of the input ``vec``. | [
"Computes",
"the",
"divergence",
"of",
"the",
"input",
"`",
"`",
"vec",
"`",
"`",
"."
] | [
"\"\"\"\n Computes the divergence of the input ``vec``.\n Provides the same interface as\n :meth:`pystella.FiniteDifferencer.divergence`, while additionally accepting\n the following arguments:\n\n :arg allocator: A :mod:`pyopencl` allocator used to allocate temporary\n ... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "vec",
"type": null
},
{
"param": "div",
"type": null
},
{
"param": "allocator",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "queue",
"type": null,
"docstring": null,
"docstring_tokens": ... |
bf05a43c06190b1af3885b87e79e7f0674752081 | zachjweiner/pystella | pystella/derivs.py | [
"MIT"
] | Python | expand_stencil | <not_specific> | def expand_stencil(f, coefs):
"""
Expands a stencil over a field.
:arg f: A :class:`~pystella.Field`.
:arg coefs: A :class:`dict` whose values are the coefficients of the stencil
at an offset given by the key. The keys must be 3-:class:`tuple`\\ s, and the
values may be :mod:`p... |
Expands a stencil over a field.
:arg f: A :class:`~pystella.Field`.
:arg coefs: A :class:`dict` whose values are the coefficients of the stencil
at an offset given by the key. The keys must be 3-:class:`tuple`\\ s, and the
values may be :mod:`pymbolic` expressions or constants.
... | Expands a stencil over a field. | [
"Expands",
"a",
"stencil",
"over",
"a",
"field",
"."
] | def expand_stencil(f, coefs):
return sum([c * shift_fields(f, shift=offset) for offset, c in coefs.items()]) | [
"def",
"expand_stencil",
"(",
"f",
",",
"coefs",
")",
":",
"return",
"sum",
"(",
"[",
"c",
"*",
"shift_fields",
"(",
"f",
",",
"shift",
"=",
"offset",
")",
"for",
"offset",
",",
"c",
"in",
"coefs",
".",
"items",
"(",
")",
"]",
")"
] | Expands a stencil over a field. | [
"Expands",
"a",
"stencil",
"over",
"a",
"field",
"."
] | [
"\"\"\"\r\n Expands a stencil over a field.\r\n\r\n :arg f: A :class:`~pystella.Field`.\r\n\r\n :arg coefs: A :class:`dict` whose values are the coefficients of the stencil\r\n at an offset given by the key. The keys must be 3-:class:`tuple`\\\\ s, and the\r\n values may be :mod:`pymbolic` ex... | [
{
"param": "f",
"type": null
},
{
"param": "coefs",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "f",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"is_optional": null
},
{
"identifier": "coefs",
"type": null,
"docstring": "A :class:`di... |
bf05a43c06190b1af3885b87e79e7f0674752081 | zachjweiner/pystella | pystella/derivs.py | [
"MIT"
] | Python | centered_diff | <not_specific> | def centered_diff(f, coefs, direction, order):
"""
A convenience wrapper to :func:`expand_stencil` for computing centered
differences. By assuming the symmetry of the stencil (which has parity given
by the parity of ``order``), no redundant coefficients need to be supplied.
Further, by supplyin... |
A convenience wrapper to :func:`expand_stencil` for computing centered
differences. By assuming the symmetry of the stencil (which has parity given
by the parity of ``order``), no redundant coefficients need to be supplied.
Further, by supplying the ``direction`` parameter, the input offset (the ke... | A convenience wrapper to :func:`expand_stencil` for computing centered
differences. By assuming the symmetry of the stencil (which has parity given
by the parity of ``order``), no redundant coefficients need to be supplied. | [
"A",
"convenience",
"wrapper",
"to",
":",
"func",
":",
"`",
"expand_stencil",
"`",
"for",
"computing",
"centered",
"differences",
".",
"By",
"assuming",
"the",
"symmetry",
"of",
"the",
"stencil",
"(",
"which",
"has",
"parity",
"given",
"by",
"the",
"parity",... | def centered_diff(f, coefs, direction, order):
all_coefs = {}
for s, c in coefs.items():
offset = [0, 0, 0]
if s != 0 or order % 2 == 0:
offset[direction-1] = s
all_coefs[tuple(offset)] = c
if s != 0:
offset[direction-1] = - s
all_coefs[tup... | [
"def",
"centered_diff",
"(",
"f",
",",
"coefs",
",",
"direction",
",",
"order",
")",
":",
"all_coefs",
"=",
"{",
"}",
"for",
"s",
",",
"c",
"in",
"coefs",
".",
"items",
"(",
")",
":",
"offset",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
"if",
"s... | A convenience wrapper to :func:`expand_stencil` for computing centered
differences. | [
"A",
"convenience",
"wrapper",
"to",
":",
"func",
":",
"`",
"expand_stencil",
"`",
"for",
"computing",
"centered",
"differences",
"."
] | [
"\"\"\"\r\n A convenience wrapper to :func:`expand_stencil` for computing centered\r\n differences. By assuming the symmetry of the stencil (which has parity given\r\n by the parity of ``order``), no redundant coefficients need to be supplied.\r\n Further, by supplying the ``direction`` parameter, the i... | [
{
"param": "f",
"type": null
},
{
"param": "coefs",
"type": null
},
{
"param": "direction",
"type": null
},
{
"param": "order",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "f",
"type": null,
"docstring": null,
"docstring_tokens": [
"None"
],
"default": null,
"is_optional": null
},
{
"identifier": "coefs",
"type": null,
"docstring": "A :class:`di... |
d95da801becce664632c401beceed55e273f0d2f | zachjweiner/pystella | pystella/fourier/spectra.py | [
"MIT"
] | Python | polarization | <not_specific> | def polarization(self, vector, projector, queue=None, k_power=3, allocator=None):
"""
Computes the power spectra of the plus and minus polarizations of a vector
field.
:arg vector: The array containing the position-space vector field
whose power spectrum is to be compu... |
Computes the power spectra of the plus and minus polarizations of a vector
field.
:arg vector: The array containing the position-space vector field
whose power spectrum is to be computed.
If ``vector`` has more than four axes, all the outer axes are
l... | Computes the power spectra of the plus and minus polarizations of a vector
field. | [
"Computes",
"the",
"power",
"spectra",
"of",
"the",
"plus",
"and",
"minus",
"polarizations",
"of",
"a",
"vector",
"field",
"."
] | def polarization(self, vector, projector, queue=None, k_power=3, allocator=None):
queue = queue or vector.queue
vec_k = cla.empty(queue, (3,)+self.kshape, self.cdtype, allocator=None)
plus = vec_k[0]
minus = vec_k[1]
outer_shape = vector.shape[:-4]
from itertools import p... | [
"def",
"polarization",
"(",
"self",
",",
"vector",
",",
"projector",
",",
"queue",
"=",
"None",
",",
"k_power",
"=",
"3",
",",
"allocator",
"=",
"None",
")",
":",
"queue",
"=",
"queue",
"or",
"vector",
".",
"queue",
"vec_k",
"=",
"cla",
".",
"empty",... | Computes the power spectra of the plus and minus polarizations of a vector
field. | [
"Computes",
"the",
"power",
"spectra",
"of",
"the",
"plus",
"and",
"minus",
"polarizations",
"of",
"a",
"vector",
"field",
"."
] | [
"\"\"\"\r\n Computes the power spectra of the plus and minus polarizations of a vector\r\n field.\r\n\r\n :arg vector: The array containing the position-space vector field\r\n whose power spectrum is to be computed.\r\n If ``vector`` has more than four axes, all the outer ... | [
{
"param": "self",
"type": null
},
{
"param": "vector",
"type": null
},
{
"param": "projector",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "k_power",
"type": null
},
{
"param": "allocator",
"type": null
}
] | {
"returns": [
{
"docstring": "A :class:`numpy.ndarray` containing the polarization spectra\nwith shape ``vector.shape[:-4]+(2, num_bins)``.",
"docstring_tokens": [
"A",
":",
"class",
":",
"`",
"numpy",
".",
"ndarray",
"`",
... |
d95da801becce664632c401beceed55e273f0d2f | zachjweiner/pystella | pystella/fourier/spectra.py | [
"MIT"
] | Python | vector_decomposition | <not_specific> | def vector_decomposition(self, vector, projector, queue=None, k_power=3,
allocator=None):
"""
Computes the power spectra of the plus and minus polarizations and
longitudinal component of a vector field.
:arg vector: The array containing the position-sp... |
Computes the power spectra of the plus and minus polarizations and
longitudinal component of a vector field.
:arg vector: The array containing the position-space vector field
whose power spectrum is to be computed.
If ``vector`` has more than four axes, all the ou... | Computes the power spectra of the plus and minus polarizations and
longitudinal component of a vector field. | [
"Computes",
"the",
"power",
"spectra",
"of",
"the",
"plus",
"and",
"minus",
"polarizations",
"and",
"longitudinal",
"component",
"of",
"a",
"vector",
"field",
"."
] | def vector_decomposition(self, vector, projector, queue=None, k_power=3,
allocator=None):
queue = queue or vector.queue
vec_k = cla.empty(queue, (3,)+self.kshape, self.cdtype, allocator=None)
plus = vec_k[0]
minus = vec_k[1]
lng = vec_k[2]
out... | [
"def",
"vector_decomposition",
"(",
"self",
",",
"vector",
",",
"projector",
",",
"queue",
"=",
"None",
",",
"k_power",
"=",
"3",
",",
"allocator",
"=",
"None",
")",
":",
"queue",
"=",
"queue",
"or",
"vector",
".",
"queue",
"vec_k",
"=",
"cla",
".",
... | Computes the power spectra of the plus and minus polarizations and
longitudinal component of a vector field. | [
"Computes",
"the",
"power",
"spectra",
"of",
"the",
"plus",
"and",
"minus",
"polarizations",
"and",
"longitudinal",
"component",
"of",
"a",
"vector",
"field",
"."
] | [
"\"\"\"\r\n Computes the power spectra of the plus and minus polarizations and\r\n longitudinal component of a vector field.\r\n\r\n :arg vector: The array containing the position-space vector field\r\n whose power spectrum is to be computed.\r\n If ``vector`` has more tha... | [
{
"param": "self",
"type": null
},
{
"param": "vector",
"type": null
},
{
"param": "projector",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "k_power",
"type": null
},
{
"param": "allocator",
"type": null
}
] | {
"returns": [
{
"docstring": "A :class:`numpy.ndarray` containing the polarization and\nlongitudinal spectra with shape ``vector.shape[:-4]+(3, num_bins)``.",
"docstring_tokens": [
"A",
":",
"class",
":",
"`",
"numpy",
".",
"ndarray",
... |
d95da801becce664632c401beceed55e273f0d2f | zachjweiner/pystella | pystella/fourier/spectra.py | [
"MIT"
] | Python | gw_polarization | <not_specific> | def gw_polarization(self, hij, projector, hubble, queue=None, k_power=3,
allocator=None):
"""
Computes the polarization components of the present gravitational wave
power spectrum.
.. math::
\\Delta_{h_\\lambda}^2(k)
= \\frac{1}{... |
Computes the polarization components of the present gravitational wave
power spectrum.
.. math::
\\Delta_{h_\\lambda}^2(k)
= \\frac{1}{24 \\pi^{2} \\mathcal{H}^{2}}
\\frac{1}{V}
\\int \\mathrm{d} \\Omega \\,
\\l... | Computes the polarization components of the present gravitational wave
power spectrum.
| [
"Computes",
"the",
"polarization",
"components",
"of",
"the",
"present",
"gravitational",
"wave",
"power",
"spectrum",
"."
] | def gw_polarization(self, hij, projector, hubble, queue=None, k_power=3,
allocator=None):
queue = queue or hij.queue
hij_k = cla.empty(queue, (6,)+self.kshape, self.cdtype, allocator=None)
plus = hij_k[0]
minus = hij_k[1]
for mu in range(6):
se... | [
"def",
"gw_polarization",
"(",
"self",
",",
"hij",
",",
"projector",
",",
"hubble",
",",
"queue",
"=",
"None",
",",
"k_power",
"=",
"3",
",",
"allocator",
"=",
"None",
")",
":",
"queue",
"=",
"queue",
"or",
"hij",
".",
"queue",
"hij_k",
"=",
"cla",
... | Computes the polarization components of the present gravitational wave
power spectrum. | [
"Computes",
"the",
"polarization",
"components",
"of",
"the",
"present",
"gravitational",
"wave",
"power",
"spectrum",
"."
] | [
"\"\"\"\r\n Computes the polarization components of the present gravitational wave\r\n power spectrum.\r\n\r\n .. math::\r\n\r\n \\\\Delta_{h_\\\\lambda}^2(k)\r\n = \\\\frac{1}{24 \\\\pi^{2} \\\\mathcal{H}^{2}}\r\n \\\\frac{1}{V}\r\n \\\\int \... | [
{
"param": "self",
"type": null
},
{
"param": "hij",
"type": null
},
{
"param": "projector",
"type": null
},
{
"param": "hubble",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "k_power",
"type": null
},
{
"param": "allocato... | {
"returns": [
{
"docstring": "A :class:`numpy.ndarray` containing\n:math:`\\\\Delta_{h_\\\\lambda}^2(k)` with shape ``(2, num_bins)``.\n\n",
"docstring_tokens": [
"A",
":",
"class",
":",
"`",
"numpy",
".",
"ndarray",
"`",
... |
a398594b6957b5517ca1ea7eb407828a425cdc3c | zachjweiner/pystella | pystella/field/__init__.py | [
"MIT"
] | Python | index_fields | <not_specific> | def index_fields(expr, prepend_with=None):
"""
Appends subscripts to :class:`Field`
instances in an expression, turning them into ordinary
:class:`pymbolic.primitives.Subscript`\\ s.
See the documentation of :class:`Field` for examples.
:arg expr: The expression(s) to be mapped.
:arg prepe... |
Appends subscripts to :class:`Field`
instances in an expression, turning them into ordinary
:class:`pymbolic.primitives.Subscript`\\ s.
See the documentation of :class:`Field` for examples.
:arg expr: The expression(s) to be mapped.
:arg prepend_with: A :class:`tuple` of indices to prepend to... | Appends subscripts to :class:`Field`
instances in an expression, turning them into ordinary | [
"Appends",
"subscripts",
"to",
":",
"class",
":",
"`",
"Field",
"`",
"instances",
"in",
"an",
"expression",
"turning",
"them",
"into",
"ordinary"
] | def index_fields(expr, prepend_with=None):
return IndexMapper()(expr, prepend_with=prepend_with) | [
"def",
"index_fields",
"(",
"expr",
",",
"prepend_with",
"=",
"None",
")",
":",
"return",
"IndexMapper",
"(",
")",
"(",
"expr",
",",
"prepend_with",
"=",
"prepend_with",
")"
] | Appends subscripts to :class:`Field`
instances in an expression, turning them into ordinary | [
"Appends",
"subscripts",
"to",
":",
"class",
":",
"`",
"Field",
"`",
"instances",
"in",
"an",
"expression",
"turning",
"them",
"into",
"ordinary"
] | [
"\"\"\"\n Appends subscripts to :class:`Field`\n instances in an expression, turning them into ordinary\n :class:`pymbolic.primitives.Subscript`\\\\ s.\n See the documentation of :class:`Field` for examples.\n\n :arg expr: The expression(s) to be mapped.\n\n :arg prepend_with: A :class:`tuple` of ... | [
{
"param": "expr",
"type": null
},
{
"param": "prepend_with",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "expr",
"type": null,
"docstring": "The expression(s) to be mapped.",
"docstring_tokens": [
"The",
"expression",
"(",
"s",
")",
"to",
"be",
"mapped",
"."
... |
54bb285bfb72dced4f3b3bafdcaa7c403a102569 | zachjweiner/pystella | pystella/multigrid/__init__.py | [
"MIT"
] | Python | transfer_down | null | def transfer_down(self, queue, i):
"""
Transfers all arrays from a fine to the next-coarser level.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg i: The level from to transfer to.
"""
for key, f1 in self.unknowns[i-1].items():
f2 = self.unknow... |
Transfers all arrays from a fine to the next-coarser level.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg i: The level from to transfer to.
| Transfers all arrays from a fine to the next-coarser level. | [
"Transfers",
"all",
"arrays",
"from",
"a",
"fine",
"to",
"the",
"next",
"-",
"coarser",
"level",
"."
] | def transfer_down(self, queue, i):
for key, f1 in self.unknowns[i-1].items():
f2 = self.unknowns[i][key]
self.restrict(queue, f1=f1, f2=f2)
self.decomp[i].share_halos(queue, f2)
self.solver.residual(queue, **self.resid_args[i-1])
for key, r1 in self.resid[i-1]... | [
"def",
"transfer_down",
"(",
"self",
",",
"queue",
",",
"i",
")",
":",
"for",
"key",
",",
"f1",
"in",
"self",
".",
"unknowns",
"[",
"i",
"-",
"1",
"]",
".",
"items",
"(",
")",
":",
"f2",
"=",
"self",
".",
"unknowns",
"[",
"i",
"]",
"[",
"key"... | Transfers all arrays from a fine to the next-coarser level. | [
"Transfers",
"all",
"arrays",
"from",
"a",
"fine",
"to",
"the",
"next",
"-",
"coarser",
"level",
"."
] | [
"\"\"\"\r\n Transfers all arrays from a fine to the next-coarser level.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg i: The level from to transfer to.\r\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "i",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "queue",
"type": null,
"docstring": null,
"docstring_tokens": ... |
54bb285bfb72dced4f3b3bafdcaa7c403a102569 | zachjweiner/pystella | pystella/multigrid/__init__.py | [
"MIT"
] | Python | transfer_up | null | def transfer_up(self, queue, i):
"""
Transfers all arrays from a coarse to the next-finer level.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg i: The level from to transfer to.
"""
for k, f1 in self.unknowns[i].items():
f2 = self.unknowns[i+1... |
Transfers all arrays from a coarse to the next-finer level.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg i: The level from to transfer to.
| Transfers all arrays from a coarse to the next-finer level. | [
"Transfers",
"all",
"arrays",
"from",
"a",
"coarse",
"to",
"the",
"next",
"-",
"finer",
"level",
"."
] | def transfer_up(self, queue, i):
for k, f1 in self.unknowns[i].items():
f2 = self.unknowns[i+1][k]
self.restrict_and_correct(queue, f1=f1, f2=f2)
self.decomp[i+1].share_halos(queue, f2)
self.interpolate_and_correct(queue, f1=f1, f2=f2)
self.decomp[i].s... | [
"def",
"transfer_up",
"(",
"self",
",",
"queue",
",",
"i",
")",
":",
"for",
"k",
",",
"f1",
"in",
"self",
".",
"unknowns",
"[",
"i",
"]",
".",
"items",
"(",
")",
":",
"f2",
"=",
"self",
".",
"unknowns",
"[",
"i",
"+",
"1",
"]",
"[",
"k",
"]... | Transfers all arrays from a coarse to the next-finer level. | [
"Transfers",
"all",
"arrays",
"from",
"a",
"coarse",
"to",
"the",
"next",
"-",
"finer",
"level",
"."
] | [
"\"\"\"\r\n Transfers all arrays from a coarse to the next-finer level.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg i: The level from to transfer to.\r\n \"\"\""
] | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "i",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "queue",
"type": null,
"docstring": null,
"docstring_tokens": ... |
54bb285bfb72dced4f3b3bafdcaa7c403a102569 | zachjweiner/pystella | pystella/multigrid/__init__.py | [
"MIT"
] | Python | smooth | <not_specific> | def smooth(self, queue, i, nu):
"""
Invokes the relaxation solver, computing the error before and after.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg i: On which level to perform the smoothing.
:arg nu: The number of smoothing iterations to perform.
:r... |
Invokes the relaxation solver, computing the error before and after.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg i: On which level to perform the smoothing.
:arg nu: The number of smoothing iterations to perform.
:returns: A list containing the errors before ... | Invokes the relaxation solver, computing the error before and after. | [
"Invokes",
"the",
"relaxation",
"solver",
"computing",
"the",
"error",
"before",
"and",
"after",
"."
] | def smooth(self, queue, i, nu):
errs1 = self.solver.get_error(queue, **self.resid_args[i])
self.solver(self.decomp[i], queue, iterations=nu, **self.smooth_args[i])
errs2 = self.solver.get_error(queue, **self.resid_args[i])
return [(i, errs1), (i, errs2)] | [
"def",
"smooth",
"(",
"self",
",",
"queue",
",",
"i",
",",
"nu",
")",
":",
"errs1",
"=",
"self",
".",
"solver",
".",
"get_error",
"(",
"queue",
",",
"**",
"self",
".",
"resid_args",
"[",
"i",
"]",
")",
"self",
".",
"solver",
"(",
"self",
".",
"... | Invokes the relaxation solver, computing the error before and after. | [
"Invokes",
"the",
"relaxation",
"solver",
"computing",
"the",
"error",
"before",
"and",
"after",
"."
] | [
"\"\"\"\r\n Invokes the relaxation solver, computing the error before and after.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg i: On which level to perform the smoothing.\r\n\r\n :arg nu: The number of smoothing iterations to perform.\r\n\r\n :returns: A list ... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "i",
"type": null
},
{
"param": "nu",
"type": null
}
] | {
"returns": [
{
"docstring": "A list containing the errors before and after of the form\n``[(i, error_before), (i, error_after)]``.",
"docstring_tokens": [
"A",
"list",
"containing",
"the",
"errors",
"before",
"and",
"after",
"of... |
b01eae5ffdab7b64545153c571c4146485c4a9d0 | zachjweiner/pystella | pystella/fourier/rayleigh.py | [
"MIT"
] | Python | generate | <not_specific> | def generate(self, queue, random=True, field_ps=lambda kmag: 1/2/kmag,
norm=1, window=lambda kmag: 1.):
"""
Generate a 3-D array of Fourier modes with a given power spectrum and
random phases.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg random: W... |
Generate a 3-D array of Fourier modes with a given power spectrum and
random phases.
:arg queue: A :class:`pyopencl.CommandQueue`.
:arg random: Whether to randomly sample the Rayleigh distribution
of mode amplitudes.
Defaults to *True*.
:arg ... | Generate a 3-D array of Fourier modes with a given power spectrum and
random phases. | [
"Generate",
"a",
"3",
"-",
"D",
"array",
"of",
"Fourier",
"modes",
"with",
"a",
"given",
"power",
"spectrum",
"and",
"random",
"phases",
"."
] | def generate(self, queue, random=True, field_ps=lambda kmag: 1/2/kmag,
norm=1, window=lambda kmag: 1.):
amplitude_sq = norm / self.volume
rands = self.rng.uniform(queue, (2,)+self.kmags.shape, self.rdtype)
if not random:
rands[0] = np.exp(-1)
f_power = (ampli... | [
"def",
"generate",
"(",
"self",
",",
"queue",
",",
"random",
"=",
"True",
",",
"field_ps",
"=",
"lambda",
"kmag",
":",
"1",
"/",
"2",
"/",
"kmag",
",",
"norm",
"=",
"1",
",",
"window",
"=",
"lambda",
"kmag",
":",
"1.",
")",
":",
"amplitude_sq",
"... | Generate a 3-D array of Fourier modes with a given power spectrum and
random phases. | [
"Generate",
"a",
"3",
"-",
"D",
"array",
"of",
"Fourier",
"modes",
"with",
"a",
"given",
"power",
"spectrum",
"and",
"random",
"phases",
"."
] | [
"\"\"\"\r\n Generate a 3-D array of Fourier modes with a given power spectrum and\r\n random phases.\r\n\r\n :arg queue: A :class:`pyopencl.CommandQueue`.\r\n\r\n :arg random: Whether to randomly sample the Rayleigh distribution\r\n of mode amplitudes.\r\n Defaults ... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "random",
"type": null
},
{
"param": "field_ps",
"type": null
},
{
"param": "norm",
"type": null
},
{
"param": "window",
"type": null
}
] | {
"returns": [
{
"docstring": "An :class:`numpy.ndarray` containing the generated Fourier modes\nof the field.",
"docstring_tokens": [
"An",
":",
"class",
":",
"`",
"numpy",
".",
"ndarray",
"`",
"containing",
"the"... |
b01eae5ffdab7b64545153c571c4146485c4a9d0 | zachjweiner/pystella | pystella/fourier/rayleigh.py | [
"MIT"
] | Python | init_field | null | def init_field(self, fx, queue=None, **kwargs):
"""
A wrapper which calls :meth:`generate` to initialize a field
in Fourier space and returns its inverse Fourier transform.
:arg fx: The array in which the field will be stored.
The following keyword arguments are recogniz... |
A wrapper which calls :meth:`generate` to initialize a field
in Fourier space and returns its inverse Fourier transform.
:arg fx: The array in which the field will be stored.
The following keyword arguments are recognized:
:arg queue: A :class:`pyopencl.CommandQueue`.... | A wrapper which calls :meth:`generate` to initialize a field
in Fourier space and returns its inverse Fourier transform. | [
"A",
"wrapper",
"which",
"calls",
":",
"meth",
":",
"`",
"generate",
"`",
"to",
"initialize",
"a",
"field",
"in",
"Fourier",
"space",
"and",
"returns",
"its",
"inverse",
"Fourier",
"transform",
"."
] | def init_field(self, fx, queue=None, **kwargs):
queue = queue or fx.queue
fk = self.generate(queue, **kwargs)
self.fft.idft(fk, fx) | [
"def",
"init_field",
"(",
"self",
",",
"fx",
",",
"queue",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"queue",
"=",
"queue",
"or",
"fx",
".",
"queue",
"fk",
"=",
"self",
".",
"generate",
"(",
"queue",
",",
"**",
"kwargs",
")",
"self",
".",
"fft"... | A wrapper which calls :meth:`generate` to initialize a field
in Fourier space and returns its inverse Fourier transform. | [
"A",
"wrapper",
"which",
"calls",
":",
"meth",
":",
"`",
"generate",
"`",
"to",
"initialize",
"a",
"field",
"in",
"Fourier",
"space",
"and",
"returns",
"its",
"inverse",
"Fourier",
"transform",
"."
] | [
"\"\"\"\r\n A wrapper which calls :meth:`generate` to initialize a field\r\n in Fourier space and returns its inverse Fourier transform.\r\n\r\n :arg fx: The array in which the field will be stored.\r\n\r\n The following keyword arguments are recognized:\r\n\r\n :arg queue: A :cla... | [
{
"param": "self",
"type": null
},
{
"param": "fx",
"type": null
},
{
"param": "queue",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "fx",
"type": null,
"docstring": "The array in which the field will ... |
b01eae5ffdab7b64545153c571c4146485c4a9d0 | zachjweiner/pystella | pystella/fourier/rayleigh.py | [
"MIT"
] | Python | init_transverse_vector | null | def init_transverse_vector(self, projector, vector, queue=None, **kwargs):
"""
A wrapper which calls :meth:`generate` to initialize a transverse
three-vector field in Fourier space and returns its inverse Fourier
transform.
Each component will have the same power spectrum.
... |
A wrapper which calls :meth:`generate` to initialize a transverse
three-vector field in Fourier space and returns its inverse Fourier
transform.
Each component will have the same power spectrum.
:arg projector: A :class:`Projector` used to project out
longitu... | A wrapper which calls :meth:`generate` to initialize a transverse
three-vector field in Fourier space and returns its inverse Fourier
transform.
Each component will have the same power spectrum. | [
"A",
"wrapper",
"which",
"calls",
":",
"meth",
":",
"`",
"generate",
"`",
"to",
"initialize",
"a",
"transverse",
"three",
"-",
"vector",
"field",
"in",
"Fourier",
"space",
"and",
"returns",
"its",
"inverse",
"Fourier",
"transform",
".",
"Each",
"component",
... | def init_transverse_vector(self, projector, vector, queue=None, **kwargs):
queue = queue or vector.queue
vector_k = cla.empty(queue, (3,)+self.fft.shape(True), self.cdtype)
for mu in range(3):
fk = self.generate(queue, **kwargs)
vector_k[mu].set(fk)
projector.tran... | [
"def",
"init_transverse_vector",
"(",
"self",
",",
"projector",
",",
"vector",
",",
"queue",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"queue",
"=",
"queue",
"or",
"vector",
".",
"queue",
"vector_k",
"=",
"cla",
".",
"empty",
"(",
"queue",
",",
"(",
... | A wrapper which calls :meth:`generate` to initialize a transverse
three-vector field in Fourier space and returns its inverse Fourier
transform. | [
"A",
"wrapper",
"which",
"calls",
":",
"meth",
":",
"`",
"generate",
"`",
"to",
"initialize",
"a",
"transverse",
"three",
"-",
"vector",
"field",
"in",
"Fourier",
"space",
"and",
"returns",
"its",
"inverse",
"Fourier",
"transform",
"."
] | [
"\"\"\"\r\n A wrapper which calls :meth:`generate` to initialize a transverse\r\n three-vector field in Fourier space and returns its inverse Fourier\r\n transform.\r\n Each component will have the same power spectrum.\r\n\r\n :arg projector: A :class:`Projector` used to project o... | [
{
"param": "self",
"type": null
},
{
"param": "projector",
"type": null
},
{
"param": "vector",
"type": null
},
{
"param": "queue",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "projector",
"type": null,
"docstring": "A :class:`Projector` used t... |
b01eae5ffdab7b64545153c571c4146485c4a9d0 | zachjweiner/pystella | pystella/fourier/rayleigh.py | [
"MIT"
] | Python | init_vector_from_pol | null | def init_vector_from_pol(self, projector, vector, plus_ps, minus_ps,
queue=None, **kwargs):
"""
A wrapper which calls :meth:`generate` to initialize a transverse
three-vector field in Fourier space and returns its inverse Fourier
transform.
In c... |
A wrapper which calls :meth:`generate` to initialize a transverse
three-vector field in Fourier space and returns its inverse Fourier
transform.
In contrast to :meth:`init_transverse_vector`, modes are generated
for the plus and minus polarizations of the vector field, from... | A wrapper which calls :meth:`generate` to initialize a transverse
three-vector field in Fourier space and returns its inverse Fourier
transform.
In contrast to :meth:`init_transverse_vector`, modes are generated
for the plus and minus polarizations of the vector field, from which
the vector field itself is constructed. | [
"A",
"wrapper",
"which",
"calls",
":",
"meth",
":",
"`",
"generate",
"`",
"to",
"initialize",
"a",
"transverse",
"three",
"-",
"vector",
"field",
"in",
"Fourier",
"space",
"and",
"returns",
"its",
"inverse",
"Fourier",
"transform",
".",
"In",
"contrast",
"... | def init_vector_from_pol(self, projector, vector, plus_ps, minus_ps,
queue=None, **kwargs):
queue = queue or vector.queue
fk = self.generate(queue, field_ps=plus_ps, **kwargs)
plus_k = cla.to_device(queue, fk)
fk = self.generate(queue, field_ps=minus_ps, **kw... | [
"def",
"init_vector_from_pol",
"(",
"self",
",",
"projector",
",",
"vector",
",",
"plus_ps",
",",
"minus_ps",
",",
"queue",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"queue",
"=",
"queue",
"or",
"vector",
".",
"queue",
"fk",
"=",
"self",
".",
"genera... | A wrapper which calls :meth:`generate` to initialize a transverse
three-vector field in Fourier space and returns its inverse Fourier
transform. | [
"A",
"wrapper",
"which",
"calls",
":",
"meth",
":",
"`",
"generate",
"`",
"to",
"initialize",
"a",
"transverse",
"three",
"-",
"vector",
"field",
"in",
"Fourier",
"space",
"and",
"returns",
"its",
"inverse",
"Fourier",
"transform",
"."
] | [
"\"\"\"\r\n A wrapper which calls :meth:`generate` to initialize a transverse\r\n three-vector field in Fourier space and returns its inverse Fourier\r\n transform.\r\n In contrast to :meth:`init_transverse_vector`, modes are generated\r\n for the plus and minus polarizations of t... | [
{
"param": "self",
"type": null
},
{
"param": "projector",
"type": null
},
{
"param": "vector",
"type": null
},
{
"param": "plus_ps",
"type": null
},
{
"param": "minus_ps",
"type": null
},
{
"param": "queue",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "projector",
"type": null,
"docstring": "A :class:`Projector` used t... |
b01eae5ffdab7b64545153c571c4146485c4a9d0 | zachjweiner/pystella | pystella/fourier/rayleigh.py | [
"MIT"
] | Python | generate_WKB | <not_specific> | def generate_WKB(self, queue, random=True,
field_ps=lambda wk: 1/2/wk,
norm=1, omega_k=lambda kmag: kmag,
hubble=0., window=lambda kmag: 1.):
"""
Generate a 3-D array of Fourier modes with a given power spectrum and
random phas... |
Generate a 3-D array of Fourier modes with a given power spectrum and
random phases, along with that of its time derivative
according to the WKB approximation (for Klein-Gordon fields in
conformal FLRW spacetime).
Arguments match those of :meth:`generate`, with the follow... | Generate a 3-D array of Fourier modes with a given power spectrum and
random phases, along with that of its time derivative
according to the WKB approximation (for Klein-Gordon fields in
conformal FLRW spacetime).
Arguments match those of :meth:`generate`, with the following
exceptions/additions. | [
"Generate",
"a",
"3",
"-",
"D",
"array",
"of",
"Fourier",
"modes",
"with",
"a",
"given",
"power",
"spectrum",
"and",
"random",
"phases",
"along",
"with",
"that",
"of",
"its",
"time",
"derivative",
"according",
"to",
"the",
"WKB",
"approximation",
"(",
"for... | def generate_WKB(self, queue, random=True,
field_ps=lambda wk: 1/2/wk,
norm=1, omega_k=lambda kmag: kmag,
hubble=0., window=lambda kmag: 1.):
amplitude_sq = norm / self.volume
kshape = self.kmags.shape
rands = self.rng.uniform(queue,... | [
"def",
"generate_WKB",
"(",
"self",
",",
"queue",
",",
"random",
"=",
"True",
",",
"field_ps",
"=",
"lambda",
"wk",
":",
"1",
"/",
"2",
"/",
"wk",
",",
"norm",
"=",
"1",
",",
"omega_k",
"=",
"lambda",
"kmag",
":",
"kmag",
",",
"hubble",
"=",
"0."... | Generate a 3-D array of Fourier modes with a given power spectrum and
random phases, along with that of its time derivative
according to the WKB approximation (for Klein-Gordon fields in
conformal FLRW spacetime). | [
"Generate",
"a",
"3",
"-",
"D",
"array",
"of",
"Fourier",
"modes",
"with",
"a",
"given",
"power",
"spectrum",
"and",
"random",
"phases",
"along",
"with",
"that",
"of",
"its",
"time",
"derivative",
"according",
"to",
"the",
"WKB",
"approximation",
"(",
"for... | [
"\"\"\"\r\n Generate a 3-D array of Fourier modes with a given power spectrum and\r\n random phases, along with that of its time derivative\r\n according to the WKB approximation (for Klein-Gordon fields in\r\n conformal FLRW spacetime).\r\n\r\n Arguments match those of :meth:`gen... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "random",
"type": null
},
{
"param": "field_ps",
"type": null
},
{
"param": "norm",
"type": null
},
{
"param": "omega_k",
"type": null
},
{
"param": "hubble",... | {
"returns": [
{
"docstring": "A tuple ``(fk, dfk)`` containing the generated Fourier modes\nof the field and its time derivative.",
"docstring_tokens": [
"A",
"tuple",
"`",
"`",
"(",
"fk",
"dfk",
")",
"`",
"`",
"c... |
b01eae5ffdab7b64545153c571c4146485c4a9d0 | zachjweiner/pystella | pystella/fourier/rayleigh.py | [
"MIT"
] | Python | init_WKB_fields | null | def init_WKB_fields(self, fx, dfx, queue=None, **kwargs):
"""
A wrapper which calls :meth:`generate_WKB` to initialize a field and
its time derivative in Fourier space and inverse Fourier transform
the results.
:arg fx: The array in which the field will be stored.
... |
A wrapper which calls :meth:`generate_WKB` to initialize a field and
its time derivative in Fourier space and inverse Fourier transform
the results.
:arg fx: The array in which the field will be stored.
:arg dfx: The array in which the field's time derivative will
... | A wrapper which calls :meth:`generate_WKB` to initialize a field and
its time derivative in Fourier space and inverse Fourier transform
the results. | [
"A",
"wrapper",
"which",
"calls",
":",
"meth",
":",
"`",
"generate_WKB",
"`",
"to",
"initialize",
"a",
"field",
"and",
"its",
"time",
"derivative",
"in",
"Fourier",
"space",
"and",
"inverse",
"Fourier",
"transform",
"the",
"results",
"."
] | def init_WKB_fields(self, fx, dfx, queue=None, **kwargs):
queue = queue or fx.queue
fk, dfk = self.generate_WKB(queue, **kwargs)
self.fft.idft(fk, fx)
self.fft.idft(dfk, dfx) | [
"def",
"init_WKB_fields",
"(",
"self",
",",
"fx",
",",
"dfx",
",",
"queue",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"queue",
"=",
"queue",
"or",
"fx",
".",
"queue",
"fk",
",",
"dfk",
"=",
"self",
".",
"generate_WKB",
"(",
"queue",
",",
"**",
... | A wrapper which calls :meth:`generate_WKB` to initialize a field and
its time derivative in Fourier space and inverse Fourier transform
the results. | [
"A",
"wrapper",
"which",
"calls",
":",
"meth",
":",
"`",
"generate_WKB",
"`",
"to",
"initialize",
"a",
"field",
"and",
"its",
"time",
"derivative",
"in",
"Fourier",
"space",
"and",
"inverse",
"Fourier",
"transform",
"the",
"results",
"."
] | [
"\"\"\"\r\n A wrapper which calls :meth:`generate_WKB` to initialize a field and\r\n its time derivative in Fourier space and inverse Fourier transform\r\n the results.\r\n\r\n :arg fx: The array in which the field will be stored.\r\n\r\n :arg dfx: The array in which the field's t... | [
{
"param": "self",
"type": null
},
{
"param": "fx",
"type": null
},
{
"param": "dfx",
"type": null
},
{
"param": "queue",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "fx",
"type": null,
"docstring": "The array in which the field will ... |
e99fb4d2e2e57292dfbfe876a35ce3f271f66b20 | zachjweiner/pystella | pystella/fourier/dft.py | [
"MIT"
] | Python | dft | <not_specific> | def dft(self, fx=None, fk=None, **kwargs):
"""
Computes the forward Fourier transform.
:arg fx: The array to be transformed.
Can be a :class:`pyopencl.array.Array` with or without halo padding
(which will be removed by
:meth:`pystella.DomainDecompositi... |
Computes the forward Fourier transform.
:arg fx: The array to be transformed.
Can be a :class:`pyopencl.array.Array` with or without halo padding
(which will be removed by
:meth:`pystella.DomainDecomposition.remove_halos`
if needed) or a :class:`n... | Computes the forward Fourier transform. | [
"Computes",
"the",
"forward",
"Fourier",
"transform",
"."
] | def dft(self, fx=None, fk=None, **kwargs):
if fx is not None:
if fx.shape != self.shape(False):
if isinstance(fx, cla.Array):
queue = fx.queue
elif isinstance(self.fx, cla.Array):
queue = self.fx.queue
else:
... | [
"def",
"dft",
"(",
"self",
",",
"fx",
"=",
"None",
",",
"fk",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"fx",
"is",
"not",
"None",
":",
"if",
"fx",
".",
"shape",
"!=",
"self",
".",
"shape",
"(",
"False",
")",
":",
"if",
"isinstance",
... | Computes the forward Fourier transform. | [
"Computes",
"the",
"forward",
"Fourier",
"transform",
"."
] | [
"\"\"\"\r\n Computes the forward Fourier transform.\r\n\r\n :arg fx: The array to be transformed.\r\n Can be a :class:`pyopencl.array.Array` with or without halo padding\r\n (which will be removed by\r\n :meth:`pystella.DomainDecomposition.remove_halos`\r\n ... | [
{
"param": "self",
"type": null
},
{
"param": "fx",
"type": null
},
{
"param": "fk",
"type": null
}
] | {
"returns": [
{
"docstring": "The forward Fourier transform of ``fx``.\nEither ``fk`` if supplied or :attr:`fk`.\n\nAny remaining keyword arguments are passed to :meth:`forward_transform`.\n\n:\nIf you need the result of multiple Fourier transforms at once, you must\neither supply an ``fk`` array or copy t... |
e99fb4d2e2e57292dfbfe876a35ce3f271f66b20 | zachjweiner/pystella | pystella/fourier/dft.py | [
"MIT"
] | Python | idft | <not_specific> | def idft(self, fk=None, fx=None, **kwargs):
"""
Computes the backward Fourier transform.
:arg fk: The array to be transformed.
Can be a :class:`pyopencl.array.Array` or a :class:`numpy.ndarray`.
Arrays are copied as necessary.
Defaults to *None*, in wh... |
Computes the backward Fourier transform.
:arg fk: The array to be transformed.
Can be a :class:`pyopencl.array.Array` or a :class:`numpy.ndarray`.
Arrays are copied as necessary.
Defaults to *None*, in which case :attr:`fk` (attached
to the transf... | Computes the backward Fourier transform. | [
"Computes",
"the",
"backward",
"Fourier",
"transform",
"."
] | def idft(self, fk=None, fx=None, **kwargs):
if fk is not None:
if not isinstance(fk, type(self.fk)):
_fk = _transfer_array(self.fk, fk)
else:
_fk = fk
else:
_fk = self.fk
if fx is not None:
if fx.shape == self.shape(... | [
"def",
"idft",
"(",
"self",
",",
"fk",
"=",
"None",
",",
"fx",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"fk",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"fk",
",",
"type",
"(",
"self",
".",
"fk",
")",
")",
":",
"_fk",
... | Computes the backward Fourier transform. | [
"Computes",
"the",
"backward",
"Fourier",
"transform",
"."
] | [
"\"\"\"\r\n Computes the backward Fourier transform.\r\n\r\n :arg fk: The array to be transformed.\r\n Can be a :class:`pyopencl.array.Array` or a :class:`numpy.ndarray`.\r\n Arrays are copied as necessary.\r\n Defaults to *None*, in which case :attr:`fk` (attached\r\n... | [
{
"param": "self",
"type": null
},
{
"param": "fk",
"type": null
},
{
"param": "fx",
"type": null
}
] | {
"returns": [
{
"docstring": "The forward Fourier transform of ``fx``.\nEither ``fk`` if supplied or :attr:`fk`.\n\nAny remaining keyword arguments are passed to :meth:`backward_transform`.\n\n:\nIf you need the result of multiple Fourier transforms at once, you must\neither supply an ``fx`` array or copy ... |
e99fb4d2e2e57292dfbfe876a35ce3f271f66b20 | zachjweiner/pystella | pystella/fourier/dft.py | [
"MIT"
] | Python | zero_corner_modes | <not_specific> | def zero_corner_modes(self, array, only_imag=False):
"""
Zeros the "corner" modes (modes where each component of its
integral wavenumber is either zero or the Nyquist along
that axis) of ``array`` (or just the imaginary part).
:arg array: The array to operate on.
... |
Zeros the "corner" modes (modes where each component of its
integral wavenumber is either zero or the Nyquist along
that axis) of ``array`` (or just the imaginary part).
:arg array: The array to operate on.
May be a :class:`pyopencl.array.Array` or a :class:`numpy.nda... | Zeros the "corner" modes (modes where each component of its
integral wavenumber is either zero or the Nyquist along
that axis) of ``array`` (or just the imaginary part). | [
"Zeros",
"the",
"\"",
"corner",
"\"",
"modes",
"(",
"modes",
"where",
"each",
"component",
"of",
"its",
"integral",
"wavenumber",
"is",
"either",
"zero",
"or",
"the",
"Nyquist",
"along",
"that",
"axis",
")",
"of",
"`",
"`",
"array",
"`",
"`",
"(",
"or"... | def zero_corner_modes(self, array, only_imag=False):
sub_k = list(x.get().astype("int") for x in self.sub_k.values())
shape = self.grid_shape
where_to_zero = []
for mu in range(3):
kk = sub_k[mu]
where_0 = np.argwhere(abs(kk) == 0).reshape(-1)
where_N2... | [
"def",
"zero_corner_modes",
"(",
"self",
",",
"array",
",",
"only_imag",
"=",
"False",
")",
":",
"sub_k",
"=",
"list",
"(",
"x",
".",
"get",
"(",
")",
".",
"astype",
"(",
"\"int\"",
")",
"for",
"x",
"in",
"self",
".",
"sub_k",
".",
"values",
"(",
... | Zeros the "corner" modes (modes where each component of its
integral wavenumber is either zero or the Nyquist along
that axis) of ``array`` (or just the imaginary part). | [
"Zeros",
"the",
"\"",
"corner",
"\"",
"modes",
"(",
"modes",
"where",
"each",
"component",
"of",
"its",
"integral",
"wavenumber",
"is",
"either",
"zero",
"or",
"the",
"Nyquist",
"along",
"that",
"axis",
")",
"of",
"`",
"`",
"array",
"`",
"`",
"(",
"or"... | [
"\"\"\"\r\n Zeros the \"corner\" modes (modes where each component of its\r\n integral wavenumber is either zero or the Nyquist along\r\n that axis) of ``array`` (or just the imaginary part).\r\n\r\n :arg array: The array to operate on.\r\n May be a :class:`pyopencl.array.Arra... | [
{
"param": "self",
"type": null
},
{
"param": "array",
"type": null
},
{
"param": "only_imag",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "array",
"type": null,
"docstring": "The array to operate on.\nMay b... |
398df17b04743449d579daa3c06fcfa7ee97555b | zachjweiner/pystella | pystella/decomp.py | [
"MIT"
] | Python | share_halos | null | def share_halos(self, queue, fx):
"""
Communicates halo data across all axes, imposing periodic boundary
conditions.
:arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.
:arg fx: The :class:`pyopencl.array.Array` whose halo elements are to be
... |
Communicates halo data across all axes, imposing periodic boundary
conditions.
:arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.
:arg fx: The :class:`pyopencl.array.Array` whose halo elements are to be
synchronized across ranks.
... | Communicates halo data across all axes, imposing periodic boundary
conditions. | [
"Communicates",
"halo",
"data",
"across",
"all",
"axes",
"imposing",
"periodic",
"boundary",
"conditions",
"."
] | def share_halos(self, queue, fx):
h = self.halo_shape
rank_shape = tuple(ni - 2 * hi for ni, hi in zip(fx.shape, h))
if h[2] > 0:
if self.proc_shape[2] == 1:
evt, _ = self.pack_unpack_z_knl(queue, arr=fx)
else:
raise NotImplementedError("do... | [
"def",
"share_halos",
"(",
"self",
",",
"queue",
",",
"fx",
")",
":",
"h",
"=",
"self",
".",
"halo_shape",
"rank_shape",
"=",
"tuple",
"(",
"ni",
"-",
"2",
"*",
"hi",
"for",
"ni",
",",
"hi",
"in",
"zip",
"(",
"fx",
".",
"shape",
",",
"h",
")",
... | Communicates halo data across all axes, imposing periodic boundary
conditions. | [
"Communicates",
"halo",
"data",
"across",
"all",
"axes",
"imposing",
"periodic",
"boundary",
"conditions",
"."
] | [
"\"\"\"\r\n Communicates halo data across all axes, imposing periodic boundary\r\n conditions.\r\n\r\n :arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.\r\n\r\n :arg fx: The :class:`pyopencl.array.Array` whose halo elements are to be\r\n synchronize... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "fx",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "queue",
"type": null,
"docstring": "The :class:`pyopencl.CommandQue... |
398df17b04743449d579daa3c06fcfa7ee97555b | zachjweiner/pystella | pystella/decomp.py | [
"MIT"
] | Python | remove_halos | null | def remove_halos(self, queue, in_array, out_array):
"""
Removes the halo padding from an array.
The only restriction on the shapes of the three-dimensional input arrays
is that the shape of ``in_array`` is larger than that of ``out_array``
by ``2*halo_shape`` along each ax... |
Removes the halo padding from an array.
The only restriction on the shapes of the three-dimensional input arrays
is that the shape of ``in_array`` is larger than that of ``out_array``
by ``2*halo_shape`` along each axis.
:arg queue: The :class:`pyopencl.CommandQueue` to... | Removes the halo padding from an array. | [
"Removes",
"the",
"halo",
"padding",
"from",
"an",
"array",
"."
] | def remove_halos(self, queue, in_array, out_array):
dtype = out_array.dtype
if in_array.dtype != dtype:
raise ValueError("in_array and out_array have different dtypes")
cl_in = isinstance(in_array, cla.Array)
cl_out = isinstance(out_array, cla.Array)
np_in = isinstanc... | [
"def",
"remove_halos",
"(",
"self",
",",
"queue",
",",
"in_array",
",",
"out_array",
")",
":",
"dtype",
"=",
"out_array",
".",
"dtype",
"if",
"in_array",
".",
"dtype",
"!=",
"dtype",
":",
"raise",
"ValueError",
"(",
"\"in_array and out_array have different dtype... | Removes the halo padding from an array. | [
"Removes",
"the",
"halo",
"padding",
"from",
"an",
"array",
"."
] | [
"\"\"\"\r\n Removes the halo padding from an array.\r\n\r\n The only restriction on the shapes of the three-dimensional input arrays\r\n is that the shape of ``in_array`` is larger than that of ``out_array``\r\n by ``2*halo_shape`` along each axis.\r\n\r\n :arg queue: The :class:`... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "in_array",
"type": null
},
{
"param": "out_array",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "queue",
"type": null,
"docstring": "The :class:`pyopencl.CommandQue... |
398df17b04743449d579daa3c06fcfa7ee97555b | zachjweiner/pystella | pystella/decomp.py | [
"MIT"
] | Python | gather_array | null | def gather_array(self, queue, in_array, out_array, root):
"""
Gathers the subdomains of an array from each rank into a single array
of the entire grid, removing halo padding from ``in_array``.
:arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.
... |
Gathers the subdomains of an array from each rank into a single array
of the entire grid, removing halo padding from ``in_array``.
:arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.
:arg in_array: The subarrays to be gathered.
May be eithe... | Gathers the subdomains of an array from each rank into a single array
of the entire grid, removing halo padding from ``in_array``. | [
"Gathers",
"the",
"subdomains",
"of",
"an",
"array",
"from",
"each",
"rank",
"into",
"a",
"single",
"array",
"of",
"the",
"entire",
"grid",
"removing",
"halo",
"padding",
"from",
"`",
"`",
"in_array",
"`",
"`",
"."
] | def gather_array(self, queue, in_array, out_array, root):
h = self.halo_shape
dtype = None if self.rank != root else out_array.dtype
dtype = self.bcast(dtype, root=root)
if in_array.dtype != dtype:
raise ValueError("in_array and out_array have different dtypes")
cl_in... | [
"def",
"gather_array",
"(",
"self",
",",
"queue",
",",
"in_array",
",",
"out_array",
",",
"root",
")",
":",
"h",
"=",
"self",
".",
"halo_shape",
"dtype",
"=",
"None",
"if",
"self",
".",
"rank",
"!=",
"root",
"else",
"out_array",
".",
"dtype",
"dtype",
... | Gathers the subdomains of an array from each rank into a single array
of the entire grid, removing halo padding from ``in_array``. | [
"Gathers",
"the",
"subdomains",
"of",
"an",
"array",
"from",
"each",
"rank",
"into",
"a",
"single",
"array",
"of",
"the",
"entire",
"grid",
"removing",
"halo",
"padding",
"from",
"`",
"`",
"in_array",
"`",
"`",
"."
] | [
"\"\"\"\r\n Gathers the subdomains of an array from each rank into a single array\r\n of the entire grid, removing halo padding from ``in_array``.\r\n\r\n :arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.\r\n\r\n :arg in_array: The subarrays to be gathered.\r\... | [
{
"param": "self",
"type": null
},
{
"param": "queue",
"type": null
},
{
"param": "in_array",
"type": null
},
{
"param": "out_array",
"type": null
},
{
"param": "root",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "queue",
"type": null,
"docstring": "The :class:`pyopencl.CommandQue... |
6a82ca38d501a4c9cce768a7b815e5f1f140593e | zachjweiner/pystella | pystella/__init__.py | [
"MIT"
] | Python | choose_device_and_make_context | <not_specific> | def choose_device_and_make_context(platform_choice=None, device_choice=None):
"""
A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
a particular device.
:arg platform_choice: An integer or string specifying which
:class:`pyopencl.Platform` to choose.
Defa... |
A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
a particular device.
:arg platform_choice: An integer or string specifying which
:class:`pyopencl.Platform` to choose.
Defaults to *None*, in which case the environment variables
``PYOPENCL_CTX`` or `... | A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
a particular device. | [
"A",
"wrapper",
"that",
"chooses",
"a",
"device",
"and",
"creates",
"a",
":",
"class",
":",
"`",
"pyopencl",
".",
"Context",
"`",
"on",
"a",
"particular",
"device",
"."
] | def choose_device_and_make_context(platform_choice=None, device_choice=None):
import pyopencl as cl
if platform_choice is None:
import os
if "PYOPENCL_CTX" in os.environ:
ctx_spec = os.environ["PYOPENCL_CTX"]
platform_choice = ctx_spec.split(":")[0]
else:
plat... | [
"def",
"choose_device_and_make_context",
"(",
"platform_choice",
"=",
"None",
",",
"device_choice",
"=",
"None",
")",
":",
"import",
"pyopencl",
"as",
"cl",
"if",
"platform_choice",
"is",
"None",
":",
"import",
"os",
"if",
"\"PYOPENCL_CTX\"",
"in",
"os",
".",
... | A wrapper that chooses a device and creates a :class:`pyopencl.Context` on
a particular device. | [
"A",
"wrapper",
"that",
"chooses",
"a",
"device",
"and",
"creates",
"a",
":",
"class",
":",
"`",
"pyopencl",
".",
"Context",
"`",
"on",
"a",
"particular",
"device",
"."
] | [
"\"\"\"\r\n A wrapper that chooses a device and creates a :class:`pyopencl.Context` on\r\n a particular device.\r\n\r\n :arg platform_choice: An integer or string specifying which\r\n :class:`pyopencl.Platform` to choose.\r\n Defaults to *None*, in which case the environment variables\r\n ... | [
{
"param": "platform_choice",
"type": null
},
{
"param": "device_choice",
"type": null
}
] | {
"returns": [
{
"docstring": null,
"docstring_tokens": [
"None"
],
"type": null
}
],
"raises": [],
"params": [
{
"identifier": "platform_choice",
"type": null,
"docstring": "An integer or string specifying which\n:class:`pyopencl.Platform` to choose... |
22cd5c5514ff7586fece21c733c4f61051000e07 | zachjweiner/pystella | pystella/expansion.py | [
"MIT"
] | Python | step | null | def step(self, stage, energy, pressure, dt):
"""
Executes one stage of the time stepper.
:arg stage: Which stage of the integrator to call.
:arg energy: The current energy density, :math:`\\bar{\\rho}`.
:arg pressure: The current pressure, :math:`\\bar{P}`.
... |
Executes one stage of the time stepper.
:arg stage: Which stage of the integrator to call.
:arg energy: The current energy density, :math:`\\bar{\\rho}`.
:arg pressure: The current pressure, :math:`\\bar{P}`.
:arg dt: The timestep to take.
| Executes one stage of the time stepper. | [
"Executes",
"one",
"stage",
"of",
"the",
"time",
"stepper",
"."
] | def step(self, stage, energy, pressure, dt):
arg_dict = dict(a=self.a, adot=self.adot, dt=dt,
energy=energy, pressure=pressure)
self.stepper(stage, **arg_dict)
self.hubble[()] = self.adot / self.a | [
"def",
"step",
"(",
"self",
",",
"stage",
",",
"energy",
",",
"pressure",
",",
"dt",
")",
":",
"arg_dict",
"=",
"dict",
"(",
"a",
"=",
"self",
".",
"a",
",",
"adot",
"=",
"self",
".",
"adot",
",",
"dt",
"=",
"dt",
",",
"energy",
"=",
"energy",
... | Executes one stage of the time stepper. | [
"Executes",
"one",
"stage",
"of",
"the",
"time",
"stepper",
"."
] | [
"\"\"\"\r\n Executes one stage of the time stepper.\r\n\r\n :arg stage: Which stage of the integrator to call.\r\n\r\n :arg energy: The current energy density, :math:`\\\\bar{\\\\rho}`.\r\n\r\n :arg pressure: The current pressure, :math:`\\\\bar{P}`.\r\n\r\n :arg dt: The timestep ... | [
{
"param": "self",
"type": null
},
{
"param": "stage",
"type": null
},
{
"param": "energy",
"type": null
},
{
"param": "pressure",
"type": null
},
{
"param": "dt",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "stage",
"type": null,
"docstring": "Which stage of the integrator t... |
22cd5c5514ff7586fece21c733c4f61051000e07 | zachjweiner/pystella | pystella/expansion.py | [
"MIT"
] | Python | constraint | <not_specific> | def constraint(self, energy):
"""
A dimensionless measure of the satisfaction of the first Friedmann equation
(as a constraint on the evolution), equal to
.. math::
\\left\\vert \\frac{1}{\\mathcal{H}}
\\sqrt{\\frac{8 \\pi a^2}{3 m_\\mathrm{pl}^2} \\rho}... |
A dimensionless measure of the satisfaction of the first Friedmann equation
(as a constraint on the evolution), equal to
.. math::
\\left\\vert \\frac{1}{\\mathcal{H}}
\\sqrt{\\frac{8 \\pi a^2}{3 m_\\mathrm{pl}^2} \\rho} - 1
\\right\\vert
... | A dimensionless measure of the satisfaction of the first Friedmann equation
(as a constraint on the evolution), equal to
| [
"A",
"dimensionless",
"measure",
"of",
"the",
"satisfaction",
"of",
"the",
"first",
"Friedmann",
"equation",
"(",
"as",
"a",
"constraint",
"on",
"the",
"evolution",
")",
"equal",
"to"
] | def constraint(self, energy):
return np.abs(self.adot_friedmann_1(self.a[0], energy) / self.adot[0] - 1) | [
"def",
"constraint",
"(",
"self",
",",
"energy",
")",
":",
"return",
"np",
".",
"abs",
"(",
"self",
".",
"adot_friedmann_1",
"(",
"self",
".",
"a",
"[",
"0",
"]",
",",
"energy",
")",
"/",
"self",
".",
"adot",
"[",
"0",
"]",
"-",
"1",
")"
] | A dimensionless measure of the satisfaction of the first Friedmann equation
(as a constraint on the evolution), equal to | [
"A",
"dimensionless",
"measure",
"of",
"the",
"satisfaction",
"of",
"the",
"first",
"Friedmann",
"equation",
"(",
"as",
"a",
"constraint",
"on",
"the",
"evolution",
")",
"equal",
"to"
] | [
"\"\"\"\r\n A dimensionless measure of the satisfaction of the first Friedmann equation\r\n (as a constraint on the evolution), equal to\r\n\r\n .. math::\r\n\r\n \\\\left\\\\vert \\\\frac{1}{\\\\mathcal{H}}\r\n \\\\sqrt{\\\\frac{8 \\\\pi a^2}{3 m_\\\\mathrm{pl}^2} \\\\rho... | [
{
"param": "self",
"type": null
},
{
"param": "energy",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "energy",
"type": null,
"docstring": "The current energy density, :m... |
de170daf548a2db7fd968e97044478d69f73ecb6 | chihming/LibMultiLabel | libmultilabel/model.py | [
"MIT"
] | Python | configure_optimizers | <not_specific> | def configure_optimizers(self):
"""Initialize an optimizer for the free parameters of the network.
"""
parameters = [p for p in self.parameters() if p.requires_grad]
optimizer_name = self.optimizer
if optimizer_name == 'sgd':
optimizer = optim.SGD(parameters, self.lea... | Initialize an optimizer for the free parameters of the network.
| Initialize an optimizer for the free parameters of the network. | [
"Initialize",
"an",
"optimizer",
"for",
"the",
"free",
"parameters",
"of",
"the",
"network",
"."
] | def configure_optimizers(self):
parameters = [p for p in self.parameters() if p.requires_grad]
optimizer_name = self.optimizer
if optimizer_name == 'sgd':
optimizer = optim.SGD(parameters, self.learning_rate,
momentum=self.momentum,
... | [
"def",
"configure_optimizers",
"(",
"self",
")",
":",
"parameters",
"=",
"[",
"p",
"for",
"p",
"in",
"self",
".",
"parameters",
"(",
")",
"if",
"p",
".",
"requires_grad",
"]",
"optimizer_name",
"=",
"self",
".",
"optimizer",
"if",
"optimizer_name",
"==",
... | Initialize an optimizer for the free parameters of the network. | [
"Initialize",
"an",
"optimizer",
"for",
"the",
"free",
"parameters",
"of",
"the",
"network",
"."
] | [
"\"\"\"Initialize an optimizer for the free parameters of the network.\n \"\"\""
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
de170daf548a2db7fd968e97044478d69f73ecb6 | chihming/LibMultiLabel | libmultilabel/model.py | [
"MIT"
] | Python | shared_step | <not_specific> | def shared_step(self, batch):
"""Return loss and predicted logits of the network.
Args:
batch (dict): A batch of text and label.
Returns:
loss (Tensor): Binary cross-entropy between target and predict logits.
pred_logits (Tensor): The predict logits (batch_s... | Return loss and predicted logits of the network.
Args:
batch (dict): A batch of text and label.
Returns:
loss (Tensor): Binary cross-entropy between target and predict logits.
pred_logits (Tensor): The predict logits (batch_size, num_classes).
| Return loss and predicted logits of the network. | [
"Return",
"loss",
"and",
"predicted",
"logits",
"of",
"the",
"network",
"."
] | def shared_step(self, batch):
target_labels = batch['label']
outputs = self.network(batch['text'])
pred_logits = outputs['logits']
loss = F.binary_cross_entropy_with_logits(pred_logits, target_labels.float())
return loss, pred_logits | [
"def",
"shared_step",
"(",
"self",
",",
"batch",
")",
":",
"target_labels",
"=",
"batch",
"[",
"'label'",
"]",
"outputs",
"=",
"self",
".",
"network",
"(",
"batch",
"[",
"'text'",
"]",
")",
"pred_logits",
"=",
"outputs",
"[",
"'logits'",
"]",
"loss",
"... | Return loss and predicted logits of the network. | [
"Return",
"loss",
"and",
"predicted",
"logits",
"of",
"the",
"network",
"."
] | [
"\"\"\"Return loss and predicted logits of the network.\n\n Args:\n batch (dict): A batch of text and label.\n\n Returns:\n loss (Tensor): Binary cross-entropy between target and predict logits.\n pred_logits (Tensor): The predict logits (batch_size, num_classes).\n ... | [
{
"param": "self",
"type": null
},
{
"param": "batch",
"type": null
}
] | {
"returns": [
{
"docstring": "loss (Tensor): Binary cross-entropy between target and predict logits.\npred_logits (Tensor): The predict logits (batch_size, num_classes).",
"docstring_tokens": [
"loss",
"(",
"Tensor",
")",
":",
"Binary",
"cross",... |
de170daf548a2db7fd968e97044478d69f73ecb6 | chihming/LibMultiLabel | libmultilabel/model.py | [
"MIT"
] | Python | print | null | def print(self, *args, **kwargs):
"""Prints only from process 0 and not in silent mode. Use this in any
distributed mode to log only once."""
if not self.silent:
# print() in LightningModule to print only from process 0
super().print(*args, **kwargs) | Prints only from process 0 and not in silent mode. Use this in any
distributed mode to log only once. | Prints only from process 0 and not in silent mode. Use this in any
distributed mode to log only once. | [
"Prints",
"only",
"from",
"process",
"0",
"and",
"not",
"in",
"silent",
"mode",
".",
"Use",
"this",
"in",
"any",
"distributed",
"mode",
"to",
"log",
"only",
"once",
"."
] | def print(self, *args, **kwargs):
if not self.silent:
super().print(*args, **kwargs) | [
"def",
"print",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"silent",
":",
"super",
"(",
")",
".",
"print",
"(",
"*",
"args",
",",
"**",
"kwargs",
")"
] | Prints only from process 0 and not in silent mode. | [
"Prints",
"only",
"from",
"process",
"0",
"and",
"not",
"in",
"silent",
"mode",
"."
] | [
"\"\"\"Prints only from process 0 and not in silent mode. Use this in any\n distributed mode to log only once.\"\"\"",
"# print() in LightningModule to print only from process 0"
] | [
{
"param": "self",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "self",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8375fc13234092af4190e338351a6ab991d4d3ab | chihming/LibMultiLabel | libmultilabel/linear/linear.py | [
"MIT"
] | Python | train_1vsrest | <not_specific> | def train_1vsrest(y: sparse.csr_matrix, x: sparse.csr_matrix, options: str):
"""
Trains a linear model for multiabel data using a one-vs-all strategy.
Returns the model.
y is a 0/1 matrix with dimensions number of instances * number of classes.
x is a matrix with dimensions number of instances * n... |
Trains a linear model for multiabel data using a one-vs-all strategy.
Returns the model.
y is a 0/1 matrix with dimensions number of instances * number of classes.
x is a matrix with dimensions number of instances * number of features.
options is the option string passed to liblinear.
| Trains a linear model for multiabel data using a one-vs-all strategy.
Returns the model.
y is a 0/1 matrix with dimensions number of instances * number of classes.
x is a matrix with dimensions number of instances * number of features.
options is the option string passed to liblinear. | [
"Trains",
"a",
"linear",
"model",
"for",
"multiabel",
"data",
"using",
"a",
"one",
"-",
"vs",
"-",
"all",
"strategy",
".",
"Returns",
"the",
"model",
".",
"y",
"is",
"a",
"0",
"/",
"1",
"matrix",
"with",
"dimensions",
"number",
"of",
"instances",
"*",
... | def train_1vsrest(y: sparse.csr_matrix, x: sparse.csr_matrix, options: str):
if options.find('-R') != -1:
raise ValueError('-R is not supported')
bias = -1.
if options.find('-B') != -1:
options_split = options.split()
i = options_split.index('-B')
bias = float(options_split[i... | [
"def",
"train_1vsrest",
"(",
"y",
":",
"sparse",
".",
"csr_matrix",
",",
"x",
":",
"sparse",
".",
"csr_matrix",
",",
"options",
":",
"str",
")",
":",
"if",
"options",
".",
"find",
"(",
"'-R'",
")",
"!=",
"-",
"1",
":",
"raise",
"ValueError",
"(",
"... | Trains a linear model for multiabel data using a one-vs-all strategy. | [
"Trains",
"a",
"linear",
"model",
"for",
"multiabel",
"data",
"using",
"a",
"one",
"-",
"vs",
"-",
"all",
"strategy",
"."
] | [
"\"\"\"\n Trains a linear model for multiabel data using a one-vs-all strategy.\n\n Returns the model.\n\n y is a 0/1 matrix with dimensions number of instances * number of classes.\n x is a matrix with dimensions number of instances * number of features.\n options is the option string passed to libl... | [
{
"param": "y",
"type": "sparse.csr_matrix"
},
{
"param": "x",
"type": "sparse.csr_matrix"
},
{
"param": "options",
"type": "str"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "y",
"type": "sparse.csr_matrix",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": "sparse.csr_matrix",
"docstring": null,
... |
8375fc13234092af4190e338351a6ab991d4d3ab | chihming/LibMultiLabel | libmultilabel/linear/linear.py | [
"MIT"
] | Python | predict_values | np.ndarray | def predict_values(model, x: sparse.csr_matrix) -> np.ndarray:
"""
Calculates the decision values associated with x.
Returns a matrix with dimension number of instances * number of classes.
x is a matrix with dimension number of instances * number of features.
"""
bias = model['-B']
bias_c... |
Calculates the decision values associated with x.
Returns a matrix with dimension number of instances * number of classes.
x is a matrix with dimension number of instances * number of features.
| Calculates the decision values associated with x.
Returns a matrix with dimension number of instances * number of classes.
x is a matrix with dimension number of instances * number of features. | [
"Calculates",
"the",
"decision",
"values",
"associated",
"with",
"x",
".",
"Returns",
"a",
"matrix",
"with",
"dimension",
"number",
"of",
"instances",
"*",
"number",
"of",
"classes",
".",
"x",
"is",
"a",
"matrix",
"with",
"dimension",
"number",
"of",
"instan... | def predict_values(model, x: sparse.csr_matrix) -> np.ndarray:
bias = model['-B']
bias_col = np.full((x.shape[0], 1 if bias > 0 else 0), bias)
nr_feature = model['weights'].shape[0]
nr_feature -= 1 if bias > 0 else 0
if x.shape[1] < nr_feature:
x = sparse.hstack([
x,
... | [
"def",
"predict_values",
"(",
"model",
",",
"x",
":",
"sparse",
".",
"csr_matrix",
")",
"->",
"np",
".",
"ndarray",
":",
"bias",
"=",
"model",
"[",
"'-B'",
"]",
"bias_col",
"=",
"np",
".",
"full",
"(",
"(",
"x",
".",
"shape",
"[",
"0",
"]",
",",
... | Calculates the decision values associated with x. | [
"Calculates",
"the",
"decision",
"values",
"associated",
"with",
"x",
"."
] | [
"\"\"\"\n Calculates the decision values associated with x.\n\n Returns a matrix with dimension number of instances * number of classes.\n\n x is a matrix with dimension number of instances * number of features.\n \"\"\""
] | [
{
"param": "model",
"type": null
},
{
"param": "x",
"type": "sparse.csr_matrix"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "model",
"type": null,
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": "sparse.csr_matrix",
"docstring": null,
"docstri... |
c1850e4358d5062e1410e2b177e4c0a55918534c | chihming/LibMultiLabel | libmultilabel/utils.py | [
"MIT"
] | Python | dump_log | null | def dump_log(log_path, metrics=None, split=None, config=None):
"""Write log including config and the evaluation scores.
Args:
log_path(str): path to log path
metrics (dict): metric and scores in dictionary format, defaults to None
split (str): val or test, defaults to None
confi... | Write log including config and the evaluation scores.
Args:
log_path(str): path to log path
metrics (dict): metric and scores in dictionary format, defaults to None
split (str): val or test, defaults to None
config (dict): config to save, defaults to None
| Write log including config and the evaluation scores. | [
"Write",
"log",
"including",
"config",
"and",
"the",
"evaluation",
"scores",
"."
] | def dump_log(log_path, metrics=None, split=None, config=None):
os.makedirs(os.path.dirname(log_path), exist_ok=True)
if os.path.isfile(log_path):
with open(log_path) as fp:
result = json.load(fp)
else:
result = dict()
if config:
config_to_save = copy.deepcopy(dict(con... | [
"def",
"dump_log",
"(",
"log_path",
",",
"metrics",
"=",
"None",
",",
"split",
"=",
"None",
",",
"config",
"=",
"None",
")",
":",
"os",
".",
"makedirs",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"log_path",
")",
",",
"exist_ok",
"=",
"True",
")"... | Write log including config and the evaluation scores. | [
"Write",
"log",
"including",
"config",
"and",
"the",
"evaluation",
"scores",
"."
] | [
"\"\"\"Write log including config and the evaluation scores.\n\n Args:\n log_path(str): path to log path\n metrics (dict): metric and scores in dictionary format, defaults to None\n split (str): val or test, defaults to None\n config (dict): config to save, defaults to None\n \"\"\... | [
{
"param": "log_path",
"type": null
},
{
"param": "metrics",
"type": null
},
{
"param": "split",
"type": null
},
{
"param": "config",
"type": null
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "log_path",
"type": null,
"docstring": "path to log path",
"docstring_tokens": [
"path",
"to",
"log",
"path"
],
"default": null,
"is_optional": false
},
{
"identif... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.