Skip to content
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

Row-wise and column-wise scaling of a sparse matrix runs out of memory #543

Open
pitsianis opened this issue Jun 21, 2024 · 1 comment
Open

Comments

@pitsianis
Copy link

As the subject says, when I try to scale the values of a large sparse matrix using .*, a dense matrix is built, and OutOfMemoryError() is raised!

For instance,

n = 10_000_000
v = rand(n)
A = sprand(n,n,2/n)
v .* A  # ERROR: OutOfMemoryError()
A .* v' # ERROR: OutOfMemoryError()

Using Diagonal or spdiagm will do the computation,

julia> @btime $A * Diagonal($v);
  97.998 ms (6 allocations: 381.50 MiB)

julia> @btime Diagonal($v) * $A;
  134.449 ms (6 allocations: 381.50 MiB)

julia> @btime spdiagm($v) * $A;
  1.794 s (31 allocations: 1.31 GiB)

julia> @btime $A * spdiagm($v);
  522.747 ms (31 allocations: 1.31 GiB)

where spdiagm(v) forms a sparse diagonal matrix at a great expense in time and space.

See discussion here

@pitsianis
Copy link
Author

This is related to a previous issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant