How to use the pypet.parameter.SparseParameter function in pypet

To help you get started, we’ve selected a few pypet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
def _load(self, load_dict):
        """Loads data from `load_dict`

        Reconstruction of sparse matrices similar to the :class:`~pypet.parameter.SparseParameter`.

        """
        for key in compat.listkeys(load_dict):
            # We delete keys over time:
            if key in load_dict:
                if SparseResult.IDENTIFIER in key:
                    new_key = key.split(SparseResult.IDENTIFIER)[0]

                    is_dia = load_dict.pop(new_key + SparseResult.IDENTIFIER + 'is_dia')

                    name_list = SparseParameter._get_name_list(is_dia)
                    rename_list = ['%s%s%s' % (new_key, SparseResult.IDENTIFIER, name)
                                   for name in name_list]

                    data_list = [load_dict.pop(name) for name in rename_list]
                    matrix = SparseParameter._reconstruct_matrix(data_list)
                    self._data[new_key] = matrix
                else:
                    self._data[key] = load_dict[key]
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
"""
        for key in compat.listkeys(load_dict):
            # We delete keys over time:
            if key in load_dict:
                if SparseResult.IDENTIFIER in key:
                    new_key = key.split(SparseResult.IDENTIFIER)[0]

                    is_dia = load_dict.pop(new_key + SparseResult.IDENTIFIER + 'is_dia')

                    name_list = SparseParameter._get_name_list(is_dia)
                    rename_list = ['%s%s%s' % (new_key, SparseResult.IDENTIFIER, name)
                                   for name in name_list]

                    data_list = [load_dict.pop(name) for name in rename_list]
                    matrix = SparseParameter._reconstruct_matrix(data_list)
                    self._data[new_key] = matrix
                else:
                    self._data[key] = load_dict[key]
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
def _store(self):
        """Returns a storage dictionary understood by the storage service.

        Sparse matrices are extracted similar to the :class:`~pypet.parameter.SparseParameter` and
        marked with the identifier `__spsp__`.

        """
        store_dict = {}
        for key in self._data:
            val = self._data[key]
            if SparseParameter._is_supported_matrix(val):

                data_list, name_list, hash_tuple = SparseParameter._serialize_matrix(val)
                rename_list = ['%s%s%s' % (key, SparseParameter.IDENTIFIER, name)
                               for name in name_list]

                is_dia = int(len(rename_list) == 4)
                store_dict[key + SparseResult.IDENTIFIER + 'is_dia'] = is_dia

                for idx, name in enumerate(rename_list):
                    store_dict[name] = data_list[idx]

            else:
                store_dict[key] = val

        return store_dict
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
for idx, elem in enumerate(self._explored_range):

                    data_list, name_list, hash_tuple = self._serialize_matrix(elem)

                    # Use the hash_tuple as a key for the smart_dict
                    if hash_tuple in smart_dict:
                        name_idx = smart_dict[hash_tuple]
                        add = False
                    else:
                        name_idx = count
                        add = True

                    is_dia = int(len(name_list) == 4)
                    rename_list = self._build_names(name_idx, is_dia)

                    store_dict['explored_data' + SparseParameter.IDENTIFIER]['idx'][idx] = name_idx

                    store_dict['explored_data' + SparseParameter.IDENTIFIER]['is_dia'][
                        idx] = is_dia

                    if add:

                        for irun, name in enumerate(rename_list):
                            store_dict[name] = data_list[irun]

                        smart_dict[hash_tuple] = name_idx
                        count += 1

            self._locked = True

            return store_dict
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
def _get_name_list(is_dia):
        if is_dia:
            return SparseParameter.DIA_NAME_LIST
        else:
            return SparseParameter.OTHER_NAME_LIST
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
A tuple containing the hashable parts of (1) in order to use the tuple as
                a key for a dictionary. Accordingly, the numpy arrays of (1) are
                changed to read-only.

        """
        if (spsp.isspmatrix_csc(matrix) or
                spsp.isspmatrix_csr(matrix) or
                spsp.isspmatrix_bsr(matrix)):
            if matrix.size > 0:
                return_list = [matrix.data, matrix.indices, matrix.indptr, matrix.shape]
            else:
                # For empty matrices we only need the shape
                return_list = ['__empty__', (), (), matrix.shape]

            return_names = SparseParameter.OTHER_NAME_LIST

            if spsp.isspmatrix_csc(matrix):
                return_list = ['csc'] + return_list
            elif spsp.isspmatrix_csr(matrix):
                return_list = ['csr'] + return_list
            elif spsp.isspmatrix_bsr(matrix):
                return_list = ['bsr'] + return_list
            else:
                raise RuntimeError('You shall not pass!')

        elif spsp.isspmatrix_dia(matrix):
            if matrix.size > 0:
                return_list = ['dia', matrix.data, matrix.offsets, matrix.shape]
            else:
                # For empty matrices we only need the shape
                return_list = ['dia', '__empty__', (), matrix.shape]
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
def _store(self):
        """Returns a storage dictionary understood by the storage service.

        Sparse matrices are extracted similar to the :class:`~pypet.parameter.SparseParameter` and
        marked with the identifier `__spsp__`.

        """
        store_dict = {}
        for key in self._data:
            val = self._data[key]
            if SparseParameter._is_supported_matrix(val):

                data_list, name_list, hash_tuple = SparseParameter._serialize_matrix(val)
                rename_list = ['%s%s%s' % (key, SparseParameter.IDENTIFIER, name)
                               for name in name_list]

                is_dia = int(len(rename_list) == 4)
                store_dict[key + SparseResult.IDENTIFIER + 'is_dia'] = is_dia

                for idx, name in enumerate(rename_list):
                    store_dict[name] = data_list[idx]

            else:
                store_dict[key] = val

        return store_dict
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
def _supports(self, item):
        """Supports everything of parent class and csr, csc, bsr, and dia sparse matrices."""
        if SparseParameter._is_supported_matrix(item):
            return True
        else:
            return super(SparseResult, self)._supports(item)
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
def _get_name_list(is_dia):
        if is_dia:
            return SparseParameter.DIA_NAME_LIST
        else:
            return SparseParameter.OTHER_NAME_LIST
github SmokinCaterpillar / pypet / pypet / __init__.py View on Github external
Trajectory.__name__,
    Environment.__name__,
    MultiprocContext.__name__,
    HDF5StorageService.__name__,
    LazyStorageService.__name__,
    ParameterGroup.__name__,
    DerivedParameterGroup.__name__,
    ConfigGroup.__name__,
    ResultGroup.__name__,
    NNGroupNode.__name__,
    NNLeafNode.__name__,
    'new_group',
    BaseParameter.__name__,
    Parameter.__name__,
    ArrayParameter.__name__,
    SparseParameter.__name__,
    PickleParameter.__name__,
    BaseResult.__name__,
    Result.__name__,
    SparseResult.__name__,
    PickleResult.__name__,
    ObjectTable.__name__,
    DataNotInStorageError.__name__,
    NoSuchServiceError.__name__,
    NotUniqueNodeError.__name__,
    ParameterLockedException.__name__,
    PresettingError.__name__,
    TooManyGroupsError.__name__,
    VersionMismatchError.__name__,
    GitDiffError.__name__,
    HasSlots.__name__,
    HasLogger.__name__,