-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A memory efficient implementation of the .mtx reading function #3389
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,13 +67,19 @@ def read_mtx_from_stream(stream: BinaryIO) -> sparse.csr_matrix: | |
max_int32 = np.iinfo(np.int32).max | ||
coord_dtype = np.int64 if n > max_int32 or m > max_int32 else np.int32 | ||
|
||
data = pd.read_csv( | ||
chunks = pd.read_csv( | ||
stream, | ||
sep=r"\s+", | ||
header=None, | ||
dtype={0: coord_dtype, 1: coord_dtype, 2: np.float32}, | ||
chunksize=1e7, | ||
) | ||
mtx = sparse.csr_matrix((data[2], (data[1] - 1, data[0] - 1)), shape=(m, n)) | ||
mtx = sparse.csr_matrix(([0], ([0], [0])), shape=(m, n)) | ||
for data in chunks: | ||
mtx_chunk = sparse.csr_matrix( | ||
(data[2], (data[1] - 1, data[0] - 1)), shape=(m, n) | ||
) | ||
mtx = mtx + mtx_chunk | ||
Comment on lines
+78
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably slightly slower than necessary, since we know the chunks don‘t overlap and The way
|
||
return mtx | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.