c ++ – Multiplication of matrices in an upper / lower triangular matrix

I am a statistician who works on DNA data sets. I'm writing an R package, and I'll routinely need to multiply matrices in higher (sparse) triangular matrices that have hundreds of millions of columns / rows.

I will be multiplying these matrices by low pass and high pass filters. For example:

enter the description of the image here

Note that when multiplying the right and the center, only the first two rows of the matrix & # 39; a & # 39; they must be multiplied by the first column of the descending sampler, since the rest have zeros in the first two entries.

Similarly, when the sample is premultured downwards with the matrix "A", only the first row should be multiplied by the first column, since the subsequent rows will be multiplied by zeros only.

Clearly when it comes to massive In these matrices, these unnecessary operations will add time to the calculation that could otherwise be avoided.

My question is: There's a & # 39; Multiplication forward & # 39; Function for upper triangular matrices. whether in the R packages Matrix or c ++ (which I can implement in Rcpp) that will avoid unnecessary row / column operations that are not necessary?