From 1090096e2bed0d288a4cecc7eee73d73cde76c50 Mon Sep 17 00:00:00 2001 From: Oscar Higgott Date: Sun, 22 May 2022 19:17:33 -0700 Subject: [PATCH] Minor changes for scipy sparse loading --- src/pymatching/matching.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pymatching/matching.py b/src/pymatching/matching.py index b03def22..08235bb3 100644 --- a/src/pymatching/matching.py +++ b/src/pymatching/matching.py @@ -371,8 +371,8 @@ def load_from_check_matrix(self, Matching objects can also be initialised from a sparse scipy matrix: >>> import pymatching - >>> from scipy.sparse import csr_matrix - >>> H = csr_matrix([[1, 1, 0], [0, 1, 1]]) + >>> from scipy.sparse import csc_matrix + >>> H = csc_matrix([[1, 1, 0], [0, 1, 1]]) >>> m = pymatching.Matching(H) >>> m @@ -389,13 +389,13 @@ def load_from_check_matrix(self, num_edges = H.shape[1] weights = 1.0 if spacelike_weights is None else spacelike_weights if isinstance(weights, (int, float, np.integer, np.floating)): - weights = np.array([weights]*num_edges).astype(float) + weights = np.ones(num_edges, dtype=float)*weights weights = np.asarray(weights) if error_probabilities is None: - error_probabilities = np.array([-1] * num_edges) + error_probabilities = np.ones(num_edges) * -1 elif isinstance(error_probabilities, (int, float)): - error_probabilities = np.array([error_probabilities] * num_edges) + error_probabilities = np.ones(num_edges) * error_probabilities column_weights = np.asarray(H.sum(axis=0))[0] unique_column_weights = np.unique(column_weights)