First, get the indexes of the non zero places in W, and then you can just get the (i,j)
element of the result matrix by multiplying the i-th row in A with the j-th column in B, and save the result as a tuple (i,j,res)
instead of saving it as a matrix (this is the right way to save sparse matrices).