I have a simple MWE below that includes a diagonal sparse matrix A
and its sub-diagonal matrices A_1,A_2,A_3
. Assuming that A
is going to be updated in values only (pattern is fixed), what is the efficient way to update A_1,A_2,A_3
correspondingly cause the below code for updating them is not efficient by using nzval
field of the sparse matrices?
#### Define section
A = sparse([100.0 200 0 0 0 0 0; 16 17 0 0 0 0 0; 0 0 300 4 5 0 0; 0 0 6 7 8 0 0; 0 0 13 14 15 0 0; 0 0 0 0 0 9 10; 0 0 0 0 0 11 12]);
n0=1;n1=3;n2=6;n3=7;
A_1 = A[n0:n1-1,n0:n1-1];
A_2 = A[n1:n2-1,n1:n2-1];
A_3 = A[n2:n3,n2:n3];
#### Update section
# First, update A values
# Second, update the individual matrices
A_1 .= A[n0:n1-1,n0:n1-1];
A_2 .= A[n1:n2-1,n1:n2-1];
A_3 .= A[n2:n3,n2:n3];