When running the following code:
import numpy as np
import scipy.sparse
import time
def test():
m = 10000
n = 10000
for i in range(5):
A = scipy.sparse.random(m, n, density=0.1, format='csr')
x = np.random.randn(n)
Ax = A.dot(x)
time.sleep(2)
if __name__ == "__main__":
test()
I observed that the memory consumption increased linearly to >4.8Gb!
I tested again with the following function:
def test2():
m = 10000
n = 10000
for i in range(5):
print(i)
A = np.random.rand(m, n)
x = np.random.randn(A.shape[1])
Ax = A.dot(x)
time.sleep(2)
The memory consumption increased linearly to >800Mb.
I have two questions:
Why does the memory consumption increase linearly in each case? No new variables were declared at each iteration...
Why in the first test the memory consumption is much much higher than in the second, given that the matrices are sparse (with only 0.1 density)?
Thank you in advance for your answers!