44
55import random
66
7+ import line_profiler
78from graphblas .binary import plus
89from graphblas .core .dtypes import BOOL , INT32
910from graphblas .core .matrix import Matrix
@@ -26,6 +27,7 @@ class BucketFactor:
2627
2728
2829class PrototypeDecomposer (AbstractDecomposer ):
30+ @line_profiler .profile
2931 def row_based_decompose (self , matrix : Matrix ) -> Tuple [Matrix , Matrix ]:
3032 row_to_column_sets = self ._extract_row_to_column_sets (matrix )
3133 row_minhash_signatures = self ._compute_row_minhash_signatures (row_to_column_sets )
@@ -34,6 +36,7 @@ def row_based_decompose(self, matrix: Matrix) -> Tuple[Matrix, Matrix]:
3436 return self ._build_factor_matrices (bucket_factors , matrix )
3537
3638 @staticmethod
39+ @line_profiler .profile
3740 def _extract_row_to_column_sets (matrix : Matrix ) -> Dict [int , Set [int ]]:
3841 row_to_column_sets : Dict [int , Set [int ]] = defaultdict (set )
3942 rows , cols , _ = matrix .to_coo ()
@@ -42,6 +45,7 @@ def _extract_row_to_column_sets(matrix: Matrix) -> Dict[int, Set[int]]:
4245 return row_to_column_sets
4346
4447 @staticmethod
48+ @line_profiler .profile
4549 def _generate_hash_coefficients_and_offsets () -> List [Tuple [int , int ]]:
4650 coefficients_and_offsets : List [Tuple [int , int ]] = []
4751 for _ in range (HASH_FUNCTIONS_COUNT ):
@@ -68,6 +72,7 @@ def _compute_row_minhash_signatures(
6872 return row_minhash_signatures
6973
7074 @staticmethod
75+ @line_profiler .profile
7176 def _group_rows_by_master_hash (
7277 row_minhash_signatures : Dict [int , Tuple [int , ...]],
7378 ) -> Dict [int , List [int ]]:
@@ -81,6 +86,7 @@ def _group_rows_by_master_hash(
8186 }
8287
8388 @staticmethod
89+ @line_profiler .profile
8490 def _build_bucket_factors (
8591 master_hash_to_rows : Dict [int , List [int ]],
8692 row_to_column_sets : Dict [int , Set [int ]],
@@ -94,6 +100,7 @@ def _build_bucket_factors(
94100 return bucket_factors
95101
96102 @staticmethod
103+ @line_profiler .profile
97104 def _filter_rows_by_frequency (
98105 candidate_rows : List [int ],
99106 row_to_column_sets : Dict [int , Set [int ]],
@@ -114,6 +121,7 @@ def _filter_rows_by_frequency(
114121 return frequency_signature , surviving_rows
115122
116123 @staticmethod
124+ @line_profiler .profile
117125 def _build_bucket_factor (
118126 bucket_rows : List [int ],
119127 row_to_column_sets : Dict [int , Set [int ]],
@@ -142,6 +150,7 @@ def _build_bucket_factor(
142150 )
143151
144152 @staticmethod
153+ @line_profiler .profile
145154 def _build_factor_matrices (
146155 bucket_factors : List [BucketFactor ],
147156 matrix : Matrix ,
0 commit comments