Skip to content

Commit

Permalink
Fix: Make dtypes consistent at float64 (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudon authored Nov 1, 2023
1 parent de89517 commit 0ab3106
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/pygenstability/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
from threadpoolctl import threadpool_limits

L = logging.getLogger(__name__)
_USE_CACHE = True
THRESHOLD = 1e-8
DTYPE = "float128"
_DTYPE = np.float64


def load_constructor(constructor, graph, **kwargs):
Expand Down Expand Up @@ -105,7 +104,7 @@ def __init__(self, graph, with_spectral_gap=False, exp_comp_mode="spectral", **k
def _get_exp(self, scale):
"""Compute matrix exponential at a given scale."""
if self.exp_comp_mode == "expm":
exp = sp.linalg.expm(-scale * self.partial_quality_matrix.toarray().astype(DTYPE))
exp = sp.linalg.expm(-scale * self.partial_quality_matrix.toarray().astype(_DTYPE))
if self.exp_comp_mode == "spectral":
lambdas, v, vinv = self.spectral_decomp
exp = v @ np.diag(np.exp(-scale * lambdas)) @ vinv
Expand Down Expand Up @@ -151,7 +150,7 @@ def prepare(self, **kwargs):
if self.with_spectral_gap:
laplacian = sp.csgraph.laplacian(self.graph, normed=False)
self.spectral_gap = _get_spectral_gap(laplacian)
self.partial_quality_matrix = (self.graph / degrees.sum()).astype(DTYPE)
self.partial_quality_matrix = (self.graph / degrees.sum()).astype(_DTYPE)

@_limit_numpy
def _get_data(self, scale):
Expand Down Expand Up @@ -185,7 +184,7 @@ def prepare(self, **kwargs):
_check_total_degree(degrees)
laplacian /= degrees.mean()
pi = np.ones(self.graph.shape[0]) / self.graph.shape[0]
self.partial_null_model = np.array([pi, pi], dtype=DTYPE)
self.partial_null_model = np.array([pi, pi], dtype=_DTYPE)
if self.with_spectral_gap:
self.spectral_gap = _get_spectral_gap(laplacian)

Expand Down Expand Up @@ -226,7 +225,7 @@ def prepare(self, **kwargs):
normed_laplacian = sp.diags(1.0 / degrees).dot(laplacian)

pi = degrees / degrees.sum()
self.partial_null_model = np.array([pi, pi], dtype=DTYPE)
self.partial_null_model = np.array([pi, pi], dtype=_DTYPE)

if self.with_spectral_gap:
self.spectral_gap = _get_spectral_gap(normed_laplacian)
Expand Down

0 comments on commit 0ab3106

Please sign in to comment.