How to use the boltons.cacheutils.cachedproperty function in boltons

To help you get started, we’ve selected a few boltons 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 broadinstitute / CellBender / proto / chimera / sources / fingerprint.py View on Github external
    @cachedproperty
    def total_molecules_per_gene_g(self) -> np.ndarray:
        self._finalize()
        self._log_caching("total_molecules_per_gene_g")
        total_gene_expression = np.zeros((self.n_genes,))
        for csr_fingerprint in self.csr_fingerprint_dict.values():
            total_gene_expression += np.asarray(np.sum(csr_fingerprint, -1)).flatten()
        return total_gene_expression
github kdeldycke / meta-package-manager / meta_package_manager / managers / apt.py View on Github external
    @cachedproperty
    def installed(self):
        """ Fetch installed packages from ``apt list`` output.

        Raw CLI output samples:

        .. code-block:: shell-session

            $ apt list --installed --quiet
            Listing...
            adduser/xenial,now 3.113+nmu3ubuntu4 all [installed]
            base-files/xenial-updates,now 9.4ubuntu4.3 amd64 [installed]
            base-passwd/xenial,now 3.5.39 amd64 [installed]
            bash/xenial-updates,now 4.3-14ubuntu1.1 amd64 [installed]
            bc/xenial,now 1.06.95-9build1 amd64 [installed]
            bsdmainutils/xenial,now 9.0.6ubuntu3 amd64 [installed,automatic]
            bsdutils/xenial-updates,now 1:2.27.1-6ubuntu3.1 amd64 [installed]
github kdeldycke / meta-package-manager / meta_package_manager / base.py View on Github external
    @cachedproperty
    def available(self):
        """ Is the package manager available and ready-to-use on the system?

        Returns True only if the main CLI:
            1 - is supported on the current platform,
            2 - was found on the system,
            3 - is executable, and
            4 - match the version requirement.
        """
        return bool(
            self.supported and
            self.cli_path and
            self.executable and
            self.fresh)
github broadinstitute / CellBender / proto / chimera / sources / fingerprint.py View on Github external
    @cachedproperty
    def gene_expression_csr_binary_matrix(self) -> CSRBinaryMatrix:
        """Returns the (gene, cell) binary expression matrix as :class:`CSRBinaryMatrix`.

        .. note:: we can get the required indptr and indices from the CSC representation of the
            (cell, gene) sparse count matrix.
        """
        return CSRBinaryMatrix(
            n_rows=self.n_genes,
            n_cols=self.n_cells,
            indices_sz=len(self.sparse_count_matrix_csc.indices),
            indptr=self.sparse_count_matrix_csc.indptr.astype(np.int32),
            indices=self.sparse_count_matrix_csc.indices.astype(np.int32))
github kdeldycke / meta-package-manager / meta_package_manager / base.py View on Github external
    @cachedproperty
    def executable(self):
        """ Is the package manager CLI can be executed by the current user? """
        if not self.cli_path:
            return False
        if not os.access(self.cli_path, os.X_OK):
            logger.debug("{} not executable.".format(self.cli_path))
            return False
        return True
github broadinstitute / CellBender / proto / chimera / sources / fingerprint.py View on Github external
    @cachedproperty
    def dense_fingerprint_ndarray(self) -> np.ndarray:
        self._log_caching("dense_fingerprint_ndarray")
        assert self.allow_dense_int_ndarray
        fingerprint_array = np.zeros((self.n_cells, self.n_genes, self.max_family_size), dtype=np.uint16)
        for i_cell, barcode in enumerate(self.sc_fingerprint_base.barcode_list):
            fingerprint_array[i_cell, :, :] = self.sc_fingerprint_base[barcode].todense()
        return fingerprint_array
github broadinstitute / CellBender / proto / chimera / sources / fsd.py View on Github external
    @cachedproperty
    def init_fsd_xi_loc_prior(self):
        (init_fsd_mu_lo, init_fsd_phi_lo, init_fsd_w_lo,
         init_fsd_mu_hi, init_fsd_phi_hi, init_fsd_w_hi) = \
            self.generate_fsd_init_params(
                mu_hi_guess=np.mean(self.sc_fingerprint_dtm.empirical_fsd_mu_hi),
                phi_hi_guess=np.mean(self.sc_fingerprint_dtm.empirical_fsd_phi_hi))

        mu_lo = torch.tensor(init_fsd_mu_lo, device=self.device, dtype=self.dtype)
        phi_lo = torch.tensor(init_fsd_phi_lo, device=self.device, dtype=self.dtype)
        w_lo = torch.tensor(init_fsd_w_lo, device=self.device, dtype=self.dtype)
        mu_hi = torch.tensor(init_fsd_mu_hi, device=self.device, dtype=self.dtype)
        phi_hi = torch.tensor(init_fsd_phi_hi, device=self.device, dtype=self.dtype)
        w_hi = torch.tensor(init_fsd_w_hi, device=self.device, dtype=self.dtype)

        return self.encode({
            'mu_lo': mu_lo,
github broadinstitute / CellBender / proto / chimera / sources / fingerprint.py View on Github external
    @cachedproperty
    def dense_count_matrix_ndarray(self) -> np.ndarray:
        self._log_caching("dense_count_matrix_ndarray")
        return np.asarray(self.sparse_count_matrix_csr.todense()).astype(self.numpy_dtype)
github broadinstitute / CellBender / proto / chimera / sources / fingerprint.py View on Github external
    @cachedproperty
    def sparse_family_size_truncated_count_matrix_csc(self) -> sp.csc_matrix:
        self._log_caching("sparse_family_size_truncated_count_matrix_csc")
        return sp.csc_matrix(self.sparse_family_size_truncated_count_matrix_csr)
github broadinstitute / CellBender / proto / chimera / sources / fingerprint.py View on Github external
    @cachedproperty
    def geometric_mean_obs_fst_expr_per_gene(self) -> np.ndarray:
        self._log_caching("geometric_mean_obs_fst_expr_per_gene")
        log1p_sparse_family_size_truncated_count_matrix_csr = sp.csr_matrix(
            (np.log1p(self.sparse_family_size_truncated_count_matrix_csr.data),
             self.sparse_family_size_truncated_count_matrix_csr.indices,
             self.sparse_family_size_truncated_count_matrix_csr.indptr))
        return np.asarray(
            np.exp(np.mean(
                log1p_sparse_family_size_truncated_count_matrix_csr,
                axis=0)) - 1).flatten().astype(self.numpy_dtype)