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_documentation_string
stringlengths
1
47.2k
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...
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
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...
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
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 ...
Performs checks on the input token. Raises an exception if unsupported. :param token: the token to check :type token: Token
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...
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
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...
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
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...
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
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("...
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
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 ...
The actual execution of the actor. :return: None if successful, otherwise error message :rtype: str
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...
Configures and returns the SplitEvaluator and Classifier instance as tuple. :return: evaluator and classifier :rtype: tuple
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"))) ...
Initializes the experiment.
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....
Executes the experiment.
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...
Loads the experiment from disk. :param filename: the filename of the experiment to load :type filename: str :return: the experiment :rtype: Experiment
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....
Configures and returns the ResultProducer and PropertyPath as tuple. :return: producer and property path :rtype: tuple
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)
Sets the row name. :param index: the 0-based row index :type index: int :param name: the name of the row :type name: str
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)
Sets the column name. :param index: the 0-based row index :type index: int :param name: the name of the column :type name: str
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...
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
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 """ ...
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
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 ...
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
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...
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
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...
Checks that at least required params exist
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...
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'|'...
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':...
Abstraction for grabbing content from a returned response
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...
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...
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 ...
Return a dictionary which can be used as is or added to for payloads
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
Returns ------- boolean : longitudinal status of this project
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...
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
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...
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...
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...
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...
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...
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 ...
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" % ...
Return the value for key for the field in the metadata
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...
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...
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...
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 ---...
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
Simple helper function to get all field names and labels
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...
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: ...
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 ...
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. ...
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...
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...
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 ...
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...
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 ...
Check that field exists and is a file field
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 ...
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...
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...
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...
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...
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 ...
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=...
Entrypoint to route messages between plugins.
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...
Gracefully cancel current tasks when app receives a shutdown signal.
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
Additively merge right side dict into left side dict.
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 ...
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...
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()
Create connection, use to send message and close. Args: transport (asyncio.DatagramTransport): Transport used for sending.
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...
Transform metric to JSON bytestring and send to server. Args: metric (dict): Complete metric to send as JSON.
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...
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...
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...
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. ...
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...
Build an absolute path from ``*filenames``, and return contents of resulting file. Defaults to UTF-8 encoding.
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...
Format and output metric. Args: metric (dict): Complete metric.
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...
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...
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. ...
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...
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. ...
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 ...
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) ...
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....
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'...
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'), ...
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
takes ciphertext, calculates index of coincidence.
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...
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
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...
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...
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] ...
If punctuation was accidently removed, use this function to restore it. requires the orignial string with punctuation.
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 +=...
convert a key word to a key by appending on the other letters of the alphabet. e.g. MONARCHY -> MONARCHYBDEFGIJKLPQSTUVWXZ
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...
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...
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. ...
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...
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...
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...
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...
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...
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...
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...
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. ...
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...
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....
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...
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...
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.
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...
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 ...
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. """ ...
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.
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. """ ...
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.
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...
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...
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. ...
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...
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...
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...
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...
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...
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...
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...
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...
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.
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...
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...
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....
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...
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...
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. ...
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]...
Matrix-vector product in TT format.
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')
Kronecker product of two TT-matrices or two TT-vectors
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')
Dot product of two TT-matrices or two TT-vectors
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([]...
Kronecker product of all the arguments
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...
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
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...
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
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
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
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) ...
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:
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), ...
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(...
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] = _...
Sum TT-vector over specified axes
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...
Creates a TT-vector of all ones
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...
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.
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...
Creates an identity TT-matrix
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...
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...
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...
Creates a QTT representation of the Laplace operator
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 ""...
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
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...
Create a QTT-representation of a uniform grid on an interval [a, b]
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(...
Create TT-vector for :math:`\\sin(\\alpha n + \\varphi)`.
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)
Create TT-vector for :math:`\\cos(\\alpha n + \\varphi)`.
https://github.com/oseledets/ttpy/blob/b440f6299a6338de4aea67f3d839d613f4ef1374/tt/core/tools.py#L707-L709