NITS = 1000 T = 5 # Seconds dt = T/NITS def test(relmatrix): state = np.zeros(N);…
- User
N_ITS = 1000 T = 5 # Seconds dt = T/N_ITS
def test(rel_matrix): state = np.zeros(N); state[0] = 1 for i in range(N_ITS): state = state + rel_matrix @ state * dt
matrix=test(relationship) csr_matrix = sparse.csr_matrix(matrix) bsr_matrix = sparse.bsr_matrix(matrix) print(f"Standard: {timeit.timeit(matrix, globals=globals(), number=10)/10:.4f}") print(f"CSR: {timeit.timeit(csr_matrix, globals=globals(), number=10)/10:.4f}") print(f"BSR: {timeit.timeit(bsr_matrix, globals=globals(), number=10)/10:.4f}")
- Assistant
It seems that there are a few issues with the code provided:
-
The variable
Nis not defined. I assume it should represent the size of the state vector, so it should be initialized with an appropriate value. -
The
timeit.timeitfunction should be called on thetestfunction, not on thematrix,csr_matrix, orbsr_matrixvariables. -
The
globalsargument oftimeit.timeitshould include the necessary imports (npandsparse).
Here is an updated version of the code with these issues addressed:
python -