Skip to content

Commit

Permalink
graph operators
Browse files Browse the repository at this point in the history
  • Loading branch information
0x00b1 committed Oct 4, 2024
1 parent 2446458 commit af2648d
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/beignet/_graph_matrix_to_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@
from scipy.sparse import csr_matrix

def _populate_graph(data, indices, indptr, graph, null_value):
"""
Populate the dense graph matrix from CSR sparse matrix attributes.
Parameters:
- data: 1D numpy array of the non-zero values in the CSR matrix.
- indices: 1D numpy array of column indices corresponding to data.
- indptr: 1D numpy array of index pointers for the CSR matrix.
- graph: 2D numpy array (N x N) initialized with infinities.
- null_value: The value to assign to null entries in the graph.
The function fills the graph with the minimum edge weights from the CSR matrix,
and assigns null_value to positions where there are no edges.
"""
N = graph.shape[0]
null_flag = numpy.ones((N, N), dtype=bool, order='C')

Expand All @@ -35,9 +22,10 @@ def _populate_graph(data, indices, indptr, graph, null_value):
# Assign null_value to positions with no edges
graph[null_flag] = null_value

def graph_matrix_to_tensor(input: csr_matrix, null_value: float = 0) -> numpy.ndarray:
# Allow only csr, lil and csc matrices: other formats when converted to csr
# combine duplicated edges: we don't want this to happen in the background.
def graph_matrix_to_tensor(
input: csr_matrix,
null_value: float = 0,
) -> numpy.ndarray:
if not scipy.sparse.issparse(input):
raise ValueError

Expand Down

0 comments on commit af2648d

Please sign in to comment.