repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
LinePlot.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None data = self.input.payload pltdataset.line_plot( data, atts=self.resolve_option("attribu...
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None data = self.input.payload pltdataset.line_plot( data, atts=self.resolve_option("attribu...
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "data", "=", "self", ".", "input", ".", "payload", "pltdataset", ".", "line_plot", "(", "data", ",", "atts", "=", "self", ".", "resolve_option", "(", "\"attributes\"", ")", ",", "percent"...
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L547-L564
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
ClassifierErrors.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(Cla...
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(Cla...
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "ClassifierErrors", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"absolute\"", "if", "opt", "not", "in", "options", ":", "options", "[", ...
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L592-L639
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
ClassifierErrors.check_input
def check_input(self, token): """ Performs checks on the input token. Raises an exception if unsupported. :param token: the token to check :type token: Token """ if not isinstance(token.payload, Evaluation): raise Exception(self.full_name + ": Input token is ...
python
def check_input(self, token): """ Performs checks on the input token. Raises an exception if unsupported. :param token: the token to check :type token: Token """ if not isinstance(token.payload, Evaluation): raise Exception(self.full_name + ": Input token is ...
[ "def", "check_input", "(", "self", ",", "token", ")", ":", "if", "not", "isinstance", "(", "token", ".", "payload", ",", "Evaluation", ")", ":", "raise", "Exception", "(", "self", ".", "full_name", "+", "\": Input token is not an Evaluation object!\"", ")" ]
Performs checks on the input token. Raises an exception if unsupported. :param token: the token to check :type token: Token
[ "Performs", "checks", "on", "the", "input", "token", ".", "Raises", "an", "exception", "if", "unsupported", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L654-L662
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
ClassifierErrors.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None evl = self.input.payload pltclassifier.plot_classifier_errors( evl.predictions, absolut...
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None evl = self.input.payload pltclassifier.plot_classifier_errors( evl.predictions, absolut...
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "evl", "=", "self", ".", "input", ".", "payload", "pltclassifier", ".", "plot_classifier_errors", "(", "evl", ".", "predictions", ",", "absolute", "=", "bool", "(", "self", ".", "resolve_op...
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L664-L681
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
ROC.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ROC...
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(ROC...
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "ROC", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"class_index\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", ...
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L709-L750
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
PRC.fix_config
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(PRC...
python
def fix_config(self, options): """ Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict """ options = super(PRC...
[ "def", "fix_config", "(", "self", ",", "options", ")", ":", "options", "=", "super", "(", "PRC", ",", "self", ")", ".", "fix_config", "(", "options", ")", "opt", "=", "\"class_index\"", "if", "opt", "not", "in", "options", ":", "options", "[", "opt", ...
Fixes the options, if necessary. I.e., it adds all required elements to the dictionary. :param options: the options to fix :type options: dict :return: the (potentially) fixed options :rtype: dict
[ "Fixes", "the", "options", "if", "necessary", ".", "I", ".", "e", ".", "it", "adds", "all", "required", "elements", "to", "the", "dictionary", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L819-L860
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
PRC.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None evl = self.input.payload pltclassifier.plot_prc( evl, class_index=self.resolve_option("...
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None evl = self.input.payload pltclassifier.plot_prc( evl, class_index=self.resolve_option("...
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "evl", "=", "self", ".", "input", ".", "payload", "pltclassifier", ".", "plot_prc", "(", "evl", ",", "class_index", "=", "self", ".", "resolve_option", "(", "\"class_index\"", ")", ",", "...
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L885-L901
fracpete/python-weka-wrapper3
python/weka/flow/sink.py
InstanceDumper.do_execute
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None data = self.input.payload if isinstance(self._input.payload, Instance): inst = self.input.payload ...
python
def do_execute(self): """ The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str """ result = None data = self.input.payload if isinstance(self._input.payload, Instance): inst = self.input.payload ...
[ "def", "do_execute", "(", "self", ")", ":", "result", "=", "None", "data", "=", "self", ".", "input", ".", "payload", "if", "isinstance", "(", "self", ".", "_input", ".", "payload", ",", "Instance", ")", ":", "inst", "=", "self", ".", "input", ".", ...
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
[ "The", "actual", "execution", "of", "the", "actor", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/flow/sink.py#L943-L983
fracpete/python-weka-wrapper3
python/weka/experiments.py
SimpleExperiment.configure_splitevaluator
def configure_splitevaluator(self): """ Configures and returns the SplitEvaluator and Classifier instance as tuple. :return: evaluator and classifier :rtype: tuple """ if self.classification: speval = javabridge.make_instance("weka/experiment/ClassifierSplitE...
python
def configure_splitevaluator(self): """ Configures and returns the SplitEvaluator and Classifier instance as tuple. :return: evaluator and classifier :rtype: tuple """ if self.classification: speval = javabridge.make_instance("weka/experiment/ClassifierSplitE...
[ "def", "configure_splitevaluator", "(", "self", ")", ":", "if", "self", ".", "classification", ":", "speval", "=", "javabridge", ".", "make_instance", "(", "\"weka/experiment/ClassifierSplitEvaluator\"", ",", "\"()V\"", ")", "else", ":", "speval", "=", "javabridge",...
Configures and returns the SplitEvaluator and Classifier instance as tuple. :return: evaluator and classifier :rtype: tuple
[ "Configures", "and", "returns", "the", "SplitEvaluator", "and", "Classifier", "instance", "as", "tuple", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L86-L98
fracpete/python-weka-wrapper3
python/weka/experiments.py
SimpleExperiment.setup
def setup(self): """ Initializes the experiment. """ # basic options javabridge.call( self.jobject, "setPropertyArray", "(Ljava/lang/Object;)V", javabridge.get_env().make_object_array(0, javabridge.get_env().find_class("weka/classifiers/Classifier"))) ...
python
def setup(self): """ Initializes the experiment. """ # basic options javabridge.call( self.jobject, "setPropertyArray", "(Ljava/lang/Object;)V", javabridge.get_env().make_object_array(0, javabridge.get_env().find_class("weka/classifiers/Classifier"))) ...
[ "def", "setup", "(", "self", ")", ":", "# basic options", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setPropertyArray\"", ",", "\"(Ljava/lang/Object;)V\"", ",", "javabridge", ".", "get_env", "(", ")", ".", "make_object_array", "(", "0", ",...
Initializes the experiment.
[ "Initializes", "the", "experiment", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L109-L164
fracpete/python-weka-wrapper3
python/weka/experiments.py
SimpleExperiment.run
def run(self): """ Executes the experiment. """ logger.info("Initializing...") javabridge.call(self.jobject, "initialize", "()V") logger.info("Running...") javabridge.call(self.jobject, "runExperiment", "()V") logger.info("Finished...") javabridge....
python
def run(self): """ Executes the experiment. """ logger.info("Initializing...") javabridge.call(self.jobject, "initialize", "()V") logger.info("Running...") javabridge.call(self.jobject, "runExperiment", "()V") logger.info("Finished...") javabridge....
[ "def", "run", "(", "self", ")", ":", "logger", ".", "info", "(", "\"Initializing...\"", ")", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"initialize\"", ",", "\"()V\"", ")", "logger", ".", "info", "(", "\"Running...\"", ")", "javabridge"...
Executes the experiment.
[ "Executes", "the", "experiment", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L166-L175
fracpete/python-weka-wrapper3
python/weka/experiments.py
SimpleExperiment.load
def load(cls, filename): """ Loads the experiment from disk. :param filename: the filename of the experiment to load :type filename: str :return: the experiment :rtype: Experiment """ jobject = javabridge.static_call( "weka/experiment/Experime...
python
def load(cls, filename): """ Loads the experiment from disk. :param filename: the filename of the experiment to load :type filename: str :return: the experiment :rtype: Experiment """ jobject = javabridge.static_call( "weka/experiment/Experime...
[ "def", "load", "(", "cls", ",", "filename", ")", ":", "jobject", "=", "javabridge", ".", "static_call", "(", "\"weka/experiment/Experiment\"", ",", "\"read\"", ",", "\"(Ljava/lang/String;)Lweka/experiment/Experiment;\"", ",", "filename", ")", "return", "Experiment", "...
Loads the experiment from disk. :param filename: the filename of the experiment to load :type filename: str :return: the experiment :rtype: Experiment
[ "Loads", "the", "experiment", "from", "disk", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L190-L202
fracpete/python-weka-wrapper3
python/weka/experiments.py
SimpleRandomSplitExperiment.configure_resultproducer
def configure_resultproducer(self): """ Configures and returns the ResultProducer and PropertyPath as tuple. :return: producer and property path :rtype: tuple """ rproducer = javabridge.make_instance("weka/experiment/RandomSplitResultProducer", "()V") javabridge....
python
def configure_resultproducer(self): """ Configures and returns the ResultProducer and PropertyPath as tuple. :return: producer and property path :rtype: tuple """ rproducer = javabridge.make_instance("weka/experiment/RandomSplitResultProducer", "()V") javabridge....
[ "def", "configure_resultproducer", "(", "self", ")", ":", "rproducer", "=", "javabridge", ".", "make_instance", "(", "\"weka/experiment/RandomSplitResultProducer\"", ",", "\"()V\"", ")", "javabridge", ".", "call", "(", "rproducer", ",", "\"setRandomizeData\"", ",", "\...
Configures and returns the ResultProducer and PropertyPath as tuple. :return: producer and property path :rtype: tuple
[ "Configures", "and", "returns", "the", "ResultProducer", "and", "PropertyPath", "as", "tuple", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L336-L365
fracpete/python-weka-wrapper3
python/weka/experiments.py
ResultMatrix.set_row_name
def set_row_name(self, index, name): """ Sets the row name. :param index: the 0-based row index :type index: int :param name: the name of the row :type name: str """ javabridge.call(self.jobject, "setRowName", "(ILjava/lang/String;)V", index, name)
python
def set_row_name(self, index, name): """ Sets the row name. :param index: the 0-based row index :type index: int :param name: the name of the row :type name: str """ javabridge.call(self.jobject, "setRowName", "(ILjava/lang/String;)V", index, name)
[ "def", "set_row_name", "(", "self", ",", "index", ",", "name", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setRowName\"", ",", "\"(ILjava/lang/String;)V\"", ",", "index", ",", "name", ")" ]
Sets the row name. :param index: the 0-based row index :type index: int :param name: the name of the row :type name: str
[ "Sets", "the", "row", "name", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L478-L487
fracpete/python-weka-wrapper3
python/weka/experiments.py
ResultMatrix.set_col_name
def set_col_name(self, index, name): """ Sets the column name. :param index: the 0-based row index :type index: int :param name: the name of the column :type name: str """ javabridge.call(self.jobject, "setColName", "(ILjava/lang/String;)V", index, name)
python
def set_col_name(self, index, name): """ Sets the column name. :param index: the 0-based row index :type index: int :param name: the name of the column :type name: str """ javabridge.call(self.jobject, "setColName", "(ILjava/lang/String;)V", index, name)
[ "def", "set_col_name", "(", "self", ",", "index", ",", "name", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setColName\"", ",", "\"(ILjava/lang/String;)V\"", ",", "index", ",", "name", ")" ]
Sets the column name. :param index: the 0-based row index :type index: int :param name: the name of the column :type name: str
[ "Sets", "the", "column", "name", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L500-L509
fracpete/python-weka-wrapper3
python/weka/experiments.py
ResultMatrix.get_mean
def get_mean(self, col, row): """ Returns the mean at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :return: the mean :rtype: float """ return javabr...
python
def get_mean(self, col, row): """ Returns the mean at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :return: the mean :rtype: float """ return javabr...
[ "def", "get_mean", "(", "self", ",", "col", ",", "row", ")", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getMean\"", ",", "\"(II)D\"", ",", "col", ",", "row", ")" ]
Returns the mean at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :return: the mean :rtype: float
[ "Returns", "the", "mean", "at", "this", "location", "(", "if", "valid", "location", ")", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L511-L522
fracpete/python-weka-wrapper3
python/weka/experiments.py
ResultMatrix.set_mean
def set_mean(self, col, row, mean): """ Sets the mean at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :param mean: the mean to set :type mean: float """ ...
python
def set_mean(self, col, row, mean): """ Sets the mean at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :param mean: the mean to set :type mean: float """ ...
[ "def", "set_mean", "(", "self", ",", "col", ",", "row", ",", "mean", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setMean\"", ",", "\"(IID)V\"", ",", "col", ",", "row", ",", "mean", ")" ]
Sets the mean at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :param mean: the mean to set :type mean: float
[ "Sets", "the", "mean", "at", "this", "location", "(", "if", "valid", "location", ")", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L524-L535
fracpete/python-weka-wrapper3
python/weka/experiments.py
ResultMatrix.get_stdev
def get_stdev(self, col, row): """ Returns the standard deviation at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :return: the standard deviation :rtype: float ...
python
def get_stdev(self, col, row): """ Returns the standard deviation at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :return: the standard deviation :rtype: float ...
[ "def", "get_stdev", "(", "self", ",", "col", ",", "row", ")", ":", "return", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"getStdDev\"", ",", "\"(II)D\"", ",", "col", ",", "row", ")" ]
Returns the standard deviation at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :return: the standard deviation :rtype: float
[ "Returns", "the", "standard", "deviation", "at", "this", "location", "(", "if", "valid", "location", ")", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L537-L548
fracpete/python-weka-wrapper3
python/weka/experiments.py
ResultMatrix.set_stdev
def set_stdev(self, col, row, stdev): """ Sets the standard deviation at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :param stdev: the standard deviation to set :t...
python
def set_stdev(self, col, row, stdev): """ Sets the standard deviation at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :param stdev: the standard deviation to set :t...
[ "def", "set_stdev", "(", "self", ",", "col", ",", "row", ",", "stdev", ")", ":", "javabridge", ".", "call", "(", "self", ".", "jobject", ",", "\"setStdDev\"", ",", "\"(IID)V\"", ",", "col", ",", "row", ",", "stdev", ")" ]
Sets the standard deviation at this location (if valid location). :param col: the 0-based column index :type col: int :param row: the 0-based row index :type row: int :param stdev: the standard deviation to set :type stdev: float
[ "Sets", "the", "standard", "deviation", "at", "this", "location", "(", "if", "valid", "location", ")", "." ]
train
https://github.com/fracpete/python-weka-wrapper3/blob/d850ab1bdb25fbd5a8d86e99f34a397975425838/python/weka/experiments.py#L550-L561
redcap-tools/PyCap
redcap/request.py
RCRequest.validate
def validate(self): """Checks that at least required params exist""" required = ['token', 'content'] valid_data = { 'exp_record': (['type', 'format'], 'record', 'Exporting record but content is not record'), 'imp_record': (['type', 'overwriteBehavior', 'da...
python
def validate(self): """Checks that at least required params exist""" required = ['token', 'content'] valid_data = { 'exp_record': (['type', 'format'], 'record', 'Exporting record but content is not record'), 'imp_record': (['type', 'overwriteBehavior', 'da...
[ "def", "validate", "(", "self", ")", ":", "required", "=", "[", "'token'", ",", "'content'", "]", "valid_data", "=", "{", "'exp_record'", ":", "(", "[", "'type'", ",", "'format'", "]", ",", "'record'", ",", "'Exporting record but content is not record'", ")", ...
Checks that at least required params exist
[ "Checks", "that", "at", "least", "required", "params", "exist" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/request.py#L64-L107
redcap-tools/PyCap
redcap/request.py
RCRequest.execute
def execute(self, **kwargs): """Execute the API request and return data Parameters ---------- kwargs : passed to requests.post() Returns ------- response : list, str data object from JSON decoding process if format=='json', el...
python
def execute(self, **kwargs): """Execute the API request and return data Parameters ---------- kwargs : passed to requests.post() Returns ------- response : list, str data object from JSON decoding process if format=='json', el...
[ "def", "execute", "(", "self", ",", "*", "*", "kwargs", ")", ":", "r", "=", "post", "(", "self", ".", "url", ",", "data", "=", "self", ".", "payload", ",", "*", "*", "kwargs", ")", "# Raise if we need to", "self", ".", "raise_for_status", "(", "r", ...
Execute the API request and return data Parameters ---------- kwargs : passed to requests.post() Returns ------- response : list, str data object from JSON decoding process if format=='json', else return raw string (ie format=='csv'|'...
[ "Execute", "the", "API", "request", "and", "return", "data" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/request.py#L109-L127
redcap-tools/PyCap
redcap/request.py
RCRequest.get_content
def get_content(self, r): """Abstraction for grabbing content from a returned response""" if self.type == 'exp_file': # don't use the decoded r.text return r.content elif self.type == 'version': return r.content else: if self.fmt == 'json':...
python
def get_content(self, r): """Abstraction for grabbing content from a returned response""" if self.type == 'exp_file': # don't use the decoded r.text return r.content elif self.type == 'version': return r.content else: if self.fmt == 'json':...
[ "def", "get_content", "(", "self", ",", "r", ")", ":", "if", "self", ".", "type", "==", "'exp_file'", ":", "# don't use the decoded r.text", "return", "r", ".", "content", "elif", "self", ".", "type", "==", "'version'", ":", "return", "r", ".", "content", ...
Abstraction for grabbing content from a returned response
[ "Abstraction", "for", "grabbing", "content", "from", "a", "returned", "response" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/request.py#L129-L150
redcap-tools/PyCap
redcap/request.py
RCRequest.raise_for_status
def raise_for_status(self, r): """Given a response, raise for bad status for certain actions Some redcap api methods don't return error messages that the user could test for or otherwise use. Therefore, we need to do the testing ourself Raising for everything wouldn't let the u...
python
def raise_for_status(self, r): """Given a response, raise for bad status for certain actions Some redcap api methods don't return error messages that the user could test for or otherwise use. Therefore, we need to do the testing ourself Raising for everything wouldn't let the u...
[ "def", "raise_for_status", "(", "self", ",", "r", ")", ":", "if", "self", ".", "type", "in", "(", "'metadata'", ",", "'exp_file'", ",", "'imp_file'", ",", "'del_file'", ")", ":", "r", ".", "raise_for_status", "(", ")", "# see http://www.w3.org/Protocols/rfc261...
Given a response, raise for bad status for certain actions Some redcap api methods don't return error messages that the user could test for or otherwise use. Therefore, we need to do the testing ourself Raising for everything wouldn't let the user see the (hopefully helpful) er...
[ "Given", "a", "response", "raise", "for", "bad", "status", "for", "certain", "actions" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/request.py#L156-L170
redcap-tools/PyCap
redcap/project.py
Project.__basepl
def __basepl(self, content, rec_type='flat', format='json'): """Return a dictionary which can be used as is or added to for payloads""" d = {'token': self.token, 'content': content, 'format': format} if content not in ['metadata', 'file']: d['type'] = rec_type return ...
python
def __basepl(self, content, rec_type='flat', format='json'): """Return a dictionary which can be used as is or added to for payloads""" d = {'token': self.token, 'content': content, 'format': format} if content not in ['metadata', 'file']: d['type'] = rec_type return ...
[ "def", "__basepl", "(", "self", ",", "content", ",", "rec_type", "=", "'flat'", ",", "format", "=", "'json'", ")", ":", "d", "=", "{", "'token'", ":", "self", ".", "token", ",", "'content'", ":", "content", ",", "'format'", ":", "format", "}", "if", ...
Return a dictionary which can be used as is or added to for payloads
[ "Return", "a", "dictionary", "which", "can", "be", "used", "as", "is", "or", "added", "to", "for", "payloads" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L95-L101
redcap-tools/PyCap
redcap/project.py
Project.is_longitudinal
def is_longitudinal(self): """ Returns ------- boolean : longitudinal status of this project """ return len(self.events) > 0 and \ len(self.arm_nums) > 0 and \ len(self.arm_names) > 0
python
def is_longitudinal(self): """ Returns ------- boolean : longitudinal status of this project """ return len(self.events) > 0 and \ len(self.arm_nums) > 0 and \ len(self.arm_names) > 0
[ "def", "is_longitudinal", "(", "self", ")", ":", "return", "len", "(", "self", ".", "events", ")", ">", "0", "and", "len", "(", "self", ".", "arm_nums", ")", ">", "0", "and", "len", "(", "self", ".", "arm_names", ")", ">", "0" ]
Returns ------- boolean : longitudinal status of this project
[ "Returns", "-------", "boolean", ":", "longitudinal", "status", "of", "this", "project" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L114-L123
redcap-tools/PyCap
redcap/project.py
Project.filter_metadata
def filter_metadata(self, key): """ Return a list of values for the metadata key from each field of the project's metadata. Parameters ---------- key: str A known key in the metadata structure Returns ------- filtered : at...
python
def filter_metadata(self, key): """ Return a list of values for the metadata key from each field of the project's metadata. Parameters ---------- key: str A known key in the metadata structure Returns ------- filtered : at...
[ "def", "filter_metadata", "(", "self", ",", "key", ")", ":", "filtered", "=", "[", "field", "[", "key", "]", "for", "field", "in", "self", ".", "metadata", "if", "key", "in", "field", "]", "if", "len", "(", "filtered", ")", "==", "0", ":", "raise",...
Return a list of values for the metadata key from each field of the project's metadata. Parameters ---------- key: str A known key in the metadata structure Returns ------- filtered : attribute list from each field
[ "Return", "a", "list", "of", "values", "for", "the", "metadata", "key", "from", "each", "field", "of", "the", "project", "s", "metadata", "." ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L125-L143
redcap-tools/PyCap
redcap/project.py
Project.export_fem
def export_fem(self, arms=None, format='json', df_kwargs=None): """ Export the project's form to event mapping Parameters ---------- arms : list Limit exported form event mappings to these arm numbers format : (``'json'``), ``'csv'``, ``'xml'`` Re...
python
def export_fem(self, arms=None, format='json', df_kwargs=None): """ Export the project's form to event mapping Parameters ---------- arms : list Limit exported form event mappings to these arm numbers format : (``'json'``), ``'csv'``, ``'xml'`` Re...
[ "def", "export_fem", "(", "self", ",", "arms", "=", "None", ",", "format", "=", "'json'", ",", "df_kwargs", "=", "None", ")", ":", "ret_format", "=", "format", "if", "format", "==", "'df'", ":", "from", "pandas", "import", "read_csv", "ret_format", "=", ...
Export the project's form to event mapping Parameters ---------- arms : list Limit exported form event mappings to these arm numbers format : (``'json'``), ``'csv'``, ``'xml'`` Return the form event mappings in native objects, csv or xml, ``'df''`` wi...
[ "Export", "the", "project", "s", "form", "to", "event", "mapping" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L157-L194
redcap-tools/PyCap
redcap/project.py
Project.export_metadata
def export_metadata(self, fields=None, forms=None, format='json', df_kwargs=None): """ Export the project's metadata Parameters ---------- fields : list Limit exported metadata to these fields forms : list Limit exported metadata to th...
python
def export_metadata(self, fields=None, forms=None, format='json', df_kwargs=None): """ Export the project's metadata Parameters ---------- fields : list Limit exported metadata to these fields forms : list Limit exported metadata to th...
[ "def", "export_metadata", "(", "self", ",", "fields", "=", "None", ",", "forms", "=", "None", ",", "format", "=", "'json'", ",", "df_kwargs", "=", "None", ")", ":", "ret_format", "=", "format", "if", "format", "==", "'df'", ":", "from", "pandas", "impo...
Export the project's metadata Parameters ---------- fields : list Limit exported metadata to these fields forms : list Limit exported metadata to these forms format : (``'json'``), ``'csv'``, ``'xml'``, ``'df'`` Return the metadata in native o...
[ "Export", "the", "project", "s", "metadata" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L196-L236
redcap-tools/PyCap
redcap/project.py
Project.export_records
def export_records(self, records=None, fields=None, forms=None, events=None, raw_or_label='raw', event_name='label', format='json', export_survey_fields=False, export_data_access_groups=False, df_kwargs=None, export_checkbox_labels=False, filter_logic=None): """ Export data from the REDC...
python
def export_records(self, records=None, fields=None, forms=None, events=None, raw_or_label='raw', event_name='label', format='json', export_survey_fields=False, export_data_access_groups=False, df_kwargs=None, export_checkbox_labels=False, filter_logic=None): """ Export data from the REDC...
[ "def", "export_records", "(", "self", ",", "records", "=", "None", ",", "fields", "=", "None", ",", "forms", "=", "None", ",", "events", "=", "None", ",", "raw_or_label", "=", "'raw'", ",", "event_name", "=", "'label'", ",", "format", "=", "'json'", ",...
Export data from the REDCap project. Parameters ---------- records : list array of record names specifying specific records to export. by default, all records are exported fields : list array of field names specifying specific fields to pull ...
[ "Export", "data", "from", "the", "REDCap", "project", "." ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L238-L335
redcap-tools/PyCap
redcap/project.py
Project.__meta_metadata
def __meta_metadata(self, field, key): """Return the value for key for the field in the metadata""" mf = '' try: mf = str([f[key] for f in self.metadata if f['field_name'] == field][0]) except IndexError: print("%s not in metadata field:%s" % ...
python
def __meta_metadata(self, field, key): """Return the value for key for the field in the metadata""" mf = '' try: mf = str([f[key] for f in self.metadata if f['field_name'] == field][0]) except IndexError: print("%s not in metadata field:%s" % ...
[ "def", "__meta_metadata", "(", "self", ",", "field", ",", "key", ")", ":", "mf", "=", "''", "try", ":", "mf", "=", "str", "(", "[", "f", "[", "key", "]", "for", "f", "in", "self", ".", "metadata", "if", "f", "[", "'field_name'", "]", "==", "fie...
Return the value for key for the field in the metadata
[ "Return", "the", "value", "for", "key", "for", "the", "field", "in", "the", "metadata" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L342-L352
redcap-tools/PyCap
redcap/project.py
Project.backfill_fields
def backfill_fields(self, fields, forms): """ Properly backfill fields to explicitly request specific keys. The issue is that >6.X servers *only* return requested fields so to improve backwards compatiblity for PyCap clients, add specific fields when required. Parameters...
python
def backfill_fields(self, fields, forms): """ Properly backfill fields to explicitly request specific keys. The issue is that >6.X servers *only* return requested fields so to improve backwards compatiblity for PyCap clients, add specific fields when required. Parameters...
[ "def", "backfill_fields", "(", "self", ",", "fields", ",", "forms", ")", ":", "if", "forms", "and", "not", "fields", ":", "new_fields", "=", "[", "self", ".", "def_field", "]", "elif", "fields", "and", "self", ".", "def_field", "not", "in", "fields", "...
Properly backfill fields to explicitly request specific keys. The issue is that >6.X servers *only* return requested fields so to improve backwards compatiblity for PyCap clients, add specific fields when required. Parameters ---------- fields: list requested...
[ "Properly", "backfill", "fields", "to", "explicitly", "request", "specific", "keys", ".", "The", "issue", "is", "that", ">", "6", ".", "X", "servers", "*", "only", "*", "return", "requested", "fields", "so", "to", "improve", "backwards", "compatiblity", "for...
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L354-L382
redcap-tools/PyCap
redcap/project.py
Project.filter
def filter(self, query, output_fields=None): """Query the database and return subject information for those who match the query logic Parameters ---------- query: Query or QueryGroup Query(Group) object to process output_fields: list The fields de...
python
def filter(self, query, output_fields=None): """Query the database and return subject information for those who match the query logic Parameters ---------- query: Query or QueryGroup Query(Group) object to process output_fields: list The fields de...
[ "def", "filter", "(", "self", ",", "query", ",", "output_fields", "=", "None", ")", ":", "query_keys", "=", "query", ".", "fields", "(", ")", "if", "not", "set", "(", "query_keys", ")", ".", "issubset", "(", "set", "(", "self", ".", "field_names", ")...
Query the database and return subject information for those who match the query logic Parameters ---------- query: Query or QueryGroup Query(Group) object to process output_fields: list The fields desired for matching subjects Returns ---...
[ "Query", "the", "database", "and", "return", "subject", "information", "for", "those", "who", "match", "the", "query", "logic" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L384-L420
redcap-tools/PyCap
redcap/project.py
Project.names_labels
def names_labels(self, do_print=False): """Simple helper function to get all field names and labels """ if do_print: for name, label in zip(self.field_names, self.field_labels): print('%s --> %s' % (str(name), str(label))) return self.field_names, self.field_labels
python
def names_labels(self, do_print=False): """Simple helper function to get all field names and labels """ if do_print: for name, label in zip(self.field_names, self.field_labels): print('%s --> %s' % (str(name), str(label))) return self.field_names, self.field_labels
[ "def", "names_labels", "(", "self", ",", "do_print", "=", "False", ")", ":", "if", "do_print", ":", "for", "name", ",", "label", "in", "zip", "(", "self", ".", "field_names", ",", "self", ".", "field_labels", ")", ":", "print", "(", "'%s --> %s'", "%",...
Simple helper function to get all field names and labels
[ "Simple", "helper", "function", "to", "get", "all", "field", "names", "and", "labels" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L422-L427
redcap-tools/PyCap
redcap/project.py
Project.import_records
def import_records(self, to_import, overwrite='normal', format='json', return_format='json', return_content='count', date_format='YMD', force_auto_number=False): """ Import data into the RedCap Project Parameters ---------- to_import : array of dicts, csv/xml str...
python
def import_records(self, to_import, overwrite='normal', format='json', return_format='json', return_content='count', date_format='YMD', force_auto_number=False): """ Import data into the RedCap Project Parameters ---------- to_import : array of dicts, csv/xml str...
[ "def", "import_records", "(", "self", ",", "to_import", ",", "overwrite", "=", "'normal'", ",", "format", "=", "'json'", ",", "return_format", "=", "'json'", ",", "return_content", "=", "'count'", ",", "date_format", "=", "'YMD'", ",", "force_auto_number", "="...
Import data into the RedCap Project Parameters ---------- to_import : array of dicts, csv/xml string, ``pandas.DataFrame`` :note: If you pass a csv or xml string, you should use the ``format`` parameter appropriately. :note: ...
[ "Import", "data", "into", "the", "RedCap", "Project" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L429-L501
redcap-tools/PyCap
redcap/project.py
Project.export_file
def export_file(self, record, field, event=None, return_format='json'): """ Export the contents of a file stored for a particular record Notes ----- Unlike other export methods, this works on a single record. Parameters ---------- record : str ...
python
def export_file(self, record, field, event=None, return_format='json'): """ Export the contents of a file stored for a particular record Notes ----- Unlike other export methods, this works on a single record. Parameters ---------- record : str ...
[ "def", "export_file", "(", "self", ",", "record", ",", "field", ",", "event", "=", "None", ",", "return_format", "=", "'json'", ")", ":", "self", ".", "_check_file_field", "(", "field", ")", "# load up payload", "pl", "=", "self", ".", "__basepl", "(", "...
Export the contents of a file stored for a particular record Notes ----- Unlike other export methods, this works on a single record. Parameters ---------- record : str record ID field : str field name containing the file to be exported. ...
[ "Export", "the", "contents", "of", "a", "file", "stored", "for", "a", "particular", "record" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L503-L549
redcap-tools/PyCap
redcap/project.py
Project.import_file
def import_file(self, record, field, fname, fobj, event=None, return_format='json'): """ Import the contents of a file represented by fobj to a particular records field Parameters ---------- record : str record ID field : str f...
python
def import_file(self, record, field, fname, fobj, event=None, return_format='json'): """ Import the contents of a file represented by fobj to a particular records field Parameters ---------- record : str record ID field : str f...
[ "def", "import_file", "(", "self", ",", "record", ",", "field", ",", "fname", ",", "fobj", ",", "event", "=", "None", ",", "return_format", "=", "'json'", ")", ":", "self", ".", "_check_file_field", "(", "field", ")", "# load up payload", "pl", "=", "sel...
Import the contents of a file represented by fobj to a particular records field Parameters ---------- record : str record ID field : str field name where the file will go fname : str file name visible in REDCap UI fobj : file o...
[ "Import", "the", "contents", "of", "a", "file", "represented", "by", "fobj", "to", "a", "particular", "records", "field" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L551-L589
redcap-tools/PyCap
redcap/project.py
Project.delete_file
def delete_file(self, record, field, return_format='json', event=None): """ Delete a file from REDCap Notes ----- There is no undo button to this. Parameters ---------- record : str record ID field : str field name ...
python
def delete_file(self, record, field, return_format='json', event=None): """ Delete a file from REDCap Notes ----- There is no undo button to this. Parameters ---------- record : str record ID field : str field name ...
[ "def", "delete_file", "(", "self", ",", "record", ",", "field", ",", "return_format", "=", "'json'", ",", "event", "=", "None", ")", ":", "self", ".", "_check_file_field", "(", "field", ")", "# Load up payload", "pl", "=", "self", ".", "__basepl", "(", "...
Delete a file from REDCap Notes ----- There is no undo button to this. Parameters ---------- record : str record ID field : str field name return_format : (``'json'``), ``'csv'``, ``'xml'`` return format for error mess...
[ "Delete", "a", "file", "from", "REDCap" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L591-L625
redcap-tools/PyCap
redcap/project.py
Project._check_file_field
def _check_file_field(self, field): """Check that field exists and is a file field""" is_field = field in self.field_names is_file = self.__meta_metadata(field, 'field_type') == 'file' if not (is_field and is_file): msg = "'%s' is not a field or not a 'file' field" % field ...
python
def _check_file_field(self, field): """Check that field exists and is a file field""" is_field = field in self.field_names is_file = self.__meta_metadata(field, 'field_type') == 'file' if not (is_field and is_file): msg = "'%s' is not a field or not a 'file' field" % field ...
[ "def", "_check_file_field", "(", "self", ",", "field", ")", ":", "is_field", "=", "field", "in", "self", ".", "field_names", "is_file", "=", "self", ".", "__meta_metadata", "(", "field", ",", "'field_type'", ")", "==", "'file'", "if", "not", "(", "is_field...
Check that field exists and is a file field
[ "Check", "that", "field", "exists", "and", "is", "a", "file", "field" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L627-L635
redcap-tools/PyCap
redcap/project.py
Project.export_users
def export_users(self, format='json'): """ Export the users of the Project Notes ----- Each user will have the following keys: * ``'firstname'`` : User's first name * ``'lastname'`` : User's last name * ``'email'`` : Email address ...
python
def export_users(self, format='json'): """ Export the users of the Project Notes ----- Each user will have the following keys: * ``'firstname'`` : User's first name * ``'lastname'`` : User's last name * ``'email'`` : Email address ...
[ "def", "export_users", "(", "self", ",", "format", "=", "'json'", ")", ":", "pl", "=", "self", ".", "__basepl", "(", "content", "=", "'user'", ",", "format", "=", "format", ")", "return", "self", ".", "_call_api", "(", "pl", ",", "'exp_user'", ")", "...
Export the users of the Project Notes ----- Each user will have the following keys: * ``'firstname'`` : User's first name * ``'lastname'`` : User's last name * ``'email'`` : Email address * ``'username'`` : User's username * ``'expira...
[ "Export", "the", "users", "of", "the", "Project" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L637-L671
redcap-tools/PyCap
redcap/project.py
Project.export_survey_participant_list
def export_survey_participant_list(self, instrument, event=None, format='json'): """ Export the Survey Participant List Notes ----- The passed instrument must be set up as a survey instrument. Parameters ---------- instrument: str Name of ins...
python
def export_survey_participant_list(self, instrument, event=None, format='json'): """ Export the Survey Participant List Notes ----- The passed instrument must be set up as a survey instrument. Parameters ---------- instrument: str Name of ins...
[ "def", "export_survey_participant_list", "(", "self", ",", "instrument", ",", "event", "=", "None", ",", "format", "=", "'json'", ")", ":", "pl", "=", "self", ".", "__basepl", "(", "content", "=", "'participantList'", ",", "format", "=", "format", ")", "pl...
Export the Survey Participant List Notes ----- The passed instrument must be set up as a survey instrument. Parameters ---------- instrument: str Name of instrument as seen in second column of Data Dictionary. event: str Unique event name...
[ "Export", "the", "Survey", "Participant", "List" ]
train
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/project.py#L673-L694
quentinsf/qhue
qhue/qhue.py
create_new_username
def create_new_username(ip, devicetype=None, timeout=_DEFAULT_TIMEOUT): """Interactive helper function to generate a new anonymous username. Args: ip: ip address of the bridge devicetype (optional): devicetype to register with the bridge. If unprovided, generates a device type based...
python
def create_new_username(ip, devicetype=None, timeout=_DEFAULT_TIMEOUT): """Interactive helper function to generate a new anonymous username. Args: ip: ip address of the bridge devicetype (optional): devicetype to register with the bridge. If unprovided, generates a device type based...
[ "def", "create_new_username", "(", "ip", ",", "devicetype", "=", "None", ",", "timeout", "=", "_DEFAULT_TIMEOUT", ")", ":", "res", "=", "Resource", "(", "_api_url", "(", "ip", ")", ",", "timeout", ")", "prompt", "=", "\"Press the Bridge button, then press Return...
Interactive helper function to generate a new anonymous username. Args: ip: ip address of the bridge devicetype (optional): devicetype to register with the bridge. If unprovided, generates a device type based on the local hostname. timeout (optional, default=5): request timeout ...
[ "Interactive", "helper", "function", "to", "generate", "a", "new", "anonymous", "username", "." ]
train
https://github.com/quentinsf/qhue/blob/faddc49de844134784f4742f4783066976d76c08/qhue/qhue.py#L73-L99
spotify/gordon
gordon/router.py
GordonRouter.run
async def run(self): """Entrypoint to route messages between plugins.""" logging.info('Starting message router...') coroutines = set() while True: coro = self._poll_channel() coroutines.add(coro) _, coroutines = await asyncio.wait(coroutines, timeout=...
python
async def run(self): """Entrypoint to route messages between plugins.""" logging.info('Starting message router...') coroutines = set() while True: coro = self._poll_channel() coroutines.add(coro) _, coroutines = await asyncio.wait(coroutines, timeout=...
[ "async", "def", "run", "(", "self", ")", ":", "logging", ".", "info", "(", "'Starting message router...'", ")", "coroutines", "=", "set", "(", ")", "while", "True", ":", "coro", "=", "self", ".", "_poll_channel", "(", ")", "coroutines", ".", "add", "(", ...
Entrypoint to route messages between plugins.
[ "Entrypoint", "to", "route", "messages", "between", "plugins", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/router.py#L193-L201
spotify/gordon
gordon/main.py
shutdown
async def shutdown(sig, loop): """Gracefully cancel current tasks when app receives a shutdown signal.""" logging.info(f'Received exit signal {sig.name}...') tasks = [task for task in asyncio.Task.all_tasks() if task is not asyncio.tasks.Task.current_task()] for task in tasks: logg...
python
async def shutdown(sig, loop): """Gracefully cancel current tasks when app receives a shutdown signal.""" logging.info(f'Received exit signal {sig.name}...') tasks = [task for task in asyncio.Task.all_tasks() if task is not asyncio.tasks.Task.current_task()] for task in tasks: logg...
[ "async", "def", "shutdown", "(", "sig", ",", "loop", ")", ":", "logging", ".", "info", "(", "f'Received exit signal {sig.name}...'", ")", "tasks", "=", "[", "task", "for", "task", "in", "asyncio", ".", "Task", ".", "all_tasks", "(", ")", "if", "task", "i...
Gracefully cancel current tasks when app receives a shutdown signal.
[ "Gracefully", "cancel", "current", "tasks", "when", "app", "receives", "a", "shutdown", "signal", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/main.py#L51-L65
spotify/gordon
gordon/main.py
_deep_merge_dict
def _deep_merge_dict(a, b): """Additively merge right side dict into left side dict.""" for k, v in b.items(): if k in a and isinstance(a[k], dict) and isinstance(v, dict): _deep_merge_dict(a[k], v) else: a[k] = v
python
def _deep_merge_dict(a, b): """Additively merge right side dict into left side dict.""" for k, v in b.items(): if k in a and isinstance(a[k], dict) and isinstance(v, dict): _deep_merge_dict(a[k], v) else: a[k] = v
[ "def", "_deep_merge_dict", "(", "a", ",", "b", ")", ":", "for", "k", ",", "v", "in", "b", ".", "items", "(", ")", ":", "if", "k", "in", "a", "and", "isinstance", "(", "a", "[", "k", "]", ",", "dict", ")", "and", "isinstance", "(", "v", ",", ...
Additively merge right side dict into left side dict.
[ "Additively", "merge", "right", "side", "dict", "into", "left", "side", "dict", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/main.py#L68-L74
spotify/gordon
gordon/plugins_loader.py
load_plugins
def load_plugins(config, plugin_kwargs): """ Discover and instantiate plugins. Args: config (dict): loaded configuration for the Gordon service. plugin_kwargs (dict): keyword arguments to give to plugins during instantiation. Returns: Tuple of 3 lists: list of names ...
python
def load_plugins(config, plugin_kwargs): """ Discover and instantiate plugins. Args: config (dict): loaded configuration for the Gordon service. plugin_kwargs (dict): keyword arguments to give to plugins during instantiation. Returns: Tuple of 3 lists: list of names ...
[ "def", "load_plugins", "(", "config", ",", "plugin_kwargs", ")", ":", "installed_plugins", "=", "_gather_installed_plugins", "(", ")", "metrics_plugin", "=", "_get_metrics_plugin", "(", "config", ",", "installed_plugins", ")", "if", "metrics_plugin", ":", "plugin_kwar...
Discover and instantiate plugins. Args: config (dict): loaded configuration for the Gordon service. plugin_kwargs (dict): keyword arguments to give to plugins during instantiation. Returns: Tuple of 3 lists: list of names of plugins, list of instantiated plugin objec...
[ "Discover", "and", "instantiate", "plugins", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/plugins_loader.py#L210-L237
spotify/gordon
gordon/metrics/ffwd.py
UDPClientProtocol.connection_made
def connection_made(self, transport): """Create connection, use to send message and close. Args: transport (asyncio.DatagramTransport): Transport used for sending. """ self.transport = transport self.transport.sendto(self.message) self.transport.close()
python
def connection_made(self, transport): """Create connection, use to send message and close. Args: transport (asyncio.DatagramTransport): Transport used for sending. """ self.transport = transport self.transport.sendto(self.message) self.transport.close()
[ "def", "connection_made", "(", "self", ",", "transport", ")", ":", "self", ".", "transport", "=", "transport", "self", ".", "transport", ".", "sendto", "(", "self", ".", "message", ")", "self", ".", "transport", ".", "close", "(", ")" ]
Create connection, use to send message and close. Args: transport (asyncio.DatagramTransport): Transport used for sending.
[ "Create", "connection", "use", "to", "send", "message", "and", "close", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/metrics/ffwd.py#L59-L67
spotify/gordon
gordon/metrics/ffwd.py
UDPClient.send
async def send(self, metric): """Transform metric to JSON bytestring and send to server. Args: metric (dict): Complete metric to send as JSON. """ message = json.dumps(metric).encode('utf-8') await self.loop.create_datagram_endpoint( lambda: UDPClientProt...
python
async def send(self, metric): """Transform metric to JSON bytestring and send to server. Args: metric (dict): Complete metric to send as JSON. """ message = json.dumps(metric).encode('utf-8') await self.loop.create_datagram_endpoint( lambda: UDPClientProt...
[ "async", "def", "send", "(", "self", ",", "metric", ")", ":", "message", "=", "json", ".", "dumps", "(", "metric", ")", ".", "encode", "(", "'utf-8'", ")", "await", "self", ".", "loop", ".", "create_datagram_endpoint", "(", "lambda", ":", "UDPClientProto...
Transform metric to JSON bytestring and send to server. Args: metric (dict): Complete metric to send as JSON.
[ "Transform", "metric", "to", "JSON", "bytestring", "and", "send", "to", "server", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/metrics/ffwd.py#L87-L96
spotify/gordon
gordon/record_checker.py
RecordChecker.check_record
async def check_record(self, record, timeout=60): """Measures the time for a DNS record to become available. Query a provided DNS server multiple times until the reply matches the information in the record or until timeout is reached. Args: record (dict): DNS record as a di...
python
async def check_record(self, record, timeout=60): """Measures the time for a DNS record to become available. Query a provided DNS server multiple times until the reply matches the information in the record or until timeout is reached. Args: record (dict): DNS record as a di...
[ "async", "def", "check_record", "(", "self", ",", "record", ",", "timeout", "=", "60", ")", ":", "start_time", "=", "time", ".", "time", "(", ")", "name", ",", "rr_data", ",", "r_type", ",", "ttl", "=", "self", ".", "_extract_record_data", "(", "record...
Measures the time for a DNS record to become available. Query a provided DNS server multiple times until the reply matches the information in the record or until timeout is reached. Args: record (dict): DNS record as a dict with record properties. timeout (int): Time th...
[ "Measures", "the", "time", "for", "a", "DNS", "record", "to", "become", "available", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/record_checker.py#L54-L94
spotify/gordon
gordon/record_checker.py
RecordChecker._check_resolver_ans
async def _check_resolver_ans( self, dns_answer_list, record_name, record_data_list, record_ttl, record_type_code): """Check if resolver answer is equal to record data. Args: dns_answer_list (list): DNS answer list contains record objects. record_name (st...
python
async def _check_resolver_ans( self, dns_answer_list, record_name, record_data_list, record_ttl, record_type_code): """Check if resolver answer is equal to record data. Args: dns_answer_list (list): DNS answer list contains record objects. record_name (st...
[ "async", "def", "_check_resolver_ans", "(", "self", ",", "dns_answer_list", ",", "record_name", ",", "record_data_list", ",", "record_ttl", ",", "record_type_code", ")", ":", "type_filtered_list", "=", "[", "ans", "for", "ans", "in", "dns_answer_list", "if", "ans"...
Check if resolver answer is equal to record data. Args: dns_answer_list (list): DNS answer list contains record objects. record_name (str): Record name. record_data_list (list): List of data values for the record. record_ttl (int): Record time-to-live info. ...
[ "Check", "if", "resolver", "answer", "is", "equal", "to", "record", "data", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/record_checker.py#L96-L131
spotify/gordon
setup.py
read
def read(*filenames, **kwargs): """ Build an absolute path from ``*filenames``, and return contents of resulting file. Defaults to UTF-8 encoding. """ encoding = kwargs.get('encoding', 'utf-8') sep = kwargs.get('sep', '\n') buf = [] for fl in filenames: with codecs.open(os.path...
python
def read(*filenames, **kwargs): """ Build an absolute path from ``*filenames``, and return contents of resulting file. Defaults to UTF-8 encoding. """ encoding = kwargs.get('encoding', 'utf-8') sep = kwargs.get('sep', '\n') buf = [] for fl in filenames: with codecs.open(os.path...
[ "def", "read", "(", "*", "filenames", ",", "*", "*", "kwargs", ")", ":", "encoding", "=", "kwargs", ".", "get", "(", "'encoding'", ",", "'utf-8'", ")", "sep", "=", "kwargs", ".", "get", "(", "'sep'", ",", "'\\n'", ")", "buf", "=", "[", "]", "for"...
Build an absolute path from ``*filenames``, and return contents of resulting file. Defaults to UTF-8 encoding.
[ "Build", "an", "absolute", "path", "from", "*", "filenames", "and", "return", "contents", "of", "resulting", "file", ".", "Defaults", "to", "UTF", "-", "8", "encoding", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/setup.py#L32-L43
spotify/gordon
gordon/metrics/log.py
LoggerAdapter.log
def log(self, metric): """Format and output metric. Args: metric (dict): Complete metric. """ message = self.LOGFMT.format(**metric) if metric['context']: message += ' context: {context}'.format(context=metric['context']) self._logger.log(self.lev...
python
def log(self, metric): """Format and output metric. Args: metric (dict): Complete metric. """ message = self.LOGFMT.format(**metric) if metric['context']: message += ' context: {context}'.format(context=metric['context']) self._logger.log(self.lev...
[ "def", "log", "(", "self", ",", "metric", ")", ":", "message", "=", "self", ".", "LOGFMT", ".", "format", "(", "*", "*", "metric", ")", "if", "metric", "[", "'context'", "]", ":", "message", "+=", "' context: {context}'", ".", "format", "(", "context",...
Format and output metric. Args: metric (dict): Complete metric.
[ "Format", "and", "output", "metric", "." ]
train
https://github.com/spotify/gordon/blob/8dbf54a032cfaa8f003264682456236b6a69c039/gordon/metrics/log.py#L89-L98
jameslyons/pycipher
pycipher/atbash.py
Atbash.encipher
def encipher(self,string,keep_punct=False): """Encipher string using Atbash cipher. Example:: ciphertext = Atbash().encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed...
python
def encipher(self,string,keep_punct=False): """Encipher string using Atbash cipher. Example:: ciphertext = Atbash().encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed...
[ "def", "encipher", "(", "self", ",", "string", ",", "keep_punct", "=", "False", ")", ":", "if", "not", "keep_punct", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ret", "=", "''", "for", "c", "in", "string", ".", "upper", ...
Encipher string using Atbash cipher. Example:: ciphertext = Atbash().encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed. Default is False. :returns: The enciphered s...
[ "Encipher", "string", "using", "Atbash", "cipher", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/atbash.py#L16-L32
jameslyons/pycipher
pycipher/polybius.py
PolybiusSquare.encipher
def encipher(self,string): """Encipher string using Polybius square cipher according to initialised key. Example:: ciphertext = Polybius('APCZWRLFBDKOTYUQGENHXMIVS',5,'MKSBU').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string. ...
python
def encipher(self,string): """Encipher string using Polybius square cipher according to initialised key. Example:: ciphertext = Polybius('APCZWRLFBDKOTYUQGENHXMIVS',5,'MKSBU').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string. ...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "#,filter='[^'+self.key+']')", "ret", "=", "''", "for", "c", "in", "range", "(", "0", ",", "len", "(", "string", ")", ")", ":...
Encipher string using Polybius square cipher according to initialised key. Example:: ciphertext = Polybius('APCZWRLFBDKOTYUQGENHXMIVS',5,'MKSBU').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string. The ciphertext will be twice the lengt...
[ "Encipher", "string", "using", "Polybius", "square", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/polybius.py#L36-L50
jameslyons/pycipher
pycipher/polybius.py
PolybiusSquare.decipher
def decipher(self,string): """Decipher string using Polybius square cipher according to initialised key. Example:: plaintext = Polybius('APCZWRLFBDKOTYUQGENHXMIVS',5,'MKSBU').decipher(ciphertext) :param string: The string to decipher. :returns: The deciphered string. ...
python
def decipher(self,string): """Decipher string using Polybius square cipher according to initialised key. Example:: plaintext = Polybius('APCZWRLFBDKOTYUQGENHXMIVS',5,'MKSBU').decipher(ciphertext) :param string: The string to decipher. :returns: The deciphered string. ...
[ "def", "decipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "#,filter='[^'+self.chars+']')", "ret", "=", "''", "for", "i", "in", "range", "(", "0", ",", "len", "(", "string", ")", ",", ...
Decipher string using Polybius square cipher according to initialised key. Example:: plaintext = Polybius('APCZWRLFBDKOTYUQGENHXMIVS',5,'MKSBU').decipher(ciphertext) :param string: The string to decipher. :returns: The deciphered string. The plaintext will be half the length ...
[ "Decipher", "string", "using", "Polybius", "square", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/polybius.py#L52-L66
jameslyons/pycipher
pycipher/adfgvx.py
ADFGVX.decipher
def decipher(self,string): """Decipher string using ADFGVX cipher according to initialised key information. Punctuation and whitespace are removed from the input. Example:: plaintext = ADFGVX('ph0qg64mea1yl2nofdxkr3cvs5zw7bj9uti8','HELLO').decipher(ciphertext) ...
python
def decipher(self,string): """Decipher string using ADFGVX cipher according to initialised key information. Punctuation and whitespace are removed from the input. Example:: plaintext = ADFGVX('ph0qg64mea1yl2nofdxkr3cvs5zw7bj9uti8','HELLO').decipher(ciphertext) ...
[ "def", "decipher", "(", "self", ",", "string", ")", ":", "step2", "=", "ColTrans", "(", "self", ".", "keyword", ")", ".", "decipher", "(", "string", ")", "step1", "=", "PolybiusSquare", "(", "self", ".", "key", ",", "size", "=", "6", ",", "chars", ...
Decipher string using ADFGVX cipher according to initialised key information. Punctuation and whitespace are removed from the input. Example:: plaintext = ADFGVX('ph0qg64mea1yl2nofdxkr3cvs5zw7bj9uti8','HELLO').decipher(ciphertext) :param string: The string to decipher....
[ "Decipher", "string", "using", "ADFGVX", "cipher", "according", "to", "initialised", "key", "information", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/adfgvx.py#L40-L53
jameslyons/pycipher
pycipher/enigma.py
Enigma.encipher
def encipher(self,string): """Encipher string using Enigma M3 cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Enigma(settings=('A','A','A'),rotors=(1,2,3),reflector='B', ringstellung=('F','V'...
python
def encipher(self,string): """Encipher string using Enigma M3 cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Enigma(settings=('A','A','A'),rotors=(1,2,3),reflector='B', ringstellung=('F','V'...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ret", "=", "''", "for", "c", "in", "string", ".", "upper", "(", ")", ":", "if", "c", ".", "isalpha", "(", ")", ":", "r...
Encipher string using Enigma M3 cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Enigma(settings=('A','A','A'),rotors=(1,2,3),reflector='B', ringstellung=('F','V','N'),steckers=[('P','O'),('M','L'), ...
[ "Encipher", "string", "using", "Enigma", "M3", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/enigma.py#L128-L147
jameslyons/pycipher
pycipher/util.py
ic
def ic(ctext): ''' takes ciphertext, calculates index of coincidence.''' counts = ngram_count(ctext,N=1) icval = 0 for k in counts.keys(): icval += counts[k]*(counts[k]-1) icval /= (len(ctext)*(len(ctext)-1)) return icval
python
def ic(ctext): ''' takes ciphertext, calculates index of coincidence.''' counts = ngram_count(ctext,N=1) icval = 0 for k in counts.keys(): icval += counts[k]*(counts[k]-1) icval /= (len(ctext)*(len(ctext)-1)) return icval
[ "def", "ic", "(", "ctext", ")", ":", "counts", "=", "ngram_count", "(", "ctext", ",", "N", "=", "1", ")", "icval", "=", "0", "for", "k", "in", "counts", ".", "keys", "(", ")", ":", "icval", "+=", "counts", "[", "k", "]", "*", "(", "counts", "...
takes ciphertext, calculates index of coincidence.
[ "takes", "ciphertext", "calculates", "index", "of", "coincidence", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/util.py#L7-L14
jameslyons/pycipher
pycipher/util.py
ngram_count
def ngram_count(text,N=1,keep_punct=False): ''' if N=1, return a dict containing each letter along with how many times the letter occurred. if N=2, returns a dict containing counts of each bigram (pair of letters) etc. There is an option to remove all spaces and punctuation prior to processi...
python
def ngram_count(text,N=1,keep_punct=False): ''' if N=1, return a dict containing each letter along with how many times the letter occurred. if N=2, returns a dict containing counts of each bigram (pair of letters) etc. There is an option to remove all spaces and punctuation prior to processi...
[ "def", "ngram_count", "(", "text", ",", "N", "=", "1", ",", "keep_punct", "=", "False", ")", ":", "if", "not", "keep_punct", ":", "text", "=", "re", ".", "sub", "(", "'[^A-Z]'", ",", "''", ",", "text", ".", "upper", "(", ")", ")", "count", "=", ...
if N=1, return a dict containing each letter along with how many times the letter occurred. if N=2, returns a dict containing counts of each bigram (pair of letters) etc. There is an option to remove all spaces and punctuation prior to processing
[ "if", "N", "=", "1", "return", "a", "dict", "containing", "each", "letter", "along", "with", "how", "many", "times", "the", "letter", "occurred", ".", "if", "N", "=", "2", "returns", "a", "dict", "containing", "counts", "of", "each", "bigram", "(", "pa...
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/util.py#L16-L27
jameslyons/pycipher
pycipher/util.py
ngram_freq
def ngram_freq(text,N=1,log=False,floor=0.01): ''' returns the n-gram frequencies of all n-grams encountered in text. Option to return log probabilities or standard probabilities. Note that only n-grams occurring in 'text' will have probabilities. For the probability of not-occurring n-grams...
python
def ngram_freq(text,N=1,log=False,floor=0.01): ''' returns the n-gram frequencies of all n-grams encountered in text. Option to return log probabilities or standard probabilities. Note that only n-grams occurring in 'text' will have probabilities. For the probability of not-occurring n-grams...
[ "def", "ngram_freq", "(", "text", ",", "N", "=", "1", ",", "log", "=", "False", ",", "floor", "=", "0.01", ")", ":", "freq", "=", "ngram_count", "(", "text", ",", "N", ")", "L", "=", "1.0", "*", "(", "len", "(", "text", ")", "-", "N", "+", ...
returns the n-gram frequencies of all n-grams encountered in text. Option to return log probabilities or standard probabilities. Note that only n-grams occurring in 'text' will have probabilities. For the probability of not-occurring n-grams, use freq['floor']. This is set to floor/len(t...
[ "returns", "the", "n", "-", "gram", "frequencies", "of", "all", "n", "-", "grams", "encountered", "in", "text", ".", "Option", "to", "return", "log", "probabilities", "or", "standard", "probabilities", ".", "Note", "that", "only", "n", "-", "grams", "occur...
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/util.py#L29-L42
jameslyons/pycipher
pycipher/util.py
restore_punctuation
def restore_punctuation(original,modified): ''' If punctuation was accidently removed, use this function to restore it. requires the orignial string with punctuation. ''' ret = '' count = 0 try: for c in original: if c.isalpha(): ret+=modified[count] ...
python
def restore_punctuation(original,modified): ''' If punctuation was accidently removed, use this function to restore it. requires the orignial string with punctuation. ''' ret = '' count = 0 try: for c in original: if c.isalpha(): ret+=modified[count] ...
[ "def", "restore_punctuation", "(", "original", ",", "modified", ")", ":", "ret", "=", "''", "count", "=", "0", "try", ":", "for", "c", "in", "original", ":", "if", "c", ".", "isalpha", "(", ")", ":", "ret", "+=", "modified", "[", "count", "]", "cou...
If punctuation was accidently removed, use this function to restore it. requires the orignial string with punctuation.
[ "If", "punctuation", "was", "accidently", "removed", "use", "this", "function", "to", "restore", "it", ".", "requires", "the", "orignial", "string", "with", "punctuation", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/util.py#L44-L58
jameslyons/pycipher
pycipher/util.py
keyword_to_key
def keyword_to_key(word,alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ'): ''' convert a key word to a key by appending on the other letters of the alphabet. e.g. MONARCHY -> MONARCHYBDEFGIJKLPQSTUVWXZ ''' ret = '' word = (word + alphabet).upper() for i in word: if i in ret: continue ret +=...
python
def keyword_to_key(word,alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ'): ''' convert a key word to a key by appending on the other letters of the alphabet. e.g. MONARCHY -> MONARCHYBDEFGIJKLPQSTUVWXZ ''' ret = '' word = (word + alphabet).upper() for i in word: if i in ret: continue ret +=...
[ "def", "keyword_to_key", "(", "word", ",", "alphabet", "=", "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'", ")", ":", "ret", "=", "''", "word", "=", "(", "word", "+", "alphabet", ")", ".", "upper", "(", ")", "for", "i", "in", "word", ":", "if", "i", "in", "ret", ":"...
convert a key word to a key by appending on the other letters of the alphabet. e.g. MONARCHY -> MONARCHYBDEFGIJKLPQSTUVWXZ
[ "convert", "a", "key", "word", "to", "a", "key", "by", "appending", "on", "the", "other", "letters", "of", "the", "alphabet", ".", "e", ".", "g", ".", "MONARCHY", "-", ">", "MONARCHYBDEFGIJKLPQSTUVWXZ" ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/util.py#L61-L70
jameslyons/pycipher
pycipher/playfair.py
Playfair.encipher
def encipher(self, string): """Encipher string using Playfair cipher according to initialised key. Punctuation and whitespace are removed from the input. If the input plaintext is not an even number of characters, an 'X' will be appended. Example:: ciphertext = Playfair(key='zgptfo...
python
def encipher(self, string): """Encipher string using Playfair cipher according to initialised key. Punctuation and whitespace are removed from the input. If the input plaintext is not an even number of characters, an 'X' will be appended. Example:: ciphertext = Playfair(key='zgptfo...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "string", "=", "re", ".", "sub", "(", "r'[J]'", ",", "'I'", ",", "string", ")", "if", "len", "(", "string", ")", "%", "2"...
Encipher string using Playfair cipher according to initialised key. Punctuation and whitespace are removed from the input. If the input plaintext is not an even number of characters, an 'X' will be appended. Example:: ciphertext = Playfair(key='zgptfoihmuwdrcnykeqaxvsbl').encipher(plaintex...
[ "Encipher", "string", "using", "Playfair", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", ".", "If", "the", "input", "plaintext", "is", "not", "an", "even", "number", "of", ...
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/playfair.py#L44-L62
jameslyons/pycipher
pycipher/playfair.py
Playfair.decipher
def decipher(self, string): """Decipher string using Playfair cipher according to initialised key. Punctuation and whitespace are removed from the input. The ciphertext should be an even number of characters. If the input ciphertext is not an even number of characters, an 'X' will be appended. ...
python
def decipher(self, string): """Decipher string using Playfair cipher according to initialised key. Punctuation and whitespace are removed from the input. The ciphertext should be an even number of characters. If the input ciphertext is not an even number of characters, an 'X' will be appended. ...
[ "def", "decipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "if", "len", "(", "string", ")", "%", "2", "==", "1", ":", "string", "+=", "'X'", "ret", "=", "''", "for", "c", "in", "...
Decipher string using Playfair cipher according to initialised key. Punctuation and whitespace are removed from the input. The ciphertext should be an even number of characters. If the input ciphertext is not an even number of characters, an 'X' will be appended. Example:: plaintext = Play...
[ "Decipher", "string", "using", "Playfair", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", ".", "The", "ciphertext", "should", "be", "an", "even", "number", "of", "characters",...
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/playfair.py#L64-L81
jameslyons/pycipher
pycipher/delastelle.py
Delastelle.encipher
def encipher(self,string): """Encipher string using Delastelle cipher according to initialised key. Example:: ciphertext = Delastelle('APCZ WRLFBDKOTYUQGENHXMIVS').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string. The cipherte...
python
def encipher(self,string): """Encipher string using Delastelle cipher according to initialised key. Example:: ciphertext = Delastelle('APCZ WRLFBDKOTYUQGENHXMIVS').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string. The cipherte...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ",", "filter", "=", "'[^'", "+", "self", ".", "key", "+", "']'", ")", "ctext", "=", "\"\"", "for", "c", "in", "string", ":", "...
Encipher string using Delastelle cipher according to initialised key. Example:: ciphertext = Delastelle('APCZ WRLFBDKOTYUQGENHXMIVS').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string. The ciphertext will be 3 times the length of the p...
[ "Encipher", "string", "using", "Delastelle", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/delastelle.py#L26-L40
jameslyons/pycipher
pycipher/delastelle.py
Delastelle.decipher
def decipher(self,string): """Decipher string using Delastelle cipher according to initialised key. Example:: plaintext = Delastelle('APCZ WRLFBDKOTYUQGENHXMIVS').decipher(ciphertext) :param string: The string to decipher. :returns: The deciphered string. The plaintex...
python
def decipher(self,string): """Decipher string using Delastelle cipher according to initialised key. Example:: plaintext = Delastelle('APCZ WRLFBDKOTYUQGENHXMIVS').decipher(ciphertext) :param string: The string to decipher. :returns: The deciphered string. The plaintex...
[ "def", "decipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ",", "filter", "=", "'[^'", "+", "self", ".", "chars", "+", "']'", ")", "ret", "=", "''", "for", "i", "in", "range", "(", "0",...
Decipher string using Delastelle cipher according to initialised key. Example:: plaintext = Delastelle('APCZ WRLFBDKOTYUQGENHXMIVS').decipher(ciphertext) :param string: The string to decipher. :returns: The deciphered string. The plaintext will be 1/3 the length of the cipher...
[ "Decipher", "string", "using", "Delastelle", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/delastelle.py#L42-L57
jameslyons/pycipher
pycipher/foursquare.py
Foursquare.encipher
def encipher(self,string): """Encipher string using Foursquare cipher according to initialised key. Punctuation and whitespace are removed from the input. If the input plaintext is not an even number of characters, an 'X' will be appended. Example:: ciphertext = Foursquare(key1='zg...
python
def encipher(self,string): """Encipher string using Foursquare cipher according to initialised key. Punctuation and whitespace are removed from the input. If the input plaintext is not an even number of characters, an 'X' will be appended. Example:: ciphertext = Foursquare(key1='zg...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "if", "len", "(", "string", ")", "%", "2", "==", "1", ":", "string", "=", "string", "+", "'X'", "ret", "=", "''", "for", ...
Encipher string using Foursquare cipher according to initialised key. Punctuation and whitespace are removed from the input. If the input plaintext is not an even number of characters, an 'X' will be appended. Example:: ciphertext = Foursquare(key1='zgptfoihmuwdrcnykeqaxvsbl',key2='mfnbdcr...
[ "Encipher", "string", "using", "Foursquare", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", ".", "If", "the", "input", "plaintext", "is", "not", "an", "even", "number", "of"...
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/foursquare.py#L34-L51
jameslyons/pycipher
pycipher/foursquare.py
Foursquare.decipher
def decipher(self,string): """Decipher string using Foursquare cipher according to initialised key. Punctuation and whitespace are removed from the input. The ciphertext should be an even number of characters. If the input ciphertext is not an even number of characters, an 'X' will be appended. ...
python
def decipher(self,string): """Decipher string using Foursquare cipher according to initialised key. Punctuation and whitespace are removed from the input. The ciphertext should be an even number of characters. If the input ciphertext is not an even number of characters, an 'X' will be appended. ...
[ "def", "decipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "if", "len", "(", "string", ")", "%", "2", "==", "1", ":", "string", "=", "string", "+", "'X'", "ret", "=", "''", "for", ...
Decipher string using Foursquare cipher according to initialised key. Punctuation and whitespace are removed from the input. The ciphertext should be an even number of characters. If the input ciphertext is not an even number of characters, an 'X' will be appended. Example:: plaintext = Fo...
[ "Decipher", "string", "using", "Foursquare", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", ".", "The", "ciphertext", "should", "be", "an", "even", "number", "of", "characters...
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/foursquare.py#L53-L70
jameslyons/pycipher
pycipher/rot13.py
Rot13.encipher
def encipher(self,string,keep_punct=False): r"""Encipher string using rot13 cipher. Example:: ciphertext = Rot13().encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed....
python
def encipher(self,string,keep_punct=False): r"""Encipher string using rot13 cipher. Example:: ciphertext = Rot13().encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed....
[ "def", "encipher", "(", "self", ",", "string", ",", "keep_punct", "=", "False", ")", ":", "if", "not", "keep_punct", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ret", "=", "''", "for", "c", "in", "string", ":", "if", "...
r"""Encipher string using rot13 cipher. Example:: ciphertext = Rot13().encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed. Default is False. :returns: The enciphered...
[ "r", "Encipher", "string", "using", "rot13", "cipher", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/rot13.py#L20-L36
jameslyons/pycipher
pycipher/porta.py
Porta.encipher
def encipher(self,string): """Encipher string using Porta cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Porta('HELLO').encipher(plaintext) :param string: The string to encipher. :retur...
python
def encipher(self,string): """Encipher string using Porta cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Porta('HELLO').encipher(plaintext) :param string: The string to encipher. :retur...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ret", "=", "''", "for", "(", "i", ",", "c", ")", "in", "enumerate", "(", "string", ")", ":", "i", "=", "i", "%", "len"...
Encipher string using Porta cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Porta('HELLO').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string.
[ "Encipher", "string", "using", "Porta", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/porta.py#L17-L45
jameslyons/pycipher
pycipher/m209.py
M209.encipher
def encipher(self,message): """Encipher string using M209 cipher according to initialised key. Punctuation and whitespace are removed from the input. Example (continuing from the example above):: ciphertext = m.encipher(plaintext) :param string: The str...
python
def encipher(self,message): """Encipher string using M209 cipher according to initialised key. Punctuation and whitespace are removed from the input. Example (continuing from the example above):: ciphertext = m.encipher(plaintext) :param string: The str...
[ "def", "encipher", "(", "self", ",", "message", ")", ":", "message", "=", "self", ".", "remove_punctuation", "(", "message", ")", "effective_ch", "=", "[", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", "]", "# these are the wheels ...
Encipher string using M209 cipher according to initialised key. Punctuation and whitespace are removed from the input. Example (continuing from the example above):: ciphertext = m.encipher(plaintext) :param string: The string to encipher. :returns: The ...
[ "Encipher", "string", "using", "M209", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/m209.py#L59-L90
jameslyons/pycipher
pycipher/fracmorse.py
FracMorse.encipher
def encipher(self,string): """Encipher string using FracMorse cipher according to initialised key. Example:: ciphertext = FracMorse('ROUNDTABLECFGHIJKMPQSVWXYZ').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string. """ ...
python
def encipher(self,string): """Encipher string using FracMorse cipher according to initialised key. Example:: ciphertext = FracMorse('ROUNDTABLECFGHIJKMPQSVWXYZ').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string. """ ...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "string", ".", "upper", "(", ")", "#print string", "morsestr", "=", "self", ".", "enmorse", "(", "string", ")", "# make sure the morse string is a multiple of 3 in length", "if", "len", "(",...
Encipher string using FracMorse cipher according to initialised key. Example:: ciphertext = FracMorse('ROUNDTABLECFGHIJKMPQSVWXYZ').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string.
[ "Encipher", "string", "using", "FracMorse", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/fracmorse.py#L21-L44
jameslyons/pycipher
pycipher/fracmorse.py
FracMorse.decipher
def decipher(self,string): """Decipher string using FracMorse cipher according to initialised key. Example:: plaintext = FracMorse('ROUNDTABLECFGHIJKMPQSVWXYZ').decipher(ciphertext) :param string: The string to decipher. :returns: The enciphered string. """ ...
python
def decipher(self,string): """Decipher string using FracMorse cipher according to initialised key. Example:: plaintext = FracMorse('ROUNDTABLECFGHIJKMPQSVWXYZ').decipher(ciphertext) :param string: The string to decipher. :returns: The enciphered string. """ ...
[ "def", "decipher", "(", "self", ",", "string", ")", ":", "string", "=", "string", ".", "upper", "(", ")", "mapping", "=", "dict", "(", "zip", "(", "self", ".", "key", ",", "self", ".", "table", ")", ")", "ptext", "=", "\"\"", "for", "i", "in", ...
Decipher string using FracMorse cipher according to initialised key. Example:: plaintext = FracMorse('ROUNDTABLECFGHIJKMPQSVWXYZ').decipher(ciphertext) :param string: The string to decipher. :returns: The enciphered string.
[ "Decipher", "string", "using", "FracMorse", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/fracmorse.py#L46-L61
jameslyons/pycipher
pycipher/columnartransposition.py
ColTrans.encipher
def encipher(self,string): """Encipher string using Columnar Transposition cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = ColTrans('GERMAN').encipher(plaintext) :param string: The string to enc...
python
def encipher(self,string): """Encipher string using Columnar Transposition cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = ColTrans('GERMAN').encipher(plaintext) :param string: The string to enc...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ret", "=", "''", "ind", "=", "self", ".", "sortind", "(", "self", ".", "keyword", ")", "for", "i", "in", "range", "(", "...
Encipher string using Columnar Transposition cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = ColTrans('GERMAN').encipher(plaintext) :param string: The string to encipher. :returns: The enciphere...
[ "Encipher", "string", "using", "Columnar", "Transposition", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/columnartransposition.py#L32-L48
jameslyons/pycipher
pycipher/columnartransposition.py
ColTrans.decipher
def decipher(self,string): '''Decipher string using Columnar Transposition cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: plaintext = ColTrans('GERMAN').decipher(ciphertext) :param string: The string to decipher. ...
python
def decipher(self,string): '''Decipher string using Columnar Transposition cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: plaintext = ColTrans('GERMAN').decipher(ciphertext) :param string: The string to decipher. ...
[ "def", "decipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ret", "=", "[", "'_'", "]", "*", "len", "(", "string", ")", "L", ",", "M", "=", "len", "(", "string", ")", ",", "len",...
Decipher string using Columnar Transposition cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: plaintext = ColTrans('GERMAN').decipher(ciphertext) :param string: The string to decipher. :returns: The deciphered strin...
[ "Decipher", "string", "using", "Columnar", "Transposition", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/columnartransposition.py#L51-L72
jameslyons/pycipher
pycipher/railfence.py
Railfence.encipher
def encipher(self,string,keep_punct=False): """Encipher string using Railfence cipher according to initialised key. Example:: ciphertext = Railfence(3).encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spaci...
python
def encipher(self,string,keep_punct=False): """Encipher string using Railfence cipher according to initialised key. Example:: ciphertext = Railfence(3).encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spaci...
[ "def", "encipher", "(", "self", ",", "string", ",", "keep_punct", "=", "False", ")", ":", "if", "not", "keep_punct", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "return", "''", ".", "join", "(", "self", ".", "buildfence", ...
Encipher string using Railfence cipher according to initialised key. Example:: ciphertext = Railfence(3).encipher(plaintext) :param string: The string to encipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed. Default i...
[ "Encipher", "string", "using", "Railfence", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/railfence.py#L20-L32
jameslyons/pycipher
pycipher/railfence.py
Railfence.decipher
def decipher(self,string,keep_punct=False): """Decipher string using Railfence cipher according to initialised key. Example:: plaintext = Railfence(3).decipher(ciphertext) :param string: The string to decipher. :param keep_punct: if true, punctuation and spaci...
python
def decipher(self,string,keep_punct=False): """Decipher string using Railfence cipher according to initialised key. Example:: plaintext = Railfence(3).decipher(ciphertext) :param string: The string to decipher. :param keep_punct: if true, punctuation and spaci...
[ "def", "decipher", "(", "self", ",", "string", ",", "keep_punct", "=", "False", ")", ":", "if", "not", "keep_punct", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ind", "=", "range", "(", "len", "(", "string", ")", ")", ...
Decipher string using Railfence cipher according to initialised key. Example:: plaintext = Railfence(3).decipher(ciphertext) :param string: The string to decipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed. Default i...
[ "Decipher", "string", "using", "Railfence", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/railfence.py#L34-L48
jameslyons/pycipher
pycipher/affine.py
Affine.decipher
def decipher(self,string,keep_punct=False): """Decipher string using affine cipher according to initialised key. Example:: plaintext = Affine(a,b).decipher(ciphertext) :param string: The string to decipher. :param keep_punct: if true, punctuation and spacing a...
python
def decipher(self,string,keep_punct=False): """Decipher string using affine cipher according to initialised key. Example:: plaintext = Affine(a,b).decipher(ciphertext) :param string: The string to decipher. :param keep_punct: if true, punctuation and spacing a...
[ "def", "decipher", "(", "self", ",", "string", ",", "keep_punct", "=", "False", ")", ":", "if", "not", "keep_punct", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ret", "=", "''", "for", "c", "in", "string", ":", "if", "...
Decipher string using affine cipher according to initialised key. Example:: plaintext = Affine(a,b).decipher(ciphertext) :param string: The string to decipher. :param keep_punct: if true, punctuation and spacing are retained. If false, it is all removed. Default is Fa...
[ "Decipher", "string", "using", "affine", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/affine.py#L50-L66
jameslyons/pycipher
pycipher/autokey.py
Autokey.encipher
def encipher(self,string): """Encipher string using Autokey cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Autokey('HELLO').encipher(plaintext) :param string: The string to encipher. :r...
python
def encipher(self,string): """Encipher string using Autokey cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Autokey('HELLO').encipher(plaintext) :param string: The string to encipher. :r...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "ret", "=", "''", "for", "(", "i", ",", "c", ")", "in", "enumerate", "(", "string", ")", ":", "if", "i", "<", "len", "(...
Encipher string using Autokey cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Autokey('HELLO').encipher(plaintext) :param string: The string to encipher. :returns: The enciphered string.
[ "Encipher", "string", "using", "Autokey", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/autokey.py#L19-L36
jameslyons/pycipher
pycipher/bifid.py
Bifid.encipher
def encipher(self,string): """Encipher string using Bifid cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Bifid('phqgmeaylnofdxkrcvszwbuti',5).encipher(plaintext) :param string: The string to en...
python
def encipher(self,string): """Encipher string using Bifid cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Bifid('phqgmeaylnofdxkrcvszwbuti',5).encipher(plaintext) :param string: The string to en...
[ "def", "encipher", "(", "self", ",", "string", ")", ":", "string", "=", "self", ".", "remove_punctuation", "(", "string", ")", "step1", "=", "self", ".", "pb", ".", "encipher", "(", "string", ")", "evens", "=", "step1", "[", ":", ":", "2", "]", "od...
Encipher string using Bifid cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: ciphertext = Bifid('phqgmeaylnofdxkrcvszwbuti',5).encipher(plaintext) :param string: The string to encipher. :returns: The encipher...
[ "Encipher", "string", "using", "Bifid", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/bifid.py#L25-L44
jameslyons/pycipher
pycipher/bifid.py
Bifid.decipher
def decipher(self,string): """Decipher string using Bifid cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: plaintext = Bifid('phqgmeaylnofdxkrcvszwbuti',5).decipher(ciphertext) :param string: The string to decipher....
python
def decipher(self,string): """Decipher string using Bifid cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: plaintext = Bifid('phqgmeaylnofdxkrcvszwbuti',5).decipher(ciphertext) :param string: The string to decipher....
[ "def", "decipher", "(", "self", ",", "string", ")", ":", "ret", "=", "''", "string", "=", "string", ".", "upper", "(", ")", "rowseq", ",", "colseq", "=", "[", "]", ",", "[", "]", "# take blocks of length period, reform rowseq,colseq from them", "for", "i", ...
Decipher string using Bifid cipher according to initialised key. Punctuation and whitespace are removed from the input. Example:: plaintext = Bifid('phqgmeaylnofdxkrcvszwbuti',5).decipher(ciphertext) :param string: The string to decipher. :returns: The deciphered stri...
[ "Decipher", "string", "using", "Bifid", "cipher", "according", "to", "initialised", "key", ".", "Punctuation", "and", "whitespace", "are", "removed", "from", "the", "input", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/bifid.py#L46-L71
jameslyons/pycipher
pycipher/simplesubstitution.py
SimpleSubstitution.decipher
def decipher(self,string,keep_punct=False): """Decipher string using Simple Substitution cipher according to initialised key. Example:: plaintext = SimpleSubstitution('AJPCZWRLFBDKOTYUQGENHXMIVS').decipher(ciphertext) :param string: The string to decipher. :param keep...
python
def decipher(self,string,keep_punct=False): """Decipher string using Simple Substitution cipher according to initialised key. Example:: plaintext = SimpleSubstitution('AJPCZWRLFBDKOTYUQGENHXMIVS').decipher(ciphertext) :param string: The string to decipher. :param keep...
[ "def", "decipher", "(", "self", ",", "string", ",", "keep_punct", "=", "False", ")", ":", "# if we have not yet calculated the inverse key, calculate it now", "if", "self", ".", "invkey", "==", "''", ":", "for", "i", "in", "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'", ":", "self"...
Decipher string using Simple Substitution cipher according to initialised key. Example:: plaintext = SimpleSubstitution('AJPCZWRLFBDKOTYUQGENHXMIVS').decipher(ciphertext) :param string: The string to decipher. :param keep_punct: if true, punctuation and spacing are retained. ...
[ "Decipher", "string", "using", "Simple", "Substitution", "cipher", "according", "to", "initialised", "key", "." ]
train
https://github.com/jameslyons/pycipher/blob/8f1d7cf3cba4e12171e27d9ce723ad890194de19/pycipher/simplesubstitution.py#L45-L65
oseledets/ttpy
tt/core/tools.py
matvec
def matvec(a, b, compression=False): """Matrix-vector product in TT format.""" acrs = _vector.vector.to_list(a.tt) bcrs = _vector.vector.to_list(b) ccrs = [] d = b.d def get_core(i): acr = _np.reshape( acrs[i], (a.tt.r[i], a.n[i], a.m[i]...
python
def matvec(a, b, compression=False): """Matrix-vector product in TT format.""" acrs = _vector.vector.to_list(a.tt) bcrs = _vector.vector.to_list(b) ccrs = [] d = b.d def get_core(i): acr = _np.reshape( acrs[i], (a.tt.r[i], a.n[i], a.m[i]...
[ "def", "matvec", "(", "a", ",", "b", ",", "compression", "=", "False", ")", ":", "acrs", "=", "_vector", ".", "vector", ".", "to_list", "(", "a", ".", "tt", ")", "bcrs", "=", "_vector", ".", "vector", ".", "to_list", "(", "b", ")", "ccrs", "=", ...
Matrix-vector product in TT format.
[ "Matrix", "-", "vector", "product", "in", "TT", "format", "." ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L25-L103
oseledets/ttpy
tt/core/tools.py
kron
def kron(a, b): """Kronecker product of two TT-matrices or two TT-vectors""" if hasattr(a, '__kron__'): return a.__kron__(b) if a is None: return b else: raise ValueError( 'Kron is waiting for two TT-vectors or two TT-matrices')
python
def kron(a, b): """Kronecker product of two TT-matrices or two TT-vectors""" if hasattr(a, '__kron__'): return a.__kron__(b) if a is None: return b else: raise ValueError( 'Kron is waiting for two TT-vectors or two TT-matrices')
[ "def", "kron", "(", "a", ",", "b", ")", ":", "if", "hasattr", "(", "a", ",", "'__kron__'", ")", ":", "return", "a", ".", "__kron__", "(", "b", ")", "if", "a", "is", "None", ":", "return", "b", "else", ":", "raise", "ValueError", "(", "'Kron is wa...
Kronecker product of two TT-matrices or two TT-vectors
[ "Kronecker", "product", "of", "two", "TT", "-", "matrices", "or", "two", "TT", "-", "vectors" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L127-L135
oseledets/ttpy
tt/core/tools.py
dot
def dot(a, b): """Dot product of two TT-matrices or two TT-vectors""" if hasattr(a, '__dot__'): return a.__dot__(b) if a is None: return b else: raise ValueError( 'Dot is waiting for two TT-vectors or two TT- matrices')
python
def dot(a, b): """Dot product of two TT-matrices or two TT-vectors""" if hasattr(a, '__dot__'): return a.__dot__(b) if a is None: return b else: raise ValueError( 'Dot is waiting for two TT-vectors or two TT- matrices')
[ "def", "dot", "(", "a", ",", "b", ")", ":", "if", "hasattr", "(", "a", ",", "'__dot__'", ")", ":", "return", "a", ".", "__dot__", "(", "b", ")", "if", "a", "is", "None", ":", "return", "b", "else", ":", "raise", "ValueError", "(", "'Dot is waitin...
Dot product of two TT-matrices or two TT-vectors
[ "Dot", "product", "of", "two", "TT", "-", "matrices", "or", "two", "TT", "-", "vectors" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L138-L146
oseledets/ttpy
tt/core/tools.py
mkron
def mkron(a, *args): """Kronecker product of all the arguments""" if not isinstance(a, list): a = [a] a = list(a) # copy list for i in args: if isinstance(i, list): a.extend(i) else: a.append(i) c = _vector.vector() c.d = 0 c.n = _np.array([]...
python
def mkron(a, *args): """Kronecker product of all the arguments""" if not isinstance(a, list): a = [a] a = list(a) # copy list for i in args: if isinstance(i, list): a.extend(i) else: a.append(i) c = _vector.vector() c.d = 0 c.n = _np.array([]...
[ "def", "mkron", "(", "a", ",", "*", "args", ")", ":", "if", "not", "isinstance", "(", "a", ",", "list", ")", ":", "a", "=", "[", "a", "]", "a", "=", "list", "(", "a", ")", "# copy list", "for", "i", "in", "args", ":", "if", "isinstance", "(",...
Kronecker product of all the arguments
[ "Kronecker", "product", "of", "all", "the", "arguments" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L157-L182
oseledets/ttpy
tt/core/tools.py
zkron
def zkron(ttA, ttB): """ Do kronecker product between cores of two matrices ttA and ttB. Look about kronecker at: https://en.wikipedia.org/wiki/Kronecker_product For details about operation refer: https://arxiv.org/abs/1802.02839 :param ttA: first TT-matrix; :param ttB: second TT-matrix; :re...
python
def zkron(ttA, ttB): """ Do kronecker product between cores of two matrices ttA and ttB. Look about kronecker at: https://en.wikipedia.org/wiki/Kronecker_product For details about operation refer: https://arxiv.org/abs/1802.02839 :param ttA: first TT-matrix; :param ttB: second TT-matrix; :re...
[ "def", "zkron", "(", "ttA", ",", "ttB", ")", ":", "Al", "=", "_matrix", ".", "matrix", ".", "to_list", "(", "ttA", ")", "Bl", "=", "_matrix", ".", "matrix", ".", "to_list", "(", "ttB", ")", "Hl", "=", "[", "_np", ".", "kron", "(", "B", ",", "...
Do kronecker product between cores of two matrices ttA and ttB. Look about kronecker at: https://en.wikipedia.org/wiki/Kronecker_product For details about operation refer: https://arxiv.org/abs/1802.02839 :param ttA: first TT-matrix; :param ttB: second TT-matrix; :return: TT-matrix in z-order
[ "Do", "kronecker", "product", "between", "cores", "of", "two", "matrices", "ttA", "and", "ttB", ".", "Look", "about", "kronecker", "at", ":", "https", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "wiki", "/", "Kronecker_product", "For", "details", ...
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L185-L197
oseledets/ttpy
tt/core/tools.py
zkronv
def zkronv(ttA, ttB): """ Do kronecker product between vectors ttA and ttB. Look about kronecker at: https://en.wikipedia.org/wiki/Kronecker_product For details about operation refer: https://arxiv.org/abs/1802.02839 :param ttA: first TT-vector; :param ttB: second TT-vector; :return: operati...
python
def zkronv(ttA, ttB): """ Do kronecker product between vectors ttA and ttB. Look about kronecker at: https://en.wikipedia.org/wiki/Kronecker_product For details about operation refer: https://arxiv.org/abs/1802.02839 :param ttA: first TT-vector; :param ttB: second TT-vector; :return: operati...
[ "def", "zkronv", "(", "ttA", ",", "ttB", ")", ":", "Al", "=", "_vector", ".", "vector", ".", "to_list", "(", "ttA", ")", "Bl", "=", "_vector", ".", "vector", ".", "to_list", "(", "ttB", ")", "Hl", "=", "[", "_np", ".", "kron", "(", "B", ",", ...
Do kronecker product between vectors ttA and ttB. Look about kronecker at: https://en.wikipedia.org/wiki/Kronecker_product For details about operation refer: https://arxiv.org/abs/1802.02839 :param ttA: first TT-vector; :param ttB: second TT-vector; :return: operation result in z-order
[ "Do", "kronecker", "product", "between", "vectors", "ttA", "and", "ttB", ".", "Look", "about", "kronecker", "at", ":", "https", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "wiki", "/", "Kronecker_product", "For", "details", "about", "operation", "r...
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L200-L212
oseledets/ttpy
tt/core/tools.py
zmeshgrid
def zmeshgrid(d): """ Returns a meshgrid like np.meshgrid but in z-order :param d: you'll get 4**d nodes in meshgrid :return: xx, yy in z-order """ lin = xfun(2, d) one = ones(2, d) xx = zkronv(lin, one) yy = zkronv(one, lin) return xx, yy
python
def zmeshgrid(d): """ Returns a meshgrid like np.meshgrid but in z-order :param d: you'll get 4**d nodes in meshgrid :return: xx, yy in z-order """ lin = xfun(2, d) one = ones(2, d) xx = zkronv(lin, one) yy = zkronv(one, lin) return xx, yy
[ "def", "zmeshgrid", "(", "d", ")", ":", "lin", "=", "xfun", "(", "2", ",", "d", ")", "one", "=", "ones", "(", "2", ",", "d", ")", "xx", "=", "zkronv", "(", "lin", ",", "one", ")", "yy", "=", "zkronv", "(", "one", ",", "lin", ")", "return", ...
Returns a meshgrid like np.meshgrid but in z-order :param d: you'll get 4**d nodes in meshgrid :return: xx, yy in z-order
[ "Returns", "a", "meshgrid", "like", "np", ".", "meshgrid", "but", "in", "z", "-", "order", ":", "param", "d", ":", "you", "ll", "get", "4", "**", "d", "nodes", "in", "meshgrid", ":", "return", ":", "xx", "yy", "in", "z", "-", "order" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L215-L227
oseledets/ttpy
tt/core/tools.py
zaffine
def zaffine(c0, c1, c2, d): """ Generate linear function c0 + c1 ex + c2 ey in z ordering with d cores in QTT :param c0: :param c1: :param c2: :param d: :return: """ xx, yy = zmeshgrid(d) Hx, Hy = _vector.vector.to_list(xx), _vector.vector.to_list(yy) Hs = _cp.deepcopy(Hx) ...
python
def zaffine(c0, c1, c2, d): """ Generate linear function c0 + c1 ex + c2 ey in z ordering with d cores in QTT :param c0: :param c1: :param c2: :param d: :return: """ xx, yy = zmeshgrid(d) Hx, Hy = _vector.vector.to_list(xx), _vector.vector.to_list(yy) Hs = _cp.deepcopy(Hx) ...
[ "def", "zaffine", "(", "c0", ",", "c1", ",", "c2", ",", "d", ")", ":", "xx", ",", "yy", "=", "zmeshgrid", "(", "d", ")", "Hx", ",", "Hy", "=", "_vector", ".", "vector", ".", "to_list", "(", "xx", ")", ",", "_vector", ".", "vector", ".", "to_l...
Generate linear function c0 + c1 ex + c2 ey in z ordering with d cores in QTT :param c0: :param c1: :param c2: :param d: :return:
[ "Generate", "linear", "function", "c0", "+", "c1", "ex", "+", "c2", "ey", "in", "z", "ordering", "with", "d", "cores", "in", "QTT", ":", "param", "c0", ":", ":", "param", "c1", ":", ":", "param", "c2", ":", ":", "param", "d", ":", ":", "return", ...
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L230-L251
oseledets/ttpy
tt/core/tools.py
concatenate
def concatenate(*args): """Concatenates given TT-vectors. For two tensors :math:`X(i_1,\\ldots,i_d),Y(i_1,\\ldots,i_d)` returns :math:`(d+1)`-dimensional tensor :math:`Z(i_0,i_1,\\ldots,i_d)`, :math:`i_0=\\overline{0,1}`, such that .. math:: Z(0, i_1, \\ldots, i_d) = X(i_1, \\ldots, i_d), ...
python
def concatenate(*args): """Concatenates given TT-vectors. For two tensors :math:`X(i_1,\\ldots,i_d),Y(i_1,\\ldots,i_d)` returns :math:`(d+1)`-dimensional tensor :math:`Z(i_0,i_1,\\ldots,i_d)`, :math:`i_0=\\overline{0,1}`, such that .. math:: Z(0, i_1, \\ldots, i_d) = X(i_1, \\ldots, i_d), ...
[ "def", "concatenate", "(", "*", "args", ")", ":", "tmp", "=", "_np", ".", "array", "(", "[", "[", "1", "]", "+", "[", "0", "]", "*", "(", "len", "(", "args", ")", "-", "1", ")", "]", ")", "result", "=", "kron", "(", "_vector", ".", "vector"...
Concatenates given TT-vectors. For two tensors :math:`X(i_1,\\ldots,i_d),Y(i_1,\\ldots,i_d)` returns :math:`(d+1)`-dimensional tensor :math:`Z(i_0,i_1,\\ldots,i_d)`, :math:`i_0=\\overline{0,1}`, such that .. math:: Z(0, i_1, \\ldots, i_d) = X(i_1, \\ldots, i_d), Z(1, i_1, \\ldots, i_d) = Y(...
[ "Concatenates", "given", "TT", "-", "vectors", "." ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L254-L271
oseledets/ttpy
tt/core/tools.py
sum
def sum(a, axis=-1): """Sum TT-vector over specified axes""" d = a.d crs = _vector.vector.to_list(a.tt if isinstance(a, _matrix.matrix) else a) if axis < 0: axis = range(a.d) elif isinstance(axis, int): axis = [axis] axis = list(axis)[::-1] for ax in axis: crs[ax] = _...
python
def sum(a, axis=-1): """Sum TT-vector over specified axes""" d = a.d crs = _vector.vector.to_list(a.tt if isinstance(a, _matrix.matrix) else a) if axis < 0: axis = range(a.d) elif isinstance(axis, int): axis = [axis] axis = list(axis)[::-1] for ax in axis: crs[ax] = _...
[ "def", "sum", "(", "a", ",", "axis", "=", "-", "1", ")", ":", "d", "=", "a", ".", "d", "crs", "=", "_vector", ".", "vector", ".", "to_list", "(", "a", ".", "tt", "if", "isinstance", "(", "a", ",", "_matrix", ".", "matrix", ")", "else", "a", ...
Sum TT-vector over specified axes
[ "Sum", "TT", "-", "vector", "over", "specified", "axes" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L274-L294
oseledets/ttpy
tt/core/tools.py
ones
def ones(n, d=None): """ Creates a TT-vector of all ones""" c = _vector.vector() if d is None: c.n = _np.array(n, dtype=_np.int32) c.d = c.n.size else: c.n = _np.array([n] * d, dtype=_np.int32) c.d = d c.r = _np.ones((c.d + 1,), dtype=_np.int32) c.get_ps() c.c...
python
def ones(n, d=None): """ Creates a TT-vector of all ones""" c = _vector.vector() if d is None: c.n = _np.array(n, dtype=_np.int32) c.d = c.n.size else: c.n = _np.array([n] * d, dtype=_np.int32) c.d = d c.r = _np.ones((c.d + 1,), dtype=_np.int32) c.get_ps() c.c...
[ "def", "ones", "(", "n", ",", "d", "=", "None", ")", ":", "c", "=", "_vector", ".", "vector", "(", ")", "if", "d", "is", "None", ":", "c", ".", "n", "=", "_np", ".", "array", "(", "n", ",", "dtype", "=", "_np", ".", "int32", ")", "c", "."...
Creates a TT-vector of all ones
[ "Creates", "a", "TT", "-", "vector", "of", "all", "ones" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L300-L312
oseledets/ttpy
tt/core/tools.py
rand
def rand(n, d=None, r=2, samplefunc=_np.random.randn): """Generate a random d-dimensional TT-vector with ranks ``r``. Distribution to sample cores is provided by the samplefunc. Default is to sample from normal distribution. """ n0 = _np.asanyarray(n, dtype=_np.int32) r0 = _np.asanyarray(r, dtyp...
python
def rand(n, d=None, r=2, samplefunc=_np.random.randn): """Generate a random d-dimensional TT-vector with ranks ``r``. Distribution to sample cores is provided by the samplefunc. Default is to sample from normal distribution. """ n0 = _np.asanyarray(n, dtype=_np.int32) r0 = _np.asanyarray(r, dtyp...
[ "def", "rand", "(", "n", ",", "d", "=", "None", ",", "r", "=", "2", ",", "samplefunc", "=", "_np", ".", "random", ".", "randn", ")", ":", "n0", "=", "_np", ".", "asanyarray", "(", "n", ",", "dtype", "=", "_np", ".", "int32", ")", "r0", "=", ...
Generate a random d-dimensional TT-vector with ranks ``r``. Distribution to sample cores is provided by the samplefunc. Default is to sample from normal distribution.
[ "Generate", "a", "random", "d", "-", "dimensional", "TT", "-", "vector", "with", "ranks", "r", ".", "Distribution", "to", "sample", "cores", "is", "provided", "by", "the", "samplefunc", ".", "Default", "is", "to", "sample", "from", "normal", "distribution", ...
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L315-L336
oseledets/ttpy
tt/core/tools.py
eye
def eye(n, d=None): """ Creates an identity TT-matrix""" c = _matrix.matrix() c.tt = _vector.vector() if d is None: n0 = _np.asanyarray(n, dtype=_np.int32) c.tt.d = n0.size else: n0 = _np.asanyarray([n] * d, dtype=_np.int32) c.tt.d = d c.n = n0.copy() c.m = n0...
python
def eye(n, d=None): """ Creates an identity TT-matrix""" c = _matrix.matrix() c.tt = _vector.vector() if d is None: n0 = _np.asanyarray(n, dtype=_np.int32) c.tt.d = n0.size else: n0 = _np.asanyarray([n] * d, dtype=_np.int32) c.tt.d = d c.n = n0.copy() c.m = n0...
[ "def", "eye", "(", "n", ",", "d", "=", "None", ")", ":", "c", "=", "_matrix", ".", "matrix", "(", ")", "c", ".", "tt", "=", "_vector", ".", "vector", "(", ")", "if", "d", "is", "None", ":", "n0", "=", "_np", ".", "asanyarray", "(", "n", ","...
Creates an identity TT-matrix
[ "Creates", "an", "identity", "TT", "-", "matrix" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L340-L364
oseledets/ttpy
tt/core/tools.py
Toeplitz
def Toeplitz(x, d=None, D=None, kind='F'): """ Creates multilevel Toeplitz TT-matrix with ``D`` levels. Possible _matrix types: * 'F' - full Toeplitz _matrix, size(x) = 2^{d+1} * 'C' - circulant _matrix, size(x) = 2^d * 'L' - lower triangular Toeplitz _m...
python
def Toeplitz(x, d=None, D=None, kind='F'): """ Creates multilevel Toeplitz TT-matrix with ``D`` levels. Possible _matrix types: * 'F' - full Toeplitz _matrix, size(x) = 2^{d+1} * 'C' - circulant _matrix, size(x) = 2^d * 'L' - lower triangular Toeplitz _m...
[ "def", "Toeplitz", "(", "x", ",", "d", "=", "None", ",", "D", "=", "None", ",", "kind", "=", "'F'", ")", ":", "# checking for arguments consistency", "def", "check_kinds", "(", "D", ",", "kind", ")", ":", "if", "D", "%", "len", "(", "kind", ")", "=...
Creates multilevel Toeplitz TT-matrix with ``D`` levels. Possible _matrix types: * 'F' - full Toeplitz _matrix, size(x) = 2^{d+1} * 'C' - circulant _matrix, size(x) = 2^d * 'L' - lower triangular Toeplitz _matrix, size(x) = 2^d * 'U' - upper triangul...
[ "Creates", "multilevel", "Toeplitz", "TT", "-", "matrix", "with", "D", "levels", "." ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L368-L525
oseledets/ttpy
tt/core/tools.py
qlaplace_dd
def qlaplace_dd(d): """Creates a QTT representation of the Laplace operator""" res = _matrix.matrix() d0 = d[::-1] D = len(d0) I = _np.eye(2) J = _np.array([[0, 1], [0, 0]]) cr = [] if D is 1: for k in xrange(1, d0[0] + 1): if k is 1: cur_core = _np.ze...
python
def qlaplace_dd(d): """Creates a QTT representation of the Laplace operator""" res = _matrix.matrix() d0 = d[::-1] D = len(d0) I = _np.eye(2) J = _np.array([[0, 1], [0, 0]]) cr = [] if D is 1: for k in xrange(1, d0[0] + 1): if k is 1: cur_core = _np.ze...
[ "def", "qlaplace_dd", "(", "d", ")", ":", "res", "=", "_matrix", ".", "matrix", "(", ")", "d0", "=", "d", "[", ":", ":", "-", "1", "]", "D", "=", "len", "(", "d0", ")", "I", "=", "_np", ".", "eye", "(", "2", ")", "J", "=", "_np", ".", "...
Creates a QTT representation of the Laplace operator
[ "Creates", "a", "QTT", "representation", "of", "the", "Laplace", "operator" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L529-L609
oseledets/ttpy
tt/core/tools.py
xfun
def xfun(n, d=None): """ Create a QTT-representation of 0:prod(n) _vector call examples: tt.xfun(2, 5) # create 2 x 2 x 2 x 2 x 2 TT-vector tt.xfun(3) # create [0, 1, 2] one-dimensional TT-vector tt.xfun([3, 5, 7], 2) # create 3 x 5 x 7 x 3 x 5 x 7 TT-vector ""...
python
def xfun(n, d=None): """ Create a QTT-representation of 0:prod(n) _vector call examples: tt.xfun(2, 5) # create 2 x 2 x 2 x 2 x 2 TT-vector tt.xfun(3) # create [0, 1, 2] one-dimensional TT-vector tt.xfun([3, 5, 7], 2) # create 3 x 5 x 7 x 3 x 5 x 7 TT-vector ""...
[ "def", "xfun", "(", "n", ",", "d", "=", "None", ")", ":", "if", "isinstance", "(", "n", ",", "six", ".", "integer_types", ")", ":", "n", "=", "[", "n", "]", "if", "d", "is", "None", ":", "n0", "=", "_np", ".", "asanyarray", "(", "n", ",", "...
Create a QTT-representation of 0:prod(n) _vector call examples: tt.xfun(2, 5) # create 2 x 2 x 2 x 2 x 2 TT-vector tt.xfun(3) # create [0, 1, 2] one-dimensional TT-vector tt.xfun([3, 5, 7], 2) # create 3 x 5 x 7 x 3 x 5 x 7 TT-vector
[ "Create", "a", "QTT", "-", "representation", "of", "0", ":", "prod", "(", "n", ")", "_vector", "call", "examples", ":", "tt", ".", "xfun", "(", "2", "5", ")", "#", "create", "2", "x", "2", "x", "2", "x", "2", "x", "2", "TT", "-", "vector", "t...
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L612-L644
oseledets/ttpy
tt/core/tools.py
linspace
def linspace(n, d=None, a=0.0, b=1.0, right=True, left=True): """ Create a QTT-representation of a uniform grid on an interval [a, b] """ if isinstance(n, six.integer_types): n = [n] if d is None: n0 = _np.asanyarray(n, dtype=_np.int32) else: n0 = _np.array(n * d, dtype=_np.int32...
python
def linspace(n, d=None, a=0.0, b=1.0, right=True, left=True): """ Create a QTT-representation of a uniform grid on an interval [a, b] """ if isinstance(n, six.integer_types): n = [n] if d is None: n0 = _np.asanyarray(n, dtype=_np.int32) else: n0 = _np.array(n * d, dtype=_np.int32...
[ "def", "linspace", "(", "n", ",", "d", "=", "None", ",", "a", "=", "0.0", ",", "b", "=", "1.0", ",", "right", "=", "True", ",", "left", "=", "True", ")", ":", "if", "isinstance", "(", "n", ",", "six", ".", "integer_types", ")", ":", "n", "=",...
Create a QTT-representation of a uniform grid on an interval [a, b]
[ "Create", "a", "QTT", "-", "representation", "of", "a", "uniform", "grid", "on", "an", "interval", "[", "a", "b", "]" ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L647-L671
oseledets/ttpy
tt/core/tools.py
sin
def sin(d, alpha=1.0, phase=0.0): """ Create TT-vector for :math:`\\sin(\\alpha n + \\varphi)`.""" cr = [] cur_core = _np.zeros([1, 2, 2], dtype=_np.float) cur_core[0, 0, :] = [_math.cos(phase), _math.sin(phase)] cur_core[0, 1, :] = [_math.cos(alpha + phase), _math.sin(alpha + phase)] cr.append(...
python
def sin(d, alpha=1.0, phase=0.0): """ Create TT-vector for :math:`\\sin(\\alpha n + \\varphi)`.""" cr = [] cur_core = _np.zeros([1, 2, 2], dtype=_np.float) cur_core[0, 0, :] = [_math.cos(phase), _math.sin(phase)] cur_core[0, 1, :] = [_math.cos(alpha + phase), _math.sin(alpha + phase)] cr.append(...
[ "def", "sin", "(", "d", ",", "alpha", "=", "1.0", ",", "phase", "=", "0.0", ")", ":", "cr", "=", "[", "]", "cur_core", "=", "_np", ".", "zeros", "(", "[", "1", ",", "2", ",", "2", "]", ",", "dtype", "=", "_np", ".", "float", ")", "cur_core"...
Create TT-vector for :math:`\\sin(\\alpha n + \\varphi)`.
[ "Create", "TT", "-", "vector", "for", ":", "math", ":", "\\\\", "sin", "(", "\\\\", "alpha", "n", "+", "\\\\", "varphi", ")", "." ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L674-L704
oseledets/ttpy
tt/core/tools.py
cos
def cos(d, alpha=1.0, phase=0.0): """ Create TT-vector for :math:`\\cos(\\alpha n + \\varphi)`.""" return sin(d, alpha, phase + _math.pi * 0.5)
python
def cos(d, alpha=1.0, phase=0.0): """ Create TT-vector for :math:`\\cos(\\alpha n + \\varphi)`.""" return sin(d, alpha, phase + _math.pi * 0.5)
[ "def", "cos", "(", "d", ",", "alpha", "=", "1.0", ",", "phase", "=", "0.0", ")", ":", "return", "sin", "(", "d", ",", "alpha", ",", "phase", "+", "_math", ".", "pi", "*", "0.5", ")" ]
Create TT-vector for :math:`\\cos(\\alpha n + \\varphi)`.
[ "Create", "TT", "-", "vector", "for", ":", "math", ":", "\\\\", "cos", "(", "\\\\", "alpha", "n", "+", "\\\\", "varphi", ")", "." ]
train
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L707-L709