Build sparse matrix from triplets. Some formatting.